From 47085ca0aed93558db6184b34a53a13e4c613212 Mon Sep 17 00:00:00 2001 From: ericprd Date: Thu, 13 Mar 2025 11:44:00 +0800 Subject: [PATCH] fix: add start date and end date of ads --- database/ads_model.go | 12 +++++++----- internal/domain/ads/spec.go | 18 +++++++++++------- internal/services/ads/create.go | 8 +++++--- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/database/ads_model.go b/database/ads_model.go index 7177d40..82d2946 100644 --- a/database/ads_model.go +++ b/database/ads_model.go @@ -3,9 +3,11 @@ package database import "time" type Ads struct { - ID string `gorm:"primaryKey;not null" json:"id"` - ImageUrl string `gorm:"not null" json:"image_url"` - Url string `gorm:"not null" json:"url"` - CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"` - UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"` + ID string `gorm:"primaryKey;not null" json:"id"` + ImageUrl string `gorm:"not null" json:"image_url"` + Url string `gorm:"not null" json:"url"` + StartDate *time.Time `gorm:"default:null" json:"start_date"` + EndDate *time.Time `gorm:"default:null" json:"end_date"` + CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"` + UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"` } diff --git a/internal/domain/ads/spec.go b/internal/domain/ads/spec.go index 83a5b28..011f063 100644 --- a/internal/domain/ads/spec.go +++ b/internal/domain/ads/spec.go @@ -5,14 +5,18 @@ import ( ) type Ads struct { - ID string `gorm:"primaryKey;not null" json:"id"` - ImageUrl string `gorm:"not null" json:"image_url"` - Url string `gorm:"not null" json:"url"` - CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"` - UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"` + ID string `json:"id"` + ImageUrl string `json:"image_url"` + Url string `json:"url"` + StartDate *time.Time `json:"start_date"` + EndDate *time.Time `json:"end_date"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } type AdsReq struct { - Image string `json:"image" validate:"required"` - URL string `json:"url" validate:"required"` + Image string `json:"image" validate:"required"` + URL string `json:"url" validate:"required"` + StartDate *time.Time `json:"start_date" validate:"required"` + EndDate *time.Time `json:"end_date" validate:"required"` } diff --git a/internal/services/ads/create.go b/internal/services/ads/create.go index 9aab95d..37866d4 100644 --- a/internal/services/ads/create.go +++ b/internal/services/ads/create.go @@ -18,9 +18,11 @@ func (i *impl) Create(spec adsdomain.AdsReq) error { } newSpec := adsdomain.Ads{ - ID: uuid.NewString(), - ImageUrl: spec.Image, - Url: spec.URL, + ID: uuid.NewString(), + ImageUrl: spec.Image, + Url: spec.URL, + StartDate: spec.StartDate, + EndDate: spec.EndDate, } return i.adsRepo.Create(newSpec)