feat: update route ads

This commit is contained in:
ericprd
2025-03-13 12:00:26 +08:00
parent 47085ca0ae
commit 1297c71200
6 changed files with 135 additions and 0 deletions
+1
View File
@@ -12,6 +12,7 @@ type accessor struct {
type Ads interface {
Create(adsdomain.Ads) error
GetAll() ([]adsdomain.Ads, error)
Update(adsdomain.Ads) error
Delete(string) error
}
+31
View File
@@ -0,0 +1,31 @@
package adsrepository
import (
"fmt"
adsdomain "legalgo-BE-go/internal/domain/ads"
"gorm.io/gorm/clause"
)
func (a *accessor) Update(spec adsdomain.Ads) error {
if err := a.db.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "id"}},
DoUpdates: clause.AssignmentColumns([]string{
"image_url",
"url",
"updated_at",
"start_date",
"end_date",
}),
}).Select(
"image_url",
"url",
"updated_at",
"start_date",
"end_date",
).Save(&spec).Error; err != nil {
return fmt.Errorf("failed to update tag: %v", err)
}
return nil
}