Follow and Following

This commit is contained in:
2024-02-03 20:44:16 +08:00
parent 6c52a862a5
commit df60a112ae
5 changed files with 66 additions and 10 deletions

View File

@ -58,6 +58,7 @@ func NewServer() {
{
api.Get("/users/me", auth, getUserinfo)
api.Get("/users/:accountId", getOthersInfo)
api.Get("/users/:accountId/follow", auth, getAccountFollowed)
api.Post("/users/:accountId/follow", auth, doFollowAccount)
api.Get("/auth", doLogin)

View File

@ -33,6 +33,24 @@ func getOthersInfo(c *fiber.Ctx) error {
return c.JSON(data)
}
func getAccountFollowed(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account)
accountId, _ := c.ParamsInt("accountId", 0)
var data models.Account
if err := database.C.
Where(&models.Account{BaseModel: models.BaseModel{ID: uint(accountId)}}).
First(&data).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
_, status := services.GetAccountFollowed(user, data)
return c.JSON(fiber.Map{
"is_followed": status,
})
}
func doFollowAccount(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account)
id, _ := c.ParamsInt("accountId", 0)