diff --git a/app/database/entity/our_product_contents.entity.go b/app/database/entity/our_product_contents.entity.go index f8be114..320ff06 100644 --- a/app/database/entity/our_product_contents.entity.go +++ b/app/database/entity/our_product_contents.entity.go @@ -11,13 +11,14 @@ type OurProductContent struct { PrimaryTitle string `json:"primary_title" gorm:"type:varchar(255)"` SecondaryTitle string `json:"secondary_title" gorm:"type:varchar(255)"` Description string `json:"description" gorm:"type:text"` + LinkURL string `json:"link_url" gorm:"type:text"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` - IsActive *bool `json:"is_active" gorm:"default:true"` + IsActive *bool `json:"is_active" gorm:"default:true"` Images []OurProductContentImage `json:"images" gorm:"foreignKey:OurProductContentID"` } func (OurProductContent) TableName() string { return "our_product_contents" -} \ No newline at end of file +} diff --git a/app/database/entity/our_service_contents.entity.go b/app/database/entity/our_service_contents.entity.go index 8a01645..13a1a71 100644 --- a/app/database/entity/our_service_contents.entity.go +++ b/app/database/entity/our_service_contents.entity.go @@ -5,16 +5,17 @@ import ( ) type OurServiceContent struct { - ID uint `json:"id" gorm:"primaryKey;autoIncrement"` - PrimaryTitle string `json:"primary_title" gorm:"type:varchar(255)"` - SecondaryTitle string `json:"secondary_title" gorm:"type:varchar(255)"` - Description string `json:"description" gorm:"type:text"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - IsActive *bool `json:"is_active" gorm:"default:true"` - Images []OurServiceContentImage `json:"images" gorm:"foreignKey:OurServiceContentID"` + ID uint `json:"id" gorm:"primaryKey;autoIncrement"` + PrimaryTitle string `json:"primary_title" gorm:"type:varchar(255)"` + SecondaryTitle string `json:"secondary_title" gorm:"type:varchar(255)"` + Description string `json:"description" gorm:"type:text"` + LinkURL string `json:"link_url" gorm:"type:text"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + IsActive *bool `json:"is_active" gorm:"default:true"` + Images []OurServiceContentImage `json:"images" gorm:"foreignKey:OurServiceContentID"` } func (OurServiceContent) TableName() string { return "our_service_contents" -} \ No newline at end of file +} diff --git a/app/module/hero_content_images/repository/hero_content_images.repository.go b/app/module/hero_content_images/repository/hero_content_images.repository.go index 47859b4..14ad3b3 100644 --- a/app/module/hero_content_images/repository/hero_content_images.repository.go +++ b/app/module/hero_content_images/repository/hero_content_images.repository.go @@ -1,6 +1,7 @@ package repository import ( + "time" "web-qudo-be/app/database" "web-qudo-be/app/database/entity" @@ -58,7 +59,11 @@ func (r *heroContentImagesRepository) Update(id uuid.UUID, data *entity.HeroCont err := r.DB.DB. Model(&entity.HeroContentImages{}). Where("id = ?", id). - Updates(data).Error + Updates(map[string]interface{}{ + "image_path": data.ImagePath, + "image_url": data.ImageURL, + "updated_at": time.Now(), + }).Error if err != nil { r.Log.Error().Err(err).Msg("failed update hero content image") @@ -76,4 +81,4 @@ func (r *heroContentImagesRepository) Delete(id uuid.UUID) error { } return nil -} \ No newline at end of file +} diff --git a/app/module/hero_contents/repository/hero_contents.repository.go b/app/module/hero_contents/repository/hero_contents.repository.go index 3460d52..71ae0eb 100644 --- a/app/module/hero_contents/repository/hero_contents.repository.go +++ b/app/module/hero_contents/repository/hero_contents.repository.go @@ -2,6 +2,7 @@ package repository import ( "errors" + "time" "web-qudo-be/app/database" "web-qudo-be/app/database/entity" @@ -60,10 +61,23 @@ func (r *heroContentsRepository) Create(data *entity.HeroContents) (*entity.Hero } func (r *heroContentsRepository) Update(id uuid.UUID, data *entity.HeroContents) error { + // map (not struct) so empty strings are persisted; GORM Updates(struct) skips zero values. + updates := map[string]interface{}{ + "primary_title": data.PrimaryTitle, + "secondary_title": data.SecondaryTitle, + "description": data.Description, + "primary_cta": data.PrimaryCta, + "secondary_cta_text": data.SecondaryCtaText, + } + if data.IsActive != nil { + updates["is_active"] = data.IsActive + } + updates["updated_at"] = time.Now() + err := r.DB.DB. Model(&entity.HeroContents{}). Where("id = ?", id). - Updates(data).Error + Updates(updates).Error if err != nil { r.Log.Error().Err(err).Msg("failed update hero content") @@ -81,4 +95,4 @@ func (r *heroContentsRepository) Delete(id uuid.UUID) error { } return nil -} \ No newline at end of file +} diff --git a/app/module/hero_contents/request/hero_contents.request.go b/app/module/hero_contents/request/hero_contents.request.go index 61ee453..b323e8f 100644 --- a/app/module/hero_contents/request/hero_contents.request.go +++ b/app/module/hero_contents/request/hero_contents.request.go @@ -21,7 +21,7 @@ func (r *HeroContentsCreateRequest) ToEntity() *entity.HeroContents { } type HeroContentsUpdateRequest struct { - PrimaryTitle string `json:"primary_title"` + PrimaryTitle string `json:"primary_title" validate:"required"` SecondaryTitle string `json:"secondary_title"` Description string `json:"description"` PrimaryCTA string `json:"primary_cta"` diff --git a/app/module/our_product_content_images/repository/our_product_content_images.repository.go b/app/module/our_product_content_images/repository/our_product_content_images.repository.go index 1f7372f..1deaf35 100644 --- a/app/module/our_product_content_images/repository/our_product_content_images.repository.go +++ b/app/module/our_product_content_images/repository/our_product_content_images.repository.go @@ -55,10 +55,18 @@ func (r *ourProductContentImagesRepository) Create(data *entity.OurProductConten } func (r *ourProductContentImagesRepository) Update(id uuid.UUID, data *entity.OurProductContentImage) error { + updates := map[string]interface{}{ + "image_path": data.ImagePath, + "image_url": data.ImageURL, + } + if data.IsThumbnail != nil { + updates["is_thumbnail"] = data.IsThumbnail + } + err := r.DB.DB. Model(&entity.OurProductContentImage{}). Where("id = ?", id). - Updates(data).Error + Updates(updates).Error if err != nil { r.Log.Error().Err(err).Msg("failed update our product content image") @@ -76,4 +84,4 @@ func (r *ourProductContentImagesRepository) Delete(id uuid.UUID) error { } return nil -} \ No newline at end of file +} diff --git a/app/module/our_product_contents/repository/our_product_contents.repository.go b/app/module/our_product_contents/repository/our_product_contents.repository.go index c0ef12e..3275d99 100644 --- a/app/module/our_product_contents/repository/our_product_contents.repository.go +++ b/app/module/our_product_contents/repository/our_product_contents.repository.go @@ -2,6 +2,7 @@ package repository import ( "errors" + "time" "web-qudo-be/app/database" "web-qudo-be/app/database/entity" @@ -74,10 +75,21 @@ func (r *ourProductContentRepository) Create(data *entity.OurProductContent) (*e } func (r *ourProductContentRepository) Update(id uuid.UUID, data *entity.OurProductContent) error { + updates := map[string]interface{}{ + "primary_title": data.PrimaryTitle, + "secondary_title": data.SecondaryTitle, + "description": data.Description, + "link_url": data.LinkURL, + "updated_at": time.Now(), + } + if data.IsActive != nil { + updates["is_active"] = data.IsActive + } + err := r.DB.DB. Model(&entity.OurProductContent{}). Where("id = ?", id). - Updates(data).Error + Updates(updates).Error if err != nil { r.Log.Error().Err(err).Msg("failed update our product content") @@ -95,4 +107,4 @@ func (r *ourProductContentRepository) Delete(id uuid.UUID) error { } return nil -} \ No newline at end of file +} diff --git a/app/module/our_product_contents/request/our_product_contents.request.go b/app/module/our_product_contents/request/our_product_contents.request.go index 78664e1..8a7cd91 100644 --- a/app/module/our_product_contents/request/our_product_contents.request.go +++ b/app/module/our_product_contents/request/our_product_contents.request.go @@ -6,6 +6,7 @@ type OurProductContentCreateRequest struct { PrimaryTitle string `json:"primary_title" form:"primary_title" validate:"required"` SecondaryTitle string `json:"secondary_title" form:"secondary_title"` Description string `json:"description" form:"description"` + LinkURL string `json:"link_url" form:"link_url"` } func (r *OurProductContentCreateRequest) ToEntity() *entity.OurProductContent { @@ -13,6 +14,7 @@ func (r *OurProductContentCreateRequest) ToEntity() *entity.OurProductContent { PrimaryTitle: r.PrimaryTitle, SecondaryTitle: r.SecondaryTitle, Description: r.Description, + LinkURL: r.LinkURL, } } @@ -20,6 +22,7 @@ type OurProductContentUpdateRequest struct { PrimaryTitle string `json:"primary_title"` SecondaryTitle string `json:"secondary_title"` Description string `json:"description"` + LinkURL string `json:"link_url"` } func (r *OurProductContentUpdateRequest) ToEntity() *entity.OurProductContent { @@ -27,5 +30,6 @@ func (r *OurProductContentUpdateRequest) ToEntity() *entity.OurProductContent { PrimaryTitle: r.PrimaryTitle, SecondaryTitle: r.SecondaryTitle, Description: r.Description, + LinkURL: r.LinkURL, } -} \ No newline at end of file +} diff --git a/app/module/our_service_content_images/repository/our_service_content_images.repository.go b/app/module/our_service_content_images/repository/our_service_content_images.repository.go index a3cf6e6..0dca1bc 100644 --- a/app/module/our_service_content_images/repository/our_service_content_images.repository.go +++ b/app/module/our_service_content_images/repository/our_service_content_images.repository.go @@ -52,10 +52,18 @@ func (r *ourServiceContentImagesRepository) Create(data *entity.OurServiceConten } func (r *ourServiceContentImagesRepository) Update(id uint, data *entity.OurServiceContentImage) error { + updates := map[string]interface{}{ + "image_path": data.ImagePath, + "image_url": data.ImageURL, + } + if data.IsThumbnail != nil { + updates["is_thumbnail"] = data.IsThumbnail + } + err := r.DB.DB. Model(&entity.OurServiceContentImage{}). Where("id = ?", id). - Updates(data).Error + Updates(updates).Error if err != nil { r.Log.Error().Err(err).Msg("failed update our service content images") @@ -73,4 +81,4 @@ func (r *ourServiceContentImagesRepository) Delete(id uint) error { } return nil -} \ No newline at end of file +} diff --git a/app/module/our_service_contents/repository/our_service_contents.repository.go b/app/module/our_service_contents/repository/our_service_contents.repository.go index 59553e6..cfc7deb 100644 --- a/app/module/our_service_contents/repository/our_service_contents.repository.go +++ b/app/module/our_service_contents/repository/our_service_contents.repository.go @@ -2,6 +2,7 @@ package repository import ( "errors" + "time" "web-qudo-be/app/database" "web-qudo-be/app/database/entity" @@ -71,10 +72,21 @@ func (r *ourServiceContentRepository) Create(data *entity.OurServiceContent) (*e } func (r *ourServiceContentRepository) Update(id uint, data *entity.OurServiceContent) error { + updates := map[string]interface{}{ + "primary_title": data.PrimaryTitle, + "secondary_title": data.SecondaryTitle, + "description": data.Description, + "link_url": data.LinkURL, + "updated_at": time.Now(), + } + if data.IsActive != nil { + updates["is_active"] = data.IsActive + } + err := r.DB.DB. Model(&entity.OurServiceContent{}). Where("id = ?", id). - Updates(data).Error + Updates(updates).Error if err != nil { r.Log.Error().Err(err).Msg("failed update our service content") @@ -92,4 +104,4 @@ func (r *ourServiceContentRepository) Delete(id uint) error { } return nil -} \ No newline at end of file +} diff --git a/app/module/our_service_contents/request/our_service_contents.request.go b/app/module/our_service_contents/request/our_service_contents.request.go index 9734133..2df2d10 100644 --- a/app/module/our_service_contents/request/our_service_contents.request.go +++ b/app/module/our_service_contents/request/our_service_contents.request.go @@ -6,6 +6,7 @@ type OurServiceContentCreateRequest struct { PrimaryTitle string `json:"primary_title" form:"primary_title" validate:"required"` SecondaryTitle string `json:"secondary_title" form:"secondary_title"` Description string `json:"description" form:"description"` + LinkURL string `json:"link_url" form:"link_url"` } func (r *OurServiceContentCreateRequest) ToEntity() *entity.OurServiceContent { @@ -13,6 +14,7 @@ func (r *OurServiceContentCreateRequest) ToEntity() *entity.OurServiceContent { PrimaryTitle: r.PrimaryTitle, SecondaryTitle: r.SecondaryTitle, Description: r.Description, + LinkURL: r.LinkURL, } } @@ -20,6 +22,7 @@ type OurServiceContentUpdateRequest struct { PrimaryTitle string `json:"primary_title"` SecondaryTitle string `json:"secondary_title"` Description string `json:"description"` + LinkURL string `json:"link_url"` } func (r *OurServiceContentUpdateRequest) ToEntity() *entity.OurServiceContent { @@ -27,5 +30,6 @@ func (r *OurServiceContentUpdateRequest) ToEntity() *entity.OurServiceContent { PrimaryTitle: r.PrimaryTitle, SecondaryTitle: r.SecondaryTitle, Description: r.Description, + LinkURL: r.LinkURL, } -} \ No newline at end of file +} diff --git a/app/module/partner_contents/repository/partner_contents.repository.go b/app/module/partner_contents/repository/partner_contents.repository.go index ec2c958..b9fab33 100644 --- a/app/module/partner_contents/repository/partner_contents.repository.go +++ b/app/module/partner_contents/repository/partner_contents.repository.go @@ -1,6 +1,7 @@ package repository import ( + "time" "web-qudo-be/app/database" "web-qudo-be/app/database/entity" @@ -59,7 +60,12 @@ func (r *partnerContentRepository) Update(id uuid.UUID, data *entity.PartnerCont err := r.DB.DB. Model(&entity.PartnerContent{}). Where("id = ?", id). - Updates(data).Error + Updates(map[string]interface{}{ + "primary_title": data.PrimaryTitle, + "image_path": data.ImagePath, + "image_url": data.ImageURL, + "updated_at": time.Now(), + }).Error if err != nil { r.Log.Error().Err(err).Msg("failed update partner content") @@ -106,4 +112,4 @@ func (r *partnerContentRepository) FindByID(id uuid.UUID) (*entity.PartnerConten } return &data, nil -} \ No newline at end of file +} diff --git a/app/module/popup_news_contents/repository/popup_news_contents.repository.go b/app/module/popup_news_contents/repository/popup_news_contents.repository.go index eb7078d..fec46c5 100644 --- a/app/module/popup_news_contents/repository/popup_news_contents.repository.go +++ b/app/module/popup_news_contents/repository/popup_news_contents.repository.go @@ -5,6 +5,8 @@ import ( "web-qudo-be/app/database/entity" "web-qudo-be/app/module/popup_news_contents/request" "web-qudo-be/utils/paginator" + + "gorm.io/gorm" ) type popupNewsContentsRepository struct { @@ -70,11 +72,22 @@ func (_i *popupNewsContentsRepository) Create(data *entity.PopupNewsContents) er // Update func (_i *popupNewsContentsRepository) Update(id uint, data *entity.PopupNewsContents) error { return _i.DB.DB.Model(&entity.PopupNewsContents{}). - Where(&entity.PopupNewsContents{ID: id}). - Updates(data).Error + Where("id = ?", id). + Updates(map[string]interface{}{ + "primary_title": data.PrimaryTitle, + "secondary_title": data.SecondaryTitle, + "description": data.Description, + "primary_cta": data.PrimaryCTA, + "secondary_cta_text": data.SecondaryCTAText, + }).Error } -// Delete +// Delete removes child images first so FK constraints do not block the parent delete. func (_i *popupNewsContentsRepository) Delete(id uint) error { - return _i.DB.DB.Delete(&entity.PopupNewsContents{}, id).Error -} \ No newline at end of file + return _i.DB.DB.Transaction(func(tx *gorm.DB) error { + if err := tx.Where("popup_news_content_id = ?", id).Delete(&entity.PopupNewsContentImages{}).Error; err != nil { + return err + } + return tx.Delete(&entity.PopupNewsContents{}, id).Error + }) +} diff --git a/config/toml/config.toml b/config/toml/config.toml index a18d711..7d6e3a2 100644 --- a/config/toml/config.toml +++ b/config/toml/config.toml @@ -9,7 +9,7 @@ idle-timeout = 5 # As seconds print-routes = false prefork = false # false: CMS preview URLs use http://localhost + port above. true: use domain (e.g. https://qudo.id/api). -production = true +production = false body-limit = 1048576000 # "100 * 1024 * 1024" [db.postgres]