Skip to content

Commit

Permalink
Merge branch 'feat/kubosaka/create-api-financial-record' into feat/ku…
Browse files Browse the repository at this point in the history
…bosaka/905-create-api-festival-item
  • Loading branch information
Kubosaka committed Jan 9, 2025
2 parents 767b068 + 38c277b commit 27c744e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions api/internals/usecase/financial_record_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (fru *financialRecordUseCase) GetFinancialRecords(
c context.Context,
) (FinancialRecordDetails, error) {
var financialRecordDetails FinancialRecordDetails
var financialRecordList []FinancialRecordWithBalance
var financialRecords []FinancialRecordWithBalance
var total Total

rows, err := fru.rep.All(c)
Expand All @@ -64,15 +64,15 @@ func (fru *financialRecordUseCase) GetFinancialRecords(
if err != nil {
return financialRecordDetails, errors.Wrapf(err, "can not connect SQL")
}
financialRecordList = append(financialRecordList, financialRecord)
financialRecords = append(financialRecords, financialRecord)
}

// totalを求める
budgetTotal := 0
expenseTotal := 0
balanceTotal := 0

for _, financialRecord := range financialRecordList {
for _, financialRecord := range financialRecords {
budgetTotal += *financialRecord.Budget
expenseTotal += *financialRecord.Expense
balanceTotal += *financialRecord.Balance
Expand All @@ -83,17 +83,17 @@ func (fru *financialRecordUseCase) GetFinancialRecords(
total.Balance = &balanceTotal

financialRecordDetails.Total = &total
financialRecordDetails.FinancialRecords = &financialRecordList
financialRecordDetails.FinancialRecords = &financialRecords

return financialRecordDetails, err
}

func (fru *financialRecordUseCase) GetFinancialRecordsByYears(
c context.Context,
year string,
) (generated.FinancialRecordDetails, error) {
) (FinancialRecordDetails, error) {
var financialRecordDetails FinancialRecordDetails
var financialRecordList []FinancialRecordWithBalance
var financialRecords []FinancialRecordWithBalance
var total Total

rows, err := fru.rep.AllByPeriod(c, year)
Expand All @@ -117,15 +117,15 @@ func (fru *financialRecordUseCase) GetFinancialRecordsByYears(
if err != nil {
return financialRecordDetails, errors.Wrapf(err, "can not connect SQL")
}
financialRecordList = append(financialRecordList, financialRecord)
financialRecords = append(financialRecords, financialRecord)
}

// totalを求める
budgetTotal := 0
expenseTotal := 0
balanceTotal := 0

for _, financialRecord := range financialRecordList {
for _, financialRecord := range financialRecords {
budgetTotal += *financialRecord.Budget
expenseTotal += *financialRecord.Expense
balanceTotal += *financialRecord.Balance
Expand All @@ -136,7 +136,7 @@ func (fru *financialRecordUseCase) GetFinancialRecordsByYears(
total.Balance = &balanceTotal

financialRecordDetails.Total = &total
financialRecordDetails.FinancialRecords = &financialRecordList
financialRecordDetails.FinancialRecords = &financialRecords

return financialRecordDetails, err
}
Expand Down

0 comments on commit 27c744e

Please sign in to comment.