use querystring in /friends methods. remove useless POST methods in /friends
This commit is contained in:
parent
9481de5e4e
commit
3942f63446
|
@ -36,13 +36,11 @@ func Start(conf common.Conf, db *sql.DB) *gin.Engine {
|
||||||
|
|
||||||
// ReadConfidential privilege required
|
// ReadConfidential privilege required
|
||||||
gv1.GET("/friends", Method(v1.FriendsGET, db, common.PrivilegeReadConfidential))
|
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
|
// Write privilege required
|
||||||
gv1.POST("/friends/add", Method(v1.FriendsAddPOST, db, common.PrivilegeWrite))
|
gv1.GET("/friends/add", Method(v1.FriendsAddGET, db, common.PrivilegeWrite))
|
||||||
gv1.GET("/friends/add/:id", Method(v1.FriendsAddGET, db, common.PrivilegeWrite))
|
gv1.GET("/friends/del", Method(v1.FriendsDelGET, db, common.PrivilegeWrite))
|
||||||
gv1.POST("/friends/del", Method(v1.FriendsDelPOST, db, common.PrivilegeWrite))
|
|
||||||
gv1.GET("/friends/del/:id", Method(v1.FriendsDelGET, db, common.PrivilegeWrite))
|
|
||||||
|
|
||||||
// Admin: beatmap
|
// Admin: beatmap
|
||||||
gv1.POST("/beatmaps/set_status", Method(v1.BeatmapSetStatusPOST, db, common.PrivilegeBeatmap))
|
gv1.POST("/beatmaps/set_status", Method(v1.BeatmapSetStatusPOST, db, common.PrivilegeBeatmap))
|
||||||
|
|
|
@ -118,7 +118,7 @@ type friendsWithResponse struct {
|
||||||
func FriendsWithGET(md common.MethodData) common.CodeMessager {
|
func FriendsWithGET(md common.MethodData) common.CodeMessager {
|
||||||
r := friendsWithResponse{}
|
r := friendsWithResponse{}
|
||||||
r.Code = 200
|
r.Code = 200
|
||||||
uid, err := strconv.Atoi(md.C.Param("id"))
|
uid, err := strconv.Atoi(md.C.Query("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.SimpleResponse(400, "That is not a number!")
|
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.
|
// FriendsAddGET is the GET version of FriendsAddPOST.
|
||||||
func FriendsAddGET(md common.MethodData) common.CodeMessager {
|
func FriendsAddGET(md common.MethodData) common.CodeMessager {
|
||||||
uidS := md.C.Param("id")
|
uidS := md.C.Query("id")
|
||||||
uid, err := strconv.Atoi(uidS)
|
uid, err := strconv.Atoi(uidS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.SimpleResponse(400, "Nope. That's not a number.")
|
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)
|
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 {
|
func addFriend(md common.MethodData, u int) common.CodeMessager {
|
||||||
if md.ID() == u {
|
if md.ID() == u {
|
||||||
return common.SimpleResponse(406, "Just so you know: you can't add yourself to your friends.")
|
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.
|
// FriendsDelGET is the GET version of FriendDelPOST.
|
||||||
func FriendsDelGET(md common.MethodData) common.CodeMessager {
|
func FriendsDelGET(md common.MethodData) common.CodeMessager {
|
||||||
uidS := md.C.Param("id")
|
uidS := md.C.Query("id")
|
||||||
uid, err := strconv.Atoi(uidS)
|
uid, err := strconv.Atoi(uidS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.SimpleResponse(400, "Nope. That's not a number.")
|
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)
|
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 {
|
func delFriend(md common.MethodData, u int) common.CodeMessager {
|
||||||
_, err := md.DB.Exec("DELETE FROM users_relationships WHERE user1 = ? AND user2 = ?", md.ID(), u)
|
_, err := md.DB.Exec("DELETE FROM users_relationships WHERE user1 = ? AND user2 = ?", md.ID(), u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user