Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0e24cbc
feat: 各階の教師データを取得するOAS定義
hikahana May 3, 2025
f8ffb0a
generated: 各棟の教師データを取得
hikahana May 3, 2025
c070fa4
fix: tags追加
hikahana May 3, 2025
4215d21
generated: description
hikahana May 3, 2025
09f14b4
feat: 各棟、各階の教師情報をパスクエリ形式で取得するAPIの作成
hikahana May 3, 2025
836d96f
fix: building_idの存在チェックを追加
hikahana May 12, 2025
4704f36
[wip]go-migration導入
May 12, 2025
9d2e24b
Revert "[wip]go-migration導入"
May 12, 2025
b74016a
refactor: campusDonationスキーマを更新し、棟ごとの教員情報を追加
hikahana May 12, 2025
048ceec
generated: /campus_donations/building/{building_id}/floor/{floor_id}周…
hikahana May 12, 2025
c69626e
feat: クエリ返り値用の型定義
hikahana May 12, 2025
9b45028
fix: fix error message
hikahana May 12, 2025
7503c95
refactor: クエリの選択項目を整理し、グループ化を削除
hikahana May 12, 2025
5b2c327
refactor: GetCampusDonationByFloorsメソッドを更新し、返り値の型を変更
hikahana May 12, 2025
6ee1b32
Merge branch 'feat/hikahana/get-rooms-by-building' of github:NUTFes/F…
hikahana May 12, 2025
538175a
Merge branch 'fix/hikahana/change-table-name-campus-donations' of git…
hikahana May 15, 2025
606ac41
Merge branch 'fix/hikahana/change-table-name-campus-donations' of git…
hikahana May 15, 2025
a0d1d9d
campus_donationsテーブルに基づいてfund_informationsの参照を更新
hikahana May 15, 2025
b64c089
Merge branch 'fix/hikahana/change-table-name-campus-donations' of git…
hikahana May 24, 2025
25534d4
fix: year_idを考慮する
hikahana May 24, 2025
eb1ff5d
generated: /campus_donations/year/{year_id}/building/{building_id}/fl…
hikahana May 24, 2025
79f58aa
fix: パス修正
hikahana May 24, 2025
5d859d4
refactor: 型変換を関数に切り分け
hikahana May 24, 2025
1f6fa2d
feat: add campus donation controller with endpoint for retrieving don…
hikahana May 25, 2025
3efc607
fix: handle NULL values in campus donations price with COALESCE
hikahana Jun 4, 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
41 changes: 41 additions & 0 deletions api/externals/controller/campus_donation_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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
}

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)
}
79 changes: 79 additions & 0 deletions api/externals/repository/campus_donation_repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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)
}

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.COALESCE(goqu.I("campus_donations.price"), 0).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)

}
59 changes: 59 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
14 changes: 14 additions & 0 deletions api/internals/domain/campus_donation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package domain

// CampusDonationRecord は、1行分のフラットな寄付データを表します
type CampusDonationRecord struct {
BuildingId int `json:"building_id"`
BuildingName *string `json:"building_name,omitempty"`
FloorId *int `json:"floor_id,omitempty"`
FloorNumber string `json:"floor_number"`
TeacherId int `json:"teacher_id"`
TeacherName string `json:"teacher_name"`
RoomName string `json:"room_name"`
Price int `json:"price"`
IsBlack *bool `json:"is_black,omitempty"`
}
Loading