mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
dev day #89
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"fotbal-club/internal/models"
|
||||
"fotbal-club/internal/services"
|
||||
@@ -45,6 +46,15 @@ type CreateArticleRequest struct {
|
||||
YouTubeVideoTitle string `json:"youtube_video_title"`
|
||||
YouTubeVideoURL string `json:"youtube_video_url"`
|
||||
YouTubeVideoThumbnail string `json:"youtube_video_thumbnail"`
|
||||
Attachments []AttachmentItem `json:"attachments"`
|
||||
}
|
||||
|
||||
// AttachmentItem represents a single attachment entry for an article
|
||||
type AttachmentItem struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Size *int `json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// CreateArticle creates a new article with comprehensive error handling
|
||||
@@ -243,6 +253,13 @@ func (ac *ArticleController) CreateArticle(c *gin.Context) {
|
||||
article.YouTubeVideoThumbnail = trimmed
|
||||
}
|
||||
|
||||
// 15. Set attachments (serialize to JSON string)
|
||||
if len(req.Attachments) > 0 {
|
||||
if b, err := json.Marshal(req.Attachments); err == nil {
|
||||
article.Attachments = string(b)
|
||||
}
|
||||
}
|
||||
|
||||
// 15. Save to database
|
||||
if err := ac.DB.Create(&article).Error; err != nil {
|
||||
logger.Error("CreateArticle: Database error: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user