mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-05 12:22:35 +02:00
Add database handlers
This commit is contained in:
parent
37b7fede91
commit
5f3d4df33a
4 changed files with 94 additions and 3 deletions
35
service/api/session.go
Normal file
35
service/api/session.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/notherealmarco/WASAPhoto/service/api/reqcontext"
|
||||
)
|
||||
|
||||
type _reqbody struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type _respbody struct {
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
|
||||
// getContextReply is an example of HTTP endpoint that returns "Hello World!" as a plain text. The signature of this
|
||||
// handler accepts a reqcontext.RequestContext (see httpRouterHandler).
|
||||
func (rt *_router) PostSession(w http.ResponseWriter, r *http.Request, ps httprouter.Params, ctx reqcontext.RequestContext) {
|
||||
|
||||
var request _reqbody
|
||||
json.NewDecoder(r.Body).Decode(&request) //todo: capire se serve close
|
||||
|
||||
uid, err := rt.db.GetUserID(request.Name)
|
||||
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("content-type", "application/json")
|
||||
json.NewEncoder(w).Encode(_respbody{UID: uid})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue