Personal Page

This commit is contained in:
2024-02-03 19:22:50 +08:00
parent 1f4164e72a
commit 6c52a862a5
13 changed files with 218 additions and 68 deletions

View File

@ -13,16 +13,22 @@ import (
func listPost(c *fiber.Ctx) error {
take := c.QueryInt("take", 0)
offset := c.QueryInt("offset", 0)
authorId := c.QueryInt("authorId", 0)
tx := database.C.Where(&models.Post{RealmID: nil}).Order("created_at desc")
if authorId > 0 {
tx = tx.Where(&models.Post{AuthorID: uint(authorId)})
}
var count int64
if err := database.C.
Where(&models.Post{RealmID: nil}).
if err := tx.
Model(&models.Post{}).
Count(&count).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
posts, err := services.ListPost(take, offset)
posts, err := services.ListPost(tx, take, offset)
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
}

View File

@ -57,7 +57,8 @@ func NewServer() {
api := A.Group("/api").Name("API")
{
api.Get("/users/me", auth, getUserinfo)
api.Get("/users/:accountId/follow", auth, doFollowAccount)
api.Get("/users/:accountId", getOthersInfo)
api.Post("/users/:accountId/follow", auth, doFollowAccount)
api.Get("/auth", doLogin)
api.Get("/auth/callback", doPostLogin)

View File

@ -20,6 +20,19 @@ func getUserinfo(c *fiber.Ctx) error {
return c.JSON(data)
}
func getOthersInfo(c *fiber.Ctx) error {
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())
}
return c.JSON(data)
}
func doFollowAccount(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account)
id, _ := c.ParamsInt("accountId", 0)