2024-06-22 09:29:53 +00:00
|
|
|
package api
|
2024-02-01 16:53:22 +00:00
|
|
|
|
|
|
|
import (
|
2024-09-11 15:42:46 +00:00
|
|
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
2024-06-22 09:29:53 +00:00
|
|
|
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
|
|
|
|
"git.solsynth.dev/hydrogen/interactive/pkg/internal/gap"
|
|
|
|
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
|
2024-07-25 14:58:47 +00:00
|
|
|
"git.solsynth.dev/hydrogen/interactive/pkg/internal/services"
|
2024-02-01 16:53:22 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getUserinfo(c *fiber.Ctx) error {
|
2024-06-22 09:29:53 +00:00
|
|
|
if err := gap.H.EnsureAuthenticated(c); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
user := c.Locals("user").(models.Account)
|
2024-02-01 16:53:22 +00:00
|
|
|
|
|
|
|
var data models.Account
|
|
|
|
if err := database.C.
|
2024-09-11 15:42:46 +00:00
|
|
|
Where(&hyper.BaseModel{ID: user.ID}).
|
2024-02-01 16:53:22 +00:00
|
|
|
First(&data).Error; err != nil {
|
|
|
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(data)
|
|
|
|
}
|
2024-02-03 07:20:32 +00:00
|
|
|
|
2024-02-03 11:22:50 +00:00
|
|
|
func getOthersInfo(c *fiber.Ctx) error {
|
2024-07-25 14:45:31 +00:00
|
|
|
account := c.Params("account")
|
2024-02-03 11:22:50 +00:00
|
|
|
|
|
|
|
var data models.Account
|
|
|
|
if err := database.C.
|
2024-09-11 15:42:46 +00:00
|
|
|
Where(&hyper.BaseUser{Name: account}).
|
2024-02-03 11:22:50 +00:00
|
|
|
First(&data).Error; err != nil {
|
|
|
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(data)
|
|
|
|
}
|
2024-07-25 14:58:47 +00:00
|
|
|
|
|
|
|
func listOthersPinnedPost(c *fiber.Ctx) error {
|
|
|
|
account := c.Params("account")
|
|
|
|
|
|
|
|
var user models.Account
|
|
|
|
if err := database.C.
|
2024-09-11 15:42:46 +00:00
|
|
|
Where(&hyper.BaseUser{Name: account}).
|
2024-07-25 14:58:47 +00:00
|
|
|
First(&user).Error; err != nil {
|
|
|
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := services.FilterPostDraft(database.C)
|
|
|
|
tx = tx.Where("author_id = ?", user.ID)
|
|
|
|
tx = tx.Where("pinned_at IS NOT NULL")
|
|
|
|
|
|
|
|
items, err := services.ListPost(tx, 100, 0, "published_at DESC")
|
|
|
|
if err != nil {
|
|
|
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(items)
|
|
|
|
}
|