Fuzzy friend invitation

This commit is contained in:
LittleSheep 2024-04-06 01:40:01 +08:00
parent 8dbb8c522a
commit e50a338378

View File

@ -35,12 +35,24 @@ func getFriendship(c *fiber.Ctx) error {
func makeFriendship(c *fiber.Ctx) error { func makeFriendship(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account) user := c.Locals("principal").(models.Account)
relatedName := c.Query("related")
relatedId, _ := c.ParamsInt("relatedId", 0) relatedId, _ := c.ParamsInt("relatedId", 0)
related, err := services.GetAccount(uint(relatedId)) var err error
var related models.Account
if relatedId > 0 {
related, err = services.GetAccount(uint(relatedId))
if err != nil { if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error()) 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.NewFriend(user, related, models.FriendshipPending) friend, err := services.NewFriend(user, related, models.FriendshipPending)
if err != nil { if err != nil {