List other user daily records

This commit is contained in:
LittleSheep 2024-09-21 22:50:01 +08:00
parent 10e4a67835
commit 53c6b2a636
2 changed files with 42 additions and 3 deletions

View File

@ -59,8 +59,6 @@ func MapAPIs(app *fiber.App, baseURL string) {
me.Delete("/tickets/:ticketId", killTicket) me.Delete("/tickets/:ticketId", killTicket)
me.Post("/confirm", doRegisterConfirm) me.Post("/confirm", doRegisterConfirm)
me.Post("/password-reset", requestResetPassword)
me.Patch("/password-reset", confirmResetPassword)
me.Get("/status", getMyselfStatus) me.Get("/status", getMyselfStatus)
me.Post("/status", setStatus) me.Post("/status", setStatus)
@ -80,14 +78,19 @@ func MapAPIs(app *fiber.App, baseURL string) {
relations.Post("/:relatedId/decline", declineFriend) relations.Post("/:relatedId/decline", declineFriend)
} }
me.Post("/password-reset", requestResetPassword)
me.Patch("/password-reset", confirmResetPassword)
me.Post("/deletion", requestDeleteAccount) me.Post("/deletion", requestDeleteAccount)
me.Post("/deletion/confirm", confirmDeleteAccount) me.Patch("/deletion", confirmDeleteAccount)
} }
directory := api.Group("/users/:alias").Name("User Directory") directory := api.Group("/users/:alias").Name("User Directory")
{ {
directory.Get("/", getOtherUserinfo) directory.Get("/", getOtherUserinfo)
directory.Get("/status", getStatus) directory.Get("/status", getStatus)
directory.Get("/daily", listOtherUserDailySignRecord)
} }
api.Get("/users", getOtherUserinfoBatch) api.Get("/users", getOtherUserinfoBatch)

View File

@ -40,6 +40,42 @@ func listDailySignRecord(c *fiber.Ctx) error {
}) })
} }
func listOtherUserDailySignRecord(c *fiber.Ctx) error {
take := c.QueryInt("take", 0)
offset := c.QueryInt("offset", 0)
alias := c.Params("alias")
var account models.Account
if err := database.C.
Where(&models.Account{Name: alias}).
First(&account).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
}
var count int64
if err := database.C.
Model(&models.SignRecord{}).
Where("account_id = ?", account.ID).
Count(&count).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
var records []models.SignRecord
if err := database.C.
Where("account_id = ?", account.ID).
Limit(take).Offset(offset).
Order("created_at DESC").
Find(&records).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(fiber.Map{
"count": count,
"data": records,
})
}
func getTodayDailySign(c *fiber.Ctx) error { func getTodayDailySign(c *fiber.Ctx) error {
if err := exts.EnsureAuthenticated(c); err != nil { if err := exts.EnsureAuthenticated(c); err != nil {
return err return err