✨ Realm directory
This commit is contained in:
@ -18,7 +18,7 @@ func listPost(c *fiber.Ctx) error {
|
||||
authorId := c.QueryInt("authorId", 0)
|
||||
|
||||
tx := database.C.
|
||||
Where(&models.Post{RealmID: nil}).
|
||||
Where("realm_id IS NULL").
|
||||
Where("published_at <= ? OR published_at IS NULL", time.Now()).
|
||||
Order("created_at desc")
|
||||
|
||||
@ -55,6 +55,7 @@ func createPost(c *fiber.Ctx) error {
|
||||
Categories []models.Category `json:"categories"`
|
||||
Attachments []models.Attachment `json:"attachments"`
|
||||
PublishedAt *time.Time `json:"published_at"`
|
||||
RealmID *uint `json:"realm_id"`
|
||||
RepostTo uint `json:"repost_to"`
|
||||
ReplyTo uint `json:"reply_to"`
|
||||
}
|
||||
@ -90,8 +91,18 @@ func createPost(c *fiber.Ctx) error {
|
||||
}
|
||||
}
|
||||
|
||||
var realm *models.Realm
|
||||
if data.RealmID != nil {
|
||||
if err := database.C.Where(&models.Realm{
|
||||
BaseModel: models.BaseModel{ID: *data.RealmID},
|
||||
}).First(&realm).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
post, err := services.NewPost(
|
||||
user,
|
||||
realm,
|
||||
data.Alias,
|
||||
data.Title,
|
||||
data.Content,
|
||||
|
@ -9,10 +9,32 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func listRealms(c *fiber.Ctx) error {
|
||||
func getRealm(c *fiber.Ctx) error {
|
||||
id, _ := c.ParamsInt("realmId", 0)
|
||||
|
||||
var realm models.Realm
|
||||
if err := database.C.Where(&models.Realm{
|
||||
BaseModel: models.BaseModel{ID: uint(id)},
|
||||
}).First(&realm).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
||||
return c.JSON(realm)
|
||||
}
|
||||
|
||||
func listRealm(c *fiber.Ctx) error {
|
||||
realms, err := services.ListRealm()
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
return c.JSON(realms)
|
||||
}
|
||||
|
||||
func listOwnedRealm(c *fiber.Ctx) error {
|
||||
user := c.Locals("principal").(models.Account)
|
||||
|
||||
realms, err := services.ListRealms(user)
|
||||
realms, err := services.ListRealmWithUser(user)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
@ -74,7 +74,9 @@ func NewServer() {
|
||||
api.Put("/posts/:postId", auth, editPost)
|
||||
api.Delete("/posts/:postId", auth, deletePost)
|
||||
|
||||
api.Get("/realms", auth, listRealms)
|
||||
api.Get("/realms", listRealm)
|
||||
api.Get("/realms/me", auth, listOwnedRealm)
|
||||
api.Get("/realms/:realmId", getRealm)
|
||||
api.Get("/realms/:realmId/posts", listPostInRealm)
|
||||
api.Post("/realms", auth, createRealm)
|
||||
api.Put("/realms/:realmId", auth, editRealm)
|
||||
|
Reference in New Issue
Block a user