From 3942f63446cb4f2d1b06323fb7f86973f47b07c9 Mon Sep 17 00:00:00 2001 From: Howl Date: Sat, 14 May 2016 21:23:17 +0200 Subject: [PATCH] use querystring in /friends methods. remove useless POST methods in /friends --- app/start.go | 8 +++----- app/v1/friend.go | 30 +++--------------------------- 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/app/start.go b/app/start.go index 5e21934..dad9636 100644 --- a/app/start.go +++ b/app/start.go @@ -36,13 +36,11 @@ func Start(conf common.Conf, db *sql.DB) *gin.Engine { // ReadConfidential privilege required gv1.GET("/friends", Method(v1.FriendsGET, db, common.PrivilegeReadConfidential)) - gv1.GET("/friends/with/:id", Method(v1.FriendsWithGET, db, common.PrivilegeReadConfidential)) + gv1.GET("/friends/with", Method(v1.FriendsWithGET, db, common.PrivilegeReadConfidential)) // Write privilege required - gv1.POST("/friends/add", Method(v1.FriendsAddPOST, db, common.PrivilegeWrite)) - gv1.GET("/friends/add/:id", Method(v1.FriendsAddGET, db, common.PrivilegeWrite)) - gv1.POST("/friends/del", Method(v1.FriendsDelPOST, db, common.PrivilegeWrite)) - gv1.GET("/friends/del/:id", Method(v1.FriendsDelGET, db, common.PrivilegeWrite)) + gv1.GET("/friends/add", Method(v1.FriendsAddGET, db, common.PrivilegeWrite)) + gv1.GET("/friends/del", Method(v1.FriendsDelGET, db, common.PrivilegeWrite)) // Admin: beatmap gv1.POST("/beatmaps/set_status", Method(v1.BeatmapSetStatusPOST, db, common.PrivilegeBeatmap)) diff --git a/app/v1/friend.go b/app/v1/friend.go index 173195f..39f8ca6 100644 --- a/app/v1/friend.go +++ b/app/v1/friend.go @@ -118,7 +118,7 @@ type friendsWithResponse struct { func FriendsWithGET(md common.MethodData) common.CodeMessager { r := friendsWithResponse{} r.Code = 200 - uid, err := strconv.Atoi(md.C.Param("id")) + uid, err := strconv.Atoi(md.C.Query("id")) if err != nil { return common.SimpleResponse(400, "That is not a number!") } @@ -135,7 +135,7 @@ func FriendsWithGET(md common.MethodData) common.CodeMessager { // FriendsAddGET is the GET version of FriendsAddPOST. func FriendsAddGET(md common.MethodData) common.CodeMessager { - uidS := md.C.Param("id") + uidS := md.C.Query("id") uid, err := strconv.Atoi(uidS) if err != nil { return common.SimpleResponse(400, "Nope. That's not a number.") @@ -143,20 +143,6 @@ func FriendsAddGET(md common.MethodData) common.CodeMessager { return addFriend(md, uid) } -type friendAddPOSTData struct { - UserID int `json:"user_id"` -} - -// FriendsAddPOST allows for adding friends. Yup. Easy as that. -func FriendsAddPOST(md common.MethodData) common.CodeMessager { - d := friendAddPOSTData{} - err := md.RequestData.Unmarshal(&d) - if err != nil { - return ErrBadJSON - } - return addFriend(md, d.UserID) -} - func addFriend(md common.MethodData, u int) common.CodeMessager { if md.ID() == u { return common.SimpleResponse(406, "Just so you know: you can't add yourself to your friends.") @@ -198,7 +184,7 @@ func userExists(md common.MethodData, u int) (r bool) { // FriendsDelGET is the GET version of FriendDelPOST. func FriendsDelGET(md common.MethodData) common.CodeMessager { - uidS := md.C.Param("id") + uidS := md.C.Query("id") uid, err := strconv.Atoi(uidS) if err != nil { return common.SimpleResponse(400, "Nope. That's not a number.") @@ -206,16 +192,6 @@ func FriendsDelGET(md common.MethodData) common.CodeMessager { return delFriend(md, uid) } -// FriendsDelPOST allows for deleting friends. -func FriendsDelPOST(md common.MethodData) common.CodeMessager { - d := friendAddPOSTData{} - err := md.RequestData.Unmarshal(&d) - if err != nil { - return ErrBadJSON - } - return delFriend(md, d.UserID) -} - func delFriend(md common.MethodData, u int) common.CodeMessager { _, err := md.DB.Exec("DELETE FROM users_relationships WHERE user1 = ? AND user2 = ?", md.ID(), u) if err != nil {