use querystring in /friends methods. remove useless POST methods in /friends
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user