diff --git a/pkg/models/posts.go b/pkg/models/posts.go index de463dd..7848ef7 100644 --- a/pkg/models/posts.go +++ b/pkg/models/posts.go @@ -16,19 +16,19 @@ type PostReactInfo struct { type Post struct { BaseModel - Alias string `json:"alias" gorm:"uniqueIndex"` - Content string `json:"content"` - Tags []Tag `json:"tags" gorm:"many2many:post_tags"` - Categories []Category `json:"categories" gorm:"many2many:post_categories"` - Reactions []Reaction `json:"reactions"` - Replies []Post `json:"replies" gorm:"foreignKey:ReplyID"` - Attachments datatypes.JSONSlice[string] `json:"attachments"` - ReplyID *uint `json:"reply_id"` - RepostID *uint `json:"repost_id"` - RealmID *uint `json:"realm_id"` - ReplyTo *Post `json:"reply_to" gorm:"foreignKey:ReplyID"` - RepostTo *Post `json:"repost_to" gorm:"foreignKey:RepostID"` - Realm *Realm `json:"realm"` + Alias string `json:"alias" gorm:"uniqueIndex"` + Content string `json:"content"` + Tags []Tag `json:"tags" gorm:"many2many:post_tags"` + Categories []Category `json:"categories" gorm:"many2many:post_categories"` + Reactions []Reaction `json:"reactions"` + Replies []Post `json:"replies" gorm:"foreignKey:ReplyID"` + Attachments datatypes.JSONSlice[uint] `json:"attachments"` + ReplyID *uint `json:"reply_id"` + RepostID *uint `json:"repost_id"` + RealmID *uint `json:"realm_id"` + ReplyTo *Post `json:"reply_to" gorm:"foreignKey:ReplyID"` + RepostTo *Post `json:"repost_to" gorm:"foreignKey:RepostID"` + Realm *Realm `json:"realm"` PublishedAt *time.Time `json:"published_at"` diff --git a/pkg/server/posts_api.go b/pkg/server/posts_api.go index 9631c14..2568083 100644 --- a/pkg/server/posts_api.go +++ b/pkg/server/posts_api.go @@ -80,7 +80,7 @@ func createPost(c *fiber.Ctx) error { Content string `json:"content" form:"content" validate:"required,max=4096"` Tags []models.Tag `json:"tags" form:"tags"` Categories []models.Category `json:"categories" form:"categories"` - Attachments []string `json:"attachments" form:"attachments"` + Attachments []uint `json:"attachments" form:"attachments"` PublishedAt *time.Time `json:"published_at" form:"published_at"` RealmAlias string `json:"realm" form:"realm"` ReplyTo *uint `json:"reply_to" form:"reply_to"` @@ -94,7 +94,7 @@ func createPost(c *fiber.Ctx) error { } for _, attachment := range data.Attachments { - if !services.CheckAttachmentByUUIDExists(attachment, "i.attachment") { + if !services.CheckAttachmentByIDExists(attachment, "i.attachment") { return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("attachment %s not found", attachment)) } } @@ -154,7 +154,7 @@ func editPost(c *fiber.Ctx) error { PublishedAt *time.Time `json:"published_at" form:"published_at"` Tags []models.Tag `json:"tags" form:"tags"` Categories []models.Category `json:"categories" form:"categories"` - Attachments []string `json:"attachments" form:"attachments"` + Attachments []uint `json:"attachments" form:"attachments"` } if err := BindAndValidate(c, &data); err != nil { @@ -170,7 +170,7 @@ func editPost(c *fiber.Ctx) error { } for _, attachment := range data.Attachments { - if !services.CheckAttachmentByUUIDExists(attachment, "i.attachment") { + if !services.CheckAttachmentByIDExists(attachment, "i.attachment") { return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("attachment %s not found", attachment)) } } diff --git a/pkg/services/attachments.go b/pkg/services/attachments.go index 79fb06e..3e90acb 100644 --- a/pkg/services/attachments.go +++ b/pkg/services/attachments.go @@ -19,9 +19,9 @@ func GetAttachmentByUUID(uuid string) (*pcpb.Attachment, error) { }) } -func CheckAttachmentByUUIDExists(uuid string, usage string) bool { +func CheckAttachmentByIDExists(id uint, usage string) bool { _, err := grpc.Attachments.CheckAttachmentExists(context.Background(), &pcpb.AttachmentLookupRequest{ - Uuid: &uuid, + Id: lo.ToPtr(uint64(id)), Usage: &usage, })