-
Notifications
You must be signed in to change notification settings - Fork 2
各棟ごとの合計募金額を取得するAPIの作成 #986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hikahana
wants to merge
22
commits into
feat/hikahana/get-rooms-by-building
Choose a base branch
from
feat/hikahana/add-get-department-by-donation
base: feat/hikahana/get-rooms-by-building
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5414852
gen: orval
hikahana 75405b6
/fund_informations/building/{year}エンドポイントを追加し、年度で指定されたfund_informatio…
hikahana 034c108
教師モデルを追加し、建物と部屋番号のオプションパラメータを含むfund_informationsエンドポイントを更新
hikahana 090464d
fund_informationに年度別の建物情報を取得する機能を追加
hikahana c9bd752
fund_informationsエンドポイントのパスを修正: building/{year}をbuildings/{year}に変更
hikahana e15837d
fund_informationsエンドポイントのパスを修正: building/{year}をbuildings/{year}に変更し、…
hikahana 6566275
fund_informationsエンドポイントに年度別の建物情報を取得する機能を追加し、関連するコントローラー、リポジトリ、ユースケースを更新
hikahana ecc2d2e
Merge branch 'fix/hikahana/er' of github:NUTFes/FinanSu into feat/hik…
hikahana 5a5fd28
[fix]]: 配列形式に変更した
hikahana e2384e4
[generated]: buildingTotal
hikahana cfa968a
[fix]: totalPriceの合算を返すように修正
hikahana 318ba7c
Merge branch 'feat/hikahana/get-rooms-by-building' of github:NUTFes/F…
hikahana 63262c4
feat: 年度で指定されたfund_informationsに紐づくデータを取得するAPIエンドポイントを追加
hikahana 3a658a9
feat: 年度で指定されたキャンパス寄付データを取得するAPIエンドポイントを追加し、fund_informations関連のエンドポイ…
hikahana 942562f
feat: 年度別のキャンパス寄付データを取得するAPIエンドポイントを追加し、fund_information関連のエンドポイントを削除
hikahana bf18310
Merge branch 'fix/hikahana/change-table-name-campus-donations' of git…
hikahana 1ffe7f0
campus_donation_repositoryのfund_informationsをcampus_donationsに置き換え
hikahana dc21071
キャンパス寄付ビルディングの構造体を追加し、関連するコードを更新
hikahana a0cccf1
fix: fund_information削除の時に消えたrouter修正
hikahana b5c4ed3
merge
hikahana 65f1478
refactor: update database dialect usage in campus_donation_repository
hikahana 296d728
fix: GetCampusDonationBuildingByPeriodでcontinueを使ってネストを低減
hikahana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"), | ||
| ). | ||
| 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) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sumとか集計関数つかったらusecaseの処理楽になるのかな、まあどっちでも
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
棟ごとに分けるの実装するのめんどみがあるからusecaseで処理させます