mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-06 04:42:36 +02:00
Add getUserProfile and database.IsBanned
This commit is contained in:
parent
44eb1e1fa6
commit
53a764e8bb
13 changed files with 328 additions and 163 deletions
46
service/api/get-userprofile.go
Normal file
46
service/api/get-userprofile.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/notherealmarco/WASAPhoto/service/api/authorization"
|
||||
"github.com/notherealmarco/WASAPhoto/service/api/helpers"
|
||||
"github.com/notherealmarco/WASAPhoto/service/api/reqcontext"
|
||||
"github.com/notherealmarco/WASAPhoto/service/database"
|
||||
)
|
||||
|
||||
func (rt *_router) GetUserProfile(w http.ResponseWriter, r *http.Request, ps httprouter.Params, ctx reqcontext.RequestContext) {
|
||||
|
||||
// Get user id
|
||||
uid := ps.ByName("user_id")
|
||||
|
||||
if !authorization.SendErrorIfNotLoggedIn(ctx.Auth.Authorized, rt.db, w, rt.baseLogger) ||
|
||||
!helpers.SendNotFoundIfBanned(rt.db, ctx.Auth.GetUserID(), uid, w, rt.baseLogger) {
|
||||
return
|
||||
}
|
||||
|
||||
// Get user profile
|
||||
status, profile, err := rt.db.GetUserProfile(uid)
|
||||
|
||||
if err != nil {
|
||||
helpers.SendInternalError(err, "Database error: GetUserProfile", w, rt.baseLogger)
|
||||
return
|
||||
}
|
||||
|
||||
if status == database.ERR_NOT_FOUND {
|
||||
helpers.SendNotFound(w, "User not found", rt.baseLogger)
|
||||
return
|
||||
}
|
||||
|
||||
// Return user profile
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
err = json.NewEncoder(w).Encode(profile)
|
||||
|
||||
if err != nil {
|
||||
helpers.SendInternalError(err, "Error encoding json", w, rt.baseLogger)
|
||||
return
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue