diff --git a/cmd/webapi/__debug_bin b/cmd/webapi/__debug_bin deleted file mode 100755 index 1377730..0000000 Binary files a/cmd/webapi/__debug_bin and /dev/null differ diff --git a/service/api/likes.go b/service/api/likes.go index 825600c..e5fb4b0 100644 --- a/service/api/likes.go +++ b/service/api/likes.go @@ -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 } - // User liked the photo successfully - helpers.SendStatus(http.StatusCreated, w, "Success", rt.baseLogger) + 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) + } } diff --git a/service/api/post-session.go b/service/api/post-session.go index 3d2761b..75dd230 100644 --- a/service/api/post-session.go +++ b/service/api/post-session.go @@ -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 } }