Fix likes response codes

This commit is contained in:
Marco Realacci 2022-11-20 19:42:15 +01:00
parent 52ae7992b1
commit 50f412cd33
3 changed files with 11 additions and 5 deletions

Binary file not shown.

View file

@ -81,7 +81,7 @@ func (rt *_router) PutDeleteLike(w http.ResponseWriter, r *http.Request, ps http
}
if success == database.ERR_NOT_FOUND {
helpers.SendBadRequest(w, "User or photo not found", rt.baseLogger)
helpers.SendNotFound(w, "User or photo not found", rt.baseLogger)
return
}
@ -91,6 +91,11 @@ func (rt *_router) PutDeleteLike(w http.ResponseWriter, r *http.Request, ps http
return
}
if r.Method == "PUT" {
// User liked the photo successfully
helpers.SendStatus(http.StatusCreated, w, "Success", rt.baseLogger)
} else {
// User unliked the photo successfully
w.WriteHeader(http.StatusNoContent)
}
}

View file

@ -5,6 +5,7 @@ import (
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/notherealmarco/WASAPhoto/service/api/helpers"
"github.com/notherealmarco/WASAPhoto/service/api/reqcontext"
"github.com/notherealmarco/WASAPhoto/service/database/db_errors"
)
@ -33,7 +34,7 @@ func (rt *_router) PostSession(w http.ResponseWriter, r *http.Request, ps httpro
uid, err = rt.db.CreateUser(request.Name)
}
if err != nil { // handle any other error
w.WriteHeader(http.StatusInternalServerError) // todo: is not ok
helpers.SendBadRequestError(err, "Bad request body", w, rt.baseLogger)
return
}
@ -41,7 +42,7 @@ func (rt *_router) PostSession(w http.ResponseWriter, r *http.Request, ps httpro
err = json.NewEncoder(w).Encode(_respbody{UID: uid})
if err != nil {
w.WriteHeader(http.StatusInternalServerError) // todo: is not ok
helpers.SendInternalError(err, "Error encoding response", w, rt.baseLogger)
return
}
}