add initial application structure with configuration, logging, and health check endpoints
This commit is contained in:
49
internal/service/hero_service.go
Normal file
49
internal/service/hero_service.go
Normal file
@@ -0,0 +1,49 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user