mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-03-14 14:16:15 +01:00
Fix likes response codes
This commit is contained in:
parent
52ae7992b1
commit
50f412cd33
3 changed files with 11 additions and 5 deletions
Binary file not shown.
|
@ -81,7 +81,7 @@ func (rt *_router) PutDeleteLike(w http.ResponseWriter, r *http.Request, ps http
|
||||||
}
|
}
|
||||||
|
|
||||||
if success == database.ERR_NOT_FOUND {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +91,11 @@ func (rt *_router) PutDeleteLike(w http.ResponseWriter, r *http.Request, ps http
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r.Method == "PUT" {
|
||||||
// User liked the photo successfully
|
// User liked the photo successfully
|
||||||
helpers.SendStatus(http.StatusCreated, w, "Success", rt.baseLogger)
|
helpers.SendStatus(http.StatusCreated, w, "Success", rt.baseLogger)
|
||||||
|
} else {
|
||||||
|
// User unliked the photo successfully
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
|
"github.com/notherealmarco/WASAPhoto/service/api/helpers"
|
||||||
"github.com/notherealmarco/WASAPhoto/service/api/reqcontext"
|
"github.com/notherealmarco/WASAPhoto/service/api/reqcontext"
|
||||||
"github.com/notherealmarco/WASAPhoto/service/database/db_errors"
|
"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)
|
uid, err = rt.db.CreateUser(request.Name)
|
||||||
}
|
}
|
||||||
if err != nil { // handle any other error
|
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
|
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})
|
err = json.NewEncoder(w).Encode(_respbody{UID: uid})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError) // todo: is not ok
|
helpers.SendInternalError(err, "Error encoding response", w, rt.baseLogger)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue