This commit is contained in:
@@ -66,6 +66,7 @@ type adminPost struct {
|
||||
ID string `json:"id"`
|
||||
PostType string `json:"postType"`
|
||||
CategoryID int `json:"categoryId,omitempty"`
|
||||
CategorySlug string `json:"categorySlug,omitempty"`
|
||||
Language string `json:"language"`
|
||||
Text string `json:"text"`
|
||||
Attachments []attachmentInput `json:"attachments"`
|
||||
@@ -223,6 +224,9 @@ func validateAdminPost(ap *adminPost) error {
|
||||
if ap.Status == "published" && !hasText && !hasAtt {
|
||||
return fmt.Errorf("published post requires text and/or at least one attachment")
|
||||
}
|
||||
if ap.Status == "published" && ap.CategoryID <= 0 {
|
||||
return fmt.Errorf("published post requires categoryId")
|
||||
}
|
||||
for i, a := range ap.Attachments {
|
||||
if strings.TrimSpace(a.URL) == "" {
|
||||
return fmt.Errorf("attachment %d: url required", i)
|
||||
@@ -365,6 +369,13 @@ func classifyAttachmentKind(mime, filename string) string {
|
||||
return "document"
|
||||
}
|
||||
|
||||
func postCategoryIDArg(id int) any {
|
||||
if id <= 0 {
|
||||
return nil
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
func nullIfEmptyStr(s, def string) string {
|
||||
if strings.TrimSpace(s) == "" {
|
||||
return def
|
||||
|
||||
Reference in New Issue
Block a user