✨ Allow user block user initially
This commit is contained in:
@ -67,12 +67,14 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
||||
|
||||
relations := me.Group("/relations").Name("Relations")
|
||||
{
|
||||
relations.Post("/", makeFriendship)
|
||||
relations.Post("/block", makeBlockship)
|
||||
|
||||
relations.Get("/", listRelationship)
|
||||
relations.Get("/:relatedId", getRelationship)
|
||||
relations.Put("/:relatedId", editRelationship)
|
||||
relations.Delete("/:relatedId", deleteRelationship)
|
||||
|
||||
relations.Post("/", makeFriendship)
|
||||
relations.Post("/:relatedId", makeFriendship)
|
||||
relations.Post("/:relatedId/accept", acceptFriend)
|
||||
relations.Post("/:relatedId/decline", declineFriend)
|
||||
|
@ -136,6 +136,38 @@ func makeFriendship(c *fiber.Ctx) error {
|
||||
}
|
||||
}
|
||||
|
||||
func makeBlockship(c *fiber.Ctx) error {
|
||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||
return err
|
||||
}
|
||||
user := c.Locals("user").(models.Account)
|
||||
relatedName := c.Query("related")
|
||||
relatedId, _ := c.ParamsInt("relatedId", 0)
|
||||
|
||||
var err error
|
||||
var related models.Account
|
||||
if relatedId > 0 {
|
||||
related, err = services.GetAccount(uint(relatedId))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
} else if len(relatedName) > 0 {
|
||||
related, err = services.LookupAccount(relatedName)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
} else {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "must one of username or user id")
|
||||
}
|
||||
|
||||
friend, err := services.NewBlockship(user, related)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
return c.JSON(friend)
|
||||
}
|
||||
}
|
||||
|
||||
func acceptFriend(c *fiber.Ctx) error {
|
||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user