From 0e24cbc608d7205e5cca03029f6cb236b4f5305c Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Sat, 3 May 2025 16:17:16 +0900 Subject: [PATCH 01/21] =?UTF-8?q?feat:=20=E5=90=84=E9=9A=8E=E3=81=AE?= =?UTF-8?q?=E6=95=99=E5=B8=AB=E3=83=87=E3=83=BC=E3=82=BF=E3=82=92=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=99=E3=82=8BOAS=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openapi/openapi.yaml | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 79d0c3a73..f06d5aeaf 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -816,6 +816,32 @@ paths: schema: $ref: "#/components/schemas/buyReportDetail" + /campus_donations/building/{building_id}/floor/{floor_id}: + get: + description: Returns a list of donation records for a specific building and floor. + parameters: + - name: building_id + in: path + required: true + schema: + type: integer + description: ID of the building + - name: floor_id + in: path + required: true + schema: + type: integer + description: ID of the floor + responses: + "200": + description: Successful response + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/campusDonationByFloor" + /departments: get: tags: @@ -3475,5 +3501,33 @@ components: - room_number - is_black - remark + campusDonationByFloor: + type: object + properties: + teacher_id: + type: integer + building_name: + type: string + unit_number: + type: string + floor_number: + type: string + room_name: + type: string + teacher_name: + type: string + price: + type: integer + is_black: + type: boolean + required: + - teacher_id + - building_name + - unit_number + - floor_number + - room_name + - teacher_name + - price + - is_black x-original-swagger-version: "2.0" From f8ffb0a6f433bb7d5592216287966ac8c881422a Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Sat, 3 May 2025 16:17:34 +0900 Subject: [PATCH 02/21] =?UTF-8?q?generated:=20=E5=90=84=E6=A3=9F=E3=81=AE?= =?UTF-8?q?=E6=95=99=E5=B8=AB=E3=83=87=E3=83=BC=E3=82=BF=E3=82=92=E5=8F=96?= =?UTF-8?q?=E5=BE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/generated/openapi_gen.go | 72 ++++++++++++++++ view/next-project/src/generated/hooks.ts | 85 ++++++++++++++++++- .../generated/model/campusDonationByFloor.ts | 18 ++++ .../next-project/src/generated/model/index.ts | 2 + .../src/generated/model/postTeachersParams.ts | 4 + .../generated/model/putTeachersIdParams.ts | 4 + .../src/generated/model/teacher.ts | 18 ++++ 7 files changed, 200 insertions(+), 3 deletions(-) create mode 100644 view/next-project/src/generated/model/campusDonationByFloor.ts create mode 100644 view/next-project/src/generated/model/teacher.ts diff --git a/api/generated/openapi_gen.go b/api/generated/openapi_gen.go index 8cbbf2dac..65b97408e 100644 --- a/api/generated/openapi_gen.go +++ b/api/generated/openapi_gen.go @@ -112,6 +112,18 @@ type BuyReportWithDivisionId struct { PaidBy *string `json:"paidBy,omitempty"` } +// CampusDonationByFloor defines model for campusDonationByFloor. +type CampusDonationByFloor struct { + BuildingName string `json:"building_name"` + FloorNumber string `json:"floor_number"` + IsBlack bool `json:"is_black"` + Price int `json:"price"` + RoomName string `json:"room_name"` + TeacherId int `json:"teacher_id"` + TeacherName string `json:"teacher_name"` + UnitNumber string `json:"unit_number"` +} + // DestroyTeacherIDs defines model for destroyTeacherIDs. type DestroyTeacherIDs struct { DeleteIDs []float32 `json:"deleteIDs"` @@ -292,6 +304,18 @@ type SponsorStyle struct { Style string `json:"style"` } +// Teacher defines model for teacher. +type Teacher struct { + Building string `json:"building"` + DepartmentId int `json:"department_id"` + Id int `json:"id"` + IsBlack bool `json:"is_black"` + Name string `json:"name"` + Position string `json:"position"` + Remark string `json:"remark"` + Room *string `json:"room,omitempty"` +} + // Total defines model for total. type Total struct { Balance *int `json:"balance,omitempty"` @@ -582,6 +606,9 @@ type PostTeachersParams struct { // DepartmentId 学科ID DepartmentId *int `form:"department_id,omitempty" json:"department_id,omitempty"` + // Building 棟 + Building *string `form:"building,omitempty" json:"building,omitempty"` + // Room 部屋番号 Room *string `form:"room,omitempty" json:"room,omitempty"` @@ -603,6 +630,9 @@ type PutTeachersIdParams struct { // DepartmentId 学科ID DepartmentId *int `form:"department_id,omitempty" json:"department_id,omitempty"` + // Building 棟 + Building *string `form:"building,omitempty" json:"building,omitempty"` + // Room 部屋番号 Room *string `form:"room,omitempty" json:"room,omitempty"` @@ -858,6 +888,9 @@ type ServerInterface interface { // (PUT /buy_reports/{id}) PutBuyReportsId(ctx echo.Context, id int) error + // (GET /campus_donations/building/{building_id}/floor/{floor_id}) + GetCampusDonationsBuildingBuildingIdFloorFloorId(ctx echo.Context, buildingId int, floorId int) error + // (GET /departments) GetDepartments(ctx echo.Context) error @@ -1774,6 +1807,30 @@ func (w *ServerInterfaceWrapper) PutBuyReportsId(ctx echo.Context) error { return err } +// GetCampusDonationsBuildingBuildingIdFloorFloorId converts echo context to params. +func (w *ServerInterfaceWrapper) GetCampusDonationsBuildingBuildingIdFloorFloorId(ctx echo.Context) error { + var err error + // ------------- Path parameter "building_id" ------------- + var buildingId int + + err = runtime.BindStyledParameterWithOptions("simple", "building_id", ctx.Param("building_id"), &buildingId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter building_id: %s", err)) + } + + // ------------- Path parameter "floor_id" ------------- + var floorId int + + err = runtime.BindStyledParameterWithOptions("simple", "floor_id", ctx.Param("floor_id"), &floorId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter floor_id: %s", err)) + } + + // Invoke the callback with all the unmarshaled arguments + err = w.Handler.GetCampusDonationsBuildingBuildingIdFloorFloorId(ctx, buildingId, floorId) + return err +} + // GetDepartments converts echo context to params. func (w *ServerInterfaceWrapper) GetDepartments(ctx echo.Context) error { var err error @@ -3063,6 +3120,13 @@ func (w *ServerInterfaceWrapper) PostTeachers(ctx echo.Context) error { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter department_id: %s", err)) } + // ------------- Optional query parameter "building" ------------- + + err = runtime.BindQueryParameter("form", true, false, "building", ctx.QueryParams(), ¶ms.Building) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter building: %s", err)) + } + // ------------- Optional query parameter "room" ------------- err = runtime.BindQueryParameter("form", true, false, "room", ctx.QueryParams(), ¶ms.Room) @@ -3180,6 +3244,13 @@ func (w *ServerInterfaceWrapper) PutTeachersId(ctx echo.Context) error { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter department_id: %s", err)) } + // ------------- Optional query parameter "building" ------------- + + err = runtime.BindQueryParameter("form", true, false, "building", ctx.QueryParams(), ¶ms.Building) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter building: %s", err)) + } + // ------------- Optional query parameter "room" ------------- err = runtime.BindQueryParameter("form", true, false, "room", ctx.QueryParams(), ¶ms.Room) @@ -3536,6 +3607,7 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL router.DELETE(baseURL+"/buy_reports/:id", wrapper.DeleteBuyReportsId) router.GET(baseURL+"/buy_reports/:id", wrapper.GetBuyReportsId) router.PUT(baseURL+"/buy_reports/:id", wrapper.PutBuyReportsId) + router.GET(baseURL+"/campus_donations/building/:building_id/floor/:floor_id", wrapper.GetCampusDonationsBuildingBuildingIdFloorFloorId) router.GET(baseURL+"/departments", wrapper.GetDepartments) router.POST(baseURL+"/departments", wrapper.PostDepartments) router.DELETE(baseURL+"/departments/:id", wrapper.DeleteDepartmentsId) diff --git a/view/next-project/src/generated/hooks.ts b/view/next-project/src/generated/hooks.ts index 53f88d1b5..017b6c05b 100644 --- a/view/next-project/src/generated/hooks.ts +++ b/view/next-project/src/generated/hooks.ts @@ -18,6 +18,7 @@ import type { BuyReport, BuyReportDetail, BuyReportWithDivisionId, + CampusDonationByFloor, DeleteActivitiesId200, DeleteActivityInformationsId200, DeleteActivityStylesId200, @@ -104,7 +105,6 @@ import type { GetSponsorstyles200, GetSponsorstylesId200, GetTeachersFundRegisteredYear200, - GetTeachersId200, GetUsersId200, Income, IncomeCategory, @@ -175,6 +175,7 @@ import type { Receipt, Sponsor, SponsorStyle, + Teacher, YearPeriods, } from './model'; @@ -2700,6 +2701,84 @@ export const usePutBuyReportStatusBuyReportId = ( }; }; +/** + * Returns a list of donation records for a specific building and floor. + */ +export type getCampusDonationsBuildingBuildingIdFloorFloorIdResponse200 = { + data: CampusDonationByFloor[]; + status: 200; +}; + +export type getCampusDonationsBuildingBuildingIdFloorFloorIdResponseComposite = + getCampusDonationsBuildingBuildingIdFloorFloorIdResponse200; + +export type getCampusDonationsBuildingBuildingIdFloorFloorIdResponse = + getCampusDonationsBuildingBuildingIdFloorFloorIdResponseComposite & { + headers: Headers; + }; + +export const getGetCampusDonationsBuildingBuildingIdFloorFloorIdUrl = ( + buildingId: number, + floorId: number, +) => { + return `/campus_donations/building/${buildingId}/floor/${floorId}`; +}; + +export const getCampusDonationsBuildingBuildingIdFloorFloorId = async ( + buildingId: number, + floorId: number, + options?: RequestInit, +): Promise => { + return customFetch( + getGetCampusDonationsBuildingBuildingIdFloorFloorIdUrl(buildingId, floorId), + { + ...options, + method: 'GET', + }, + ); +}; + +export const getGetCampusDonationsBuildingBuildingIdFloorFloorIdKey = ( + buildingId: number, + floorId: number, +) => [`/campus_donations/building/${buildingId}/floor/${floorId}`] as const; + +export type GetCampusDonationsBuildingBuildingIdFloorFloorIdQueryResult = NonNullable< + Awaited> +>; +export type GetCampusDonationsBuildingBuildingIdFloorFloorIdQueryError = unknown; + +export const useGetCampusDonationsBuildingBuildingIdFloorFloorId = ( + buildingId: number, + floorId: number, + options?: { + swr?: SWRConfiguration< + Awaited>, + TError + > & { swrKey?: Key; enabled?: boolean }; + request?: SecondParameter; + }, +) => { + const { swr: swrOptions, request: requestOptions } = options ?? {}; + + const isEnabled = swrOptions?.enabled !== false && !!(buildingId && floorId); + const swrKey = + swrOptions?.swrKey ?? + (() => + isEnabled + ? getGetCampusDonationsBuildingBuildingIdFloorFloorIdKey(buildingId, floorId) + : null); + const swrFn = () => + getCampusDonationsBuildingBuildingIdFloorFloorId(buildingId, floorId, requestOptions); + + const query = useSwr>, TError>(swrKey, swrFn, swrOptions); + + return { + swrKey, + ...query, + }; +}; + /** * departmentの一覧の取得 */ @@ -7585,7 +7664,7 @@ export const useDeleteSponsorstylesId = ( * teacherの一覧を取得 */ export type getTeachersResponse200 = { - data: void; + data: Teacher; status: 200; }; @@ -7781,7 +7860,7 @@ export const useDeleteTeachersDelete = (options?: { * IDで指定されたteacherの取得 */ export type getTeachersIdResponse200 = { - data: GetTeachersId200; + data: Teacher; status: 200; }; diff --git a/view/next-project/src/generated/model/campusDonationByFloor.ts b/view/next-project/src/generated/model/campusDonationByFloor.ts new file mode 100644 index 000000000..1173c9170 --- /dev/null +++ b/view/next-project/src/generated/model/campusDonationByFloor.ts @@ -0,0 +1,18 @@ +/** + * Generated by orval v7.6.0 🍺 + * Do not edit manually. + * NUTFes FinanSu API + * FinanSu APIドキュメント + * OpenAPI spec version: 2.0.0 + */ + +export interface CampusDonationByFloor { + teacher_id: number; + building_name: string; + unit_number: string; + floor_number: string; + room_name: string; + teacher_name: string; + price: number; + is_black: boolean; +} diff --git a/view/next-project/src/generated/model/index.ts b/view/next-project/src/generated/model/index.ts index c5d721c24..1b9275a0d 100644 --- a/view/next-project/src/generated/model/index.ts +++ b/view/next-project/src/generated/model/index.ts @@ -14,6 +14,7 @@ export * from './buyReportDetail'; export * from './buyReportInformation'; export * from './buyReportInformationStatus'; export * from './buyReportWithDivisionId'; +export * from './campusDonationByFloor'; export * from './deleteActivitiesId200'; export * from './deleteActivityInformationsId200'; export * from './deleteActivityStylesId200'; @@ -182,5 +183,6 @@ export * from './putYearsPeriodsId200'; export * from './receipt'; export * from './sponsor'; export * from './sponsorStyle'; +export * from './teacher'; export * from './total'; export * from './yearPeriods'; diff --git a/view/next-project/src/generated/model/postTeachersParams.ts b/view/next-project/src/generated/model/postTeachersParams.ts index 6721f1edf..4c6a69dd9 100644 --- a/view/next-project/src/generated/model/postTeachersParams.ts +++ b/view/next-project/src/generated/model/postTeachersParams.ts @@ -19,6 +19,10 @@ export type PostTeachersParams = { * 学科ID */ department_id?: number; + /** + * 棟 + */ + building?: string; /** * 部屋番号 */ diff --git a/view/next-project/src/generated/model/putTeachersIdParams.ts b/view/next-project/src/generated/model/putTeachersIdParams.ts index 0b98142d3..22d2c1fc3 100644 --- a/view/next-project/src/generated/model/putTeachersIdParams.ts +++ b/view/next-project/src/generated/model/putTeachersIdParams.ts @@ -19,6 +19,10 @@ export type PutTeachersIdParams = { * 学科ID */ department_id?: number; + /** + * 棟 + */ + building?: string; /** * 部屋番号 */ diff --git a/view/next-project/src/generated/model/teacher.ts b/view/next-project/src/generated/model/teacher.ts new file mode 100644 index 000000000..ed47351df --- /dev/null +++ b/view/next-project/src/generated/model/teacher.ts @@ -0,0 +1,18 @@ +/** + * Generated by orval v7.6.0 🍺 + * Do not edit manually. + * NUTFes FinanSu API + * FinanSu APIドキュメント + * OpenAPI spec version: 2.0.0 + */ + +export interface Teacher { + id: number; + name: string; + position: string; + department_id: number; + building: string; + room?: string; + is_black: boolean; + remark: string; +} From c070fa4bdadabd5ce3677b19e73c8ea9ca7bafbe Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Sat, 3 May 2025 18:17:43 +0900 Subject: [PATCH 03/21] =?UTF-8?q?fix:=20tags=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openapi/openapi.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index f06d5aeaf..6b3b4a3e7 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -818,7 +818,9 @@ paths: /campus_donations/building/{building_id}/floor/{floor_id}: get: - description: Returns a list of donation records for a specific building and floor. + tags: + - campus_donation + description: 各棟の各階の学内募金情報を取得するAPI parameters: - name: building_id in: path From 4215d216c6020b0038772af2023a3e283315c817 Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Sat, 3 May 2025 18:17:58 +0900 Subject: [PATCH 04/21] generated: description --- view/next-project/src/generated/hooks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/next-project/src/generated/hooks.ts b/view/next-project/src/generated/hooks.ts index 017b6c05b..cf942a4e4 100644 --- a/view/next-project/src/generated/hooks.ts +++ b/view/next-project/src/generated/hooks.ts @@ -2702,7 +2702,7 @@ export const usePutBuyReportStatusBuyReportId = ( }; /** - * Returns a list of donation records for a specific building and floor. + * 各棟の各階の学内募金情報を取得するAPI */ export type getCampusDonationsBuildingBuildingIdFloorFloorIdResponse200 = { data: CampusDonationByFloor[]; From 09f14b4b986c1789fa7f07524ede7199ef26890e Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Sat, 3 May 2025 18:19:02 +0900 Subject: [PATCH 05/21] =?UTF-8?q?feat:=20=E5=90=84=E6=A3=9F=E3=80=81?= =?UTF-8?q?=E5=90=84=E9=9A=8E=E3=81=AE=E6=95=99=E5=B8=AB=E6=83=85=E5=A0=B1?= =?UTF-8?q?=E3=82=92=E3=83=91=E3=82=B9=E3=82=AF=E3=82=A8=E3=83=AA=E5=BD=A2?= =?UTF-8?q?=E5=BC=8F=E3=81=A7=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8BAPI?= =?UTF-8?q?=E3=81=AE=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/cmapus_donation_controller.go | 37 ++++++++ .../repository/campus_donation_repository.go | 90 +++++++++++++++++++ api/internals/di/di.go | 4 + .../usecase/campus_donation_usecase.go | 59 ++++++++++++ api/router/router.go | 6 ++ 5 files changed, 196 insertions(+) create mode 100644 api/externals/controller/cmapus_donation_controller.go create mode 100644 api/externals/repository/campus_donation_repository.go create mode 100644 api/internals/usecase/campus_donation_usecase.go diff --git a/api/externals/controller/cmapus_donation_controller.go b/api/externals/controller/cmapus_donation_controller.go new file mode 100644 index 000000000..b09ca27a4 --- /dev/null +++ b/api/externals/controller/cmapus_donation_controller.go @@ -0,0 +1,37 @@ +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 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 buy_reports") + } + + return c.JSON(http.StatusOK, campusDonationByFloors) +} diff --git a/api/externals/repository/campus_donation_repository.go b/api/externals/repository/campus_donation_repository.go new file mode 100644 index 000000000..9f74592ed --- /dev/null +++ b/api/externals/repository/campus_donation_repository.go @@ -0,0 +1,90 @@ +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("fund_informations"), + goqu.On(goqu.Ex{"fund_informations.teacher_id": goqu.I("teachers.id")}), + ). + Select( + goqu.I("buildings.name"), + goqu.I("building_units.unit_number"), + goqu.I("floors.floor_number"), + goqu.I("rooms.room_name"), + goqu.I("teachers.id"), + goqu.I("teachers.name"), + goqu.I("teachers.is_black"), + goqu.COALESCE(goqu.SUM(goqu.I("fund_informations.price")), 0), + ). + Where( + goqu.Ex{"buildings.id": buildingId, "floors.id": floorId}, + ). + GroupBy( + goqu.I("buildings.name"), + goqu.I("building_units.unit_number"), + goqu.I("floors.floor_number"), + goqu.I("rooms.room_name"), + goqu.I("teachers.id"), + goqu.I("teachers.name"), + goqu.I("teachers.is_black"), + ). + Order( + goqu.I("building_units.unit_number").Asc(), + goqu.I("floors.floor_number").Asc(), + goqu.I("rooms.room_name").Asc(), + goqu.I("teachers.name").Asc(), + ). + ToSQL() + + if err != nil { + // エラーハンドリング + log.Fatal(err) + } + + return cdr.crud.Read(c, query) + +} diff --git a/api/internals/di/di.go b/api/internals/di/di.go index 3d8708398..c63fe86d1 100644 --- a/api/internals/di/di.go +++ b/api/internals/di/di.go @@ -61,6 +61,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 @@ -101,6 +102,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 @@ -136,6 +138,7 @@ func InitializeServer() (db.Client, *echo.Echo) { teacherController := controller.NewTeacherController(teacherUseCase) userController := controller.NewUserController(userUseCase) yearController := controller.NewYearController(yearUseCase) + campusDonationController := controller.NewCampusDonationController(campusDonationUseCase) // ↓ // router @@ -168,6 +171,7 @@ func InitializeServer() (db.Client, *echo.Echo) { teacherController, userController, yearController, + campusDonationController, ) // ↓ diff --git a/api/internals/usecase/campus_donation_usecase.go b/api/internals/usecase/campus_donation_usecase.go new file mode 100644 index 000000000..561480595 --- /dev/null +++ b/api/internals/usecase/campus_donation_usecase.go @@ -0,0 +1,59 @@ +package usecase + +import ( + "context" + "log" + + rep "github.com/NUTFes/FinanSu/api/externals/repository" + "github.com/NUTFes/FinanSu/api/generated" + "github.com/pkg/errors" +) + +type campusDonationUseCase struct { + rep rep.CampusDonationRepository +} + +type CampusDonationUseCase interface { + GetCampusDonationByFloors(context.Context, string, string) ([]CampusDonationByFloor, error) +} + +func NewCampusDonationUseCase(rep rep.CampusDonationRepository) CampusDonationUseCase { + return &campusDonationUseCase{rep} +} + +func (cdu *campusDonationUseCase) GetCampusDonationByFloors(c context.Context, buildingId string, floorId string) ([]CampusDonationByFloor, error) { + var campusDonation CampusDonationByFloor + var campusDonations []CampusDonationByFloor + + //クエリ実行 + rows, err := cdu.rep.AllCampusDonationByFloor(c, buildingId, floorId) + if err != nil { + return nil, err + } + defer func() { + if err := rows.Close(); err != nil { + log.Println(err) + } + }() + + for rows.Next() { + err := rows.Scan( + &campusDonation.BuildingName, + &campusDonation.UnitNumber, + &campusDonation.FloorNumber, + &campusDonation.RoomName, + &campusDonation.TeacherId, + &campusDonation.TeacherName, + &campusDonation.IsBlack, + &campusDonation.Price, + ) + + if err != nil { + return nil, errors.Wrapf(err, "can not connect SQL") + } + campusDonations = append(campusDonations, campusDonation) + } + return campusDonations, nil +} + +type CampusDonationByFloor = generated.CampusDonationByFloor diff --git a/api/router/router.go b/api/router/router.go index 8b9beadf4..949f5ce9a 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -34,6 +34,7 @@ type router struct { teacherController controller.TeacherController userController controller.UserController yearController controller.YearController + campusDonationController controller.CampusDonationController } type Router interface { @@ -69,6 +70,7 @@ func NewRouter( teacherController controller.TeacherController, userController controller.UserController, yearController controller.YearController, + campusDonationController controller.CampusDonationController, ) Router { return router{ activityController, @@ -99,6 +101,7 @@ func NewRouter( teacherController, userController, yearController, + campusDonationController, } } @@ -162,6 +165,9 @@ func (r router) ProvideRouter(e *echo.Echo) { e.GET("/buy_reports/details", r.buyReportController.IndexBuyReport) e.PUT("/buy_report/status/:buy_report_id", r.buyReportController.UpdateBuyReportStatus) + // campus_donationsのRoute + e.GET("/campus_donations/building/:building_id/floor/:floor_id", r.campusDonationController.IndexCampusDonationByFloor) + // current_user e.GET("/current_user", r.userController.GetCurrentUser) From 836d96f851f54084ac09b8193c0f6a57d189bb8d Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Mon, 12 May 2025 16:03:33 +0900 Subject: [PATCH 06/21] =?UTF-8?q?fix:=20building=5Fid=E3=81=AE=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/externals/controller/cmapus_donation_controller.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/externals/controller/cmapus_donation_controller.go b/api/externals/controller/cmapus_donation_controller.go index b09ca27a4..587bcee72 100644 --- a/api/externals/controller/cmapus_donation_controller.go +++ b/api/externals/controller/cmapus_donation_controller.go @@ -24,6 +24,10 @@ func (cdc *campusDonationController) IndexCampusDonationByFloor(c echo.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") } From 4704f36642a0d65e49903b06a9f6c796547dc44c Mon Sep 17 00:00:00 2001 From: Kubosaka Date: Mon, 12 May 2025 23:36:15 +0900 Subject: [PATCH 07/21] =?UTF-8?q?[wip]go-migration=E5=B0=8E=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 21 + compose.db.yml | 8 +- compose.migrate.yml | 9 + .../migrations/000001_initial_schema.down.sql | 70 +++ mysql/migrations/000001_initial_schema.up.sql | 440 ++++++++++++++++ mysql/seed/000001_initial_schema_seed.sql | 494 ++++++++++++++++++ scripts/create_migration.sh | 3 + scripts/seed.sh | 31 ++ 8 files changed, 1072 insertions(+), 4 deletions(-) create mode 100644 compose.migrate.yml create mode 100644 mysql/migrations/000001_initial_schema.down.sql create mode 100644 mysql/migrations/000001_initial_schema.up.sql create mode 100644 mysql/seed/000001_initial_schema_seed.sql create mode 100755 scripts/create_migration.sh create mode 100644 scripts/seed.sh diff --git a/Makefile b/Makefile index 49de15d6a..010d84c91 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ # アプリコンテナ=view,api、DBコンテナ=db,minio +include finansu.env # アプリコンテナのイメージのビルド build: @@ -106,3 +107,23 @@ gen-er: format: docker compose run --rm view npm run format + +# マイグレーションの実行 +migrate: + docker compose -f compose.migrate.yml run --rm migrate \ + --path /migrations \ + --database "mysql://${NUTMEG_DB_USER}:${NUTMEG_DB_PASSWORD}@tcp(${NUTMEG_DB_HOST}:${NUTMEG_DB_PORT})/${NUTMEG_DB_NAME}" \ + up + +# マイグレーションの実行(ダウングレード) +migrate-down: + docker compose -f compose.migrate.yml run --rm migrate \ + --path /migrations \ + --database "mysql://${NUTMEG_DB_USER}:${NUTMEG_DB_PASSWORD}@tcp(${NUTMEG_DB_HOST}:${NUTMEG_DB_PORT})/${NUTMEG_DB_NAME}" \ + down + +# マイグレーションファイルの作成 +create-migration: + ./scripts/create_migration.sh + + diff --git a/compose.db.yml b/compose.db.yml index 1054d8bb9..795dfbe93 100644 --- a/compose.db.yml +++ b/compose.db.yml @@ -2,16 +2,16 @@ services: db: image: mysql:8.0 container_name: "nutfes-finansu-db" - volumes: - - ./mysql/db:/docker-entrypoint-initdb.d # 初期データ - - ./mysql/testdb:/docker-entrypoint-testdb.d # テスト用初期データ - - ./my.cnf:/etc/mysql/conf.d/my.cnf environment: MYSQL_DATABASE: finansu_db MYSQL_USER: finansu MYSQL_PASSWORD: password MYSQL_ROOT_PASSWORD: root TZ: "Asia/Tokyo" + volumes: + - ./mysql/seed:/seed # 初期データ + - ./scripts:/scripts # スクリプト + - ./my.cnf:/etc/mysql/conf.d/my.cnf ports: - "3306:3306" restart: always diff --git a/compose.migrate.yml b/compose.migrate.yml new file mode 100644 index 000000000..7f3c2567d --- /dev/null +++ b/compose.migrate.yml @@ -0,0 +1,9 @@ +services: + migrate: + image: migrate/migrate:latest + container_name: "nutfes-finansu-migrate" + command: "migrate -version" + env_file: + - finansu.env + volumes: + - ./mysql/migrations:/migrations diff --git a/mysql/migrations/000001_initial_schema.down.sql b/mysql/migrations/000001_initial_schema.down.sql new file mode 100644 index 000000000..39dad940e --- /dev/null +++ b/mysql/migrations/000001_initial_schema.down.sql @@ -0,0 +1,70 @@ +-- テーブル削除のSQL文 +DROP TABLE IF EXISTS spot_sponsor_names; + +DROP TABLE IF EXISTS room_teachers; + +DROP TABLE IF EXISTS rooms; + +DROP TABLE IF EXISTS floors; + +DROP TABLE IF EXISTS building_units; + +DROP TABLE IF EXISTS buildings; + +DROP TABLE IF EXISTS income_income_expenditure_managements; + +DROP TABLE IF EXISTS incomes; + +DROP TABLE IF EXISTS year_periods; + +DROP TABLE IF EXISTS teachers; + +DROP TABLE IF EXISTS sponsors; + +DROP TABLE IF EXISTS sponsor_styles; + +DROP TABLE IF EXISTS session; + +DROP TABLE IF EXISTS roles; + +DROP TABLE IF EXISTS password_reset_tokens; + +DROP TABLE IF EXISTS mail_auth; + +DROP TABLE IF EXISTS fund_informations; + +DROP TABLE IF EXISTS departments; + +DROP TABLE IF EXISTS bureaus; + +DROP TABLE IF EXISTS activity_informations; + +DROP TABLE IF EXISTS sponsor_activity_balance_managements; + +DROP TABLE IF EXISTS activity_styles; + +DROP TABLE IF EXISTS activities; + +DROP TABLE IF EXISTS buy_report_income_expenditure_managements; + +DROP TABLE IF EXISTS income_expenditure_managements; + +DROP TABLE IF EXISTS buy_statuses; + +DROP TABLE IF EXISTS payment_receipts; + +DROP TABLE IF EXISTS buy_reports; + +DROP TABLE IF EXISTS user_groups; + +DROP TABLE IF EXISTS item_budgets; + +DROP TABLE IF EXISTS festival_items; + +DROP TABLE IF EXISTS divisions; + +DROP TABLE IF EXISTS financial_records; + +DROP TABLE IF EXISTS users; + +DROP TABLE IF EXISTS years; diff --git a/mysql/migrations/000001_initial_schema.up.sql b/mysql/migrations/000001_initial_schema.up.sql new file mode 100644 index 000000000..f93e849ad --- /dev/null +++ b/mysql/migrations/000001_initial_schema.up.sql @@ -0,0 +1,440 @@ +-- 年度テーブル +CREATE TABLE + years ( + id int(10) unsigned not null auto_increment, + year int(10) not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- ユーザーテーブル +CREATE TABLE + users ( + id int(10) unsigned not null auto_increment, + name varchar(255) not null, + bureau_id int(10) not null, + role_id int(10) not null, + is_deleted boolean DEFAULT false, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- 局・予算テーブル +CREATE TABLE + financial_records ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + name VARCHAR(255) NOT NULL, + year_id INT(10) UNSIGNED NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY year_id_foreign_key (year_id) REFERENCES years (id) ON DELETE CASCADE + ); + +-- 部門テーブル +CREATE TABLE + divisions ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + name VARCHAR(255) NOT NULL, + financial_record_id INT(10) UNSIGNED NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY financial_record_id_foreign_key (financial_record_id) REFERENCES financial_records (id) ON DELETE CASCADE + ); + +-- 物品テーブル +CREATE TABLE + festival_items ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + name VARCHAR(255) NOT NULL, + memo VARCHAR(255), + division_id INT(10) UNSIGNED NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY division_id_foreign_key (division_id) REFERENCES divisions (id) ON DELETE CASCADE + ); + +-- 予算テーブル +CREATE TABLE + item_budgets ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + amount INT(10) NOT NULL, + festival_item_id INT(10) UNSIGNED NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY festival_item_id_foreign_key (festival_item_id) REFERENCES festival_items (id) ON DELETE CASCADE + ); + +-- ユーザー部門テーブル +CREATE TABLE + user_groups ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + user_id INT(10) UNSIGNED NOT NULL, + group_id INT(10) UNSIGNED NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY user_id_foreign_key (user_id) REFERENCES users (id) ON DELETE CASCADE, + FOREIGN KEY group_id_foreign_key (group_id) REFERENCES divisions (id) ON DELETE CASCADE + ); + +-- 購入報告テーブル +CREATE TABLE + buy_reports ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + festival_item_id INT(10) UNSIGNED NOT NULL, + amount INT(10) NOT NULL, + memo VARCHAR(255) NOT NULL, + paid_by VARCHAR(255) NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY festival_item_id_foreign_key (festival_item_id) REFERENCES festival_items (id) ON DELETE CASCADE + ); + +-- 購入レシートテーブル +CREATE TABLE + payment_receipts ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + buy_report_id INT(10) UNSIGNED NOT NULL, + bucket_name VARCHAR(255) NOT NULL, + file_name VARCHAR(255) NOT NULL, + file_type VARCHAR(255) NOT NULL, + remark VARCHAR(255), + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY buy_report_id_foreign_key (buy_report_id) REFERENCES buy_reports (id) ON DELETE CASCADE + ); + +-- 購入ステータステーブル +CREATE TABLE + buy_statuses ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + buy_report_id INT(10) UNSIGNED NOT NULL, + is_packed BOOLEAN NOT NULL DEFAULT FALSE, + is_settled BOOLEAN NOT NULL DEFAULT FALSE, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY buy_report_id_foreign_key (buy_report_id) REFERENCES buy_reports (id) ON DELETE CASCADE + ); + +-- 収支管理テーブル +CREATE TABLE + income_expenditure_managements ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + amount INT(10) NOT NULL, + log_category ENUM("income", "expenditure", "sponsor's income") NOT NULL, + year_id INT(10) UNSIGNED NOT NULL, + receive_option ENUM("transfer", "hand"), -- expenditureはNULLを許可する + is_checked BOOLEAN NOT NULL DEFAULT FALSE, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY year_id_foreign_key (year_id) REFERENCES years (id) ON DELETE CASCADE + ); + +-- buy_reportとincome_expenditure_managementsの中間テーブル +CREATE TABLE + buy_report_income_expenditure_managements ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + buy_report_id INT(10) UNSIGNED NOT NULL, + income_expenditure_management_id INT(10) UNSIGNED NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY buy_report_id_foreign_key (buy_report_id) REFERENCES buy_reports (id) ON DELETE CASCADE, + FOREIGN KEY income_expenditure_management_id_foreign_key (income_expenditure_management_id) REFERENCES income_expenditure_managements (id) ON DELETE CASCADE + ); + +-- 協賛活動テーブル +CREATE TABLE + activities ( + id int(10) unsigned not null auto_increment, + user_id int(10), + is_done boolean, + sponsor_id int(10), + feature varchar(255), + expense int(10), + remark varchar(255), + design int(10), + url varchar(255), + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- 協賛スタイル中間テーブル +CREATE TABLE + activity_styles ( + id int(10) unsigned not null auto_increment, + activity_id int(10), + sponsor_style_id int(10), + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- 協賛活動と収支管理の中間テーブル +CREATE TABLE + sponsor_activity_balance_managements ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + sponsor_activity_id INT(10) UNSIGNED NOT NULL, + income_expenditure_management_id INT(10) UNSIGNED NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY sponsor_activity_id_foreign_key (sponsor_activity_id) REFERENCES activities (id) ON DELETE CASCADE, + FOREIGN KEY income_expenditure_management_id_foreign_key (income_expenditure_management_id) REFERENCES income_expenditure_managements (id) ON DELETE CASCADE + ); + +-- 協賛活動情報テーブル +CREATE TABLE + activity_informations ( + id int(10) unsigned not null auto_increment, + activity_id int(10), + bucket_name varchar(255), + file_name varchar(255), + file_type varchar(255), + design_progress int(10), + file_information varchar(255), + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- 局テーブル +CREATE TABLE + bureaus ( + id int(10) unsigned not null auto_increment, + name varchar(255) not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- 学科・分野テーブル +CREATE TABLE + departments ( + id int(10) unsigned not null auto_increment, + name varchar(255), + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- 募金テーブル +CREATE TABLE + fund_informations ( + id int(10) unsigned not null auto_increment, + user_id int(10) not null, + teacher_id int(10) not null, + price int(10) not null, + remark varchar(255), + is_first_check boolean, + is_last_check boolean, + received_at varchar(255) not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- メール認証テーブル +CREATE TABLE + mail_auth ( + id int(10) unsigned not null unique auto_increment, + email varchar(255) unique, + password varchar(255) not null, + user_id int(10) not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- パスワードリセットトークンテーブル +CREATE TABLE + password_reset_tokens ( + id int(10) unsigned not null unique auto_increment, + user_id int(10) not null, + token varchar(255) not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- ユーザーロールテーブル +CREATE TABLE + roles ( + id int(10) unsigned not null auto_increment, + name varchar(255) not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- セッションテーブル +CREATE TABLE + session ( + id int(10) unsigned not null unique auto_increment, + auth_id int(10) not null, + user_id int(10) not null, + access_token varchar(255) not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (auth_id) + ); + +-- 協賛スタイルテーブル +CREATE TABLE + sponsor_styles ( + id int(10) unsigned not null auto_increment, + style varchar(255) not null, + feature varchar(255) not null, + price int(10), + is_deleted boolean default false, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- 協賛企業テーブル +CREATE TABLE + sponsors ( + id int(10) unsigned not null auto_increment, + name varchar(255) not null, + tel varchar(255) not null, + email varchar(255) not null, + address varchar(255) not null, + representative varchar(255) not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- 教員テーブル +CREATE TABLE + teachers ( + id int(10) unsigned not null auto_increment, + name varchar(255) not null, + position varchar(255) not null, + department_id int(10), + room varchar(255), + is_black boolean, + remark varchar(255), + is_deleted boolean default false, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- 年度期間テーブル +CREATE TABLE + year_periods ( + id int(10) unsigned not null auto_increment, + year_id int(10) not null, + started_at datetime not null, + ended_at datetime not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- 収入テーブル +CREATE TABLE + incomes ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, -- 自動採番のID + name VARCHAR(255) NOT NULL, -- 名前 + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 作成日時 + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- 更新日時 + PRIMARY KEY (id) -- 主キー + ); + +-- 収支管理と収入の中間テーブル +CREATE TABLE + income_income_expenditure_managements ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + income_expenditure_id INT(10) UNSIGNED NOT NULL, + income_id INT(10) UNSIGNED NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (income_expenditure_id) REFERENCES income_expenditure_managements (id) ON DELETE CASCADE, + FOREIGN KEY (income_id) REFERENCES incomes (id) ON DELETE CASCADE + ); + +-- 棟テーブル +CREATE TABLE + buildings ( + id int(10) unsigned not null auto_increment, + name varchar(255) not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id) + ); + +-- 号棟テーブル +CREATE TABLE + building_units ( + id int(10) unsigned not null auto_increment, + building_id int(10) unsigned not null default 1, + unit_number varchar(255) not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id), + FOREIGN KEY (building_id) REFERENCES buildings (id) + ); + +-- 階テーブル +CREATE TABLE + floors ( + id int(10) unsigned not null auto_increment, + building_unit_id int(10) unsigned not null, + floor_number varchar(255) not null, + created_at datetime not null default current_timestamp, + updated_at datetime not null default current_timestamp on update current_timestamp, + PRIMARY KEY (id), + FOREIGN KEY (building_unit_id) REFERENCES building_units (id) + ); + +-- 部屋テーブル +CREATE TABLE + rooms ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + floor_id INT(10) UNSIGNED not null, + room_name varchar(255) NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (floor_id) REFERENCES floors (id) + ); + +-- roomsとteachersの中間テーブル +CREATE TABLE + room_teachers ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + room_id INT(10) unsigned not null, + teacher_id INT(10) unsigned not null, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (room_id) REFERENCES rooms (id) ON DELETE CASCADE, + FOREIGN KEY (teacher_id) REFERENCES teachers (id) ON DELETE CASCADE + ); + +-- 2025年度の企業協賛の名前を登録するようのspotのテーブル +CREATE TABLE + spot_sponsor_names ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + sponsor_name VARCHAR(255) NOT NULL, + income_expenditure_id INT(10) UNSIGNED NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (income_expenditure_id) REFERENCES income_expenditure_managements (id) ON DELETE CASCADE + ); diff --git a/mysql/seed/000001_initial_schema_seed.sql b/mysql/seed/000001_initial_schema_seed.sql new file mode 100644 index 000000000..c1bf07ead --- /dev/null +++ b/mysql/seed/000001_initial_schema_seed.sql @@ -0,0 +1,494 @@ +-- TODO: シードを整理する +use finansu_db; + +INSERT INTO + years (year) +VALUES + (2025); + +-- ユーザーを一括で挿入 +INSERT INTO + users (name, bureau_id, role_id) +VALUES + -- 一般ユーザー + ('技大太郎1', 1, 1), + -- 管理者ユーザー + ('技大太郎2', 6, 2), + -- 財務局長 + ('技大太郎3', 3, 3), + -- 財務局員 + ('技大太郎4', 3, 4); + +INSERT INTO + financial_records (name, year_id) +VALUES + ('総務局', 1), + ('渉外局', 1); + +INSERT INTO + divisions (name, financial_record_id) +VALUES + ('衛生管理部門', 1), + ('国際部門', 1), + ('広報部門', 2), + ('ゲスト部門', 2); + +INSERT INTO + festival_items (name, memo, division_id) +VALUES + ('農ポリ', '', 1), + ('養生テープ', '', 1), + ('ラミ', '', 2), + ('広報物郵送費', '', 3), + ('折込チラシ用費', '', 3), + ('ゲストブッキング費', '', 4), + ('ゲスト用菓子折り費', '', 4); + +INSERT INTO + item_budgets (amount, festival_item_id) +VALUES + (10000, 1), + (10000, 2), + (10000, 3), + (20000, 4), + (50000, 5), + (1500000, 6), + (10000, 7); + +INSERT INTO + user_groups (user_id, group_id) +VALUES + (1, 1), + (1, 2), + (2, 3); + +INSERT INTO + buy_reports (festival_item_id, amount, memo, paid_by) +VALUES + (1, 5000, '', 'テスト太郎'), + (1, 4000, '', 'テスト太郎'), + (2, 5000, '', 'テスト太郎'), + (3, 2000, '', 'テスト2太郎'), + (3, 2000, '', 'テスト2太郎'), + (3, 2000, '', 'テスト2太郎'), + (4, 10000, '', 'テスト3太郎'); + +INSERT INTO + payment_receipts (buy_report_id, bucket_name, file_name, file_type, remark) +VALUES + (1, 'payment-receipts', 'receipt-1.jpg', 'image/jpeg', ''), + (2, 'payment-receipts', 'receipt-2.jpg', 'image/jpeg', ''), + (3, 'payment-receipts', 'receipt-3.jpg', 'image/jpeg', ''); + +INSERT INTO + buy_statuses (buy_report_id, is_packed, is_settled) +VALUES + (1, TRUE, TRUE), + (2, TRUE, FALSE), + (3, TRUE, FALSE), + (4, FALSE, FALSE), + (5, FALSE, FALSE), + (6, TRUE, FALSE), + (7, FALSE, FALSE); + +INSERT INTO + income_expenditure_managements (amount, log_category, year_id, receive_option, is_checked, created_at, updated_at) +VALUES + (50000, "income", 1, "hand", FALSE, NOW(), NOW()), + (100000, "sponsor's income", 1, "transfer", FALSE, NOW(), NOW()), + (5000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), + (4000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), + (5000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), + (2000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), + (2000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), + (2000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), + (10000, "expenditure", 1, NULL, FALSE, NOW(), NOW()); + +INSERT INTO + buy_report_income_expenditure_managements (buy_report_id, income_expenditure_management_id, created_at, updated_at) +VALUES + (1, 3, NOW(), NOW()), -- buy_reports.id: 1 と income_expenditure_managements.id: 3 の対応 + (2, 4, NOW(), NOW()), -- buy_reports.id: 2 と income_expenditure_managements.id: 4 の対応 + (3, 5, NOW(), NOW()), -- buy_reports.id: 3 と income_expenditure_managements.id: 5 の対応 + (4, 6, NOW(), NOW()), -- buy_reports.id: 4 と income_expenditure_managements.id: 6 の対応 + (5, 7, NOW(), NOW()), -- buy_reports.id: 5 と income_expenditure_managements.id: 7 の対応 + (6, 8, NOW(), NOW()), -- buy_reports.id: 6 と income_expenditure_managements.id: 8 の対応 + (7, 9, NOW(), NOW()); + +INSERT INTO + activities (user_id, is_done, sponsor_id, feature, expense, remark, design, url) +VALUES + (1, false, 1, "なし", 11, "", 1, ""), + (2, false, 2, "クーポン", 22, "味玉or大盛無料", 1, ""); + +INSERT INTO + activity_styles (activity_id, sponsor_style_id) +VALUES + (1, 1), + (2, 2), + (1, 2), + (2, 1); + +INSERT INTO + bureaus (name) +VALUES + ('総務局'), + ('渉外局'), + ('財務局'), + ('企画局'), + ('制作局'), + ('情報局'); + +INSERT INTO + departments (name) +VALUES + ('電気電子情報'), + ('物質生物'), + ('機械創造'), + ('環境社会基盤'), + ('情報・経営システム'), + ('基盤共通教育'), + ('原子力システム安全'), + ('技術科学イノベーション'), + ('システム安全'), + ('技術支援'), + ('その他'), + ('学長・事務'), + ('FL'); + +INSERT INTO + fund_informations (user_id, teacher_id, price, remark, is_first_check, is_last_check, received_at) +VALUES + (1, 1, 2000, "nothing", false, false, '2023-02-22'), + (2, 2, 2000, "nothing", false, false, '2022-02-22'); + +INSERT INTO + mail_auth (email, password, user_id) +VALUES + ("test1@example.com", "$2a$10$vtmStGYxc8/HdhBYJWyztOMrdpw1QaKxsuGdi72i8iqeyp.1997ke", 1), + ("test2@example.com", "$2a$10$vtmStGYxc8/HdhBYJWyztOMrdpw1QaKxsuGdi72i8iqeyp.1997ke", 2), + ("test3@example.com", "$2a$10$vtmStGYxc8/HdhBYJWyJWyztOMrdpw1QaKxsuGdi72i8iqeyp.1997ke", 3), + ("test4@example.com", "$2a$10$vtmStGYxc8/HdhBYJWyztOMrdpw1QaKxsuGdi72i8iqeyp.1997ke", 4); + +INSERT INTO + roles (name) +VALUES + ('user'), + ('admin'), + ('Finance Director'), + ('Finance Staff'); + +INSERT INTO + sponsor_styles (style, feature, price) +VALUES + ('8分の1', 'モノクロ', 3000), + ('8分の1', 'カラー', 5000), + ('4分の1', 'モノクロ', 8000), + ('4分の1', 'カラー', 10000), + ('2分の1', 'モノクロ', 12000), + ('2分の1', 'カラー', 15000), + ('1ページ', 'モノクロ', 20000), + ('2ページ', 'カラー', 30000), + ('企業ブース', 'なし', 30000); + +INSERT INTO + teachers (name, position, department_id, room, is_black, remark) +VALUES + ('test-name', 'test-position', 1, '605', false, 'test-remark'), + ('test-teacher', 'test-position2', 1, '605', false, 'test-remark'); + +INSERT INTO + teachers (name, position, department_id, room, is_black, remark) +VALUES + ('小野 浩司', '教授', 1, '電気棟-602', false, ''), + ('岩橋 政宏', '教授', 1, '電気棟-510', false, ''), + ('木村 宗弘', '教授', 1, '電気棟-607', false, ''), + ('大石 潔', '教授', 1, '実験実習2号棟情報システム実験室', false, ''), + ('三浦 友史', '教授', 1, '電気棟-403', false, ''), + ('坪根 正', '教授', 1, '電気棟-306', false, ''), + ('田中 久仁彦', '教授', 1, '電気2号棟-452', false, ''), + ('宮崎 敏昌', '教授', 1, '電気2号棟-374', false, ''), + ('岡元 智一郎', '准教授', 1, '電気棟-401', false, ''), + ('圓道 知博', '准教授', 1, '電気棟-610', false, ''), + ('杉田 泰則', '准教授', 1, '電気棟-503', false, ''), + ('鵜沼 毅也', '准教授', 1, '電気棟-502', false, ''), + ('佐々木 友之', '准教授', 1, '電気棟-604', false, ''), + ('玉山 泰宏', '准教授', 1, '電気棟-402', false, ''), + ('南部 功夫', '准教授', 1, '電気棟-606', false, ''), + ('和田森 直', '助教', 1, '電気2号棟-233', false, ''), + ('横倉 勇希', '助教授', 1, '実験実習2号棟-115', false, ''), + ('高橋 一匡', '助教', 1, '原子力棟-401', false, ''), + ('白清 学', '助教', 1, '情報処理センター102', false, ''), + ('渡部 康平', '准教授', 1, '電気棟-316', false, ''), + ('坂本 盛嗣', '准教授', 1, '電気2号棟-669', false, ''), + ('原川 良介', '助教', 1, '電気2号棟-554', false, ''), + ('眞田 亜紀子', '准教授', 1, '電気1号棟-302', false, ''), + ('日高 勇気', '准教授', 1, '電気1号棟-505', false, ''), + ('LE THI TINH MINH', '准教授', 1, '', false, ''), + ('TRAN PHUONG THAO', '助教', 1, '実験実習2号棟120', false, ''), + ('圓山 由子', '助教', 1, '電気2号棟-659', false, ''), + ('金井 綾香', '助教', 1, '電気2号棟-451', false, ''), + ('渡辺 大貴', '助教', 1, '', false, ''), + ('滝本 浩一', '教授', 2, '生物棟-656', false, ''), + ('政井 英司', '教授', 2, '生物棟-353', false, ''), + ('城所 俊一', '教授', 2, '生物棟-756', false, ''), + ('本多 元', '教授', 2, '生物棟-657', false, ''), + ('高橋 祥司', '教授', 2, '生物棟-668', false, ''), + ('志田 洋介', '准教授', 2, '生物棟-357', false, ''), + ('木村 悟隆', '准教授', 2, '生物棟-554', false, ''), + ('高原 美規', '准教授', 2, '生物棟-557', false, ''), + ('霜田 靖', '准教授', 2, '生物棟-753', false, ''), + ('佐藤 武史', '准教授', 2, '生物棟-556', false, ''), + ('山本 麻希', '准教授', 2, '生物棟-255', false, ''), + ('西村 泰介', '准教授', 2, '生物棟-755', false, ''), + ('笠井 大輔', '准教授', 2, '生物棟-351', false, ''), + ('桑原 敬司', '准教授', 2, '生物棟-257', false, ''), + ('藤原 郁子', '准教授', 2, '生物棟-656', false, ''), + ('上村 直史', '准教授', 2, '生物棟-367', false, ''), + ('内山 尚志', '助教', 2, '生物棟-563', false, ''), + ('早乙女 友規', '助教', 2, '生物棟-756', false, ''), + ('斎藤 秀俊', '教授', 2, '物材経情棟-428', false, ''), + ('竹中 克彦', '教授', 2, '物材経情棟-326', false, ''), + ('前川 博史', '教授', 2, '物材経情棟-329', false, ''), + ('石橋 隆幸', '教授', 2, '物材経情棟-423', false, ''), + ('今久保 達郎', '教授', 2, '物材経情棟-524', false, ''), + ('梅田 実', '教授', 2, '物材経情棟-523', false, ''), + ('河原 成元', '教授', 2, '物材経情棟-327', false, ''), + ('伊藤 治彦', '准教授', 2, '物材経情棟-530', false, ''), + ('内田 希', '准教授', 2, '物材経情2号棟-430', false, ''), + ('齊藤 信雄', '准教授', 2, '分析計測センター209', false, ''), + ('本間 剛', '准教授', 2, '物材経情棟-424', false, ''), + ('高橋 由紀子', '准教授', 2, '環境棟-464', false, ''), + ('多賀谷 基博', '准教授', 2, '物材経情棟-525', false, ''), + ('白仁田 沙代子', '准教授', 2, '物材経情棟-215', false, ''), + ('西川 雅美', '准教授', 2, '環境棟-465', false, ''), + ('船津 麻美', '准教授', 2, '環境棟-466', false, ''), + ('小松 啓志', '助教', 2, '物材経情棟-522', false, ''), + ('戸田 智之', '助教', 2, '物材経情棟-522', false, ''), + ('シリポーン タオガァオ', '助教', 2, '物材経情棟-522', false, ''), + ('松田 翔風', '助教', 2, '物材経情棟-522', false, ''), + ('張 田原', '助教', 2, '物財経情棟-427', false, ''), + ('明田川 正人', '教授', 3, '機械・建設棟-508', false, ''), + ('井原 郁夫', '教授', 3, '機械・建設棟-503', false, ''), + ('高橋 勉', '教授', 3, '機械・建設棟-601', false, ''), + ('太田 浩之', '教授', 3, '機械・建設棟-506', false, ''), + ('武田 雅敏', '教授', 3, '機械・建設棟-509', false, ''), + ('上村 靖司', '教授', 3, '機械・建設棟-407', false, ''), + ('南口 誠', '教授', 3, '機械・建設棟-302', false, ''), + ('木村 哲也', '教授', 3, '機械・建設棟-308', false, ''), + ('磯部 浩巳', '教授', 3, '機械・建設棟-603', false, ''), + ('小林 泰秀', '准教授', 3, '機械・建設棟-405', false, ''), + ('宮下 幸雄', '教授', 3, '機械・建設棟-304', false, ''), + ('本間 智之', '准教授', 3, '機械・建設棟-501', false, ''), + ('倉橋 貴彦', '准教授', 3, '機械・建設棟-608', false, ''), + ('勝身 俊之', '准教授', 3, '機械・建設棟-602', false, ''), + ('會田 英雄', '准教授', 3, '機械・建設棟-607', false, ''), + ('鈴木 正太郎', '准教授', 3, '機械・建設棟-604', false, ''), + ('庄司 観', '准教授', 3, '機械・建設棟-408', false, ''), + ('溝尻 瑞枝', '准教授', 3, '機械・建設棟-401', false, ''), + ('韋 冬', '准教授', 3, '機械・建設棟-404', false, ''), + ('NGUYEN THI PHUONG MAI ', '准教授', 3, '機械・建設棟-', false, ''), + ('山下 健', '助教', 3, '機械・建設棟‐2号568', false, ''), + ('梅本 和希', '助教', 3, '機械・建設棟-2号568‐B', false, ''), + ('馬場 将亮', '助教', 3, '機械・建設棟-2号574', false, ''), + ('横田 和哉', '助教', 3, '機械・建設棟-2号572', false, ''), + ('原 圭祐', '助教', 3, '機械・建設棟-1号610', false, ''), + ('郭 妍伶', '助教', 3, '機械・建設棟-369', false, ''), + ('陸 旻皎', '教授', 4, '環境棟-653', false, ''), + ('細山田 得三', '教授', 4, '機械・建設棟-807', false, ''), + ('池田 隆明', '教授', 4, '機械・建設棟-805', false, ''), + ('豊田 浩史', '教授', 4, '機械・建設棟-705', false, ''), + ('高橋 修', '教授', 4, '機械・建設棟-704', false, ''), + ('下村 匠', '教授', 4, '機械・建設棟-703', false, ''), + ('岩崎 英治', '教授', 4, '機械・建設棟-701', false, ''), + ('佐野 可寸志', '教授', 4, '環境棟-366/原子力棟411', false, ''), + ('小松 俊哉', '准教授', 4, '環境棟-554', false, ''), + ('熊倉 俊郎', '准教授', 4, '環境棟-652', false, ''), + ('高橋 一義', '准教授', 4, '環境棟-654', false, ''), + ('宮下 剛', '准教授', 4, '機械・建設棟-706', false, ''), + ('松田 曜子', '准教授', 4, '環境棟-651', false, ''), + ('犬飼 直之', '准教授', 4, '機械・建設棟-801', false, ''), + ('松川 寿也', '助教授', 4, '環境棟-364', false, ''), + ('中村 文則', '准教授', 4, '機械・建設棟-708', false, ''), + ('福元 豊', '准教授', 4, '機械・建設棟-804', false, ''), + ('幡本 将史', '准教授', 4, '環境棟-569', false, ''), + ('楊 宏選', '助教', 4, '環境棟-659', false, ''), + ('渡利 高大', '助教授', 4, '環境棟-571', false, ''), + ('坂田 健太', '助手', 4, '環境棟-655', false, ''), + ('高橋 貴生', '助教授', 4, '環境棟-367', false, ''), + ('加藤 哲平', '講師', 4, '物材経情棟-365', false, ''), + ('李 志東', '教授', 5, '物材経情棟-302', false, ''), + ('塩野谷 明', '教授', 5, '体育保健センター-108', false, ''), + ('野村 収作', '教授', 5, '機械・建設3号棟-534', false, ''), + ('秋元 頼孝', '准教授', 5, '物材経情棟-304', false, ''), + ('羽山 徹彩', '教授', 5, '総合研究棟‐408', false, ''), + ('伊藤 喜浩', '教授', 5, '総合研究棟‐305', false, ''), + ('綿引 宣道', '教授', 5, '総合研究棟‐303', false, 'メールアポ必須'), + ('西山 雄大', '教授', 5, '総合研究棟-603', false, ''), + ('大村 哲臣', '教授', 5, '', false, '居室不明'), + ('鈴木 信貴', '准教授', 5, '物材経情棟-402', false, ''), + ('大橋 智志', '准教授', 5, '物材経情棟-403', false, ''), + ('白川 智弘', '准教授', 5, '物材経情棟-404', false, ''), + ('中平 勝子', '准教授', 5, '語学センター棟‐212', false, '居室不明'), + ('吉田 富美男', '助教', 5, '機械・建設3号棟-539', false, ''), + ('鈴木 泉', '助教', 5, '総合研究棟-407', false, ''), + ('畦原 宗之', '助教', 5, '総合研究棟-406', false, ''), + ('永森 正仁', '助教', 5, '総合研究棟-506', false, ''), + ('安藤 雅洋', '助教', 5, 'マルチメディアセンター-201', false, ''), + ('高橋 光子', '教授', 6, '物材情経棟-504', false, ''), + ('原 信一郎', '教授', 6, '環境棟-267', false, ''), + ('加藤 有行', '教授', 6, '電気1号棟-303', false, ''), + ('若林 敦', '教授', 6, '物質材開棟-503', false, ''), + ('松原 浩', '教授', 6, '物材経情棟-308', false, ''), + ('加納 満', '准教授', 6, '物材経情棟-307', false, ''), + ('リー 飯塚 尚子', '准教授', 6, '物質材開棟-306', false, ''), + ('伊藤 敦美', '准教授', 6, '物材経情棟-509', false, ''), + ('藤井 数馬', '准教授', 6, '物材経情棟-507', false, ''), + ('山本 謙一郎', '准教授', 6, '環境棟-268', false, ''), + ('重田 謙', '准教授', 6, '物材経情棟-', false, ''), + ('永野 建二郎', '講師', 6, '物材経情棟-310', false, ''), + ('五十嵐 啓太', '講師', 6, '物材経情棟-506', false, ''), + ('山口 勇気', '講師', 6, '機械建設1号棟-505', false, ''), + ('片野 洋平', '講師', 6, '物材経情棟-309', false, ''), + ('ドライアー ブライアン', '助教', 6, '物材経情棟-508', false, ''), + ('江 偉華', '教授', 7, '極限-粒子棟201', false, ''), + ('末松 久幸', '教授', 7, '極限-粒子棟203', false, ''), + ('鈴木 達也', '教授', 7, '原子力安全・シス安棟-412', false, ''), + ('大塚 悟', '教授', 7, '機械・建設棟-802', false, ''), + ('菊池 崇志', '准教授', 7, '原子力安全・シス安棟-409', false, ''), + ('鈴木 常生', '准教授', 7, '原子力安全・シス安棟-410', false, ''), + ('村上 健太', '准教授', 7, '原子力安全・シス安棟-310', false, ''), + ('大場 恭子', '准教授', 7, '原子力安全・シス安棟-312', false, ''), + ('竹澤 宏樹', '准教授', 7, '原子力安全・シス安棟-313', false, ''), + ('太田 朋子', '准教授', 7, '原子力安全・シス安棟-508', false, ''), + ('松本 義伸', '助教', 7, 'ラジオアイソトープセンター 101', false, ''), + ('須貝 太一', '助教', 7, '極限棟-201', false, ''), + ('立花 優', '助教授', 7, '原子力安全・シス安棟-311', false, ''), + ('ドウ テイ マイ ズン', '助教授', 7, '原子力安全・シス安棟-205', false, ''), + ('VLAD CRISTIAN IULIAN', '教授', 8, '', false, '居室不明'), + ('中川 匡弘', '教授', 8, '電気棟-609/3号棟外プレハブ カオス・フラクタル研究室', false, ''), + ('小林 高臣', '教授', 8, '物材経情棟-526', false, ''), + ('改田 哲也', '教授', 8, '博士棟-358', false, ''), + ('小笠原 渉', '教授', 8, '生物棟-371', false, ''), + ('山田 昇', '教授', 8, '機械・建設棟-507', false, ''), + ('中山 忠親', '教授', 8, '極限-粒子棟-202', false, ''), + ('伊東 淳一', '教授', 8, '電気棟-407', false, ''), + ('山口 隆司', '教授', 8, '環境棟-570', false, ''), + ('湯川 高志', '教授', 8, '総合研究棟-510', false, ''), + ('山崎 渉', '准教授', 8, '機械・建設棟-603', false, ''), + ('牧 慎也', '准教授', 8, '機械・建設1号棟-807', false, ''), + ('姫野 修司', '准教授', 8, '環境棟-553', false, ''), + ('佐々木 徹', '准教授', 8, '環境棟-304', false, ''), + ('大沼 清', '准教授', 8, '生物棟-560', false, ''), + ('田中 諭', '准教授', 8, '物材2号棟-429', false, ''), + ('門脇 敏', '教授', 9, '機械・建設棟-502', false, ''), + ('三好 孝典', '教授', 9, '原子力安全・シス安棟-614', false, ''), + ('阿部 雅二郎', '教授', 9, '機械・建設1号棟-504', false, ''), + ('木村 哲也', '教授', 9, '機械・建設棟-308', false, ''), + ('山形 浩史', '教授', 9, '原子力安全・シス安棟-612', false, ''), + ('大塚 雄市', '准教授', 9, '原子力安全・シス安棟-562', false, ''), + ('北條 理恵子', '准教授', 9, '原子力安全・シス安棟609', false, ''), + ('張 坤', '准教授', 9, '原子力安全・シス安棟-613', false, ''), + ('吉田 昌弘', '技術職員', 10, '機械・建設棟-314', false, ''), + ('安部 真', '技術職員', 10, '機械・建設2号棟-370', false, ''), + ('山田 修一', '技術職員', 10, '原子力安全・シス安棟-511', false, ''), + ('吉井 一夫', '技術職員', 10, '工作センター103', false, ''), + ('山本 浩', '技術職員', 10, '機械・建設3号棟-240', false, ''), + ('高田 晋', '技術職員', 10, '建設大型実験棟-205', false, ''), + ('高橋 智', '技術職員', 10, '機械・建設2号棟-663', false, ''), + ('渡邉 高子', '技術職員', 10, '環境棟-569', false, ''), + ('中村 健', '技術職員', 10, '機械・建設1号棟-712', false, ''), + ('豊田 英之', '技術職員', 10, '電気2号棟-471', false, ''), + ('山口 貴幸', '技術職員', 10, '大型実験棟-203', false, ''), + ('田中 徹', '技術職員', 10, '実験実習2号棟118', false, ''), + ('志田 暁雄', '技術職員', 10, '極限-極限棟201W', false, ''), + ('佐藤 賢太', '技術職員', 10, '工作センター103', false, ''), + ('小池 孝侑', '技術職員', 10, '工作センター103', false, ''), + ('河原 夏江', '技術職員', 10, '物材経情棟-2号562', false, ''), + ('高橋 美幸', '技術職員', 10, '分析計測センター-118', false, ''), + ('小杉 健一郎', '技術職員', 10, '分析計測センター-118', false, ''), + ('高柳 充寛', '技術職員', 10, '生物棟-565', false, ''), + ('野田 浩平', '技術職員', 10, '電気2号棟-666', false, ''), + ('山浦 賢太郎', '技術職員', 10, '電気2号棟-569', false, ''), + ('近藤 みずき', '技術職員', 10, '生物棟-258', false, ''), + ('草野 利樹', '技術職員', 10, '', false, '居室不明'), + ('上野 悠一', '技術職員', 10, '', false, '居室不明'), + ('中山 佳子', '技術職員', 10, '環境棟-155', false, ''), + ('山下 智樹', '特任准教授', 11, '', false, '居室不明'), + ('日下 佳祐', '特任講師', 11, '実験実習1号棟-110', false, ''), + ('藤沢 慶', '特任講師', 11, '機械建設1号棟-606', false, ''), + ('中田 大貴', '特任講師', 11, '機械建設2号棟-457', false, ''), + ('鎌土 重晴', '学長', 12, '学長室/機械・建設棟-306', false, '秘書へアポ'), + ('和田 安弘', '副学長', 12, '電気棟-608', false, ''), + ('秋山 和男', '理事・事務局長', 12, '理事室', false, ''), + ('梅田 実', '副学長', 12, '実験実習2号棟-情報システム実験室', false, ''), + ('学生支援課', '事務', 12, '', false, ''), + ('学務課', '事務', 12, '', false, ''), + ('国際課', '事務', 12, '', false, ''), + ('総務課', '事務', 12, '', false, ''), + ('財務課', '事務', 12, '', false, ''), + ('研究・地域連携課', '事務', 12, '', false, ''), + ('入試課', '事務', 12, '', false, ''), + ('総合情報課', '事務', 12, '', false, ''), + ('施設課', '事務', 12, '', false, ''), + ('大学戦略課(3F)', '事務', 12, '', false, ''), + ('大学戦略課(2F)', '事務', 12, '', false, ''), + ('電気系', '系事務室', 12, '', false, ''), + ('物質・材料・経営情報系', '系事務室', 12, '', false, ''), + ('機械・建設事務室', '系事務室', 12, '', false, ''), + ('生物系', '系事務室', 12, '', false, ''), + ('環境事務室', '系事務室', 12, '', false, ''), + ('芳賀 仁', '助教', 12, '電気2号棟-364', false, '同窓会代表。局長が挨拶へ。学内募金は毎回断っている'); + +INSERT INTO + year_periods (year_id, started_at, ended_at) +VALUES + (1, '2024-11-15 00:00:00', '2025-11-15 00:00:00'); + +INSERT INTO + incomes (name, created_at, updated_at) +VALUES + ("教育振興会費", NOW(), NOW()), + ("学内募金", NOW(), NOW()), + ("同窓会費", NOW(), NOW()), + ("雑収入", NOW(), NOW()), + ("繰越金", NOW(), NOW()), + ("企業協賛金", NOW(), NOW()); + +INSERT INTO + buildings (name) +VALUES + ('機械・建設棟'), + ('電気棟'), + ('生物棟'), + ('環境・システム棟'), + ('物質・材料経営情報棟'), + ('総合研究棟'), + ('原子力・システム安全棟'), + ('事務局棟'), + ('極限エネルギ密度工学研究センター'), + ('工作センター'), + ('大型実験棟'), + ('分析計測センター'), + ('その他'); + +INSERT INTO + building_units (building_id, unit_number) +VALUES + (1, "1号棟"), + (1, "2号棟"), + (1, "3号棟"), + (2, "1号棟"), + (2, "2号棟"), + (3, "1号棟"), + (4, "1号棟"), + (5, "1号棟"), + (5, "2号棟"), + (6, "1号棟"), + (7, "1号棟"), + (8, "1号棟"), + (9, "1号棟"), + (10, "1号棟"), + (11, "1号棟"), + (12, "1号棟"), + (13, "1号棟"); diff --git a/scripts/create_migration.sh b/scripts/create_migration.sh new file mode 100755 index 000000000..de6f5f697 --- /dev/null +++ b/scripts/create_migration.sh @@ -0,0 +1,3 @@ +read -p "input migration name: " migration_name + +docker compose -f compose.migrate.yml run --rm migrate create -ext sql -dir /migrations -seq $migration_name diff --git a/scripts/seed.sh b/scripts/seed.sh new file mode 100644 index 000000000..900f722e2 --- /dev/null +++ b/scripts/seed.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# テーブルデータを初期化するためのSQLファイルを実行するよ〜!🐣 +{ + echo "SET FOREIGN_KEY_CHECKS = 0;" + mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -D "$MYSQL_DATABASE" --batch --silent -N \ + -e "SELECT CONCAT('TRUNCATE FROM \`', table_name, '\`;') \ + FROM information_schema.tables \ + WHERE table_schema = '${MYSQL_DATABASE}' AND table_name != 'schema_migrations';" + echo "SET FOREIGN_KEY_CHECKS = 1;" +} | mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" + +# ディレクトリのパスを指定 +SQL_DIR="../seed" + +# SQLファイルを順番に実行 +for sql_file in "$SQL_DIR"/*.sql; do + if [ -f "$sql_file" ]; then + echo "実行中: $sql_file 🚀" + mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" < "$sql_file" + if [ $? -eq 0 ]; then + echo "成功: $sql_file 🎉" + else + echo "失敗: $sql_file 😭" + fi + else + echo "SQLファイルが見つからないよ〜!ぴえん🥺" + fi +done + +echo "全てのSQLファイルの実行が完了したよ!おけまる水産🐟✨" From 9d2e24bfce565db512df497dff9f230bac5f70cc Mon Sep 17 00:00:00 2001 From: Kubosaka Date: Mon, 12 May 2025 23:38:52 +0900 Subject: [PATCH 08/21] =?UTF-8?q?Revert=20"[wip]go-migration=E5=B0=8E?= =?UTF-8?q?=E5=85=A5"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 4704f36642a0d65e49903b06a9f6c796547dc44c. --- Makefile | 21 - compose.db.yml | 8 +- compose.migrate.yml | 9 - .../migrations/000001_initial_schema.down.sql | 70 --- mysql/migrations/000001_initial_schema.up.sql | 440 ---------------- mysql/seed/000001_initial_schema_seed.sql | 494 ------------------ scripts/create_migration.sh | 3 - scripts/seed.sh | 31 -- 8 files changed, 4 insertions(+), 1072 deletions(-) delete mode 100644 compose.migrate.yml delete mode 100644 mysql/migrations/000001_initial_schema.down.sql delete mode 100644 mysql/migrations/000001_initial_schema.up.sql delete mode 100644 mysql/seed/000001_initial_schema_seed.sql delete mode 100755 scripts/create_migration.sh delete mode 100644 scripts/seed.sh diff --git a/Makefile b/Makefile index 010d84c91..49de15d6a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ # アプリコンテナ=view,api、DBコンテナ=db,minio -include finansu.env # アプリコンテナのイメージのビルド build: @@ -107,23 +106,3 @@ gen-er: format: docker compose run --rm view npm run format - -# マイグレーションの実行 -migrate: - docker compose -f compose.migrate.yml run --rm migrate \ - --path /migrations \ - --database "mysql://${NUTMEG_DB_USER}:${NUTMEG_DB_PASSWORD}@tcp(${NUTMEG_DB_HOST}:${NUTMEG_DB_PORT})/${NUTMEG_DB_NAME}" \ - up - -# マイグレーションの実行(ダウングレード) -migrate-down: - docker compose -f compose.migrate.yml run --rm migrate \ - --path /migrations \ - --database "mysql://${NUTMEG_DB_USER}:${NUTMEG_DB_PASSWORD}@tcp(${NUTMEG_DB_HOST}:${NUTMEG_DB_PORT})/${NUTMEG_DB_NAME}" \ - down - -# マイグレーションファイルの作成 -create-migration: - ./scripts/create_migration.sh - - diff --git a/compose.db.yml b/compose.db.yml index 795dfbe93..1054d8bb9 100644 --- a/compose.db.yml +++ b/compose.db.yml @@ -2,16 +2,16 @@ services: db: image: mysql:8.0 container_name: "nutfes-finansu-db" + volumes: + - ./mysql/db:/docker-entrypoint-initdb.d # 初期データ + - ./mysql/testdb:/docker-entrypoint-testdb.d # テスト用初期データ + - ./my.cnf:/etc/mysql/conf.d/my.cnf environment: MYSQL_DATABASE: finansu_db MYSQL_USER: finansu MYSQL_PASSWORD: password MYSQL_ROOT_PASSWORD: root TZ: "Asia/Tokyo" - volumes: - - ./mysql/seed:/seed # 初期データ - - ./scripts:/scripts # スクリプト - - ./my.cnf:/etc/mysql/conf.d/my.cnf ports: - "3306:3306" restart: always diff --git a/compose.migrate.yml b/compose.migrate.yml deleted file mode 100644 index 7f3c2567d..000000000 --- a/compose.migrate.yml +++ /dev/null @@ -1,9 +0,0 @@ -services: - migrate: - image: migrate/migrate:latest - container_name: "nutfes-finansu-migrate" - command: "migrate -version" - env_file: - - finansu.env - volumes: - - ./mysql/migrations:/migrations diff --git a/mysql/migrations/000001_initial_schema.down.sql b/mysql/migrations/000001_initial_schema.down.sql deleted file mode 100644 index 39dad940e..000000000 --- a/mysql/migrations/000001_initial_schema.down.sql +++ /dev/null @@ -1,70 +0,0 @@ --- テーブル削除のSQL文 -DROP TABLE IF EXISTS spot_sponsor_names; - -DROP TABLE IF EXISTS room_teachers; - -DROP TABLE IF EXISTS rooms; - -DROP TABLE IF EXISTS floors; - -DROP TABLE IF EXISTS building_units; - -DROP TABLE IF EXISTS buildings; - -DROP TABLE IF EXISTS income_income_expenditure_managements; - -DROP TABLE IF EXISTS incomes; - -DROP TABLE IF EXISTS year_periods; - -DROP TABLE IF EXISTS teachers; - -DROP TABLE IF EXISTS sponsors; - -DROP TABLE IF EXISTS sponsor_styles; - -DROP TABLE IF EXISTS session; - -DROP TABLE IF EXISTS roles; - -DROP TABLE IF EXISTS password_reset_tokens; - -DROP TABLE IF EXISTS mail_auth; - -DROP TABLE IF EXISTS fund_informations; - -DROP TABLE IF EXISTS departments; - -DROP TABLE IF EXISTS bureaus; - -DROP TABLE IF EXISTS activity_informations; - -DROP TABLE IF EXISTS sponsor_activity_balance_managements; - -DROP TABLE IF EXISTS activity_styles; - -DROP TABLE IF EXISTS activities; - -DROP TABLE IF EXISTS buy_report_income_expenditure_managements; - -DROP TABLE IF EXISTS income_expenditure_managements; - -DROP TABLE IF EXISTS buy_statuses; - -DROP TABLE IF EXISTS payment_receipts; - -DROP TABLE IF EXISTS buy_reports; - -DROP TABLE IF EXISTS user_groups; - -DROP TABLE IF EXISTS item_budgets; - -DROP TABLE IF EXISTS festival_items; - -DROP TABLE IF EXISTS divisions; - -DROP TABLE IF EXISTS financial_records; - -DROP TABLE IF EXISTS users; - -DROP TABLE IF EXISTS years; diff --git a/mysql/migrations/000001_initial_schema.up.sql b/mysql/migrations/000001_initial_schema.up.sql deleted file mode 100644 index f93e849ad..000000000 --- a/mysql/migrations/000001_initial_schema.up.sql +++ /dev/null @@ -1,440 +0,0 @@ --- 年度テーブル -CREATE TABLE - years ( - id int(10) unsigned not null auto_increment, - year int(10) not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- ユーザーテーブル -CREATE TABLE - users ( - id int(10) unsigned not null auto_increment, - name varchar(255) not null, - bureau_id int(10) not null, - role_id int(10) not null, - is_deleted boolean DEFAULT false, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- 局・予算テーブル -CREATE TABLE - financial_records ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - name VARCHAR(255) NOT NULL, - year_id INT(10) UNSIGNED NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY year_id_foreign_key (year_id) REFERENCES years (id) ON DELETE CASCADE - ); - --- 部門テーブル -CREATE TABLE - divisions ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - name VARCHAR(255) NOT NULL, - financial_record_id INT(10) UNSIGNED NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY financial_record_id_foreign_key (financial_record_id) REFERENCES financial_records (id) ON DELETE CASCADE - ); - --- 物品テーブル -CREATE TABLE - festival_items ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - name VARCHAR(255) NOT NULL, - memo VARCHAR(255), - division_id INT(10) UNSIGNED NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY division_id_foreign_key (division_id) REFERENCES divisions (id) ON DELETE CASCADE - ); - --- 予算テーブル -CREATE TABLE - item_budgets ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - amount INT(10) NOT NULL, - festival_item_id INT(10) UNSIGNED NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY festival_item_id_foreign_key (festival_item_id) REFERENCES festival_items (id) ON DELETE CASCADE - ); - --- ユーザー部門テーブル -CREATE TABLE - user_groups ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - user_id INT(10) UNSIGNED NOT NULL, - group_id INT(10) UNSIGNED NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY user_id_foreign_key (user_id) REFERENCES users (id) ON DELETE CASCADE, - FOREIGN KEY group_id_foreign_key (group_id) REFERENCES divisions (id) ON DELETE CASCADE - ); - --- 購入報告テーブル -CREATE TABLE - buy_reports ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - festival_item_id INT(10) UNSIGNED NOT NULL, - amount INT(10) NOT NULL, - memo VARCHAR(255) NOT NULL, - paid_by VARCHAR(255) NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY festival_item_id_foreign_key (festival_item_id) REFERENCES festival_items (id) ON DELETE CASCADE - ); - --- 購入レシートテーブル -CREATE TABLE - payment_receipts ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - buy_report_id INT(10) UNSIGNED NOT NULL, - bucket_name VARCHAR(255) NOT NULL, - file_name VARCHAR(255) NOT NULL, - file_type VARCHAR(255) NOT NULL, - remark VARCHAR(255), - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY buy_report_id_foreign_key (buy_report_id) REFERENCES buy_reports (id) ON DELETE CASCADE - ); - --- 購入ステータステーブル -CREATE TABLE - buy_statuses ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - buy_report_id INT(10) UNSIGNED NOT NULL, - is_packed BOOLEAN NOT NULL DEFAULT FALSE, - is_settled BOOLEAN NOT NULL DEFAULT FALSE, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY buy_report_id_foreign_key (buy_report_id) REFERENCES buy_reports (id) ON DELETE CASCADE - ); - --- 収支管理テーブル -CREATE TABLE - income_expenditure_managements ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - amount INT(10) NOT NULL, - log_category ENUM("income", "expenditure", "sponsor's income") NOT NULL, - year_id INT(10) UNSIGNED NOT NULL, - receive_option ENUM("transfer", "hand"), -- expenditureはNULLを許可する - is_checked BOOLEAN NOT NULL DEFAULT FALSE, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY year_id_foreign_key (year_id) REFERENCES years (id) ON DELETE CASCADE - ); - --- buy_reportとincome_expenditure_managementsの中間テーブル -CREATE TABLE - buy_report_income_expenditure_managements ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - buy_report_id INT(10) UNSIGNED NOT NULL, - income_expenditure_management_id INT(10) UNSIGNED NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY buy_report_id_foreign_key (buy_report_id) REFERENCES buy_reports (id) ON DELETE CASCADE, - FOREIGN KEY income_expenditure_management_id_foreign_key (income_expenditure_management_id) REFERENCES income_expenditure_managements (id) ON DELETE CASCADE - ); - --- 協賛活動テーブル -CREATE TABLE - activities ( - id int(10) unsigned not null auto_increment, - user_id int(10), - is_done boolean, - sponsor_id int(10), - feature varchar(255), - expense int(10), - remark varchar(255), - design int(10), - url varchar(255), - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- 協賛スタイル中間テーブル -CREATE TABLE - activity_styles ( - id int(10) unsigned not null auto_increment, - activity_id int(10), - sponsor_style_id int(10), - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- 協賛活動と収支管理の中間テーブル -CREATE TABLE - sponsor_activity_balance_managements ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - sponsor_activity_id INT(10) UNSIGNED NOT NULL, - income_expenditure_management_id INT(10) UNSIGNED NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY sponsor_activity_id_foreign_key (sponsor_activity_id) REFERENCES activities (id) ON DELETE CASCADE, - FOREIGN KEY income_expenditure_management_id_foreign_key (income_expenditure_management_id) REFERENCES income_expenditure_managements (id) ON DELETE CASCADE - ); - --- 協賛活動情報テーブル -CREATE TABLE - activity_informations ( - id int(10) unsigned not null auto_increment, - activity_id int(10), - bucket_name varchar(255), - file_name varchar(255), - file_type varchar(255), - design_progress int(10), - file_information varchar(255), - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- 局テーブル -CREATE TABLE - bureaus ( - id int(10) unsigned not null auto_increment, - name varchar(255) not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- 学科・分野テーブル -CREATE TABLE - departments ( - id int(10) unsigned not null auto_increment, - name varchar(255), - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- 募金テーブル -CREATE TABLE - fund_informations ( - id int(10) unsigned not null auto_increment, - user_id int(10) not null, - teacher_id int(10) not null, - price int(10) not null, - remark varchar(255), - is_first_check boolean, - is_last_check boolean, - received_at varchar(255) not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- メール認証テーブル -CREATE TABLE - mail_auth ( - id int(10) unsigned not null unique auto_increment, - email varchar(255) unique, - password varchar(255) not null, - user_id int(10) not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- パスワードリセットトークンテーブル -CREATE TABLE - password_reset_tokens ( - id int(10) unsigned not null unique auto_increment, - user_id int(10) not null, - token varchar(255) not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- ユーザーロールテーブル -CREATE TABLE - roles ( - id int(10) unsigned not null auto_increment, - name varchar(255) not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- セッションテーブル -CREATE TABLE - session ( - id int(10) unsigned not null unique auto_increment, - auth_id int(10) not null, - user_id int(10) not null, - access_token varchar(255) not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (auth_id) - ); - --- 協賛スタイルテーブル -CREATE TABLE - sponsor_styles ( - id int(10) unsigned not null auto_increment, - style varchar(255) not null, - feature varchar(255) not null, - price int(10), - is_deleted boolean default false, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- 協賛企業テーブル -CREATE TABLE - sponsors ( - id int(10) unsigned not null auto_increment, - name varchar(255) not null, - tel varchar(255) not null, - email varchar(255) not null, - address varchar(255) not null, - representative varchar(255) not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- 教員テーブル -CREATE TABLE - teachers ( - id int(10) unsigned not null auto_increment, - name varchar(255) not null, - position varchar(255) not null, - department_id int(10), - room varchar(255), - is_black boolean, - remark varchar(255), - is_deleted boolean default false, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- 年度期間テーブル -CREATE TABLE - year_periods ( - id int(10) unsigned not null auto_increment, - year_id int(10) not null, - started_at datetime not null, - ended_at datetime not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- 収入テーブル -CREATE TABLE - incomes ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, -- 自動採番のID - name VARCHAR(255) NOT NULL, -- 名前 - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 作成日時 - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- 更新日時 - PRIMARY KEY (id) -- 主キー - ); - --- 収支管理と収入の中間テーブル -CREATE TABLE - income_income_expenditure_managements ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - income_expenditure_id INT(10) UNSIGNED NOT NULL, - income_id INT(10) UNSIGNED NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (income_expenditure_id) REFERENCES income_expenditure_managements (id) ON DELETE CASCADE, - FOREIGN KEY (income_id) REFERENCES incomes (id) ON DELETE CASCADE - ); - --- 棟テーブル -CREATE TABLE - buildings ( - id int(10) unsigned not null auto_increment, - name varchar(255) not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id) - ); - --- 号棟テーブル -CREATE TABLE - building_units ( - id int(10) unsigned not null auto_increment, - building_id int(10) unsigned not null default 1, - unit_number varchar(255) not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id), - FOREIGN KEY (building_id) REFERENCES buildings (id) - ); - --- 階テーブル -CREATE TABLE - floors ( - id int(10) unsigned not null auto_increment, - building_unit_id int(10) unsigned not null, - floor_number varchar(255) not null, - created_at datetime not null default current_timestamp, - updated_at datetime not null default current_timestamp on update current_timestamp, - PRIMARY KEY (id), - FOREIGN KEY (building_unit_id) REFERENCES building_units (id) - ); - --- 部屋テーブル -CREATE TABLE - rooms ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - floor_id INT(10) UNSIGNED not null, - room_name varchar(255) NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (floor_id) REFERENCES floors (id) - ); - --- roomsとteachersの中間テーブル -CREATE TABLE - room_teachers ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - room_id INT(10) unsigned not null, - teacher_id INT(10) unsigned not null, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (room_id) REFERENCES rooms (id) ON DELETE CASCADE, - FOREIGN KEY (teacher_id) REFERENCES teachers (id) ON DELETE CASCADE - ); - --- 2025年度の企業協賛の名前を登録するようのspotのテーブル -CREATE TABLE - spot_sponsor_names ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - sponsor_name VARCHAR(255) NOT NULL, - income_expenditure_id INT(10) UNSIGNED NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (income_expenditure_id) REFERENCES income_expenditure_managements (id) ON DELETE CASCADE - ); diff --git a/mysql/seed/000001_initial_schema_seed.sql b/mysql/seed/000001_initial_schema_seed.sql deleted file mode 100644 index c1bf07ead..000000000 --- a/mysql/seed/000001_initial_schema_seed.sql +++ /dev/null @@ -1,494 +0,0 @@ --- TODO: シードを整理する -use finansu_db; - -INSERT INTO - years (year) -VALUES - (2025); - --- ユーザーを一括で挿入 -INSERT INTO - users (name, bureau_id, role_id) -VALUES - -- 一般ユーザー - ('技大太郎1', 1, 1), - -- 管理者ユーザー - ('技大太郎2', 6, 2), - -- 財務局長 - ('技大太郎3', 3, 3), - -- 財務局員 - ('技大太郎4', 3, 4); - -INSERT INTO - financial_records (name, year_id) -VALUES - ('総務局', 1), - ('渉外局', 1); - -INSERT INTO - divisions (name, financial_record_id) -VALUES - ('衛生管理部門', 1), - ('国際部門', 1), - ('広報部門', 2), - ('ゲスト部門', 2); - -INSERT INTO - festival_items (name, memo, division_id) -VALUES - ('農ポリ', '', 1), - ('養生テープ', '', 1), - ('ラミ', '', 2), - ('広報物郵送費', '', 3), - ('折込チラシ用費', '', 3), - ('ゲストブッキング費', '', 4), - ('ゲスト用菓子折り費', '', 4); - -INSERT INTO - item_budgets (amount, festival_item_id) -VALUES - (10000, 1), - (10000, 2), - (10000, 3), - (20000, 4), - (50000, 5), - (1500000, 6), - (10000, 7); - -INSERT INTO - user_groups (user_id, group_id) -VALUES - (1, 1), - (1, 2), - (2, 3); - -INSERT INTO - buy_reports (festival_item_id, amount, memo, paid_by) -VALUES - (1, 5000, '', 'テスト太郎'), - (1, 4000, '', 'テスト太郎'), - (2, 5000, '', 'テスト太郎'), - (3, 2000, '', 'テスト2太郎'), - (3, 2000, '', 'テスト2太郎'), - (3, 2000, '', 'テスト2太郎'), - (4, 10000, '', 'テスト3太郎'); - -INSERT INTO - payment_receipts (buy_report_id, bucket_name, file_name, file_type, remark) -VALUES - (1, 'payment-receipts', 'receipt-1.jpg', 'image/jpeg', ''), - (2, 'payment-receipts', 'receipt-2.jpg', 'image/jpeg', ''), - (3, 'payment-receipts', 'receipt-3.jpg', 'image/jpeg', ''); - -INSERT INTO - buy_statuses (buy_report_id, is_packed, is_settled) -VALUES - (1, TRUE, TRUE), - (2, TRUE, FALSE), - (3, TRUE, FALSE), - (4, FALSE, FALSE), - (5, FALSE, FALSE), - (6, TRUE, FALSE), - (7, FALSE, FALSE); - -INSERT INTO - income_expenditure_managements (amount, log_category, year_id, receive_option, is_checked, created_at, updated_at) -VALUES - (50000, "income", 1, "hand", FALSE, NOW(), NOW()), - (100000, "sponsor's income", 1, "transfer", FALSE, NOW(), NOW()), - (5000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), - (4000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), - (5000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), - (2000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), - (2000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), - (2000, "expenditure", 1, NULL, FALSE, NOW(), NOW()), - (10000, "expenditure", 1, NULL, FALSE, NOW(), NOW()); - -INSERT INTO - buy_report_income_expenditure_managements (buy_report_id, income_expenditure_management_id, created_at, updated_at) -VALUES - (1, 3, NOW(), NOW()), -- buy_reports.id: 1 と income_expenditure_managements.id: 3 の対応 - (2, 4, NOW(), NOW()), -- buy_reports.id: 2 と income_expenditure_managements.id: 4 の対応 - (3, 5, NOW(), NOW()), -- buy_reports.id: 3 と income_expenditure_managements.id: 5 の対応 - (4, 6, NOW(), NOW()), -- buy_reports.id: 4 と income_expenditure_managements.id: 6 の対応 - (5, 7, NOW(), NOW()), -- buy_reports.id: 5 と income_expenditure_managements.id: 7 の対応 - (6, 8, NOW(), NOW()), -- buy_reports.id: 6 と income_expenditure_managements.id: 8 の対応 - (7, 9, NOW(), NOW()); - -INSERT INTO - activities (user_id, is_done, sponsor_id, feature, expense, remark, design, url) -VALUES - (1, false, 1, "なし", 11, "", 1, ""), - (2, false, 2, "クーポン", 22, "味玉or大盛無料", 1, ""); - -INSERT INTO - activity_styles (activity_id, sponsor_style_id) -VALUES - (1, 1), - (2, 2), - (1, 2), - (2, 1); - -INSERT INTO - bureaus (name) -VALUES - ('総務局'), - ('渉外局'), - ('財務局'), - ('企画局'), - ('制作局'), - ('情報局'); - -INSERT INTO - departments (name) -VALUES - ('電気電子情報'), - ('物質生物'), - ('機械創造'), - ('環境社会基盤'), - ('情報・経営システム'), - ('基盤共通教育'), - ('原子力システム安全'), - ('技術科学イノベーション'), - ('システム安全'), - ('技術支援'), - ('その他'), - ('学長・事務'), - ('FL'); - -INSERT INTO - fund_informations (user_id, teacher_id, price, remark, is_first_check, is_last_check, received_at) -VALUES - (1, 1, 2000, "nothing", false, false, '2023-02-22'), - (2, 2, 2000, "nothing", false, false, '2022-02-22'); - -INSERT INTO - mail_auth (email, password, user_id) -VALUES - ("test1@example.com", "$2a$10$vtmStGYxc8/HdhBYJWyztOMrdpw1QaKxsuGdi72i8iqeyp.1997ke", 1), - ("test2@example.com", "$2a$10$vtmStGYxc8/HdhBYJWyztOMrdpw1QaKxsuGdi72i8iqeyp.1997ke", 2), - ("test3@example.com", "$2a$10$vtmStGYxc8/HdhBYJWyJWyztOMrdpw1QaKxsuGdi72i8iqeyp.1997ke", 3), - ("test4@example.com", "$2a$10$vtmStGYxc8/HdhBYJWyztOMrdpw1QaKxsuGdi72i8iqeyp.1997ke", 4); - -INSERT INTO - roles (name) -VALUES - ('user'), - ('admin'), - ('Finance Director'), - ('Finance Staff'); - -INSERT INTO - sponsor_styles (style, feature, price) -VALUES - ('8分の1', 'モノクロ', 3000), - ('8分の1', 'カラー', 5000), - ('4分の1', 'モノクロ', 8000), - ('4分の1', 'カラー', 10000), - ('2分の1', 'モノクロ', 12000), - ('2分の1', 'カラー', 15000), - ('1ページ', 'モノクロ', 20000), - ('2ページ', 'カラー', 30000), - ('企業ブース', 'なし', 30000); - -INSERT INTO - teachers (name, position, department_id, room, is_black, remark) -VALUES - ('test-name', 'test-position', 1, '605', false, 'test-remark'), - ('test-teacher', 'test-position2', 1, '605', false, 'test-remark'); - -INSERT INTO - teachers (name, position, department_id, room, is_black, remark) -VALUES - ('小野 浩司', '教授', 1, '電気棟-602', false, ''), - ('岩橋 政宏', '教授', 1, '電気棟-510', false, ''), - ('木村 宗弘', '教授', 1, '電気棟-607', false, ''), - ('大石 潔', '教授', 1, '実験実習2号棟情報システム実験室', false, ''), - ('三浦 友史', '教授', 1, '電気棟-403', false, ''), - ('坪根 正', '教授', 1, '電気棟-306', false, ''), - ('田中 久仁彦', '教授', 1, '電気2号棟-452', false, ''), - ('宮崎 敏昌', '教授', 1, '電気2号棟-374', false, ''), - ('岡元 智一郎', '准教授', 1, '電気棟-401', false, ''), - ('圓道 知博', '准教授', 1, '電気棟-610', false, ''), - ('杉田 泰則', '准教授', 1, '電気棟-503', false, ''), - ('鵜沼 毅也', '准教授', 1, '電気棟-502', false, ''), - ('佐々木 友之', '准教授', 1, '電気棟-604', false, ''), - ('玉山 泰宏', '准教授', 1, '電気棟-402', false, ''), - ('南部 功夫', '准教授', 1, '電気棟-606', false, ''), - ('和田森 直', '助教', 1, '電気2号棟-233', false, ''), - ('横倉 勇希', '助教授', 1, '実験実習2号棟-115', false, ''), - ('高橋 一匡', '助教', 1, '原子力棟-401', false, ''), - ('白清 学', '助教', 1, '情報処理センター102', false, ''), - ('渡部 康平', '准教授', 1, '電気棟-316', false, ''), - ('坂本 盛嗣', '准教授', 1, '電気2号棟-669', false, ''), - ('原川 良介', '助教', 1, '電気2号棟-554', false, ''), - ('眞田 亜紀子', '准教授', 1, '電気1号棟-302', false, ''), - ('日高 勇気', '准教授', 1, '電気1号棟-505', false, ''), - ('LE THI TINH MINH', '准教授', 1, '', false, ''), - ('TRAN PHUONG THAO', '助教', 1, '実験実習2号棟120', false, ''), - ('圓山 由子', '助教', 1, '電気2号棟-659', false, ''), - ('金井 綾香', '助教', 1, '電気2号棟-451', false, ''), - ('渡辺 大貴', '助教', 1, '', false, ''), - ('滝本 浩一', '教授', 2, '生物棟-656', false, ''), - ('政井 英司', '教授', 2, '生物棟-353', false, ''), - ('城所 俊一', '教授', 2, '生物棟-756', false, ''), - ('本多 元', '教授', 2, '生物棟-657', false, ''), - ('高橋 祥司', '教授', 2, '生物棟-668', false, ''), - ('志田 洋介', '准教授', 2, '生物棟-357', false, ''), - ('木村 悟隆', '准教授', 2, '生物棟-554', false, ''), - ('高原 美規', '准教授', 2, '生物棟-557', false, ''), - ('霜田 靖', '准教授', 2, '生物棟-753', false, ''), - ('佐藤 武史', '准教授', 2, '生物棟-556', false, ''), - ('山本 麻希', '准教授', 2, '生物棟-255', false, ''), - ('西村 泰介', '准教授', 2, '生物棟-755', false, ''), - ('笠井 大輔', '准教授', 2, '生物棟-351', false, ''), - ('桑原 敬司', '准教授', 2, '生物棟-257', false, ''), - ('藤原 郁子', '准教授', 2, '生物棟-656', false, ''), - ('上村 直史', '准教授', 2, '生物棟-367', false, ''), - ('内山 尚志', '助教', 2, '生物棟-563', false, ''), - ('早乙女 友規', '助教', 2, '生物棟-756', false, ''), - ('斎藤 秀俊', '教授', 2, '物材経情棟-428', false, ''), - ('竹中 克彦', '教授', 2, '物材経情棟-326', false, ''), - ('前川 博史', '教授', 2, '物材経情棟-329', false, ''), - ('石橋 隆幸', '教授', 2, '物材経情棟-423', false, ''), - ('今久保 達郎', '教授', 2, '物材経情棟-524', false, ''), - ('梅田 実', '教授', 2, '物材経情棟-523', false, ''), - ('河原 成元', '教授', 2, '物材経情棟-327', false, ''), - ('伊藤 治彦', '准教授', 2, '物材経情棟-530', false, ''), - ('内田 希', '准教授', 2, '物材経情2号棟-430', false, ''), - ('齊藤 信雄', '准教授', 2, '分析計測センター209', false, ''), - ('本間 剛', '准教授', 2, '物材経情棟-424', false, ''), - ('高橋 由紀子', '准教授', 2, '環境棟-464', false, ''), - ('多賀谷 基博', '准教授', 2, '物材経情棟-525', false, ''), - ('白仁田 沙代子', '准教授', 2, '物材経情棟-215', false, ''), - ('西川 雅美', '准教授', 2, '環境棟-465', false, ''), - ('船津 麻美', '准教授', 2, '環境棟-466', false, ''), - ('小松 啓志', '助教', 2, '物材経情棟-522', false, ''), - ('戸田 智之', '助教', 2, '物材経情棟-522', false, ''), - ('シリポーン タオガァオ', '助教', 2, '物材経情棟-522', false, ''), - ('松田 翔風', '助教', 2, '物材経情棟-522', false, ''), - ('張 田原', '助教', 2, '物財経情棟-427', false, ''), - ('明田川 正人', '教授', 3, '機械・建設棟-508', false, ''), - ('井原 郁夫', '教授', 3, '機械・建設棟-503', false, ''), - ('高橋 勉', '教授', 3, '機械・建設棟-601', false, ''), - ('太田 浩之', '教授', 3, '機械・建設棟-506', false, ''), - ('武田 雅敏', '教授', 3, '機械・建設棟-509', false, ''), - ('上村 靖司', '教授', 3, '機械・建設棟-407', false, ''), - ('南口 誠', '教授', 3, '機械・建設棟-302', false, ''), - ('木村 哲也', '教授', 3, '機械・建設棟-308', false, ''), - ('磯部 浩巳', '教授', 3, '機械・建設棟-603', false, ''), - ('小林 泰秀', '准教授', 3, '機械・建設棟-405', false, ''), - ('宮下 幸雄', '教授', 3, '機械・建設棟-304', false, ''), - ('本間 智之', '准教授', 3, '機械・建設棟-501', false, ''), - ('倉橋 貴彦', '准教授', 3, '機械・建設棟-608', false, ''), - ('勝身 俊之', '准教授', 3, '機械・建設棟-602', false, ''), - ('會田 英雄', '准教授', 3, '機械・建設棟-607', false, ''), - ('鈴木 正太郎', '准教授', 3, '機械・建設棟-604', false, ''), - ('庄司 観', '准教授', 3, '機械・建設棟-408', false, ''), - ('溝尻 瑞枝', '准教授', 3, '機械・建設棟-401', false, ''), - ('韋 冬', '准教授', 3, '機械・建設棟-404', false, ''), - ('NGUYEN THI PHUONG MAI ', '准教授', 3, '機械・建設棟-', false, ''), - ('山下 健', '助教', 3, '機械・建設棟‐2号568', false, ''), - ('梅本 和希', '助教', 3, '機械・建設棟-2号568‐B', false, ''), - ('馬場 将亮', '助教', 3, '機械・建設棟-2号574', false, ''), - ('横田 和哉', '助教', 3, '機械・建設棟-2号572', false, ''), - ('原 圭祐', '助教', 3, '機械・建設棟-1号610', false, ''), - ('郭 妍伶', '助教', 3, '機械・建設棟-369', false, ''), - ('陸 旻皎', '教授', 4, '環境棟-653', false, ''), - ('細山田 得三', '教授', 4, '機械・建設棟-807', false, ''), - ('池田 隆明', '教授', 4, '機械・建設棟-805', false, ''), - ('豊田 浩史', '教授', 4, '機械・建設棟-705', false, ''), - ('高橋 修', '教授', 4, '機械・建設棟-704', false, ''), - ('下村 匠', '教授', 4, '機械・建設棟-703', false, ''), - ('岩崎 英治', '教授', 4, '機械・建設棟-701', false, ''), - ('佐野 可寸志', '教授', 4, '環境棟-366/原子力棟411', false, ''), - ('小松 俊哉', '准教授', 4, '環境棟-554', false, ''), - ('熊倉 俊郎', '准教授', 4, '環境棟-652', false, ''), - ('高橋 一義', '准教授', 4, '環境棟-654', false, ''), - ('宮下 剛', '准教授', 4, '機械・建設棟-706', false, ''), - ('松田 曜子', '准教授', 4, '環境棟-651', false, ''), - ('犬飼 直之', '准教授', 4, '機械・建設棟-801', false, ''), - ('松川 寿也', '助教授', 4, '環境棟-364', false, ''), - ('中村 文則', '准教授', 4, '機械・建設棟-708', false, ''), - ('福元 豊', '准教授', 4, '機械・建設棟-804', false, ''), - ('幡本 将史', '准教授', 4, '環境棟-569', false, ''), - ('楊 宏選', '助教', 4, '環境棟-659', false, ''), - ('渡利 高大', '助教授', 4, '環境棟-571', false, ''), - ('坂田 健太', '助手', 4, '環境棟-655', false, ''), - ('高橋 貴生', '助教授', 4, '環境棟-367', false, ''), - ('加藤 哲平', '講師', 4, '物材経情棟-365', false, ''), - ('李 志東', '教授', 5, '物材経情棟-302', false, ''), - ('塩野谷 明', '教授', 5, '体育保健センター-108', false, ''), - ('野村 収作', '教授', 5, '機械・建設3号棟-534', false, ''), - ('秋元 頼孝', '准教授', 5, '物材経情棟-304', false, ''), - ('羽山 徹彩', '教授', 5, '総合研究棟‐408', false, ''), - ('伊藤 喜浩', '教授', 5, '総合研究棟‐305', false, ''), - ('綿引 宣道', '教授', 5, '総合研究棟‐303', false, 'メールアポ必須'), - ('西山 雄大', '教授', 5, '総合研究棟-603', false, ''), - ('大村 哲臣', '教授', 5, '', false, '居室不明'), - ('鈴木 信貴', '准教授', 5, '物材経情棟-402', false, ''), - ('大橋 智志', '准教授', 5, '物材経情棟-403', false, ''), - ('白川 智弘', '准教授', 5, '物材経情棟-404', false, ''), - ('中平 勝子', '准教授', 5, '語学センター棟‐212', false, '居室不明'), - ('吉田 富美男', '助教', 5, '機械・建設3号棟-539', false, ''), - ('鈴木 泉', '助教', 5, '総合研究棟-407', false, ''), - ('畦原 宗之', '助教', 5, '総合研究棟-406', false, ''), - ('永森 正仁', '助教', 5, '総合研究棟-506', false, ''), - ('安藤 雅洋', '助教', 5, 'マルチメディアセンター-201', false, ''), - ('高橋 光子', '教授', 6, '物材情経棟-504', false, ''), - ('原 信一郎', '教授', 6, '環境棟-267', false, ''), - ('加藤 有行', '教授', 6, '電気1号棟-303', false, ''), - ('若林 敦', '教授', 6, '物質材開棟-503', false, ''), - ('松原 浩', '教授', 6, '物材経情棟-308', false, ''), - ('加納 満', '准教授', 6, '物材経情棟-307', false, ''), - ('リー 飯塚 尚子', '准教授', 6, '物質材開棟-306', false, ''), - ('伊藤 敦美', '准教授', 6, '物材経情棟-509', false, ''), - ('藤井 数馬', '准教授', 6, '物材経情棟-507', false, ''), - ('山本 謙一郎', '准教授', 6, '環境棟-268', false, ''), - ('重田 謙', '准教授', 6, '物材経情棟-', false, ''), - ('永野 建二郎', '講師', 6, '物材経情棟-310', false, ''), - ('五十嵐 啓太', '講師', 6, '物材経情棟-506', false, ''), - ('山口 勇気', '講師', 6, '機械建設1号棟-505', false, ''), - ('片野 洋平', '講師', 6, '物材経情棟-309', false, ''), - ('ドライアー ブライアン', '助教', 6, '物材経情棟-508', false, ''), - ('江 偉華', '教授', 7, '極限-粒子棟201', false, ''), - ('末松 久幸', '教授', 7, '極限-粒子棟203', false, ''), - ('鈴木 達也', '教授', 7, '原子力安全・シス安棟-412', false, ''), - ('大塚 悟', '教授', 7, '機械・建設棟-802', false, ''), - ('菊池 崇志', '准教授', 7, '原子力安全・シス安棟-409', false, ''), - ('鈴木 常生', '准教授', 7, '原子力安全・シス安棟-410', false, ''), - ('村上 健太', '准教授', 7, '原子力安全・シス安棟-310', false, ''), - ('大場 恭子', '准教授', 7, '原子力安全・シス安棟-312', false, ''), - ('竹澤 宏樹', '准教授', 7, '原子力安全・シス安棟-313', false, ''), - ('太田 朋子', '准教授', 7, '原子力安全・シス安棟-508', false, ''), - ('松本 義伸', '助教', 7, 'ラジオアイソトープセンター 101', false, ''), - ('須貝 太一', '助教', 7, '極限棟-201', false, ''), - ('立花 優', '助教授', 7, '原子力安全・シス安棟-311', false, ''), - ('ドウ テイ マイ ズン', '助教授', 7, '原子力安全・シス安棟-205', false, ''), - ('VLAD CRISTIAN IULIAN', '教授', 8, '', false, '居室不明'), - ('中川 匡弘', '教授', 8, '電気棟-609/3号棟外プレハブ カオス・フラクタル研究室', false, ''), - ('小林 高臣', '教授', 8, '物材経情棟-526', false, ''), - ('改田 哲也', '教授', 8, '博士棟-358', false, ''), - ('小笠原 渉', '教授', 8, '生物棟-371', false, ''), - ('山田 昇', '教授', 8, '機械・建設棟-507', false, ''), - ('中山 忠親', '教授', 8, '極限-粒子棟-202', false, ''), - ('伊東 淳一', '教授', 8, '電気棟-407', false, ''), - ('山口 隆司', '教授', 8, '環境棟-570', false, ''), - ('湯川 高志', '教授', 8, '総合研究棟-510', false, ''), - ('山崎 渉', '准教授', 8, '機械・建設棟-603', false, ''), - ('牧 慎也', '准教授', 8, '機械・建設1号棟-807', false, ''), - ('姫野 修司', '准教授', 8, '環境棟-553', false, ''), - ('佐々木 徹', '准教授', 8, '環境棟-304', false, ''), - ('大沼 清', '准教授', 8, '生物棟-560', false, ''), - ('田中 諭', '准教授', 8, '物材2号棟-429', false, ''), - ('門脇 敏', '教授', 9, '機械・建設棟-502', false, ''), - ('三好 孝典', '教授', 9, '原子力安全・シス安棟-614', false, ''), - ('阿部 雅二郎', '教授', 9, '機械・建設1号棟-504', false, ''), - ('木村 哲也', '教授', 9, '機械・建設棟-308', false, ''), - ('山形 浩史', '教授', 9, '原子力安全・シス安棟-612', false, ''), - ('大塚 雄市', '准教授', 9, '原子力安全・シス安棟-562', false, ''), - ('北條 理恵子', '准教授', 9, '原子力安全・シス安棟609', false, ''), - ('張 坤', '准教授', 9, '原子力安全・シス安棟-613', false, ''), - ('吉田 昌弘', '技術職員', 10, '機械・建設棟-314', false, ''), - ('安部 真', '技術職員', 10, '機械・建設2号棟-370', false, ''), - ('山田 修一', '技術職員', 10, '原子力安全・シス安棟-511', false, ''), - ('吉井 一夫', '技術職員', 10, '工作センター103', false, ''), - ('山本 浩', '技術職員', 10, '機械・建設3号棟-240', false, ''), - ('高田 晋', '技術職員', 10, '建設大型実験棟-205', false, ''), - ('高橋 智', '技術職員', 10, '機械・建設2号棟-663', false, ''), - ('渡邉 高子', '技術職員', 10, '環境棟-569', false, ''), - ('中村 健', '技術職員', 10, '機械・建設1号棟-712', false, ''), - ('豊田 英之', '技術職員', 10, '電気2号棟-471', false, ''), - ('山口 貴幸', '技術職員', 10, '大型実験棟-203', false, ''), - ('田中 徹', '技術職員', 10, '実験実習2号棟118', false, ''), - ('志田 暁雄', '技術職員', 10, '極限-極限棟201W', false, ''), - ('佐藤 賢太', '技術職員', 10, '工作センター103', false, ''), - ('小池 孝侑', '技術職員', 10, '工作センター103', false, ''), - ('河原 夏江', '技術職員', 10, '物材経情棟-2号562', false, ''), - ('高橋 美幸', '技術職員', 10, '分析計測センター-118', false, ''), - ('小杉 健一郎', '技術職員', 10, '分析計測センター-118', false, ''), - ('高柳 充寛', '技術職員', 10, '生物棟-565', false, ''), - ('野田 浩平', '技術職員', 10, '電気2号棟-666', false, ''), - ('山浦 賢太郎', '技術職員', 10, '電気2号棟-569', false, ''), - ('近藤 みずき', '技術職員', 10, '生物棟-258', false, ''), - ('草野 利樹', '技術職員', 10, '', false, '居室不明'), - ('上野 悠一', '技術職員', 10, '', false, '居室不明'), - ('中山 佳子', '技術職員', 10, '環境棟-155', false, ''), - ('山下 智樹', '特任准教授', 11, '', false, '居室不明'), - ('日下 佳祐', '特任講師', 11, '実験実習1号棟-110', false, ''), - ('藤沢 慶', '特任講師', 11, '機械建設1号棟-606', false, ''), - ('中田 大貴', '特任講師', 11, '機械建設2号棟-457', false, ''), - ('鎌土 重晴', '学長', 12, '学長室/機械・建設棟-306', false, '秘書へアポ'), - ('和田 安弘', '副学長', 12, '電気棟-608', false, ''), - ('秋山 和男', '理事・事務局長', 12, '理事室', false, ''), - ('梅田 実', '副学長', 12, '実験実習2号棟-情報システム実験室', false, ''), - ('学生支援課', '事務', 12, '', false, ''), - ('学務課', '事務', 12, '', false, ''), - ('国際課', '事務', 12, '', false, ''), - ('総務課', '事務', 12, '', false, ''), - ('財務課', '事務', 12, '', false, ''), - ('研究・地域連携課', '事務', 12, '', false, ''), - ('入試課', '事務', 12, '', false, ''), - ('総合情報課', '事務', 12, '', false, ''), - ('施設課', '事務', 12, '', false, ''), - ('大学戦略課(3F)', '事務', 12, '', false, ''), - ('大学戦略課(2F)', '事務', 12, '', false, ''), - ('電気系', '系事務室', 12, '', false, ''), - ('物質・材料・経営情報系', '系事務室', 12, '', false, ''), - ('機械・建設事務室', '系事務室', 12, '', false, ''), - ('生物系', '系事務室', 12, '', false, ''), - ('環境事務室', '系事務室', 12, '', false, ''), - ('芳賀 仁', '助教', 12, '電気2号棟-364', false, '同窓会代表。局長が挨拶へ。学内募金は毎回断っている'); - -INSERT INTO - year_periods (year_id, started_at, ended_at) -VALUES - (1, '2024-11-15 00:00:00', '2025-11-15 00:00:00'); - -INSERT INTO - incomes (name, created_at, updated_at) -VALUES - ("教育振興会費", NOW(), NOW()), - ("学内募金", NOW(), NOW()), - ("同窓会費", NOW(), NOW()), - ("雑収入", NOW(), NOW()), - ("繰越金", NOW(), NOW()), - ("企業協賛金", NOW(), NOW()); - -INSERT INTO - buildings (name) -VALUES - ('機械・建設棟'), - ('電気棟'), - ('生物棟'), - ('環境・システム棟'), - ('物質・材料経営情報棟'), - ('総合研究棟'), - ('原子力・システム安全棟'), - ('事務局棟'), - ('極限エネルギ密度工学研究センター'), - ('工作センター'), - ('大型実験棟'), - ('分析計測センター'), - ('その他'); - -INSERT INTO - building_units (building_id, unit_number) -VALUES - (1, "1号棟"), - (1, "2号棟"), - (1, "3号棟"), - (2, "1号棟"), - (2, "2号棟"), - (3, "1号棟"), - (4, "1号棟"), - (5, "1号棟"), - (5, "2号棟"), - (6, "1号棟"), - (7, "1号棟"), - (8, "1号棟"), - (9, "1号棟"), - (10, "1号棟"), - (11, "1号棟"), - (12, "1号棟"), - (13, "1号棟"); diff --git a/scripts/create_migration.sh b/scripts/create_migration.sh deleted file mode 100755 index de6f5f697..000000000 --- a/scripts/create_migration.sh +++ /dev/null @@ -1,3 +0,0 @@ -read -p "input migration name: " migration_name - -docker compose -f compose.migrate.yml run --rm migrate create -ext sql -dir /migrations -seq $migration_name diff --git a/scripts/seed.sh b/scripts/seed.sh deleted file mode 100644 index 900f722e2..000000000 --- a/scripts/seed.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# テーブルデータを初期化するためのSQLファイルを実行するよ〜!🐣 -{ - echo "SET FOREIGN_KEY_CHECKS = 0;" - mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -D "$MYSQL_DATABASE" --batch --silent -N \ - -e "SELECT CONCAT('TRUNCATE FROM \`', table_name, '\`;') \ - FROM information_schema.tables \ - WHERE table_schema = '${MYSQL_DATABASE}' AND table_name != 'schema_migrations';" - echo "SET FOREIGN_KEY_CHECKS = 1;" -} | mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" - -# ディレクトリのパスを指定 -SQL_DIR="../seed" - -# SQLファイルを順番に実行 -for sql_file in "$SQL_DIR"/*.sql; do - if [ -f "$sql_file" ]; then - echo "実行中: $sql_file 🚀" - mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" < "$sql_file" - if [ $? -eq 0 ]; then - echo "成功: $sql_file 🎉" - else - echo "失敗: $sql_file 😭" - fi - else - echo "SQLファイルが見つからないよ〜!ぴえん🥺" - fi -done - -echo "全てのSQLファイルの実行が完了したよ!おけまる水産🐟✨" From b74016a245fb68b7faa0d32a42494dbda02b042c Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Tue, 13 May 2025 00:43:44 +0900 Subject: [PATCH 09/21] =?UTF-8?q?refactor:=20campusDonation=E3=82=B9?= =?UTF-8?q?=E3=82=AD=E3=83=BC=E3=83=9E=E3=82=92=E6=9B=B4=E6=96=B0=E3=81=97?= =?UTF-8?q?=E3=80=81=E6=A3=9F=E3=81=94=E3=81=A8=E3=81=AE=E6=95=99=E5=93=A1?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openapi/openapi.yaml | 48 +++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 6b3b4a3e7..d8b5b715c 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -842,7 +842,7 @@ paths: schema: type: array items: - $ref: "#/components/schemas/campusDonationByFloor" + $ref: "#/components/schemas/campusDonationByFloorAndBuilding" /departments: get: @@ -3503,17 +3503,12 @@ components: - room_number - is_black - remark - campusDonationByFloor: + campusDonation: type: object + description: 教員単体の情報 properties: teacher_id: type: integer - building_name: - type: string - unit_number: - type: string - floor_number: - type: string room_name: type: string teacher_name: @@ -3524,12 +3519,41 @@ components: type: boolean required: - teacher_id - - building_name - - unit_number - - floor_number - room_name - teacher_name - price - - is_black + - is_Black + floorGroup: + type: object + description: フロアごとの教員情報 + properties: + floor_id: + type: integer + floor_number: + type: string + donations: + type: array + items: + $ref: '#/components/schemas/campusDonation' + required: + - floor_ud + - floor_number + - donations + campusDonationByFloorAndBuilding: + type: object + description: 棟ごとの教員情報 + properties: + building_id: + type: integer + building_name: + type: string + floors: + type: array + items: + $ref: '#/components/schemas/floorGroup' + required: + - building_id + - building_Name + - floors x-original-swagger-version: "2.0" From 048ceecaeff7e15a5888b38f3416d1ac04d6c564 Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Tue, 13 May 2025 00:44:47 +0900 Subject: [PATCH 10/21] =?UTF-8?q?generated:=20/campus=5Fdonations/building?= =?UTF-8?q?/{building=5Fid}/floor/{floor=5Fid}=E5=91=A8=E3=82=8A=E3=81=AE?= =?UTF-8?q?=E8=87=AA=E5=8B=95=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/generated/openapi_gen.go | 31 +++++++++++++------ view/next-project/src/generated/hooks.ts | 4 +-- .../src/generated/model/campusDonation.ts | 18 +++++++++++ .../model/campusDonationByFloorAndBuilding.ts | 17 ++++++++++ .../src/generated/model/floorGroup.ts | 17 ++++++++++ .../next-project/src/generated/model/index.ts | 3 ++ 6 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 view/next-project/src/generated/model/campusDonation.ts create mode 100644 view/next-project/src/generated/model/campusDonationByFloorAndBuilding.ts create mode 100644 view/next-project/src/generated/model/floorGroup.ts diff --git a/api/generated/openapi_gen.go b/api/generated/openapi_gen.go index 65b97408e..2f1991847 100644 --- a/api/generated/openapi_gen.go +++ b/api/generated/openapi_gen.go @@ -112,16 +112,20 @@ type BuyReportWithDivisionId struct { PaidBy *string `json:"paidBy,omitempty"` } -// CampusDonationByFloor defines model for campusDonationByFloor. -type CampusDonationByFloor struct { - BuildingName string `json:"building_name"` - FloorNumber string `json:"floor_number"` - IsBlack bool `json:"is_black"` - Price int `json:"price"` - RoomName string `json:"room_name"` - TeacherId int `json:"teacher_id"` - TeacherName string `json:"teacher_name"` - UnitNumber string `json:"unit_number"` +// CampusDonation 教員単体の情報 +type CampusDonation struct { + IsBlack *bool `json:"is_black,omitempty"` + Price int `json:"price"` + RoomName string `json:"room_name"` + TeacherId int `json:"teacher_id"` + TeacherName string `json:"teacher_name"` +} + +// CampusDonationByFloorAndBuilding 棟ごとの教員情報 +type CampusDonationByFloorAndBuilding struct { + BuildingId int `json:"building_id"` + BuildingName *string `json:"building_name,omitempty"` + Floors []FloorGroup `json:"floors"` } // DestroyTeacherIDs defines model for destroyTeacherIDs. @@ -234,6 +238,13 @@ type FinancialRecordWithBalance struct { Year *int `json:"year,omitempty"` } +// FloorGroup フロアごとの教員情報 +type FloorGroup struct { + Donations []CampusDonation `json:"donations"` + FloorId *int `json:"floor_id,omitempty"` + FloorNumber string `json:"floor_number"` +} + // Income defines model for income. type Income struct { Amount int `json:"amount"` diff --git a/view/next-project/src/generated/hooks.ts b/view/next-project/src/generated/hooks.ts index cf942a4e4..4bf0af4d4 100644 --- a/view/next-project/src/generated/hooks.ts +++ b/view/next-project/src/generated/hooks.ts @@ -18,7 +18,7 @@ import type { BuyReport, BuyReportDetail, BuyReportWithDivisionId, - CampusDonationByFloor, + CampusDonationByFloorAndBuilding, DeleteActivitiesId200, DeleteActivityInformationsId200, DeleteActivityStylesId200, @@ -2705,7 +2705,7 @@ export const usePutBuyReportStatusBuyReportId = ( * 各棟の各階の学内募金情報を取得するAPI */ export type getCampusDonationsBuildingBuildingIdFloorFloorIdResponse200 = { - data: CampusDonationByFloor[]; + data: CampusDonationByFloorAndBuilding[]; status: 200; }; diff --git a/view/next-project/src/generated/model/campusDonation.ts b/view/next-project/src/generated/model/campusDonation.ts new file mode 100644 index 000000000..bacbb3c77 --- /dev/null +++ b/view/next-project/src/generated/model/campusDonation.ts @@ -0,0 +1,18 @@ +/** + * Generated by orval v7.6.0 🍺 + * Do not edit manually. + * NUTFes FinanSu API + * FinanSu APIドキュメント + * OpenAPI spec version: 2.0.0 + */ + +/** + * 教員単体の情報 + */ +export interface CampusDonation { + teacher_id: number; + room_name: string; + teacher_name: string; + price: number; + is_black?: boolean; +} diff --git a/view/next-project/src/generated/model/campusDonationByFloorAndBuilding.ts b/view/next-project/src/generated/model/campusDonationByFloorAndBuilding.ts new file mode 100644 index 000000000..d3ef56399 --- /dev/null +++ b/view/next-project/src/generated/model/campusDonationByFloorAndBuilding.ts @@ -0,0 +1,17 @@ +/** + * Generated by orval v7.6.0 🍺 + * Do not edit manually. + * NUTFes FinanSu API + * FinanSu APIドキュメント + * OpenAPI spec version: 2.0.0 + */ +import type { FloorGroup } from './floorGroup'; + +/** + * 棟ごとの教員情報 + */ +export interface CampusDonationByFloorAndBuilding { + building_id: number; + building_name?: string; + floors: FloorGroup[]; +} diff --git a/view/next-project/src/generated/model/floorGroup.ts b/view/next-project/src/generated/model/floorGroup.ts new file mode 100644 index 000000000..4a777394c --- /dev/null +++ b/view/next-project/src/generated/model/floorGroup.ts @@ -0,0 +1,17 @@ +/** + * Generated by orval v7.6.0 🍺 + * Do not edit manually. + * NUTFes FinanSu API + * FinanSu APIドキュメント + * OpenAPI spec version: 2.0.0 + */ +import type { CampusDonation } from './campusDonation'; + +/** + * フロアごとの教員情報 + */ +export interface FloorGroup { + floor_id?: number; + floor_number: string; + donations: CampusDonation[]; +} diff --git a/view/next-project/src/generated/model/index.ts b/view/next-project/src/generated/model/index.ts index 1b9275a0d..23d5f1c80 100644 --- a/view/next-project/src/generated/model/index.ts +++ b/view/next-project/src/generated/model/index.ts @@ -14,7 +14,9 @@ export * from './buyReportDetail'; export * from './buyReportInformation'; export * from './buyReportInformationStatus'; export * from './buyReportWithDivisionId'; +export * from './campusDonation'; export * from './campusDonationByFloor'; +export * from './campusDonationByFloorAndBuilding'; export * from './deleteActivitiesId200'; export * from './deleteActivityInformationsId200'; export * from './deleteActivityStylesId200'; @@ -54,6 +56,7 @@ export * from './festivalItemsForMyPage'; export * from './financialRecord'; export * from './financialRecordDetails'; export * from './financialRecordWithBalance'; +export * from './floorGroup'; export * from './getActivities200'; export * from './getActivitiesDetails200'; export * from './getActivitiesDetailsYear200'; From c69626e84f68988b1ff17ada096f5ac5f57aa8e4 Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Tue, 13 May 2025 00:45:14 +0900 Subject: [PATCH 11/21] =?UTF-8?q?feat:=20=E3=82=AF=E3=82=A8=E3=83=AA?= =?UTF-8?q?=E8=BF=94=E3=82=8A=E5=80=A4=E7=94=A8=E3=81=AE=E5=9E=8B=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/internals/domain/campus_donation.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 api/internals/domain/campus_donation.go diff --git a/api/internals/domain/campus_donation.go b/api/internals/domain/campus_donation.go new file mode 100644 index 000000000..69152b86a --- /dev/null +++ b/api/internals/domain/campus_donation.go @@ -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"` +} From 9b450282327d8b0f6d3f09f9d27990c7577d723d Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Tue, 13 May 2025 00:45:40 +0900 Subject: [PATCH 12/21] fix: fix error message --- api/externals/controller/cmapus_donation_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/externals/controller/cmapus_donation_controller.go b/api/externals/controller/cmapus_donation_controller.go index 587bcee72..6449de583 100644 --- a/api/externals/controller/cmapus_donation_controller.go +++ b/api/externals/controller/cmapus_donation_controller.go @@ -34,7 +34,7 @@ func (cdc *campusDonationController) IndexCampusDonationByFloor(c echo.Context) campusDonationByFloors, err := cdc.u.GetCampusDonationByFloors(ctx, buildingId, floorId) if err != nil { - return c.String(http.StatusBadRequest, "failed to buy_reports") + return c.String(http.StatusBadRequest, "failed to get campus donation by floor") } return c.JSON(http.StatusOK, campusDonationByFloors) From 7503c9555fdeb4dee64f7f15ef7f6658514044c6 Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Tue, 13 May 2025 00:45:57 +0900 Subject: [PATCH 13/21] =?UTF-8?q?refactor:=20=E3=82=AF=E3=82=A8=E3=83=AA?= =?UTF-8?q?=E3=81=AE=E9=81=B8=E6=8A=9E=E9=A0=85=E7=9B=AE=E3=82=92=E6=95=B4?= =?UTF-8?q?=E7=90=86=E3=81=97=E3=80=81=E3=82=B0=E3=83=AB=E3=83=BC=E3=83=97?= =?UTF-8?q?=E5=8C=96=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/campus_donation_repository.go | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/api/externals/repository/campus_donation_repository.go b/api/externals/repository/campus_donation_repository.go index 9f74592ed..fa55cd289 100644 --- a/api/externals/repository/campus_donation_repository.go +++ b/api/externals/repository/campus_donation_repository.go @@ -51,37 +51,26 @@ func (cdr *campusDonationRepository) AllCampusDonationByFloor(c context.Context, goqu.On(goqu.Ex{"fund_informations.teacher_id": goqu.I("teachers.id")}), ). Select( - goqu.I("buildings.name"), - goqu.I("building_units.unit_number"), - goqu.I("floors.floor_number"), - goqu.I("rooms.room_name"), - goqu.I("teachers.id"), - goqu.I("teachers.name"), - goqu.I("teachers.is_black"), - goqu.COALESCE(goqu.SUM(goqu.I("fund_informations.price")), 0), + 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("fund_informations.price").As("price"), + goqu.I("teachers.is_black").As("is_black"), ). Where( goqu.Ex{"buildings.id": buildingId, "floors.id": floorId}, ). - GroupBy( - goqu.I("buildings.name"), - goqu.I("building_units.unit_number"), - goqu.I("floors.floor_number"), - goqu.I("rooms.room_name"), - goqu.I("teachers.id"), - goqu.I("teachers.name"), - goqu.I("teachers.is_black"), - ). Order( goqu.I("building_units.unit_number").Asc(), goqu.I("floors.floor_number").Asc(), - goqu.I("rooms.room_name").Asc(), - goqu.I("teachers.name").Asc(), ). ToSQL() if err != nil { - // エラーハンドリング log.Fatal(err) } From 5b2c327cae04e27403c8e005005bd6914c23227c Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Tue, 13 May 2025 00:46:07 +0900 Subject: [PATCH 14/21] =?UTF-8?q?refactor:=20GetCampusDonationByFloors?= =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E3=81=97=E3=80=81=E8=BF=94=E3=82=8A=E5=80=A4=E3=81=AE=E5=9E=8B?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/campus_donation_usecase.go | 86 ++++++++++++++----- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/api/internals/usecase/campus_donation_usecase.go b/api/internals/usecase/campus_donation_usecase.go index 561480595..4d240b31e 100644 --- a/api/internals/usecase/campus_donation_usecase.go +++ b/api/internals/usecase/campus_donation_usecase.go @@ -6,6 +6,7 @@ import ( rep "github.com/NUTFes/FinanSu/api/externals/repository" "github.com/NUTFes/FinanSu/api/generated" + "github.com/NUTFes/FinanSu/api/internals/domain" "github.com/pkg/errors" ) @@ -14,16 +15,14 @@ type campusDonationUseCase struct { } type CampusDonationUseCase interface { - GetCampusDonationByFloors(context.Context, string, string) ([]CampusDonationByFloor, error) + GetCampusDonationByFloors(context.Context, string, string) ([]CampusDonationByFloorAndBuilding, error) } func NewCampusDonationUseCase(rep rep.CampusDonationRepository) CampusDonationUseCase { return &campusDonationUseCase{rep} } -func (cdu *campusDonationUseCase) GetCampusDonationByFloors(c context.Context, buildingId string, floorId string) ([]CampusDonationByFloor, error) { - var campusDonation CampusDonationByFloor - var campusDonations []CampusDonationByFloor +func (cdu *campusDonationUseCase) GetCampusDonationByFloors(c context.Context, buildingId string, floorId string) ([]CampusDonationByFloorAndBuilding, error) { //クエリ実行 rows, err := cdu.rep.AllCampusDonationByFloor(c, buildingId, floorId) @@ -36,24 +35,71 @@ func (cdu *campusDonationUseCase) GetCampusDonationByFloors(c context.Context, b } }() + var campusDonationRecords []domain.CampusDonationRecord for rows.Next() { - err := rows.Scan( - &campusDonation.BuildingName, - &campusDonation.UnitNumber, - &campusDonation.FloorNumber, - &campusDonation.RoomName, - &campusDonation.TeacherId, - &campusDonation.TeacherName, - &campusDonation.IsBlack, - &campusDonation.Price, - ) - - if err != nil { - return nil, errors.Wrapf(err, "can not connect SQL") + var campusDonationRecord domain.CampusDonationRecord + if err := rows.Scan( + &campusDonationRecord.BuildingId, + &campusDonationRecord.BuildingName, + &campusDonationRecord.FloorId, + &campusDonationRecord.FloorNumber, + &campusDonationRecord.TeacherId, + &campusDonationRecord.TeacherName, + &campusDonationRecord.RoomName, + &campusDonationRecord.Price, + &campusDonationRecord.IsBlack, + ); err != nil { + return nil, errors.Wrap(err, "scanning flat campus donation record") } - campusDonations = append(campusDonations, campusDonation) + campusDonationRecords = append(campusDonationRecords, campusDonationRecord) } - return campusDonations, nil + + // --- (2)ネスト構造にマップ→スライス化 --- + groupMap := make(map[int]*generated.CampusDonationByFloorAndBuilding) + for _, r := range campusDonationRecords { + buildingGroup, ok := groupMap[r.BuildingId] + if !ok { + buildingGroup = &generated.CampusDonationByFloorAndBuilding{ + BuildingId: r.BuildingId, + BuildingName: r.BuildingName, + Floors: []generated.FloorGroup{}, + } + groupMap[r.BuildingId] = buildingGroup + } + // Floor レベル取得 or 初期化 + var floorGroup *generated.FloorGroup + for i := range buildingGroup.Floors { + if buildingGroup.Floors[i].FloorId != nil && r.FloorId != nil && + *buildingGroup.Floors[i].FloorId == *r.FloorId { + floorGroup = &buildingGroup.Floors[i] + break + } + } + if floorGroup == nil { + newFg := generated.FloorGroup{ + FloorId: r.FloorId, + FloorNumber: r.FloorNumber, + Donations: []generated.CampusDonation{}, + } + buildingGroup.Floors = append(buildingGroup.Floors, newFg) + floorGroup = &buildingGroup.Floors[len(buildingGroup.Floors)-1] + } + // Donation 追加 + floorGroup.Donations = append(floorGroup.Donations, generated.CampusDonation{ + TeacherId: r.TeacherId, + TeacherName: r.TeacherName, + RoomName: r.RoomName, + Price: r.Price, + IsBlack: r.IsBlack, + }) + } + // map→slice + var result []generated.CampusDonationByFloorAndBuilding + for _, gb := range groupMap { + result = append(result, *gb) + } + return result, nil } -type CampusDonationByFloor = generated.CampusDonationByFloor +type CampusDonationByFloorAndBuilding = generated.CampusDonationByFloorAndBuilding +type CampusDonationRecord = domain.CampusDonationRecord From a0d1d9d028f26cc772f0245a23ccc76c3d5b2ab9 Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Thu, 15 May 2025 19:24:46 +0900 Subject: [PATCH 15/21] =?UTF-8?q?campus=5Fdonations=E3=83=86=E3=83=BC?= =?UTF-8?q?=E3=83=96=E3=83=AB=E3=81=AB=E5=9F=BA=E3=81=A5=E3=81=84=E3=81=A6?= =?UTF-8?q?fund=5Finformations=E3=81=AE=E5=8F=82=E7=85=A7=E3=82=92?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/externals/repository/campus_donation_repository.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/externals/repository/campus_donation_repository.go b/api/externals/repository/campus_donation_repository.go index fa55cd289..a2d7d7934 100644 --- a/api/externals/repository/campus_donation_repository.go +++ b/api/externals/repository/campus_donation_repository.go @@ -47,8 +47,8 @@ func (cdr *campusDonationRepository) AllCampusDonationByFloor(c context.Context, goqu.On(goqu.Ex{"teachers.id": goqu.I("room_teachers.teacher_id")}), ). LeftJoin( - goqu.T("fund_informations"), - goqu.On(goqu.Ex{"fund_informations.teacher_id": goqu.I("teachers.id")}), + goqu.T("campus_donations"), + goqu.On(goqu.Ex{"campus_donations.teacher_id": goqu.I("teachers.id")}), ). Select( goqu.I("buildings.id").As("building_id"), @@ -58,7 +58,7 @@ func (cdr *campusDonationRepository) AllCampusDonationByFloor(c context.Context, goqu.I("teachers.id").As("teacher_id"), goqu.I("teachers.name").As("teacher_name"), goqu.I("rooms.room_name").As("room_name"), - goqu.I("fund_informations.price").As("price"), + goqu.I("campus_donations.price").As("price"), goqu.I("teachers.is_black").As("is_black"), ). Where( From 25534d409767b2a7dfa54ce3dbcb3f7453fe1ad6 Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Sat, 24 May 2025 17:30:22 +0900 Subject: [PATCH 16/21] =?UTF-8?q?fix:=20year=5Fid=E3=82=92=E8=80=83?= =?UTF-8?q?=E6=85=AE=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openapi/openapi.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 992f32627..b24ff3fb2 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -816,7 +816,7 @@ paths: schema: $ref: "#/components/schemas/buyReportDetail" - /campus_donations/building/{building_id}/floor/{floor_id}: + /campus_donations/year/{year_id}/building/{building_id}/floor/{floor_id}: get: tags: - campus_donation @@ -834,6 +834,12 @@ paths: schema: type: integer description: ID of the floor + - name: year_id + in: path + required: true + schema: + type: integer + description: ID of the year responses: "200": description: Successful response @@ -3325,7 +3331,7 @@ components: donations: type: array items: - $ref: '#/components/schemas/campusDonation' + $ref: "#/components/schemas/campusDonation" required: - floor_ud - floor_number @@ -3341,7 +3347,7 @@ components: floors: type: array items: - $ref: '#/components/schemas/floorGroup' + $ref: "#/components/schemas/floorGroup" required: - building_id - building_Name From eb1ff5ddf87325e0a3554de765c325f053573fab Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Sat, 24 May 2025 17:30:47 +0900 Subject: [PATCH 17/21] generated: /campus_donations/year/{year_id}/building/{building_id}/floor/{floor_id} --- api/generated/openapi_gen.go | 20 ++++++--- api/go.mod | 3 +- api/go.sum | 4 ++ view/next-project/src/generated/hooks.ts | 55 +++++++++++++++--------- 4 files changed, 54 insertions(+), 28 deletions(-) diff --git a/api/generated/openapi_gen.go b/api/generated/openapi_gen.go index a08177306..6d130ed7f 100644 --- a/api/generated/openapi_gen.go +++ b/api/generated/openapi_gen.go @@ -851,8 +851,8 @@ type ServerInterface interface { // (PUT /buy_reports/{id}) PutBuyReportsId(ctx echo.Context, id int) error - // (GET /campus_donations/building/{building_id}/floor/{floor_id}) - GetCampusDonationsBuildingBuildingIdFloorFloorId(ctx echo.Context, buildingId int, floorId int) error + // (GET /campus_donations/year/{year_id}/building/{building_id}/floor/{floor_id}) + GetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorId(ctx echo.Context, yearId int, buildingId int, floorId int) error // (GET /departments) GetDepartments(ctx echo.Context) error @@ -1746,9 +1746,17 @@ func (w *ServerInterfaceWrapper) PutBuyReportsId(ctx echo.Context) error { return err } -// GetCampusDonationsBuildingBuildingIdFloorFloorId converts echo context to params. -func (w *ServerInterfaceWrapper) GetCampusDonationsBuildingBuildingIdFloorFloorId(ctx echo.Context) error { +// GetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorId converts echo context to params. +func (w *ServerInterfaceWrapper) GetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorId(ctx echo.Context) error { var err error + // ------------- Path parameter "year_id" ------------- + var yearId int + + err = runtime.BindStyledParameterWithOptions("simple", "year_id", ctx.Param("year_id"), &yearId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter year_id: %s", err)) + } + // ------------- Path parameter "building_id" ------------- var buildingId int @@ -1766,7 +1774,7 @@ func (w *ServerInterfaceWrapper) GetCampusDonationsBuildingBuildingIdFloorFloorI } // Invoke the callback with all the unmarshaled arguments - err = w.Handler.GetCampusDonationsBuildingBuildingIdFloorFloorId(ctx, buildingId, floorId) + err = w.Handler.GetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorId(ctx, yearId, buildingId, floorId) return err } @@ -3337,7 +3345,7 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL router.DELETE(baseURL+"/buy_reports/:id", wrapper.DeleteBuyReportsId) router.GET(baseURL+"/buy_reports/:id", wrapper.GetBuyReportsId) router.PUT(baseURL+"/buy_reports/:id", wrapper.PutBuyReportsId) - router.GET(baseURL+"/campus_donations/building/:building_id/floor/:floor_id", wrapper.GetCampusDonationsBuildingBuildingIdFloorFloorId) + router.GET(baseURL+"/campus_donations/year/:year_id/building/:building_id/floor/:floor_id", wrapper.GetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorId) router.GET(baseURL+"/departments", wrapper.GetDepartments) router.POST(baseURL+"/departments", wrapper.PostDepartments) router.DELETE(baseURL+"/departments/:id", wrapper.DeleteDepartmentsId) diff --git a/api/go.mod b/api/go.mod index f51e9c27d..62c68c674 100644 --- a/api/go.mod +++ b/api/go.mod @@ -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 @@ -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 diff --git a/api/go.sum b/api/go.sum index 65cde78ce..c7d706f64 100644 --- a/api/go.sum +++ b/api/go.sum @@ -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= @@ -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= diff --git a/view/next-project/src/generated/hooks.ts b/view/next-project/src/generated/hooks.ts index 1f3627bdc..20022d447 100644 --- a/view/next-project/src/generated/hooks.ts +++ b/view/next-project/src/generated/hooks.ts @@ -2694,33 +2694,35 @@ export const usePutBuyReportStatusBuyReportId = ( /** * 各棟の各階の学内募金情報を取得するAPI */ -export type getCampusDonationsBuildingBuildingIdFloorFloorIdResponse200 = { +export type getCampusDonationsYearYearIdBuildingBuildingIdFloorFloorIdResponse200 = { data: CampusDonationByFloorAndBuilding[]; status: 200; }; -export type getCampusDonationsBuildingBuildingIdFloorFloorIdResponseComposite = - getCampusDonationsBuildingBuildingIdFloorFloorIdResponse200; +export type getCampusDonationsYearYearIdBuildingBuildingIdFloorFloorIdResponseComposite = + getCampusDonationsYearYearIdBuildingBuildingIdFloorFloorIdResponse200; -export type getCampusDonationsBuildingBuildingIdFloorFloorIdResponse = - getCampusDonationsBuildingBuildingIdFloorFloorIdResponseComposite & { +export type getCampusDonationsYearYearIdBuildingBuildingIdFloorFloorIdResponse = + getCampusDonationsYearYearIdBuildingBuildingIdFloorFloorIdResponseComposite & { headers: Headers; }; -export const getGetCampusDonationsBuildingBuildingIdFloorFloorIdUrl = ( +export const getGetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorIdUrl = ( + yearId: number, buildingId: number, floorId: number, ) => { - return `/campus_donations/building/${buildingId}/floor/${floorId}`; + return `/campus_donations/year/${yearId}/building/${buildingId}/floor/${floorId}`; }; -export const getCampusDonationsBuildingBuildingIdFloorFloorId = async ( +export const getCampusDonationsYearYearIdBuildingBuildingIdFloorFloorId = async ( + yearId: number, buildingId: number, floorId: number, options?: RequestInit, -): Promise => { - return customFetch( - getGetCampusDonationsBuildingBuildingIdFloorFloorIdUrl(buildingId, floorId), +): Promise => { + return customFetch( + getGetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorIdUrl(yearId, buildingId, floorId), { ...options, method: 'GET', @@ -2728,22 +2730,24 @@ export const getCampusDonationsBuildingBuildingIdFloorFloorId = async ( ); }; -export const getGetCampusDonationsBuildingBuildingIdFloorFloorIdKey = ( +export const getGetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorIdKey = ( + yearId: number, buildingId: number, floorId: number, -) => [`/campus_donations/building/${buildingId}/floor/${floorId}`] as const; +) => [`/campus_donations/year/${yearId}/building/${buildingId}/floor/${floorId}`] as const; -export type GetCampusDonationsBuildingBuildingIdFloorFloorIdQueryResult = NonNullable< - Awaited> +export type GetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorIdQueryResult = NonNullable< + Awaited> >; -export type GetCampusDonationsBuildingBuildingIdFloorFloorIdQueryError = unknown; +export type GetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorIdQueryError = unknown; -export const useGetCampusDonationsBuildingBuildingIdFloorFloorId = ( +export const useGetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorId = ( + yearId: number, buildingId: number, floorId: number, options?: { swr?: SWRConfiguration< - Awaited>, + Awaited>, TError > & { swrKey?: Key; enabled?: boolean }; request?: SecondParameter; @@ -2751,15 +2755,24 @@ export const useGetCampusDonationsBuildingBuildingIdFloorFloorId = { const { swr: swrOptions, request: requestOptions } = options ?? {}; - const isEnabled = swrOptions?.enabled !== false && !!(buildingId && floorId); + const isEnabled = swrOptions?.enabled !== false && !!(yearId && buildingId && floorId); const swrKey = swrOptions?.swrKey ?? (() => isEnabled - ? getGetCampusDonationsBuildingBuildingIdFloorFloorIdKey(buildingId, floorId) + ? getGetCampusDonationsYearYearIdBuildingBuildingIdFloorFloorIdKey( + yearId, + buildingId, + floorId, + ) : null); const swrFn = () => - getCampusDonationsBuildingBuildingIdFloorFloorId(buildingId, floorId, requestOptions); + getCampusDonationsYearYearIdBuildingBuildingIdFloorFloorId( + yearId, + buildingId, + floorId, + requestOptions, + ); const query = useSwr>, TError>(swrKey, swrFn, swrOptions); From 79f58aa8551ba37df1da0a9225e7da00ed32ea85 Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Sat, 24 May 2025 17:30:57 +0900 Subject: [PATCH 18/21] =?UTF-8?q?fix:=20=E3=83=91=E3=82=B9=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/router/router.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/router/router.go b/api/router/router.go index 8d780f831..62d033b97 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -163,7 +163,7 @@ func (r router) ProvideRouter(e *echo.Echo) { e.PUT("/buy_report/status/:buy_report_id", r.buyReportController.UpdateBuyReportStatus) // campus_donationsのRoute - e.GET("/campus_donations/building/:building_id/floor/:floor_id", r.campusDonationController.IndexCampusDonationByFloor) + e.GET("/campus_donations/year/:year_id/building/:building_id/floor/:floor_id", r.campusDonationController.IndexCampusDonationByFloor) // current_user e.GET("/current_user", r.userController.GetCurrentUser) From 5d859d4e973f585dc50a8578fa56e5ddc414515a Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Sat, 24 May 2025 17:31:26 +0900 Subject: [PATCH 19/21] =?UTF-8?q?refactor:=20=E5=9E=8B=E5=A4=89=E6=8F=9B?= =?UTF-8?q?=E3=82=92=E9=96=A2=E6=95=B0=E3=81=AB=E5=88=87=E3=82=8A=E5=88=86?= =?UTF-8?q?=E3=81=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/campus_donation_usecase.go | 78 +++++++++++-------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/api/internals/usecase/campus_donation_usecase.go b/api/internals/usecase/campus_donation_usecase.go index 4d240b31e..a543a8b76 100644 --- a/api/internals/usecase/campus_donation_usecase.go +++ b/api/internals/usecase/campus_donation_usecase.go @@ -8,6 +8,7 @@ import ( "github.com/NUTFes/FinanSu/api/generated" "github.com/NUTFes/FinanSu/api/internals/domain" "github.com/pkg/errors" + "github.com/samber/lo" ) type campusDonationUseCase struct { @@ -23,7 +24,6 @@ func NewCampusDonationUseCase(rep rep.CampusDonationRepository) CampusDonationUs } func (cdu *campusDonationUseCase) GetCampusDonationByFloors(c context.Context, buildingId string, floorId string) ([]CampusDonationByFloorAndBuilding, error) { - //クエリ実行 rows, err := cdu.rep.AllCampusDonationByFloor(c, buildingId, floorId) if err != nil { @@ -54,52 +54,62 @@ func (cdu *campusDonationUseCase) GetCampusDonationByFloors(c context.Context, b campusDonationRecords = append(campusDonationRecords, campusDonationRecord) } - // --- (2)ネスト構造にマップ→スライス化 --- - groupMap := make(map[int]*generated.CampusDonationByFloorAndBuilding) - for _, r := range campusDonationRecords { - buildingGroup, ok := groupMap[r.BuildingId] + return convertCampusDonationRecordsToNestedStructure(campusDonationRecords), nil +} + +// convertCampusDonationRecordsToNestedStructure はcampusDonationRecordをネスト構造に変換する。 +func convertCampusDonationRecordsToNestedStructure(records []domain.CampusDonationRecord) []CampusDonationByFloorAndBuilding { + // 建物ごとにグループ化するためのマップを作成 + groupMap := make(map[int]*CampusDonationByFloorAndBuilding) + + for _, record := range records { + buildingGroup, ok := groupMap[record.BuildingId] if !ok { - buildingGroup = &generated.CampusDonationByFloorAndBuilding{ - BuildingId: r.BuildingId, - BuildingName: r.BuildingName, - Floors: []generated.FloorGroup{}, + buildingGroup = &CampusDonationByFloorAndBuilding{ + BuildingId: record.BuildingId, + BuildingName: record.BuildingName, + Floors: []FloorGroup{}, } - groupMap[r.BuildingId] = buildingGroup + groupMap[record.BuildingId] = buildingGroup } - // Floor レベル取得 or 初期化 - var floorGroup *generated.FloorGroup + + // floorGroupの検索 + var floorGroup *FloorGroup for i := range buildingGroup.Floors { - if buildingGroup.Floors[i].FloorId != nil && r.FloorId != nil && - *buildingGroup.Floors[i].FloorId == *r.FloorId { - floorGroup = &buildingGroup.Floors[i] - break + if buildingGroup.Floors[i].FloorId != nil && record.FloorId != nil && + *buildingGroup.Floors[i].FloorId == *record.FloorId { + floorGroup = &buildingGroup.Floors[i] + break } } + // ない場合、floorGroupを作成 if floorGroup == nil { - newFg := generated.FloorGroup{ - FloorId: r.FloorId, - FloorNumber: r.FloorNumber, - Donations: []generated.CampusDonation{}, + newFloorGroup := FloorGroup{ + FloorId: record.FloorId, + FloorNumber: record.FloorNumber, + Donations: []CampusDonation{}, } - buildingGroup.Floors = append(buildingGroup.Floors, newFg) + buildingGroup.Floors = append(buildingGroup.Floors, newFloorGroup) floorGroup = &buildingGroup.Floors[len(buildingGroup.Floors)-1] } - // Donation 追加 - floorGroup.Donations = append(floorGroup.Donations, generated.CampusDonation{ - TeacherId: r.TeacherId, - TeacherName: r.TeacherName, - RoomName: r.RoomName, - Price: r.Price, - IsBlack: r.IsBlack, + + // campusDonationの追加 + floorGroup.Donations = append(floorGroup.Donations, CampusDonation{ + TeacherId: record.TeacherId, + TeacherName: record.TeacherName, + RoomName: record.RoomName, + Price: record.Price, + IsBlack: record.IsBlack, }) } - // map→slice - var result []generated.CampusDonationByFloorAndBuilding - for _, gb := range groupMap { - result = append(result, *gb) - } - return result, nil + + // lo.MapToSliceを使用してマップをスライスに変換 + return lo.MapToSlice(groupMap, func(_ int, v *CampusDonationByFloorAndBuilding) CampusDonationByFloorAndBuilding { + return *v + }) } type CampusDonationByFloorAndBuilding = generated.CampusDonationByFloorAndBuilding type CampusDonationRecord = domain.CampusDonationRecord +type FloorGroup = generated.FloorGroup +type CampusDonation = generated.CampusDonation From 1f6fa2d20499e9311229d8945b17ab6b9e820741 Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Sun, 25 May 2025 18:57:47 +0900 Subject: [PATCH 20/21] feat: add campus donation controller with endpoint for retrieving donations by floor --- ...mapus_donation_controller.go => campus_donation_controller.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename api/externals/controller/{cmapus_donation_controller.go => campus_donation_controller.go} (100%) diff --git a/api/externals/controller/cmapus_donation_controller.go b/api/externals/controller/campus_donation_controller.go similarity index 100% rename from api/externals/controller/cmapus_donation_controller.go rename to api/externals/controller/campus_donation_controller.go From 3efc607f7842190eb1005fbf55998bf335a8efcb Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Wed, 4 Jun 2025 22:44:35 +0900 Subject: [PATCH 21/21] fix: handle NULL values in campus donations price with COALESCE --- api/externals/repository/campus_donation_repository.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/externals/repository/campus_donation_repository.go b/api/externals/repository/campus_donation_repository.go index a2d7d7934..5645af421 100644 --- a/api/externals/repository/campus_donation_repository.go +++ b/api/externals/repository/campus_donation_repository.go @@ -58,7 +58,7 @@ func (cdr *campusDonationRepository) AllCampusDonationByFloor(c context.Context, 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.COALESCE(goqu.I("campus_donations.price"), 0).As("price"), goqu.I("teachers.is_black").As("is_black"), ). Where(