30 lines
585 B
Go
Raw Normal View History

2025-03-09 00:47:24 +08:00
package adssvc
import (
"fmt"
adsdomain "legalgo-BE-go/internal/domain/ads"
2025-03-10 10:28:23 +08:00
"strings"
2025-03-09 00:47:24 +08:00
"github.com/google/uuid"
)
2025-03-10 10:28:23 +08:00
func (i *impl) Create(spec adsdomain.AdsReq) error {
if !(strings.HasPrefix(spec.Image, "http")) {
return fmt.Errorf("image url is not started with http")
2025-03-09 00:47:24 +08:00
}
2025-03-10 10:28:23 +08:00
if !(strings.HasPrefix(spec.URL, "http")) {
return fmt.Errorf("url is not started with http")
2025-03-09 00:47:24 +08:00
}
newSpec := adsdomain.Ads{
ID: uuid.NewString(),
ImageUrl: spec.Image,
Url: spec.URL,
StartDate: spec.StartDate,
EndDate: spec.EndDate,
2025-03-09 00:47:24 +08:00
}
2025-03-10 10:28:23 +08:00
return i.adsRepo.Create(newSpec)
2025-03-09 00:47:24 +08:00
}