From 767b068ba6bb0d1266094991a5380893181bd0df Mon Sep 17 00:00:00 2001 From: Kubosaka Date: Thu, 9 Jan 2025 00:43:00 +0900 Subject: [PATCH] =?UTF-8?q?=E5=9E=8B=E5=90=8D=E7=9C=81=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/festival_item_repository.go | 17 +++---- .../usecase/financial_record_usecase.go | 47 ++++++++++--------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/api/externals/repository/festival_item_repository.go b/api/externals/repository/festival_item_repository.go index 63a216b2..43edac5d 100644 --- a/api/externals/repository/festival_item_repository.go +++ b/api/externals/repository/festival_item_repository.go @@ -16,15 +16,16 @@ type festivalItemRepository struct { crud abstract.Crud } +type FestivalItem = generated.FestivalItem type FestivalItemRepository interface { All(context.Context) (*sql.Rows, error) AllByPeriod(context.Context, string) (*sql.Rows, error) AllByPeriodAndDivision(context.Context, string, string) (*sql.Rows, error) GetById(context.Context, string) (*sql.Row, error) - CreateFestivalItem(context.Context, *sql.Tx, generated.FestivalItem) error - CreateItemBudget(context.Context, *sql.Tx, generated.FestivalItem) error - UpdateFestivalItem(context.Context, *sql.Tx, string, generated.FestivalItem) error - UpdateItemBudget(context.Context, *sql.Tx, string, generated.FestivalItem) error + CreateFestivalItem(context.Context, *sql.Tx, FestivalItem) error + CreateItemBudget(context.Context, *sql.Tx, FestivalItem) error + UpdateFestivalItem(context.Context, *sql.Tx, string, FestivalItem) error + UpdateItemBudget(context.Context, *sql.Tx, string, FestivalItem) error DeleteFestivalItem(context.Context, *sql.Tx, string) error DeleteItemBudget(context.Context, *sql.Tx, string) error FindLatestRecord(context.Context) (*sql.Row, error) @@ -162,7 +163,7 @@ func (fir *festivalItemRepository) GetById( func (fir *festivalItemRepository) CreateFestivalItem( c context.Context, tx *sql.Tx, - festivalItem generated.FestivalItem, + festivalItem FestivalItem, ) error { ds := dialect.Insert("festival_items"). Rows(goqu.Record{"name": festivalItem.Name, "memo": festivalItem.Memo, "division_id": festivalItem.DivisionId}) @@ -178,7 +179,7 @@ func (fir *festivalItemRepository) CreateFestivalItem( func (fir *festivalItemRepository) CreateItemBudget( c context.Context, tx *sql.Tx, - festivalItem generated.FestivalItem, + festivalItem FestivalItem, ) error { ds := dialect.Insert("item_budgets"). Rows(goqu.Record{"amount": festivalItem.Amount, "festival_item_id": goqu.L("LAST_INSERT_ID()")}) @@ -196,7 +197,7 @@ func (fir *festivalItemRepository) UpdateFestivalItem( c context.Context, tx *sql.Tx, id string, - festivalItem generated.FestivalItem, + festivalItem FestivalItem, ) error { ds := dialect.Update("festival_items"). Set(goqu.Record{"name": festivalItem.Name, "memo": festivalItem.Memo, "division_id": festivalItem.DivisionId}). @@ -214,7 +215,7 @@ func (fir *festivalItemRepository) UpdateItemBudget( c context.Context, tx *sql.Tx, id string, - festivalItem generated.FestivalItem, + festivalItem FestivalItem, ) error { ds := dialect.Update("item_budgets"). Set(goqu.Record{"amount": festivalItem.Amount}). diff --git a/api/internals/usecase/financial_record_usecase.go b/api/internals/usecase/financial_record_usecase.go index d470483e..25d0c6af 100644 --- a/api/internals/usecase/financial_record_usecase.go +++ b/api/internals/usecase/financial_record_usecase.go @@ -12,18 +12,23 @@ type financialRecordUseCase struct { rep rep.FinancialRecordRepository } +type FinancialRecordDetails = generated.FinancialRecordDetails +type FinancialRecord = generated.FinancialRecord +type FinancialRecordWithBalance = generated.FinancialRecordWithBalance +type Total = generated.Total + type FinancialRecordUseCase interface { - GetFinancialRecords(context.Context) (generated.FinancialRecordDetails, error) - GetFinancialRecordsByYears(context.Context, string) (generated.FinancialRecordDetails, error) + GetFinancialRecords(context.Context) (FinancialRecordDetails, error) + GetFinancialRecordsByYears(context.Context, string) (FinancialRecordDetails, error) CreateFinancialRecord( context.Context, - generated.FinancialRecord, - ) (generated.FinancialRecordWithBalance, error) + FinancialRecord, + ) (FinancialRecordWithBalance, error) UpdateFinancialRecord( context.Context, string, - generated.FinancialRecord, - ) (generated.FinancialRecordWithBalance, error) + FinancialRecord, + ) (FinancialRecordWithBalance, error) DestroyFinancialRecord(context.Context, string) error } @@ -33,10 +38,10 @@ func NewFinancialRecordUseCase(rep rep.FinancialRecordRepository) FinancialRecor func (fru *financialRecordUseCase) GetFinancialRecords( c context.Context, -) (generated.FinancialRecordDetails, error) { - var financialRecordDetails generated.FinancialRecordDetails - var financialRecordList []generated.FinancialRecordWithBalance - var total generated.Total +) (FinancialRecordDetails, error) { + var financialRecordDetails FinancialRecordDetails + var financialRecordList []FinancialRecordWithBalance + var total Total rows, err := fru.rep.All(c) if err != nil { @@ -46,7 +51,7 @@ func (fru *financialRecordUseCase) GetFinancialRecords( defer rows.Close() for rows.Next() { - var financialRecord generated.FinancialRecordWithBalance + var financialRecord FinancialRecordWithBalance err := rows.Scan( &financialRecord.Id, &financialRecord.Name, @@ -87,9 +92,9 @@ func (fru *financialRecordUseCase) GetFinancialRecordsByYears( c context.Context, year string, ) (generated.FinancialRecordDetails, error) { - var financialRecordDetails generated.FinancialRecordDetails - var financialRecordList []generated.FinancialRecordWithBalance - var total generated.Total + var financialRecordDetails FinancialRecordDetails + var financialRecordList []FinancialRecordWithBalance + var total Total rows, err := fru.rep.AllByPeriod(c, year) if err != nil { @@ -99,7 +104,7 @@ func (fru *financialRecordUseCase) GetFinancialRecordsByYears( defer rows.Close() for rows.Next() { - var financialRecord generated.FinancialRecordWithBalance + var financialRecord FinancialRecordWithBalance err := rows.Scan( &financialRecord.Id, &financialRecord.Name, @@ -138,9 +143,9 @@ func (fru *financialRecordUseCase) GetFinancialRecordsByYears( func (fru *financialRecordUseCase) CreateFinancialRecord( c context.Context, - financialRecord generated.FinancialRecord, -) (generated.FinancialRecordWithBalance, error) { - latastFinancialRecordWithBalance := generated.FinancialRecordWithBalance{} + financialRecord FinancialRecord, +) (FinancialRecordWithBalance, error) { + latastFinancialRecordWithBalance := FinancialRecordWithBalance{} err := fru.rep.Create(c, financialRecord) if err != nil { return latastFinancialRecordWithBalance, err @@ -166,9 +171,9 @@ func (fru *financialRecordUseCase) CreateFinancialRecord( func (fru *financialRecordUseCase) UpdateFinancialRecord( c context.Context, id string, - financialRecord generated.FinancialRecord, -) (generated.FinancialRecordWithBalance, error) { - updateFinancialRecord := generated.FinancialRecordWithBalance{} + financialRecord FinancialRecord, +) (FinancialRecordWithBalance, error) { + updateFinancialRecord := FinancialRecordWithBalance{} if err := fru.rep.Update(c, id, financialRecord); err != nil { return updateFinancialRecord, err