Commit 278c3908 authored by Lukas Matt's avatar Lukas Matt

Implement ApiSearch for searching remote user

parent fbdb6a3a
package controllers
//
// GangGo API Library
// Copyright (C) 2017 Lukas Matt <lukas@zauberstuhl.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
import (
"net/http"
"github.com/revel/revel"
"gopkg.in/ganggo/ganggo.v0/app/jobs"
)
/**
* @apiDefine Search Search endpoint
*
* Discover new people in the network
*/
type ApiSearch struct {
*revel.Controller
ApiHelper
}
/**
* @api {post} /search Discover a new person
* @apiName ApiSearch.Create
* @apiGroup Search
*
* @apiParam {String} handle Person network handle
* @apiParam {String} access_token Oauth access token
*
* @apiSuccess {String} CreatedAt Timestamp of creation
* @apiSuccess {String} UpdatedAt Timestamp of last replacment
* @apiSuccess {Number} ID Unique database ID
* @apiSuccess {String} Guid Person global ID
* @apiSuccess {String} Author Handle with TLD
* @apiSuccess {String} SerializedPublicKey Public key
* @apiSuccess {Number} UserID User database ID (null if not a local user)
*
* @apiSuccessExample {json} Success-Response
* HTTP/1.1 200 OK
* {
* "ID": 12,
* "CreatedAt": "2018-01-08T15:25:43Z",
* "UpdatedAt": "2018-01-08T15:25:43Z",
* "Guid": "cc783a9749f09c7d817a1707a4c052bc",
* "Author": "test@localhost",
* "SerializedPublicKey": "[...]",
* "UserID": 1,
* }
*
* @apiError (Errors) {String} error Contains the recent error message
*
* @apiErrorExample {json} NotFound
* HTTP/1.1 404 Not Found
* {
* "error": "[...]"
* }
*
*/
func (p ApiSearch) Create(handle string) revel.Result {
fetch := jobs.FetchAuthor{Author: handle}; fetch.Run()
if fetch.Err != nil {
p.Log.Error(TAG, "err", fetch.Err, "api", ERR_NOT_FOUND)
return p.ApiError(http.StatusNotFound, ERR_NOT_FOUND)
}
return p.RenderJSON(fetch.Person)
}
......@@ -41,5 +41,7 @@ GET /api/v0/people/:id/aspects ApiAspect.ShowPerson
POST /api/v0/people/:id/aspects/:aspect_id ApiAspect.CreatePerson
DELETE /api/v0/people/:id/aspects/:aspect_id ApiAspect.DeletePerson
POST /api/v0/search ApiSearch.Create
# API catch-all-rule will result in "not implemented" error
* /api/v0/*catchall ApiHelper.CatchAll
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment