Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
52 changes: 52 additions & 0 deletions api/externals/controller/campus_donation_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package controller

import (
"net/http"

"github.com/NUTFes/FinanSu/api/internals/usecase"
"github.com/labstack/echo/v4"
)

type campusDonationController struct {
u usecase.CampusDonationUseCase
}

type CampusDonationController interface {
IndexCampusDonationByFloor(echo.Context) error
IndexCampusDonationBuildingByPeriod(echo.Context) error
}

func NewCampusDonationController(u usecase.CampusDonationUseCase) CampusDonationController {
return &campusDonationController{u}
}

func (cdc *campusDonationController) IndexCampusDonationByFloor(c echo.Context) error {
ctx := c.Request().Context()
buildingId := c.Param("building_id")
floorId := c.Param("floor_id")

if buildingId == "" {
return c.String(http.StatusBadRequest, "building_id is required")
}

if floorId == "" {
return c.String(http.StatusBadRequest, "floor_id is required")
}

campusDonationByFloors, err := cdc.u.GetCampusDonationByFloors(ctx, buildingId, floorId)
if err != nil {
return c.String(http.StatusBadRequest, "failed to get campus donation by floor")
}

return c.JSON(http.StatusOK, campusDonationByFloors)
}

func (f *campusDonationController) IndexCampusDonationBuildingByPeriod(c echo.Context) error {
ctx := c.Request().Context()
year := c.Param("year")
fundInformationBuildingByPeriod, err := f.u.GetCampusDonationBuildingByPeriod(ctx, year)
if err != nil {
return err
}
return c.JSON(http.StatusOK, fundInformationBuildingByPeriod)
}
132 changes: 132 additions & 0 deletions api/externals/repository/campus_donation_repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package repository

import (
"context"
"database/sql"
"log"

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

type campusDonationRepository struct {
client db.Client
crud abstract.Crud
}

type CampusDonationRepository interface {
AllCampusDonationByFloor(context.Context, string, string) (*sql.Rows, error)
AllBuildingsByPeriod(context.Context, string) (*sql.Rows, error)
}

func NewCampusDonationRepository(c db.Client, ac abstract.Crud) CampusDonationRepository {
return &campusDonationRepository{c, ac}
}

func (cdr *campusDonationRepository) AllCampusDonationByFloor(c context.Context, buildingId string, floorId string) (*sql.Rows, error) {

query, _, err := dialect.From("buildings").
Join(
goqu.T("building_units"),
goqu.On(goqu.Ex{"building_units.building_id": goqu.I("buildings.id")}),
).
Join(
goqu.T("floors"),
goqu.On(goqu.Ex{"floors.building_unit_id": goqu.I("building_units.id")}),
).
Join(
goqu.T("rooms"),
goqu.On(goqu.Ex{"rooms.floor_id": goqu.I("floors.id")}),
).
Join(
goqu.T("room_teachers"),
goqu.On(goqu.Ex{"room_teachers.room_id": goqu.I("rooms.id")}),
).
Join(
goqu.T("teachers"),
goqu.On(goqu.Ex{"teachers.id": goqu.I("room_teachers.teacher_id")}),
).
LeftJoin(
goqu.T("campus_donations"),
goqu.On(goqu.Ex{"campus_donations.teacher_id": goqu.I("teachers.id")}),
).
Select(
goqu.I("buildings.id").As("building_id"),
goqu.I("buildings.name").As("building_name"),
goqu.I("floors.id").As("floor_id"),
goqu.I("floors.floor_number").As("floor_number"),
goqu.I("teachers.id").As("teacher_id"),
goqu.I("teachers.name").As("teacher_name"),
goqu.I("rooms.room_name").As("room_name"),
goqu.I("campus_donations.price").As("price"),
goqu.I("teachers.is_black").As("is_black"),
).
Where(
goqu.Ex{"buildings.id": buildingId, "floors.id": floorId},
).
Order(
goqu.I("building_units.unit_number").Asc(),
goqu.I("floors.floor_number").Asc(),
).
ToSQL()

if err != nil {
log.Fatal(err)
}

return cdr.crud.Read(c, query)

}

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

ds := dialect.From("campus_donations").
Select(
goqu.I("buildings.id"),
goqu.I("buildings.name"),
goqu.I("campus_donations.price"),
Comment on lines +86 to +88
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sumとか集計関数つかったらusecaseの処理楽になるのかな、まあどっちでも

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

棟ごとに分けるの実装するのめんどみがあるからusecaseで処理させます

).
Join(goqu.T("teachers"), goqu.On(goqu.Ex{
"campus_donations.teacher_id": goqu.I("teachers.id"),
})).
Join(goqu.T("users"), goqu.On(goqu.Ex{
"campus_donations.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("campus_donations.created_at").Gt(goqu.I("year_periods.started_at")),
goqu.I("campus_donations.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("campus_donations.updated_at").Desc())

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

return fir.crud.Read(c, query)
}
86 changes: 86 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.

3 changes: 2 additions & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/oapi-codegen/runtime v1.1.1
github.com/pkg/errors v0.9.1
github.com/slack-go/slack v0.13.0
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
golang.org/x/crypto v0.31.0
gorm.io/driver/mysql v1.3.3
gorm.io/gorm v1.23.4
Expand Down Expand Up @@ -77,6 +77,7 @@ require (
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/samber/lo v1.50.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.29.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,8 @@ github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk=
github.com/samber/lo v1.50.0 h1:XrG0xOeHs+4FQ8gJR97zDz5uOFMW7OwFWiFVzqopKgY=
github.com/samber/lo v1.50.0/go.mod h1:RjZyNk6WSnUFRKK6EyOhsRJMqft3G+pg7dCWHQCWvsc=
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
Expand Down Expand Up @@ -1009,6 +1011,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
Expand Down
4 changes: 4 additions & 0 deletions api/internals/di/di.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func InitializeServer() (db.Client, *echo.Echo) {
transactionRepository := repository.NewTransactionRepository(client, crud)
userRepository := repository.NewUserRepository(client, crud)
yearRepository := repository.NewYearRepository(client, crud)
campusDonationRepository := repository.NewCampusDonationRepository(client, crud)
// ↓

// UseCase
Expand Down Expand Up @@ -99,6 +100,7 @@ func InitializeServer() (db.Client, *echo.Echo) {
teacherUseCase := usecase.NewTeacherUseCase(teacherRepository)
userUseCase := usecase.NewUserUseCase(userRepository, sessionRepository)
yearUseCase := usecase.NewYearUseCase(yearRepository)
campusDonationUseCase := usecase.NewCampusDonationUseCase(campusDonationRepository)
// ↓

// Controller
Expand Down Expand Up @@ -133,6 +135,7 @@ func InitializeServer() (db.Client, *echo.Echo) {
teacherController := controller.NewTeacherController(teacherUseCase)
userController := controller.NewUserController(userUseCase)
yearController := controller.NewYearController(yearUseCase)
campusDonationController := controller.NewCampusDonationController(campusDonationUseCase)
// ↓

// router
Expand Down Expand Up @@ -164,6 +167,7 @@ func InitializeServer() (db.Client, *echo.Echo) {
teacherController,
userController,
yearController,
campusDonationController,
)

// ↓
Expand Down
Loading