Files
epic-ent/internal/service/hero_service.go

50 lines
1.0 KiB
Go

package service
import (
"context"
"time"
"epic-ent/internal/domain/dto"
"epic-ent/internal/domain/vo"
"epic-ent/internal/repository"
)
type HeroService struct {
repo *repository.HeroRepository
}
func NewHeroService(repo *repository.HeroRepository) *HeroService {
return &HeroService{repo: repo}
}
func (s *HeroService) Create(ctx context.Context, req dto.HeroCreateRequest) (vo.Hero, error) {
now := time.Now()
if req.CreateTime == nil {
req.CreateTime = &now
}
if req.UpdateTime == nil {
req.UpdateTime = &now
}
if req.Deleted == nil {
req.Deleted = boolPtr(false)
}
return s.repo.Create(ctx, req)
}
func (s *HeroService) GetByID(ctx context.Context, id int64) (vo.Hero, error) {
return s.repo.GetByID(ctx, id)
}
func (s *HeroService) Update(ctx context.Context, id int64, req dto.HeroUpdateRequest) (vo.Hero, error) {
return s.repo.Update(ctx, id, req)
}
func (s *HeroService) Delete(ctx context.Context, id int64) error {
return s.repo.Delete(ctx, id)
}
func boolPtr(v bool) *bool {
return &v
}