diff --git a/pkg/internal/http/api/articles_api.go b/pkg/internal/http/api/articles_api.go index 464f78d..02fd12f 100644 --- a/pkg/internal/http/api/articles_api.go +++ b/pkg/internal/http/api/articles_api.go @@ -30,7 +30,7 @@ func createArticle(c *fiber.Ctx) error { Title string `json:"title" validate:"required,max=1024"` Description *string `json:"description"` Content string `json:"content" validate:"required"` - Thumbnail string `json:"thumbnail"` + Thumbnail *string `json:"thumbnail"` Attachments []string `json:"attachments"` Tags []models.Tag `json:"tags"` Categories []models.Category `json:"categories"` @@ -116,7 +116,7 @@ func editArticle(c *fiber.Ctx) error { Title string `json:"title" validate:"required,max=1024"` Description *string `json:"description"` Content string `json:"content" validate:"required"` - Thumbnail string `json:"thumbnail"` + Thumbnail *string `json:"thumbnail"` Attachments []string `json:"attachments"` Tags []models.Tag `json:"tags"` Categories []models.Category `json:"categories"` diff --git a/pkg/internal/http/api/stories_api.go b/pkg/internal/http/api/stories_api.go index 067eb57..cd1bedb 100644 --- a/pkg/internal/http/api/stories_api.go +++ b/pkg/internal/http/api/stories_api.go @@ -29,9 +29,9 @@ func createStory(c *fiber.Ctx) error { Publisher uint `json:"publisher"` Alias *string `json:"alias"` Title *string `json:"title"` - Content string `json:"content" validate:"required,max=4096"` + Content string `json:"content" validate:"max=4096"` Location *string `json:"location"` - Thumbnail string `json:"thumbnail"` + Thumbnail *string `json:"thumbnail"` Attachments []string `json:"attachments"` Tags []models.Tag `json:"tags"` Categories []models.Category `json:"categories"` @@ -47,6 +47,8 @@ func createStory(c *fiber.Ctx) error { if err := exts.BindAndValidate(c, &data); err != nil { return err + } else if len(data.Content) == 0 && len(data.Attachments) == 0 { + return fiber.NewError(fiber.StatusBadRequest, "content or attachments are required") } publisher, err := services.GetPublisher(data.Publisher, user.ID) @@ -134,8 +136,8 @@ func editStory(c *fiber.Ctx) error { Publisher uint `json:"publisher"` Alias *string `json:"alias"` Title *string `json:"title"` - Content string `json:"content" validate:"required,max=4096"` - Thumbnail string `json:"thumbnail"` + Content string `json:"content" validate:"max=4096"` + Thumbnail *string `json:"thumbnail"` Location *string `json:"location"` Attachments []string `json:"attachments"` Tags []models.Tag `json:"tags"` @@ -150,6 +152,8 @@ func editStory(c *fiber.Ctx) error { if err := exts.BindAndValidate(c, &data); err != nil { return err + } else if len(data.Content) == 0 && len(data.Attachments) == 0 { + return fiber.NewError(fiber.StatusBadRequest, "content or attachments are required") } publisher, err := services.GetPublisher(data.Publisher, user.ID) diff --git a/pkg/internal/models/posts.go b/pkg/internal/models/posts.go index 95b9e66..b9e09fa 100644 --- a/pkg/internal/models/posts.go +++ b/pkg/internal/models/posts.go @@ -65,7 +65,7 @@ type Post struct { } type PostStoryBody struct { - Thumbnail string `json:"thumbnail"` + Thumbnail *string `json:"thumbnail"` Title *string `json:"title"` Content string `json:"content"` Location *string `json:"location"` @@ -73,7 +73,7 @@ type PostStoryBody struct { } type PostArticleBody struct { - Thumbnail string `json:"thumbnail"` + Thumbnail *string `json:"thumbnail"` Title string `json:"title"` Description *string `json:"description"` Content string `json:"content"`