diff --git a/api/docs/docs.go b/api/docs/docs.go index deac96a02..7a35689f4 100644 --- a/api/docs/docs.go +++ b/api/docs/docs.go @@ -870,6 +870,26 @@ const docTemplate = `{ } }, }, + "/fund_informations/details/{year}": { + "get": { + tags: ["fund_information"], + "description": "年度で指定されたfund_informationsに紐づくデータを取得", + "parameters": [ + { + "name": "year", + "in": "path", + "description": "year", + "required": true, + "type": "integer" + } + ], + "responses": { + "200": { + "description": "年度で指定されたfund_informationsに紐づくデータを取得", + } + } + }, + }, "/purchaseitems": { "get": { tags: ["purchase_item"], diff --git a/api/externals/controller/fund_information_controller.go b/api/externals/controller/fund_information_controller.go index eb7b91add..138dbf011 100644 --- a/api/externals/controller/fund_information_controller.go +++ b/api/externals/controller/fund_information_controller.go @@ -19,6 +19,7 @@ type FundInformationController interface { DestroyFundInformation(echo.Context) error IndexFundInformationDetails(echo.Context) error ShowFundInformationDetailByID(echo.Context) error + IndexFundInformationDetailsByPeriod(echo.Context) error } func NewFundInformationController(u usecase.FundInformationUseCase) FundInformationController { @@ -106,3 +107,13 @@ func (f *fundInformationController) ShowFundInformationDetailByID(c echo.Context } return c.JSON(http.StatusOK, fundinforuserandteacher) } + +// IndexFundInformationDetailsByPeriod +func (f *fundInformationController) IndexFundInformationDetailsByPeriod(c echo.Context) error { + year := c.Param("year") + fundInformationDetailsByPeriod, err := f.u.GetFundInformationDetailsByPeriod(c.Request().Context(), year) + if err != nil { + return err + } + return c.JSON(http.StatusOK, fundInformationDetailsByPeriod) +} diff --git a/api/externals/repository/fund_information_repository.go b/api/externals/repository/fund_information_repository.go index 31ffa7b70..8eb67305c 100644 --- a/api/externals/repository/fund_information_repository.go +++ b/api/externals/repository/fund_information_repository.go @@ -22,6 +22,7 @@ type FundInformationRepository interface { FindDetails(context.Context) (*sql.Rows, error) FindDetailByID(context.Context, string) (*sql.Row, error) FindLatestRecord(context.Context) (*sql.Row, error) + AllDetailsByPeriod(context.Context, string) (*sql.Rows, error) } func NewFundInformationRepository(c db.Client, ac abstract.Crud) FundInformationRepository { @@ -66,7 +67,7 @@ func (fir *fundInformationRepository) Create( "," + price + ",'" + remark + "'," + isFirstCheck + - "," + isLastCheck + + "," + isLastCheck + "," + receivedAt + ")" return fir.crud.UpdateDB(c, query) } @@ -93,7 +94,7 @@ func (fir *fundInformationRepository) Update( ", remark ='" + remark + "', is_first_check = " + isFirstCheck + ", is_last_check = " + isLastCheck + - ", received_at = " + receivedAt + + ", received_at = " + receivedAt + " WHERE id = " + id return fir.crud.UpdateDB(c, query) } @@ -162,3 +163,41 @@ func (fir *fundInformationRepository) FindLatestRecord(c context.Context) (*sql. ` return fir.crud.ReadByID(c, query) } + +// 年度別のfund_informationに紐づくuserとteacherを取得する +func (fir *fundInformationRepository) AllDetailsByPeriod(c context.Context, year string) (*sql.Rows, error) { + query := ` + SELECT + fund_informations.*, + users.*, + teachers.*, + departments.* + FROM + fund_informations + INNER JOIN + users + ON + fund_informations.user_id = users.id + INNER JOIN + teachers + ON + fund_informations.teacher_id = teachers.id + INNER JOIN + departments + ON + teachers.department_id = departments.id + INNER JOIN + year_periods + ON + fund_informations.created_at > year_periods.started_at + AND + fund_informations.created_at < year_periods.ended_at + INNER JOIN + years + ON + year_periods.year_id = years.id + WHERE + years.year = ` + year + + " ORDER BY fund_informations.id;" + return fir.crud.Read(c, query) +} diff --git a/api/internals/usecase/fund_information_usecase.go b/api/internals/usecase/fund_information_usecase.go index bb7fc2756..083097c58 100644 --- a/api/internals/usecase/fund_information_usecase.go +++ b/api/internals/usecase/fund_information_usecase.go @@ -19,6 +19,7 @@ type FundInformationUseCase interface { DestroyFundInformation(context.Context, string) error GetFundInformationDetails(context.Context) ([]domain.FundInformationDetail, error) GetFundInformationDetailByID(context.Context, string) (domain.FundInformationDetail, error) + GetFundInformationDetailsByPeriod(context.Context, string) ([]domain.FundInformationDetail, error) } func NewFundInformationUseCase(rep rep.FundInformationRepository) FundInformationUseCase { @@ -194,6 +195,7 @@ func (f *fundInformationUseCase) GetFundInformationDetails(c context.Context) ([ return nil, err } fundInformationDetails = append(fundInformationDetails, fundInformationDetail) + } return fundInformationDetails, nil } @@ -240,3 +242,54 @@ func (f *fundInformationUseCase) GetFundInformationDetailByID(c context.Context, } return fundInformationDetail, nil } + +//fund_informations_byyear-api(GETS) +func (f *fundInformationUseCase) GetFundInformationDetailsByPeriod(c context.Context, year string) ([]domain.FundInformationDetail, error) { + fundInformationDetail:= domain.FundInformationDetail{} + var fundInformationDetails []domain.FundInformationDetail + + rows, err := f.rep.AllDetailsByPeriod(c, year) + if err != nil { + return nil, err + } + defer rows.Close() + + for rows.Next() { + err := rows.Scan( + &fundInformationDetail.FundInformation.ID, + &fundInformationDetail.FundInformation.UserID, + &fundInformationDetail.FundInformation.TeacherID, + &fundInformationDetail.FundInformation.Price, + &fundInformationDetail.FundInformation.Remark, + &fundInformationDetail.FundInformation.IsFirstCheck, + &fundInformationDetail.FundInformation.IsLastCheck, + &fundInformationDetail.FundInformation.ReceivedAt, + &fundInformationDetail.FundInformation.CreatedAt, + &fundInformationDetail.FundInformation.UpdatedAt, + &fundInformationDetail.User.ID, + &fundInformationDetail.User.Name, + &fundInformationDetail.User.BureauID, + &fundInformationDetail.User.RoleID, + &fundInformationDetail.User.CreatedAt, + &fundInformationDetail.User.UpdatedAt, + &fundInformationDetail.Teacher.ID, + &fundInformationDetail.Teacher.Name, + &fundInformationDetail.Teacher.Position, + &fundInformationDetail.Teacher.DepartmentID, + &fundInformationDetail.Teacher.Room, + &fundInformationDetail.Teacher.IsBlack, + &fundInformationDetail.Teacher.Remark, + &fundInformationDetail.Teacher.CreatedAt, + &fundInformationDetail.Teacher.UpdatedAt, + &fundInformationDetail.Department.ID, + &fundInformationDetail.Department.Name, + &fundInformationDetail.Department.CreatedAt, + &fundInformationDetail.Department.UpdatedAt, + ) + if err != nil { + return nil, err + } + fundInformationDetails = append(fundInformationDetails, fundInformationDetail) + } + return fundInformationDetails, nil +} diff --git a/api/router/router.go b/api/router/router.go index feacb5514..f46f5399d 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -135,6 +135,7 @@ func (r router) ProvideRouter(e *echo.Echo) { e.DELETE("/fund_informations/:id", r.fundInformationController.DestroyFundInformation) e.GET("/fund_informations/details", r.fundInformationController.IndexFundInformationDetails) e.GET("/fund_informations/:id/details", r.fundInformationController.ShowFundInformationDetailByID) + e.GET("/fund_informations/details/:year", r.fundInformationController.IndexFundInformationDetailsByPeriod) // mail auth e.POST("/mail_auth/signup", r.mailAuthController.SignUp)