add initial application structure with configuration, logging, and health check endpoints

This commit is contained in:
kever
2026-01-15 22:48:28 +08:00
parent fe67f09e72
commit 2efefc7e05
24 changed files with 178 additions and 83 deletions

View File

@@ -5,6 +5,8 @@ import (
"database/sql"
"time"
"github.com/pkg/errors"
"epic-ent/internal/domain/dto"
"epic-ent/internal/domain/vo"
"epic-ent/internal/ent"
@@ -49,7 +51,7 @@ func (r *HeroRepository) Create(ctx context.Context, req dto.HeroCreateRequest)
hero, err := create.Save(ctx)
if err != nil {
return vo.Hero{}, err
return vo.Hero{}, errors.Wrap(err, "create hero")
}
return toVO(hero), nil
@@ -63,7 +65,10 @@ func (r *HeroRepository) GetByID(ctx context.Context, id int64) (vo.Hero, error)
).
Only(ctx)
if err != nil {
return vo.Hero{}, err
if ent.IsNotFound(err) {
return vo.Hero{}, sql.ErrNoRows
}
return vo.Hero{}, errors.Wrap(err, "get hero by id")
}
return toVO(hero), nil
@@ -151,7 +156,7 @@ func (r *HeroRepository) Update(ctx context.Context, id int64, req dto.HeroUpdat
affected, err := update.Save(ctx)
if err != nil {
return vo.Hero{}, err
return vo.Hero{}, errors.Wrap(err, "update hero")
}
if affected == 0 {
return vo.Hero{}, sql.ErrNoRows
@@ -170,7 +175,7 @@ func (r *HeroRepository) Delete(ctx context.Context, id int64) error {
SetUpdateTime(time.Now()).
Save(ctx)
if err != nil {
return err
return errors.Wrap(err, "delete hero")
}
if affected == 0 {
return sql.ErrNoRows