Skip to content

Commit

Permalink
[fix] クエリ修正&アッパーキャメルに統一
Browse files Browse the repository at this point in the history
  • Loading branch information
hikahana committed Jan 16, 2025
1 parent 1b4fcc3 commit 827a0c4
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions api/externals/repository/division_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type divisionRepository struct {
type DivisionRepository interface {
AllByPeriodAndFinancialRecord(context.Context, string, string) (*sql.Rows, error)
GetById(context.Context, string) (*sql.Row, error)
Create(context.Context, division) error
Update(context.Context, string, division) error
Create(context.Context, Division) error
Update(context.Context, string, Division) error
Delete(context.Context, string) error
FindLatestRecord(context.Context) (*sql.Row, error)
}
Expand All @@ -38,15 +38,14 @@ func (dr *divisionRepository) AllByPeriodAndFinancialRecord(
ds := selectDivisionQuery

if year != "" {
ds = ds.Where(goqu.C("years.year").Eq(year))
ds = ds.Where(goqu.Ex{"years.year": year})
}

if financialRecordId != "" {
ds = ds.Where(goqu.C("financial_records.id").Eq(financialRecordId))
ds = ds.Where(goqu.Ex{"financial_records.idr": financialRecordId})
}

// クエリを構築し、SQLを生成
query, _, err := ds.GroupBy("divisions.id").ToSQL()
query, _, err := ds.ToSQL()
if err != nil {
return nil, err
}
Expand All @@ -70,7 +69,7 @@ func (dr *divisionRepository) GetById(
// 部門作成
func (dr *divisionRepository) Create(
c context.Context,
division division,
division Division,
) error {
ds := dialect.Insert("divisions").
Rows(goqu.Record{"name": division.Name, "financial_record_id": division.FinancialRecordID})
Expand All @@ -85,7 +84,7 @@ func (dr *divisionRepository) Create(
func (dr *divisionRepository) Update(
c context.Context,
id string,
division division,
division Division,
) error {
ds := dialect.Update("divisions").
Set(goqu.Record{"name": division.Name, "financial_record_id": division.FinancialRecordID}).
Expand Down Expand Up @@ -121,8 +120,7 @@ func (dr *divisionRepository) FindLatestRecord(c context.Context) (*sql.Row, err
return dr.crud.ReadByID(c, query)
}

// Note: この中のみで呼ぶために小文字宣言
type division = generated.Division
type Division = generated.Division

// NOTE: getの共通部分抜き出し
var selectDivisionQuery = dialect.From("divisions").
Expand Down

0 comments on commit 827a0c4

Please sign in to comment.