-
Notifications
You must be signed in to change notification settings - Fork 2
募金登録と更新APIの作成 #996
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
base: feat/hikahana/add-get-department-by-donation
Are you sure you want to change the base?
募金登録と更新APIの作成 #996
Changes from all commits
d4af303
2326f2b
9a90395
0cdadf5
85e343b
ce78cac
0dcbee5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ type campusDonationController struct { | |
| type CampusDonationController interface { | ||
| IndexCampusDonationByFloor(echo.Context) error | ||
| IndexCampusDonationBuildingByPeriod(echo.Context) error | ||
| CreateCampusDonation(echo.Context) error | ||
| UpdateCampusDonation(echo.Context) error | ||
| } | ||
|
|
||
| func NewCampusDonationController(u usecase.CampusDonationUseCase) CampusDonationController { | ||
|
|
@@ -46,3 +48,69 @@ func (f *campusDonationController) IndexCampusDonationBuildingByPeriod(c echo.Co | |
| } | ||
| return c.JSON(http.StatusOK, fundInformationBuildingByPeriod) | ||
| } | ||
|
|
||
| func (f *campusDonationController) CreateCampusDonation(c echo.Context) error { | ||
| ctx := c.Request().Context() | ||
| userId := c.QueryParam("user_id") | ||
| teacherId := c.QueryParam("teacher_id") | ||
| price := c.QueryParam("price") | ||
| receivedAt := c.QueryParam("received_at") | ||
| yearId := c.QueryParam("year_id") | ||
|
|
||
| if userId == "" { | ||
| return c.String(http.StatusBadRequest, "user_id is required") | ||
| } | ||
| if teacherId == "" { | ||
| return c.String(http.StatusBadRequest, "teacher_id is required") | ||
| } | ||
| if price == "" { | ||
| return c.String(http.StatusBadRequest, "price is required") | ||
| } | ||
| if receivedAt == "" { | ||
| return c.String(http.StatusBadRequest, "received_at is required") | ||
| } | ||
| if yearId == "" { | ||
| return c.String(http.StatusBadRequest, "year_id is required") | ||
| } | ||
|
|
||
| err := f.u.CreateCampusDonation(ctx, userId, teacherId, price, receivedAt, yearId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return c.NoContent(http.StatusCreated) | ||
| } | ||
|
|
||
| func (f *campusDonationController) UpdateCampusDonation(c echo.Context) error { | ||
| ctx := c.Request().Context() | ||
| id := c.QueryParam("id") | ||
| userId := c.QueryParam("user_id") | ||
| teacherId := c.QueryParam("teacher_id") | ||
| price := c.QueryParam("price") | ||
| receivedAt := c.QueryParam("received_at") | ||
| yearId := c.QueryParam("year_id") | ||
|
|
||
| if id == "" { | ||
| return c.String(http.StatusBadRequest, "id is required") | ||
| } | ||
| if userId == "" { | ||
| return c.String(http.StatusBadRequest, "user_id is required") | ||
| } | ||
| if teacherId == "" { | ||
| return c.String(http.StatusBadRequest, "teacher_id is required") | ||
| } | ||
| if price == "" { | ||
| return c.String(http.StatusBadRequest, "price is required") | ||
| } | ||
| if receivedAt == "" { | ||
| return c.String(http.StatusBadRequest, "received_at is required") | ||
| } | ||
| if yearId == "" { | ||
| return c.String(http.StatusBadRequest, "year_id is required") | ||
| } | ||
|
|
||
| err := f.u.UpdateCampusDonation(ctx, id, userId, teacherId, price, receivedAt, yearId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return c.NoContent(http.StatusOK) | ||
| } | ||
|
Comment on lines
+83
to
+116
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ type campusDonationRepository struct { | |
| type CampusDonationRepository interface { | ||
| AllCampusDonationByFloor(context.Context, string, string) (*sql.Rows, error) | ||
| AllBuildingsByPeriod(context.Context, string) (*sql.Rows, error) | ||
| CreateCampusDonation(context.Context, string, string, string, string, string) error | ||
| UpdateCampusDonation(context.Context, string, string, string, string, string, string) error | ||
| } | ||
|
|
||
| func NewCampusDonationRepository(c db.Client, ac abstract.Crud) CampusDonationRepository { | ||
|
|
@@ -143,3 +145,35 @@ func (fir *campusDonationRepository) AllBuildingsByPeriod(c context.Context, yea | |
|
|
||
| return fir.crud.Read(c, query) | ||
| } | ||
|
|
||
| func (fir *campusDonationRepository) CreateCampusDonation(c context.Context, userId string, teacherId string, price string, receivedAt string, yearId string) error { | ||
| dbDialect := goqu.Dialect("mysql") | ||
| ds := dbDialect.Insert("campus_donations").Rows(goqu.Record{ | ||
| "user_id": userId, | ||
| "teacher_id": teacherId, | ||
| "price": price, | ||
| "received_at": receivedAt, | ||
| "year_id": yearId, | ||
| }) | ||
| query, _, err := ds.ToSQL() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return fir.crud.UpdateDB(c, query) | ||
| } | ||
|
|
||
| func (fir *campusDonationRepository) UpdateCampusDonation(c context.Context, id string, userId string, teacherId string, price string, receivedAt string, yearId string) error { | ||
| dbDialect := goqu.Dialect("mysql") | ||
| ds := dbDialect.Update("campus_donations").Set(goqu.Record{ | ||
| "user_id": userId, | ||
| "teacher_id": teacherId, | ||
| "price": price, | ||
| "received_at": receivedAt, | ||
| "year_id": yearId, | ||
| }).Where(goqu.Ex{"id": id}) | ||
| query, _, err := ds.ToSQL() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return fir.crud.UpdateDB(c, query) | ||
| } | ||
|
Comment on lines
+149
to
+179
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ type campusDonationUseCase struct { | |
| type CampusDonationUseCase interface { | ||
| GetCampusDonationByFloors(context.Context, string, string) ([]CampusDonationByFloor, error) | ||
| GetCampusDonationBuildingByPeriod(context.Context, string) ([]BuildingTotal, error) | ||
| CreateCampusDonation(context.Context, string, string, string, string, string) error | ||
| UpdateCampusDonation(context.Context, string, string, string, string, string, string) error | ||
| } | ||
|
|
||
| func NewCampusDonationUseCase(rep rep.CampusDonationRepository) CampusDonationUseCase { | ||
|
|
@@ -104,4 +106,20 @@ func (f *campusDonationUseCase) GetCampusDonationBuildingByPeriod(c context.Cont | |
| return result, nil | ||
| } | ||
|
|
||
| func (f *campusDonationUseCase) CreateCampusDonation(c context.Context, userId string, teacherId string, price string, receivedAt string, yearId string) error { | ||
| err := f.rep.CreateCampusDonation(c, userId, teacherId, price, receivedAt, yearId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (f *campusDonationUseCase) UpdateCampusDonation(c context.Context, id string, userId string, teacherId string, price string, receivedAt string, yearId string) error { | ||
| err := f.rep.UpdateCampusDonation(c, id, userId, teacherId, price, receivedAt, yearId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
Comment on lines
+109
to
+123
|
||
|
|
||
| type BuildingTotal generated.BuildingTotal | ||
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.
The CreateCampusDonation method is reading parameters from query parameters using c.QueryParam instead of from the JSON request body using c.Bind. According to the OpenAPI specification, this endpoint expects a JSON request body (application/json with schema postRequestBodyCampusDonation), not query parameters.
This is inconsistent with the OpenAPI specification and with other controllers in the codebase (e.g., activity_controller.go, receipt_controller.go) which use c.Bind to parse JSON request bodies for POST requests.
The method should bind the JSON request body to a struct (generated.PostRequestBodyCampusDonation) and extract the values from there.