Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5414852
gen: orval
hikahana Apr 30, 2025
75405b6
/fund_informations/building/{year}エンドポイントを追加し、年度で指定されたfund_informatio…
hikahana Apr 30, 2025
034c108
教師モデルを追加し、建物と部屋番号のオプションパラメータを含むfund_informationsエンドポイントを更新
hikahana Apr 30, 2025
090464d
fund_informationに年度別の建物情報を取得する機能を追加
hikahana Apr 30, 2025
c9bd752
fund_informationsエンドポイントのパスを修正: building/{year}をbuildings/{year}に変更
hikahana May 1, 2025
e15837d
fund_informationsエンドポイントのパスを修正: building/{year}をbuildings/{year}に変更し、…
hikahana May 1, 2025
6566275
fund_informationsエンドポイントに年度別の建物情報を取得する機能を追加し、関連するコントローラー、リポジトリ、ユースケースを更新
hikahana May 1, 2025
ecc2d2e
Merge branch 'fix/hikahana/er' of github:NUTFes/FinanSu into feat/hik…
hikahana May 2, 2025
5a5fd28
[fix]]: 配列形式に変更した
hikahana May 2, 2025
e2384e4
[generated]: buildingTotal
hikahana May 2, 2025
cfa968a
[fix]: totalPriceの合算を返すように修正
hikahana May 2, 2025
318ba7c
Merge branch 'feat/hikahana/get-rooms-by-building' of github:NUTFes/F…
hikahana May 9, 2025
63262c4
feat: 年度で指定されたfund_informationsに紐づくデータを取得するAPIエンドポイントを追加
hikahana May 9, 2025
3a658a9
feat: 年度で指定されたキャンパス寄付データを取得するAPIエンドポイントを追加し、fund_informations関連のエンドポイ…
hikahana May 9, 2025
942562f
feat: 年度別のキャンパス寄付データを取得するAPIエンドポイントを追加し、fund_information関連のエンドポイントを削除
hikahana May 9, 2025
bf18310
Merge branch 'fix/hikahana/change-table-name-campus-donations' of git…
hikahana May 15, 2025
1ffe7f0
campus_donation_repositoryのfund_informationsをcampus_donationsに置き換え
hikahana May 15, 2025
dc21071
キャンパス寄付ビルディングの構造体を追加し、関連するコードを更新
hikahana May 15, 2025
a0cccf1
fix: fund_information削除の時に消えたrouter修正
hikahana May 16, 2025
b5c4ed3
merge
hikahana May 25, 2025
65f1478
refactor: update database dialect usage in campus_donation_repository
hikahana May 25, 2025
296d728
fix: GetCampusDonationBuildingByPeriodでcontinueを使ってネストを低減
hikahana Jun 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/externals/controller/fund_information_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type FundInformationController interface {
IndexFundInformationDetails(echo.Context) error
ShowFundInformationDetailByID(echo.Context) error
IndexFundInformationDetailsByPeriod(echo.Context) error
IndexFundInformationBuildingsByPeriod(echo.Context) error
}

func NewFundInformationController(u usecase.FundInformationUseCase) FundInformationController {
Expand Down Expand Up @@ -117,3 +118,13 @@ func (f *fundInformationController) IndexFundInformationDetailsByPeriod(c echo.C
}
return c.JSON(http.StatusOK, fundInformationDetailsByPeriod)
}

func (f *fundInformationController) IndexFundInformationBuildingsByPeriod(c echo.Context) error {
ctx := c.Request().Context()
year := c.Param("year")
fundInformationBuildingByPeriod, err := f.u.GetFundInformationBuildingsByPeriod(ctx, year)
if err != nil {
return err
}
return c.JSON(http.StatusOK, fundInformationBuildingByPeriod)
}
71 changes: 64 additions & 7 deletions api/externals/repository/fund_information_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/NUTFes/FinanSu/api/drivers/db"
"github.com/NUTFes/FinanSu/api/externals/repository/abstract"
goqu "github.com/doug-martin/goqu/v9"
)

type fundInformationRepository struct {
Expand All @@ -23,6 +24,7 @@ type FundInformationRepository interface {
FindDetailByID(context.Context, string) (*sql.Row, error)
FindLatestRecord(context.Context) (*sql.Row, error)
AllDetailsByPeriod(context.Context, string) (*sql.Rows, error)
AllBuildingsByPeriod(context.Context, string) (*sql.Rows, error)
}

func NewFundInformationRepository(c db.Client, ac abstract.Crud) FundInformationRepository {
Expand Down Expand Up @@ -63,12 +65,12 @@ func (fir *fundInformationRepository) Create(
received_at
) VALUES (
` + userID +
"," + teacherID +
"," + price +
",'" + remark +
"'," + isFirstCheck +
"," + isLastCheck +
",'" + receivedAt + "')"
"," + teacherID +
"," + price +
",'" + remark +
"'," + isFirstCheck +
"," + isLastCheck +
",'" + receivedAt + "')"
return fir.crud.UpdateDB(c, query)
}

Expand Down Expand Up @@ -198,6 +200,61 @@ func (fir *fundInformationRepository) AllDetailsByPeriod(c context.Context, year
year_periods.year_id = years.id
WHERE
years.year = ` + year +
" ORDER BY fund_informations.updated_at DESC;"
" ORDER BY fund_informations.updated_at DESC;"
return fir.crud.Read(c, query)
}

func (fir *fundInformationRepository) AllBuildingsByPeriod(c context.Context, year string) (*sql.Rows, error) {

db := goqu.Dialect("mysql")

ds := db.From("fund_informations").
Select(
goqu.I("buildings.id").As("building_id"),
goqu.I("buildings.name").As("building_name"),
goqu.I("fund_informations.price").As("price"),
goqu.I("years.year").As("year"),
).
Join(goqu.T("teachers"), goqu.On(goqu.Ex{
"fund_informations.teacher_id": goqu.I("teachers.id"),
})).
Join(goqu.T("users"), goqu.On(goqu.Ex{
"fund_informations.user_id": goqu.I("users.id"),
})).
Join(goqu.T("departments"), goqu.On(goqu.Ex{
"teachers.department_id": goqu.I("departments.id"),
})).
Join(goqu.T("room_teachers"), goqu.On(goqu.Ex{
"room_teachers.teacher_id": goqu.I("teachers.id"),
})).
Join(goqu.T("rooms"), goqu.On(goqu.Ex{
"room_teachers.room_id": goqu.I("rooms.id"),
})).
Join(goqu.T("floors"), goqu.On(goqu.Ex{
"rooms.floor_id": goqu.I("floors.id"),
})).
Join(goqu.T("building_units"), goqu.On(goqu.Ex{
"floors.building_unit_id": goqu.I("building_units.id"),
})).
Join(goqu.T("buildings"), goqu.On(goqu.Ex{
"building_units.building_id": goqu.I("buildings.id"),
})).
Join(goqu.T("year_periods"),
goqu.On(goqu.And(
goqu.I("fund_informations.created_at").Gt(goqu.I("year_periods.started_at")),
goqu.I("fund_informations.created_at").Lt(goqu.I("year_periods.ended_at")),
)),
).
Join(goqu.T("years"), goqu.On(goqu.Ex{
"year_periods.year_id": goqu.I("years.id"),
})).
Where(goqu.Ex{"years.year": year}).
Order(goqu.I("fund_informations.updated_at").Desc())

query, _, err := ds.ToSQL()
if err != nil {
panic(err)
}

return fir.crud.Read(c, query)
}
52 changes: 52 additions & 0 deletions api/generated/openapi_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion api/internals/domain/fund_information.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,12 @@ type FundInformationDetail struct {
FundInformation FundInformation `json:"fundInformation"`
User User `json:"user"`
Teacher Teacher `json:"teacher"`
Department Department `json:"department"`
Department Department `json:"department"`
}

type FundInformationBuilding struct {
BuildingID int `json:"buildingId"`
BuildingName string `json:"buildingName"`
Price int `json:"price"`
Year int `json:"year"`
}
31 changes: 31 additions & 0 deletions api/internals/usecase/fund_information_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type FundInformationUseCase interface {
GetFundInformationDetails(context.Context) ([]domain.FundInformationDetail, error)
GetFundInformationDetailByID(context.Context, string) (domain.FundInformationDetail, error)
GetFundInformationDetailsByPeriod(context.Context, string) ([]domain.FundInformationDetail, error)
GetFundInformationBuildingsByPeriod(context.Context, string) ([]domain.FundInformationBuilding, error)
}

func NewFundInformationUseCase(rep rep.FundInformationRepository) FundInformationUseCase {
Expand Down Expand Up @@ -325,3 +326,33 @@ func (f *fundInformationUseCase) GetFundInformationDetailsByPeriod(c context.Con
}
return fundInformationDetails, nil
}

func (f *fundInformationUseCase) GetFundInformationBuildingsByPeriod(c context.Context, year string) ([]domain.FundInformationBuilding, error) {
var fundInformationBuildings []domain.FundInformationBuilding

rows, err := f.rep.AllBuildingsByPeriod(c, year)
if err != nil {
return nil, err
}
defer func() {
if err := rows.Close(); err != nil {
log.Println(err)
}
}()

for rows.Next() {
fundInformationBuilding := domain.FundInformationBuilding{}
err := rows.Scan(
&fundInformationBuilding.BuildingID,
&fundInformationBuilding.BuildingName,
&fundInformationBuilding.Price,
&fundInformationBuilding.Year,
)
if err != nil {
return fundInformationBuildings, err
}
fundInformationBuildings = append(fundInformationBuildings, fundInformationBuilding)
}

return fundInformationBuildings, nil
}
1 change: 1 addition & 0 deletions api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (r router) ProvideRouter(e *echo.Echo) {
"/fund_informations/details/:year",
r.fundInformationController.IndexFundInformationDetailsByPeriod,
)
e.GET("/fund_informations/buildings/:year", r.fundInformationController.IndexFundInformationBuildingsByPeriod)

// incomes
e.GET("/incomes", r.incomeController.IndexIncome)
Expand Down
31 changes: 31 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,25 @@ paths:
application/json:
schema:
type: object
/fund_informations/buildings/{year}:
get:
tags:
- fund_information
description: 年度で指定されたfund_informationsに紐づくデータを取得
parameters:
- name: year
in: path
description: year
required: true
schema:
type: integer
responses:
"200":
description: 年度で指定されたfund_informationsに紐づくデータを取得
content:
application/json:
schema:
type: object
/incomes:
get:
tags:
Expand Down Expand Up @@ -3475,5 +3494,17 @@ components:
- room_number
- is_black
- remark
buildingTotal:
type: object
properties:
id:
type: integer
example: 1
name:
type: string
example: 技大太郎
totalPrice:
type: integer
example: 10000

x-original-swagger-version: "2.0"
Loading
Loading