diff --git a/Makefile b/Makefile index cb8fd12..cdac291 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,7 @@ remove-db: # Attach to the running PostgreSQL container attach-db: - docker exec -it ctf01d-postgres psql -U postgres + docker exec -it ctf01d-postgres psql -U postgres -d ctf01d_training_platform # Generate Go server boilerplate from OpenAPI 3 codegen: diff --git a/api/openapi.yaml b/api/openapi.yaml index 373fe8f..90abe31 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -160,20 +160,21 @@ paths: description: Bad request '500': description: Failed response - '/api/v1/users/{id}': + '/api/v1/users/{uuid}': get: tags: - Users summary: Get a user by ID operationId: getUserById parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid responses: '200': description: Detailed information of a user @@ -191,13 +192,14 @@ paths: summary: Update a user operationId: updateUser parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid requestBody: content: application/json: @@ -217,13 +219,14 @@ paths: summary: Delete a user operationId: deleteUser parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid responses: '200': description: User deleted successfully @@ -270,20 +273,21 @@ paths: description: Bad request '500': description: Failed response - '/api/v1/games/{id}': + '/api/v1/games/{uuid}': get: tags: - Games summary: Get a game by ID operationId: getGameById parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid responses: '200': description: Detailed information of a game @@ -301,13 +305,14 @@ paths: summary: Update a game operationId: updateGame parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid requestBody: content: application/json: @@ -333,13 +338,14 @@ paths: summary: Delete a game operationId: deleteGame parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid responses: '200': description: Game deleted successfully @@ -399,20 +405,21 @@ paths: content: application/json: schema: {} - '/api/v1/teams/{id}': + '/api/v1/teams/{uuid}': get: tags: - Teams summary: Get a team by ID operationId: getTeamById parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid responses: '200': description: Detailed information of a team @@ -426,13 +433,14 @@ paths: summary: Update a team operationId: updateTeam parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid requestBody: content: application/json: @@ -448,13 +456,14 @@ paths: summary: Delete a team operationId: deleteTeam parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid responses: '200': description: Team deleted successfully @@ -490,20 +499,21 @@ paths: responses: '200': description: Result created successfully - '/api/v1/results/{id}': + '/api/v1/results/{uuid}': get: tags: - Results summary: Get a result by ID operationId: getResultById parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid responses: '200': description: Detailed information of a result @@ -543,20 +553,21 @@ paths: responses: '200': description: Service created successfully - '/api/v1/services/{id}': + '/api/v1/services/{uuid}': get: tags: - Services summary: Get a service by ID operationId: getServiceById parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid responses: '200': description: Detailed information of a service @@ -570,13 +581,14 @@ paths: summary: Update a service operationId: updateService parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid requestBody: content: application/json: @@ -592,13 +604,14 @@ paths: summary: Delete a service operationId: deleteService parameters: - - name: id + - name: uuid in: path required: true style: simple explode: false schema: - type: integer + type: string + format: uuid responses: '200': description: Service deleted successfully @@ -655,14 +668,16 @@ components: team_ids: type: array items: - type: integer + type: string + format: uuid example: 1 description: Unique identifier for the result entry UserResponse: type: object properties: id: - type: integer + type: string + format: uuid description: The unique identifier for the user display_name: type: string @@ -711,7 +726,8 @@ components: type: object properties: id: - type: integer + type: string + format: uuid description: Unique identifier for the game start_time: type: string @@ -756,7 +772,8 @@ components: type: object properties: id: - type: integer + type: string + format: uuid description: Unique identifier for the result entry team_id: type: string @@ -801,7 +818,8 @@ components: type: object properties: id: - type: integer + type: string + format: uuid description: Unique identifier for the service name: type: string @@ -846,7 +864,8 @@ components: type: object properties: id: - type: integer + type: string + format: uuid description: Unique identifier for the team name: type: string @@ -870,7 +889,8 @@ components: - name properties: id: - type: integer + type: string + format: uuid description: The unique identifier of the university example: 1 name: diff --git a/internal/app/database/struct_updater.go b/internal/app/database/struct_updater.go index 65cde86..e7bd1cb 100644 --- a/internal/app/database/struct_updater.go +++ b/internal/app/database/struct_updater.go @@ -37,6 +37,7 @@ func RegisterAllUpdates() map[string][]DatabaseUpdateFunc { allUpdates = RegisterDatabaseUpdate(allUpdates, DatabaseUpdate_update0012_update0012testdata) allUpdates = RegisterDatabaseUpdate(allUpdates, DatabaseUpdate_update0012_update0013) allUpdates = RegisterDatabaseUpdate(allUpdates, DatabaseUpdate_update0013_update0013testdata) + allUpdates = RegisterDatabaseUpdate(allUpdates, DatabaseUpdate_update0013_update0014) return allUpdates } diff --git a/internal/app/database/update0013_update0014.go b/internal/app/database/update0013_update0014.go new file mode 100644 index 0000000..ea937ff --- /dev/null +++ b/internal/app/database/update0013_update0014.go @@ -0,0 +1,143 @@ +package database + +import ( + "database/sql" + "log/slog" + "runtime" +) + +func DatabaseUpdate_update0013_update0014(db *sql.DB, getInfo bool) (string, string, string, error) { + + // WARNING!!! + // Do not change the update if it has already been installed by other developers or in production. + // To correct the database, create a new update and register it in the list of updates. + + fromUpdateId, toUpdateId := ParseNameFuncUpdate(runtime.Caller(0)) + description := "Add new_id uuid to all table" + if getInfo { + return fromUpdateId, toUpdateId, description, nil + } + query := ` + BEGIN; + + ALTER TABLE results ADD COLUMN new_id UUID DEFAULT gen_random_uuid(); + UPDATE results SET new_id = gen_random_uuid(); + ALTER TABLE results DROP COLUMN id; + ALTER TABLE results ADD CONSTRAINT new_id_pkey PRIMARY KEY (new_id); + ALTER TABLE results RENAME COLUMN new_id TO id; + + + ALTER TABLE games ADD COLUMN new_id UUID DEFAULT gen_random_uuid(); + ALTER TABLE services ADD COLUMN new_id UUID DEFAULT gen_random_uuid(); + ALTER TABLE sessions ADD COLUMN new_id UUID DEFAULT gen_random_uuid(); + ALTER TABLE teams ADD COLUMN new_id UUID DEFAULT gen_random_uuid(); + ALTER TABLE universities ADD COLUMN new_id UUID DEFAULT gen_random_uuid(); + ALTER TABLE users ADD COLUMN new_id UUID DEFAULT gen_random_uuid(); + + + ALTER TABLE team_games ADD COLUMN new_team_id UUID; + ALTER TABLE team_games ADD COLUMN new_game_id UUID; + --- + UPDATE team_games tg + SET new_team_id = t.new_id + FROM teams t + WHERE tg.team_id = t.id; + --- + UPDATE team_games tg + SET new_game_id = g.new_id + FROM games g + WHERE tg.game_id = g.id; + --- + ALTER TABLE team_games DROP COLUMN team_id; + ALTER TABLE team_games DROP COLUMN game_id; + ALTER TABLE team_games RENAME COLUMN new_team_id TO team_id; + ALTER TABLE team_games RENAME COLUMN new_game_id TO game_id; + + + ALTER TABLE team_members ADD COLUMN new_team_id UUID; + ALTER TABLE team_members ADD COLUMN new_user_id UUID; + --- + UPDATE team_members tm + SET new_team_id = t.new_id + FROM teams t + WHERE tm.team_id = t.id; + --- + UPDATE team_members tm + SET new_user_id = u.new_id + FROM users u + WHERE tm.user_id = u.id; + --- + ALTER TABLE team_members DROP COLUMN team_id; + ALTER TABLE team_members DROP COLUMN user_id; + ALTER TABLE team_members RENAME COLUMN new_team_id TO team_id; + ALTER TABLE team_members RENAME COLUMN new_user_id TO user_id; + + + ALTER TABLE game_services ADD COLUMN new_game_id UUID; + ALTER TABLE game_services ADD COLUMN new_service_id UUID; + --- + UPDATE game_services gm + SET new_game_id = g.new_id + FROM games g + WHERE gm.game_id = g.id; + --- + UPDATE game_services gs + SET new_service_id = s.new_id + FROM services s + WHERE gs.service_id = s.id; + --- + ALTER TABLE game_services DROP COLUMN game_id; + ALTER TABLE game_services DROP COLUMN service_id; + ALTER TABLE game_services RENAME COLUMN new_game_id TO game_id; + ALTER TABLE game_services RENAME COLUMN new_service_id TO service_id; + + + ALTER TABLE results drop constraint results_game_id_fkey; + ALTER TABLE results drop constraint results_team_id_fkey; + ALTER TABLE results DROP COLUMN team_id; + ALTER TABLE results DROP COLUMN game_id; + ALTER TABLE results ADD COLUMN team_id UUID not null; + ALTER TABLE results ADD COLUMN game_id UUID not null; + + ALTER TABLE sessions drop constraint sessions_user_id_fkey; + ALTER TABLE sessions DROP COLUMN user_id; + ALTER TABLE sessions ADD COLUMN user_id UUID not null; + + ALTER TABLE teams DROP constraint teams_university_id_fkey; + ALTER TABLE teams DROP COLUMN university_id; + ALTER TABLE teams ADD COLUMN university_id UUID; + + ALTER TABLE games DROP COLUMN id; + ALTER TABLE games RENAME COLUMN new_id TO id; + ALTER TABLE teams DROP COLUMN id; + ALTER TABLE teams RENAME COLUMN new_id TO id; + ALTER TABLE users DROP COLUMN id; + ALTER TABLE users RENAME COLUMN new_id TO id; + ALTER TABLE universities DROP COLUMN id; + ALTER TABLE universities RENAME COLUMN new_id TO id; + ALTER TABLE services DROP COLUMN id; + ALTER TABLE services RENAME COLUMN new_id TO id; + + + ALTER TABLE games ADD CONSTRAINT games_id_unique UNIQUE (id); + ALTER TABLE teams ADD CONSTRAINT teams_id_unique UNIQUE (id); + ALTER TABLE users ADD CONSTRAINT users_id_unique UNIQUE (id); + ALTER TABLE universities ADD CONSTRAINT universities_id_unique UNIQUE (id); + ALTER TABLE services ADD CONSTRAINT services_id_unique UNIQUE (id); + + + ALTER TABLE results ADD CONSTRAINT results_game_id_fkey FOREIGN KEY (game_id) REFERENCES games(id); + ALTER TABLE results ADD CONSTRAINT results_team_id_fkey FOREIGN KEY (team_id) REFERENCES teams(id); + ALTER TABLE sessions ADD CONSTRAINT sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); + ALTER TABLE teams ADD CONSTRAINT teams_university_id_fkey FOREIGN KEY (university_id) REFERENCES universities(id); + + COMMIT; + ` + _, err := db.Exec(query) + if err != nil { + slog.Error("Problem with update, query: " + query + "\n error:" + err.Error()) + return fromUpdateId, toUpdateId, description, err + } + + return fromUpdateId, toUpdateId, description, nil +} diff --git a/internal/app/db/game.go b/internal/app/db/game.go index 925784c..e27f48f 100644 --- a/internal/app/db/game.go +++ b/internal/app/db/game.go @@ -2,13 +2,15 @@ package db import ( "time" + + openapi_types "github.com/oapi-codegen/runtime/types" ) type Game struct { - Id int `db:"id"` - StartTime time.Time `db:"start_time"` - EndTime time.Time `db:"end_time"` - Description string `db:"description"` + Id openapi_types.UUID `db:"id"` + StartTime time.Time `db:"start_time"` + EndTime time.Time `db:"end_time"` + Description string `db:"description"` } type GameDetails struct { diff --git a/internal/app/db/result.go b/internal/app/db/result.go index 6d5982a..b24e9a0 100644 --- a/internal/app/db/result.go +++ b/internal/app/db/result.go @@ -1,9 +1,11 @@ package db +import openapi_types "github.com/oapi-codegen/runtime/types" + type Result struct { - Id int `db:"id"` - TeamId string `db:"team_id"` - GameId string `db:"game_id"` - Score int `db:"score"` - Rank int `db:"rank"` + Id openapi_types.UUID `db:"id"` + TeamId string `db:"team_id"` + GameId string `db:"game_id"` + Score int `db:"score"` + Rank int `db:"rank"` } diff --git a/internal/app/db/service.go b/internal/app/db/service.go index 6d0a3ea..cae072c 100644 --- a/internal/app/db/service.go +++ b/internal/app/db/service.go @@ -1,10 +1,12 @@ package db +import openapi_types "github.com/oapi-codegen/runtime/types" + type Service struct { - Id int `db:"id"` - Name string `db:"name"` - Author string `db:"author"` - LogoUrl string `db:"logo_url"` - Description string `db:"description"` - IsPublic bool `db:"is_public"` + Id openapi_types.UUID `db:"id"` + Name string `db:"name"` + Author string `db:"author"` + LogoUrl string `db:"logo_url"` + Description string `db:"description"` + IsPublic bool `db:"is_public"` } diff --git a/internal/app/db/team.go b/internal/app/db/team.go index b2dc37b..0a35f5d 100644 --- a/internal/app/db/team.go +++ b/internal/app/db/team.go @@ -1,10 +1,12 @@ package db +import openapi_types "github.com/oapi-codegen/runtime/types" + type Team struct { - Id int `db:"id"` - Name string `db:"name"` - Description string `db:"description"` - UniversityId int `db:"university_id"` + Id openapi_types.UUID `db:"id"` + Name string `db:"name"` + Description string `db:"description"` + UniversityId int `db:"university_id"` University string SocialLinks string `db:"social_links"` AvatarUrl string `db:"avatar_url"` diff --git a/internal/app/db/university.go b/internal/app/db/university.go index 04dba16..d7efdcb 100644 --- a/internal/app/db/university.go +++ b/internal/app/db/university.go @@ -1,6 +1,8 @@ package db +import openapi_types "github.com/oapi-codegen/runtime/types" + type University struct { - Id int `db:"id"` - Name string `db:"name"` + Id openapi_types.UUID `db:"id"` + Name string `db:"name"` } diff --git a/internal/app/db/user.go b/internal/app/db/user.go index 9ef4aff..0807b14 100644 --- a/internal/app/db/user.go +++ b/internal/app/db/user.go @@ -1,9 +1,13 @@ package db -import "ctf01d/internal/app/server" +import ( + "ctf01d/internal/app/server" + + openapi_types "github.com/oapi-codegen/runtime/types" +) type User struct { - Id int `db:"id"` + Id openapi_types.UUID `db:"id"` DisplayName string `db:"display_name"` Username string `db:"user_name"` Role server.UserRequestRole `db:"role"` diff --git a/internal/app/handlers/games.go b/internal/app/handlers/games.go index fddeddd..d9a2586 100644 --- a/internal/app/handlers/games.go +++ b/internal/app/handlers/games.go @@ -11,6 +11,8 @@ import ( "ctf01d/internal/app/server" api_helpers "ctf01d/internal/app/utils" "ctf01d/internal/app/view" + + openapi_types "github.com/oapi-codegen/runtime/types" ) type Handlers struct { @@ -42,7 +44,7 @@ func (h *Handlers) CreateGame(w http.ResponseWriter, r *http.Request) { api_helpers.RespondWithJSON(w, http.StatusOK, map[string]string{"data": "Game created successfully"}) } -func (h *Handlers) DeleteGame(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) DeleteGame(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { repo := repository.NewGameRepository(h.DB) if err := repo.Delete(r.Context(), id); err != nil { slog.Warn(err.Error(), "handler", "DeleteGame") @@ -52,7 +54,7 @@ func (h *Handlers) DeleteGame(w http.ResponseWriter, r *http.Request, id int) { api_helpers.RespondWithJSON(w, http.StatusOK, map[string]string{"data": "Game deleted successfully"}) } -func (h *Handlers) GetGameById(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) GetGameById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { repo := repository.NewGameRepository(h.DB) game, err := repo.GetGameDetails(r.Context(), id) // короткий ответ, если нужен см. GetById if err != nil { @@ -74,7 +76,7 @@ func (h *Handlers) ListGames(w http.ResponseWriter, r *http.Request) { api_helpers.RespondWithJSON(w, http.StatusOK, view.NewGamesFromModels(games)) } -func (h *Handlers) UpdateGame(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) UpdateGame(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { // fixme update не проверяет есть ли запись в бд var game server.GameRequest if err := json.NewDecoder(r.Body).Decode(&game); err != nil { diff --git a/internal/app/handlers/interface.go b/internal/app/handlers/interface.go index 6a04b5e..e732cba 100644 --- a/internal/app/handlers/interface.go +++ b/internal/app/handlers/interface.go @@ -3,6 +3,8 @@ package handlers import ( "ctf01d/internal/app/server" "net/http" + + openapi_types "github.com/oapi-codegen/runtime/types" ) // ServerInterfaceWrapper wraps Handlers to conform to the generated interface @@ -22,15 +24,15 @@ func (siw *ServerInterfaceWrapper) CreateGame(w http.ResponseWriter, r *http.Req siw.handlers.CreateGame(w, r) } -func (siw *ServerInterfaceWrapper) DeleteGame(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) DeleteGame(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.DeleteGame(w, r, id) } -func (siw *ServerInterfaceWrapper) GetGameById(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) GetGameById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.GetGameById(w, r, id) } -func (siw *ServerInterfaceWrapper) UpdateGame(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) UpdateGame(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.UpdateGame(w, r, id) } @@ -54,7 +56,7 @@ func (siw *ServerInterfaceWrapper) CreateResult(w http.ResponseWriter, r *http.R siw.handlers.CreateResult(w, r) } -func (siw *ServerInterfaceWrapper) GetResultById(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) GetResultById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.GetResultById(w, r, id) } @@ -66,15 +68,15 @@ func (siw *ServerInterfaceWrapper) CreateService(w http.ResponseWriter, r *http. siw.handlers.CreateService(w, r) } -func (siw *ServerInterfaceWrapper) DeleteService(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) DeleteService(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.DeleteService(w, r, id) } -func (siw *ServerInterfaceWrapper) GetServiceById(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) GetServiceById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.GetServiceById(w, r, id) } -func (siw *ServerInterfaceWrapper) UpdateService(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) UpdateService(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.UpdateService(w, r, id) } @@ -86,15 +88,15 @@ func (siw *ServerInterfaceWrapper) CreateTeam(w http.ResponseWriter, r *http.Req siw.handlers.CreateTeam(w, r) } -func (siw *ServerInterfaceWrapper) DeleteTeam(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) DeleteTeam(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.DeleteTeam(w, r, id) } -func (siw *ServerInterfaceWrapper) GetTeamById(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) GetTeamById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.GetTeamById(w, r, id) } -func (siw *ServerInterfaceWrapper) UpdateTeam(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) UpdateTeam(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.UpdateTeam(w, r, id) } @@ -110,14 +112,14 @@ func (siw *ServerInterfaceWrapper) CreateUser(w http.ResponseWriter, r *http.Req siw.handlers.CreateUser(w, r) } -func (siw *ServerInterfaceWrapper) DeleteUser(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) DeleteUser(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.DeleteUser(w, r, id) } -func (siw *ServerInterfaceWrapper) GetUserById(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) GetUserById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.GetUserById(w, r, id) } -func (siw *ServerInterfaceWrapper) UpdateUser(w http.ResponseWriter, r *http.Request, id int) { +func (siw *ServerInterfaceWrapper) UpdateUser(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.UpdateUser(w, r, id) } diff --git a/internal/app/handlers/results.go b/internal/app/handlers/results.go index 7d8b08b..a55f225 100644 --- a/internal/app/handlers/results.go +++ b/internal/app/handlers/results.go @@ -10,6 +10,8 @@ import ( "ctf01d/internal/app/server" api_helpers "ctf01d/internal/app/utils" "ctf01d/internal/app/view" + + openapi_types "github.com/oapi-codegen/runtime/types" ) func (h *Handlers) CreateResult(w http.ResponseWriter, r *http.Request) { @@ -34,7 +36,7 @@ func (h *Handlers) CreateResult(w http.ResponseWriter, r *http.Request) { api_helpers.RespondWithJSON(w, http.StatusOK, map[string]string{"data": "Game created successfully"}) } -func (h *Handlers) GetResultById(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) GetResultById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { repo := repository.NewResultRepository(h.DB) result, err := repo.GetById(r.Context(), id) if err != nil { diff --git a/internal/app/handlers/services.go b/internal/app/handlers/services.go index 40af0c3..a539164 100644 --- a/internal/app/handlers/services.go +++ b/internal/app/handlers/services.go @@ -10,6 +10,8 @@ import ( "ctf01d/internal/app/server" api_helpers "ctf01d/internal/app/utils" "ctf01d/internal/app/view" + + openapi_types "github.com/oapi-codegen/runtime/types" ) func (h *Handlers) CreateService(w http.ResponseWriter, r *http.Request) { @@ -35,7 +37,7 @@ func (h *Handlers) CreateService(w http.ResponseWriter, r *http.Request) { api_helpers.RespondWithJSON(w, http.StatusOK, map[string]string{"data": "Service created successfully"}) } -func (h *Handlers) DeleteService(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) DeleteService(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { repo := repository.NewServiceRepository(h.DB) if err := repo.Delete(r.Context(), id); err != nil { slog.Warn(err.Error(), "handler", "DeleteServiceHandler") @@ -45,7 +47,7 @@ func (h *Handlers) DeleteService(w http.ResponseWriter, r *http.Request, id int) api_helpers.RespondWithJSON(w, http.StatusOK, map[string]string{"data": "Service deleted successfully"}) } -func (h *Handlers) GetServiceById(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) GetServiceById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { repo := repository.NewServiceRepository(h.DB) service, err := repo.GetById(r.Context(), id) if err != nil { @@ -68,7 +70,7 @@ func (h *Handlers) ListServices(w http.ResponseWriter, r *http.Request) { } // fixme implement -func (h *Handlers) UpdateService(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) UpdateService(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusNotImplemented) } diff --git a/internal/app/handlers/teams.go b/internal/app/handlers/teams.go index adc934a..914c7c5 100644 --- a/internal/app/handlers/teams.go +++ b/internal/app/handlers/teams.go @@ -10,6 +10,8 @@ import ( "ctf01d/internal/app/server" api_helpers "ctf01d/internal/app/utils" "ctf01d/internal/app/view" + + openapi_types "github.com/oapi-codegen/runtime/types" ) func (h *Handlers) CreateTeam(w http.ResponseWriter, r *http.Request) { @@ -36,7 +38,7 @@ func (h *Handlers) CreateTeam(w http.ResponseWriter, r *http.Request) { api_helpers.RespondWithJSON(w, http.StatusOK, map[string]string{"data": "Team created successfully"}) } -func (h *Handlers) DeleteTeam(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) DeleteTeam(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { teamRepo := repository.NewTeamRepository(h.DB) if err := teamRepo.Delete(r.Context(), id); err != nil { slog.Warn(err.Error(), "handler", "DeleteTeamHandler") @@ -46,7 +48,7 @@ func (h *Handlers) DeleteTeam(w http.ResponseWriter, r *http.Request, id int) { api_helpers.RespondWithJSON(w, http.StatusOK, map[string]string{"data": "Team deleted successfully"}) } -func (h *Handlers) GetTeamById(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) GetTeamById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { teamRepo := repository.NewTeamRepository(h.DB) team, err := teamRepo.GetById(r.Context(), id) if err != nil { @@ -68,7 +70,7 @@ func (h *Handlers) ListTeams(w http.ResponseWriter, r *http.Request) { api_helpers.RespondWithJSON(w, http.StatusOK, view.NewTeamsFromModels(teams)) } -func (h *Handlers) UpdateTeam(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) UpdateTeam(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { var team server.TeamRequest if err := json.NewDecoder(r.Body).Decode(&team); err != nil { slog.Warn(err.Error(), "handler", "UpdateTeamHandler") diff --git a/internal/app/handlers/users.go b/internal/app/handlers/users.go index 8432250..6f959b0 100644 --- a/internal/app/handlers/users.go +++ b/internal/app/handlers/users.go @@ -10,6 +10,8 @@ import ( "ctf01d/internal/app/server" api_helpers "ctf01d/internal/app/utils" "ctf01d/internal/app/view" + + openapi_types "github.com/oapi-codegen/runtime/types" ) func (h *Handlers) CreateUser(w http.ResponseWriter, r *http.Request) { @@ -50,7 +52,7 @@ func (h *Handlers) CreateUser(w http.ResponseWriter, r *http.Request) { api_helpers.RespondWithJSON(w, http.StatusOK, map[string]string{"data": "User created successfully"}) } -func (h *Handlers) DeleteUser(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) DeleteUser(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { repo := repository.NewUserRepository(h.DB) if err := repo.Delete(r.Context(), id); err != nil { slog.Warn(err.Error(), "handler", "DeleteUserHandler") @@ -60,7 +62,7 @@ func (h *Handlers) DeleteUser(w http.ResponseWriter, r *http.Request, id int) { api_helpers.RespondWithJSON(w, http.StatusOK, map[string]string{"data": "User deleted successfully"}) } -func (h *Handlers) GetUserById(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) GetUserById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { repo := repository.NewUserRepository(h.DB) user, err := repo.GetById(r.Context(), id) if err != nil { @@ -82,7 +84,7 @@ func (h *Handlers) ListUsers(w http.ResponseWriter, r *http.Request) { api_helpers.RespondWithJSON(w, http.StatusOK, view.NewUsersFromModels(users)) } -func (h *Handlers) UpdateUser(w http.ResponseWriter, r *http.Request, id int) { +func (h *Handlers) UpdateUser(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { // fixme update не проверяет есть ли запись в бд var user server.UserRequest if err := json.NewDecoder(r.Body).Decode(&user); err != nil { diff --git a/internal/app/repository/game.go b/internal/app/repository/game.go index 5b5aa02..b241fb2 100644 --- a/internal/app/repository/game.go +++ b/internal/app/repository/game.go @@ -4,15 +4,18 @@ import ( "context" models "ctf01d/internal/app/db" "database/sql" + "time" + + openapi_types "github.com/oapi-codegen/runtime/types" ) type GameRepository interface { Create(ctx context.Context, game *models.Game) error - GetById(ctx context.Context, id int) (*models.Game, error) - GetGameDetails(ctx context.Context, id int) (*models.GameDetails, error) + GetById(ctx context.Context, id openapi_types.UUID) (*models.Game, error) + GetGameDetails(ctx context.Context, id openapi_types.UUID) (*models.GameDetails, error) Update(ctx context.Context, game *models.Game) error - Delete(ctx context.Context, id int) error + Delete(ctx context.Context, id openapi_types.UUID) error List(ctx context.Context) ([]*models.Game, error) } @@ -30,7 +33,7 @@ func (r *gameRepo) Create(ctx context.Context, game *models.Game) error { return err } -func (r *gameRepo) GetGameDetails(ctx context.Context, id int) (*models.GameDetails, error) { +func (r *gameRepo) GetGameDetails(ctx context.Context, id openapi_types.UUID) (*models.GameDetails, error) { query := ` SELECT g.id, g.start_time, g.end_time, g.description, t.id, t.name, t.description, u.id, u.user_name FROM games g @@ -47,16 +50,16 @@ func (r *gameRepo) GetGameDetails(ctx context.Context, id int) (*models.GameDeta defer rows.Close() gameDetails := &models.GameDetails{} - teams := map[int]*models.TeamDetails{} + teams := map[openapi_types.UUID]*models.TeamDetails{} for rows.Next() { - var gameId int + var gameId openapi_types.UUID var startTime, endTime time.Time var description string - var teamId int + var teamId openapi_types.UUID var teamName string var teamDescription string - var userId int + var userId openapi_types.UUID var userName string err := rows.Scan(&gameId, &startTime, &endTime, &description, &teamId, &teamName, &teamDescription, &userId, &userName) @@ -64,13 +67,6 @@ func (r *gameRepo) GetGameDetails(ctx context.Context, id int) (*models.GameDeta return nil, err } - if gameDetails.Id == 0 { - gameDetails.Id = gameId - gameDetails.StartTime = startTime - gameDetails.EndTime = endTime - gameDetails.Description = description - } - if team, ok := teams[teamId]; ok { team.Members = append(team.Members, &models.User{Id: userId, Username: userName}) } else { @@ -90,7 +86,7 @@ func (r *gameRepo) GetGameDetails(ctx context.Context, id int) (*models.GameDeta return gameDetails, nil } -func (r *gameRepo) GetById(ctx context.Context, id int) (*models.Game, error) { +func (r *gameRepo) GetById(ctx context.Context, id openapi_types.UUID) (*models.Game, error) { query := `SELECT id, start_time, end_time, description FROM games WHERE id = $1` game := &models.Game{} err := r.db.QueryRowContext(ctx, query, id).Scan(&game.Id, &game.StartTime, &game.EndTime, &game.Description) @@ -106,7 +102,7 @@ func (r *gameRepo) Update(ctx context.Context, game *models.Game) error { return err } -func (r *gameRepo) Delete(ctx context.Context, id int) error { +func (r *gameRepo) Delete(ctx context.Context, id openapi_types.UUID) error { query := `DELETE FROM games WHERE id = $1` _, err := r.db.ExecContext(ctx, query, id) return err diff --git a/internal/app/repository/result.go b/internal/app/repository/result.go index 9aba892..08b61fa 100644 --- a/internal/app/repository/result.go +++ b/internal/app/repository/result.go @@ -4,11 +4,13 @@ import ( "context" models "ctf01d/internal/app/db" "database/sql" + + openapi_types "github.com/oapi-codegen/runtime/types" ) type ResultRepository interface { Create(ctx context.Context, result *models.Result) error - GetById(ctx context.Context, id int) (*models.Result, error) + GetById(ctx context.Context, id openapi_types.UUID) (*models.Result, error) Update(ctx context.Context, result *models.Result) error Delete(ctx context.Context, id string) error List(ctx context.Context) ([]*models.Result, error) @@ -28,7 +30,7 @@ func (r *resultRepo) Create(ctx context.Context, result *models.Result) error { return err } -func (r *resultRepo) GetById(ctx context.Context, id int) (*models.Result, error) { +func (r *resultRepo) GetById(ctx context.Context, id openapi_types.UUID) (*models.Result, error) { query := `SELECT id, team_id, game_id, score, rank FROM results WHERE id = $1` result := &models.Result{} err := r.db.QueryRowContext(ctx, query, id).Scan(&result.Id, &result.TeamId, &result.GameId, &result.Score, &result.Rank) diff --git a/internal/app/repository/service.go b/internal/app/repository/service.go index 8085a41..d282290 100644 --- a/internal/app/repository/service.go +++ b/internal/app/repository/service.go @@ -4,13 +4,15 @@ import ( "context" models "ctf01d/internal/app/db" "database/sql" + + openapi_types "github.com/oapi-codegen/runtime/types" ) type ServiceRepository interface { Create(ctx context.Context, service *models.Service) error - GetById(ctx context.Context, id int) (*models.Service, error) + GetById(ctx context.Context, id openapi_types.UUID) (*models.Service, error) Update(ctx context.Context, service *models.Service) error - Delete(ctx context.Context, id int) error + Delete(ctx context.Context, id openapi_types.UUID) error List(ctx context.Context) ([]*models.Service, error) } @@ -28,7 +30,7 @@ func (r *serviceRepo) Create(ctx context.Context, service *models.Service) error return err } -func (r *serviceRepo) GetById(ctx context.Context, id int) (*models.Service, error) { +func (r *serviceRepo) GetById(ctx context.Context, id openapi_types.UUID) (*models.Service, error) { query := `SELECT id, name, author, logo_url, description, is_public FROM services WHERE id = $1` service := &models.Service{} err := r.db.QueryRowContext(ctx, query, id).Scan(&service.Id, &service.Name, &service.Author, &service.LogoUrl, &service.Description, &service.IsPublic) @@ -44,7 +46,7 @@ func (r *serviceRepo) Update(ctx context.Context, service *models.Service) error return err } -func (r *serviceRepo) Delete(ctx context.Context, id int) error { +func (r *serviceRepo) Delete(ctx context.Context, id openapi_types.UUID) error { query := `DELETE FROM services WHERE id = $1` _, err := r.db.ExecContext(ctx, query, id) return err diff --git a/internal/app/repository/session.go b/internal/app/repository/session.go index 5325577..258771b 100644 --- a/internal/app/repository/session.go +++ b/internal/app/repository/session.go @@ -5,11 +5,13 @@ import ( "database/sql" "fmt" "time" + + openapi_types "github.com/oapi-codegen/runtime/types" ) type SessionRepository interface { GetSessionFromDB(ctx context.Context, sessionId string) (int, error) - StoreSessionInDB(ctx context.Context, userId int) (string, error) + StoreSessionInDB(ctx context.Context, userId openapi_types.UUID) (string, error) DeleteSessionInDB(ctx context.Context, cookie string) error } @@ -27,7 +29,7 @@ func (r *sessionRepo) GetSessionFromDB(ctx context.Context, sessionId string) (i return userId, err } -func (r *sessionRepo) StoreSessionInDB(ctx context.Context, userId int) (string, error) { +func (r *sessionRepo) StoreSessionInDB(ctx context.Context, userId openapi_types.UUID) (string, error) { var session string query := ` INSERT INTO sessions (user_id, expires_at) diff --git a/internal/app/repository/team.go b/internal/app/repository/team.go index e8a0297..7135c2f 100644 --- a/internal/app/repository/team.go +++ b/internal/app/repository/team.go @@ -4,13 +4,15 @@ import ( "context" models "ctf01d/internal/app/db" "database/sql" + + openapi_types "github.com/oapi-codegen/runtime/types" ) type TeamRepository interface { Create(ctx context.Context, team *models.Team) error - GetById(ctx context.Context, id int) (*models.Team, error) + GetById(ctx context.Context, id openapi_types.UUID) (*models.Team, error) Update(ctx context.Context, team *models.Team) error - Delete(ctx context.Context, id int) error + Delete(ctx context.Context, id openapi_types.UUID) error List(ctx context.Context) ([]*models.Team, error) } @@ -28,7 +30,7 @@ func (r *teamRepo) Create(ctx context.Context, team *models.Team) error { return err } -func (r *teamRepo) GetById(ctx context.Context, id int) (*models.Team, error) { +func (r *teamRepo) GetById(ctx context.Context, id openapi_types.UUID) (*models.Team, error) { query := `SELECT t.id, t.name, t.description, t.social_links, t.avatar_url, u.name as university_name FROM teams t JOIN universities u ON t.university_id = u.id @@ -47,7 +49,7 @@ func (r *teamRepo) Update(ctx context.Context, team *models.Team) error { return err } -func (r *teamRepo) Delete(ctx context.Context, id int) error { +func (r *teamRepo) Delete(ctx context.Context, id openapi_types.UUID) error { query := `DELETE FROM teams WHERE id = $1` _, err := r.db.ExecContext(ctx, query, id) return err diff --git a/internal/app/repository/user.go b/internal/app/repository/user.go index c9e3374..40cc4f0 100644 --- a/internal/app/repository/user.go +++ b/internal/app/repository/user.go @@ -4,15 +4,17 @@ import ( "context" models "ctf01d/internal/app/db" "database/sql" + + openapi_types "github.com/oapi-codegen/runtime/types" ) type UserRepository interface { Create(ctx context.Context, user *models.User) error - AddUserToTeams(ctx context.Context, userId int, teamIds *[]int) error - GetById(ctx context.Context, id int) (*models.User, error) + AddUserToTeams(ctx context.Context, userId openapi_types.UUID, teamIds *[]openapi_types.UUID) error + GetById(ctx context.Context, id openapi_types.UUID) (*models.User, error) GetByUserName(ctx context.Context, id string) (*models.User, error) Update(ctx context.Context, user *models.User) error - Delete(ctx context.Context, id int) error + Delete(ctx context.Context, id openapi_types.UUID) error List(ctx context.Context) ([]*models.User, error) } @@ -34,7 +36,7 @@ func (r *userRepo) Create(ctx context.Context, user *models.User) error { return nil } -func (r *userRepo) AddUserToTeams(ctx context.Context, userId int, teamIds *[]int) error { +func (r *userRepo) AddUserToTeams(ctx context.Context, userId openapi_types.UUID, teamIds *[]openapi_types.UUID) error { for _, teamId := range *teamIds { _, err := r.db.ExecContext(ctx, "INSERT INTO team_members (user_id, team_id) VALUES ($1, $2)", userId, teamId) if err != nil { @@ -45,7 +47,7 @@ func (r *userRepo) AddUserToTeams(ctx context.Context, userId int, teamIds *[]in return nil } -func (r *userRepo) GetById(ctx context.Context, id int) (*models.User, error) { +func (r *userRepo) GetById(ctx context.Context, id openapi_types.UUID) (*models.User, error) { query := `SELECT id, display_name, user_name, avatar_url, role, status FROM users WHERE id = $1` user := &models.User{} err := r.db.QueryRowContext(ctx, query, id).Scan(&user.Id, &user.DisplayName, &user.Username, &user.AvatarUrl, &user.Role, &user.Status) @@ -71,7 +73,7 @@ func (r *userRepo) Update(ctx context.Context, user *models.User) error { return err } -func (r *userRepo) Delete(ctx context.Context, id int) error { +func (r *userRepo) Delete(ctx context.Context, id openapi_types.UUID) error { tx, err := r.db.BeginTx(ctx, nil) if err != nil { return err diff --git a/internal/app/server/server.gen.go b/internal/app/server/server.gen.go index 083669e..0d45532 100644 --- a/internal/app/server/server.gen.go +++ b/internal/app/server/server.gen.go @@ -10,6 +10,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/oapi-codegen/runtime" + openapi_types "github.com/oapi-codegen/runtime/types" ) // Defines values for UserRequestRole. @@ -47,7 +48,7 @@ type GameResponse struct { EndTime time.Time `json:"end_time"` // Id Unique identifier for the game - Id int `json:"id"` + Id openapi_types.UUID `json:"id"` // StartTime The start time of the game StartTime time.Time `json:"start_time"` @@ -74,7 +75,7 @@ type ResultResponse struct { GameId string `json:"game_id"` // Id Unique identifier for the result entry - Id int `json:"id"` + Id openapi_types.UUID `json:"id"` // Rank The rank achieved by the team in this game Rank int `json:"rank"` @@ -113,7 +114,7 @@ type ServiceResponse struct { Description *string `json:"description,omitempty"` // Id Unique identifier for the service - Id int `json:"id"` + Id openapi_types.UUID `json:"id"` // IsPublic Boolean indicating if the service is public IsPublic bool `json:"is_public"` @@ -152,7 +153,7 @@ type TeamResponse struct { Description *string `json:"description,omitempty"` // Id Unique identifier for the team - Id int `json:"id"` + Id openapi_types.UUID `json:"id"` // Name Name of the team Name string `json:"name"` @@ -170,7 +171,7 @@ type UniversitiesResponse = []UniversityResponse // UniversityResponse defines model for UniversityResponse. type UniversityResponse struct { // Id The unique identifier of the university - Id int `json:"id"` + Id openapi_types.UUID `json:"id"` // Name The name of the university Name string `json:"name"` @@ -191,8 +192,8 @@ type UserRequest struct { Role *UserRequestRole `json:"role,omitempty"` // Status Status of the user (active, disabled) - Status *string `json:"status,omitempty"` - TeamIds *[]int `json:"team_ids,omitempty"` + Status *string `json:"status,omitempty"` + TeamIds *[]openapi_types.UUID `json:"team_ids,omitempty"` // UserName The login of the user UserName *string `json:"user_name,omitempty"` @@ -210,7 +211,7 @@ type UserResponse struct { DisplayName *string `json:"display_name,omitempty"` // Id The unique identifier for the user - Id *int `json:"id,omitempty"` + Id *openapi_types.UUID `json:"id,omitempty"` // Role The role of the user (admin, player or guest) Role *UserResponseRole `json:"role,omitempty"` @@ -285,14 +286,14 @@ type ServerInterface interface { // (POST /api/v1/games) CreateGame(w http.ResponseWriter, r *http.Request) // Delete a game - // (DELETE /api/v1/games/{id}) - DeleteGame(w http.ResponseWriter, r *http.Request, id int) + // (DELETE /api/v1/games/{uuid}) + DeleteGame(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // Get a game by ID - // (GET /api/v1/games/{id}) - GetGameById(w http.ResponseWriter, r *http.Request, id int) + // (GET /api/v1/games/{uuid}) + GetGameById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // Update a game - // (PUT /api/v1/games/{id}) - UpdateGame(w http.ResponseWriter, r *http.Request, id int) + // (PUT /api/v1/games/{uuid}) + UpdateGame(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // List all results // (GET /api/v1/results) ListResults(w http.ResponseWriter, r *http.Request) @@ -300,8 +301,8 @@ type ServerInterface interface { // (POST /api/v1/results) CreateResult(w http.ResponseWriter, r *http.Request) // Get a result by ID - // (GET /api/v1/results/{id}) - GetResultById(w http.ResponseWriter, r *http.Request, id int) + // (GET /api/v1/results/{uuid}) + GetResultById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // List all services // (GET /api/v1/services) ListServices(w http.ResponseWriter, r *http.Request) @@ -309,14 +310,14 @@ type ServerInterface interface { // (POST /api/v1/services) CreateService(w http.ResponseWriter, r *http.Request) // Delete a service - // (DELETE /api/v1/services/{id}) - DeleteService(w http.ResponseWriter, r *http.Request, id int) + // (DELETE /api/v1/services/{uuid}) + DeleteService(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // Get a service by ID - // (GET /api/v1/services/{id}) - GetServiceById(w http.ResponseWriter, r *http.Request, id int) + // (GET /api/v1/services/{uuid}) + GetServiceById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // Update a service - // (PUT /api/v1/services/{id}) - UpdateService(w http.ResponseWriter, r *http.Request, id int) + // (PUT /api/v1/services/{uuid}) + UpdateService(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // List all teams // (GET /api/v1/teams) ListTeams(w http.ResponseWriter, r *http.Request) @@ -324,14 +325,14 @@ type ServerInterface interface { // (POST /api/v1/teams) CreateTeam(w http.ResponseWriter, r *http.Request) // Delete a team - // (DELETE /api/v1/teams/{id}) - DeleteTeam(w http.ResponseWriter, r *http.Request, id int) + // (DELETE /api/v1/teams/{uuid}) + DeleteTeam(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // Get a team by ID - // (GET /api/v1/teams/{id}) - GetTeamById(w http.ResponseWriter, r *http.Request, id int) + // (GET /api/v1/teams/{uuid}) + GetTeamById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // Update a team - // (PUT /api/v1/teams/{id}) - UpdateTeam(w http.ResponseWriter, r *http.Request, id int) + // (PUT /api/v1/teams/{uuid}) + UpdateTeam(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // Retrieves a list of universities // (GET /api/v1/universities) GetApiV1Universities(w http.ResponseWriter, r *http.Request, params GetApiV1UniversitiesParams) @@ -342,14 +343,14 @@ type ServerInterface interface { // (POST /api/v1/users) CreateUser(w http.ResponseWriter, r *http.Request) // Delete a user - // (DELETE /api/v1/users/{id}) - DeleteUser(w http.ResponseWriter, r *http.Request, id int) + // (DELETE /api/v1/users/{uuid}) + DeleteUser(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // Get a user by ID - // (GET /api/v1/users/{id}) - GetUserById(w http.ResponseWriter, r *http.Request, id int) + // (GET /api/v1/users/{uuid}) + GetUserById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) // Update a user - // (PUT /api/v1/users/{id}) - UpdateUser(w http.ResponseWriter, r *http.Request, id int) + // (PUT /api/v1/users/{uuid}) + UpdateUser(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) } // Unimplemented server implementation that returns http.StatusNotImplemented for each endpoint. @@ -387,20 +388,20 @@ func (_ Unimplemented) CreateGame(w http.ResponseWriter, r *http.Request) { } // Delete a game -// (DELETE /api/v1/games/{id}) -func (_ Unimplemented) DeleteGame(w http.ResponseWriter, r *http.Request, id int) { +// (DELETE /api/v1/games/{uuid}) +func (_ Unimplemented) DeleteGame(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Get a game by ID -// (GET /api/v1/games/{id}) -func (_ Unimplemented) GetGameById(w http.ResponseWriter, r *http.Request, id int) { +// (GET /api/v1/games/{uuid}) +func (_ Unimplemented) GetGameById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Update a game -// (PUT /api/v1/games/{id}) -func (_ Unimplemented) UpdateGame(w http.ResponseWriter, r *http.Request, id int) { +// (PUT /api/v1/games/{uuid}) +func (_ Unimplemented) UpdateGame(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } @@ -417,8 +418,8 @@ func (_ Unimplemented) CreateResult(w http.ResponseWriter, r *http.Request) { } // Get a result by ID -// (GET /api/v1/results/{id}) -func (_ Unimplemented) GetResultById(w http.ResponseWriter, r *http.Request, id int) { +// (GET /api/v1/results/{uuid}) +func (_ Unimplemented) GetResultById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } @@ -435,20 +436,20 @@ func (_ Unimplemented) CreateService(w http.ResponseWriter, r *http.Request) { } // Delete a service -// (DELETE /api/v1/services/{id}) -func (_ Unimplemented) DeleteService(w http.ResponseWriter, r *http.Request, id int) { +// (DELETE /api/v1/services/{uuid}) +func (_ Unimplemented) DeleteService(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Get a service by ID -// (GET /api/v1/services/{id}) -func (_ Unimplemented) GetServiceById(w http.ResponseWriter, r *http.Request, id int) { +// (GET /api/v1/services/{uuid}) +func (_ Unimplemented) GetServiceById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Update a service -// (PUT /api/v1/services/{id}) -func (_ Unimplemented) UpdateService(w http.ResponseWriter, r *http.Request, id int) { +// (PUT /api/v1/services/{uuid}) +func (_ Unimplemented) UpdateService(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } @@ -465,20 +466,20 @@ func (_ Unimplemented) CreateTeam(w http.ResponseWriter, r *http.Request) { } // Delete a team -// (DELETE /api/v1/teams/{id}) -func (_ Unimplemented) DeleteTeam(w http.ResponseWriter, r *http.Request, id int) { +// (DELETE /api/v1/teams/{uuid}) +func (_ Unimplemented) DeleteTeam(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Get a team by ID -// (GET /api/v1/teams/{id}) -func (_ Unimplemented) GetTeamById(w http.ResponseWriter, r *http.Request, id int) { +// (GET /api/v1/teams/{uuid}) +func (_ Unimplemented) GetTeamById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Update a team -// (PUT /api/v1/teams/{id}) -func (_ Unimplemented) UpdateTeam(w http.ResponseWriter, r *http.Request, id int) { +// (PUT /api/v1/teams/{uuid}) +func (_ Unimplemented) UpdateTeam(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } @@ -501,20 +502,20 @@ func (_ Unimplemented) CreateUser(w http.ResponseWriter, r *http.Request) { } // Delete a user -// (DELETE /api/v1/users/{id}) -func (_ Unimplemented) DeleteUser(w http.ResponseWriter, r *http.Request, id int) { +// (DELETE /api/v1/users/{uuid}) +func (_ Unimplemented) DeleteUser(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Get a user by ID -// (GET /api/v1/users/{id}) -func (_ Unimplemented) GetUserById(w http.ResponseWriter, r *http.Request, id int) { +// (GET /api/v1/users/{uuid}) +func (_ Unimplemented) GetUserById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Update a user -// (PUT /api/v1/users/{id}) -func (_ Unimplemented) UpdateUser(w http.ResponseWriter, r *http.Request, id int) { +// (PUT /api/v1/users/{uuid}) +func (_ Unimplemented) UpdateUser(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } @@ -608,17 +609,17 @@ func (siw *ServerInterfaceWrapper) DeleteGame(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.DeleteGame(w, r, id) + siw.Handler.DeleteGame(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -634,17 +635,17 @@ func (siw *ServerInterfaceWrapper) GetGameById(w http.ResponseWriter, r *http.Re var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetGameById(w, r, id) + siw.Handler.GetGameById(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -660,17 +661,17 @@ func (siw *ServerInterfaceWrapper) UpdateGame(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.UpdateGame(w, r, id) + siw.Handler.UpdateGame(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -716,17 +717,17 @@ func (siw *ServerInterfaceWrapper) GetResultById(w http.ResponseWriter, r *http. var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetResultById(w, r, id) + siw.Handler.GetResultById(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -772,17 +773,17 @@ func (siw *ServerInterfaceWrapper) DeleteService(w http.ResponseWriter, r *http. var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.DeleteService(w, r, id) + siw.Handler.DeleteService(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -798,17 +799,17 @@ func (siw *ServerInterfaceWrapper) GetServiceById(w http.ResponseWriter, r *http var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetServiceById(w, r, id) + siw.Handler.GetServiceById(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -824,17 +825,17 @@ func (siw *ServerInterfaceWrapper) UpdateService(w http.ResponseWriter, r *http. var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.UpdateService(w, r, id) + siw.Handler.UpdateService(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -880,17 +881,17 @@ func (siw *ServerInterfaceWrapper) DeleteTeam(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.DeleteTeam(w, r, id) + siw.Handler.DeleteTeam(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -906,17 +907,17 @@ func (siw *ServerInterfaceWrapper) GetTeamById(w http.ResponseWriter, r *http.Re var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetTeamById(w, r, id) + siw.Handler.GetTeamById(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -932,17 +933,17 @@ func (siw *ServerInterfaceWrapper) UpdateTeam(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.UpdateTeam(w, r, id) + siw.Handler.UpdateTeam(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -1016,17 +1017,17 @@ func (siw *ServerInterfaceWrapper) DeleteUser(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.DeleteUser(w, r, id) + siw.Handler.DeleteUser(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -1042,17 +1043,17 @@ func (siw *ServerInterfaceWrapper) GetUserById(w http.ResponseWriter, r *http.Re var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetUserById(w, r, id) + siw.Handler.GetUserById(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -1068,17 +1069,17 @@ func (siw *ServerInterfaceWrapper) UpdateUser(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "id" ------------- - var id int + // ------------- Path parameter "uuid" ------------- + var uuid openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "id", chi.URLParam(r, "id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.UpdateUser(w, r, id) + siw.Handler.UpdateUser(w, r, uuid) })) for _, middleware := range siw.HandlerMiddlewares { @@ -1217,13 +1218,13 @@ func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handl r.Post(options.BaseURL+"/api/v1/games", wrapper.CreateGame) }) r.Group(func(r chi.Router) { - r.Delete(options.BaseURL+"/api/v1/games/{id}", wrapper.DeleteGame) + r.Delete(options.BaseURL+"/api/v1/games/{uuid}", wrapper.DeleteGame) }) r.Group(func(r chi.Router) { - r.Get(options.BaseURL+"/api/v1/games/{id}", wrapper.GetGameById) + r.Get(options.BaseURL+"/api/v1/games/{uuid}", wrapper.GetGameById) }) r.Group(func(r chi.Router) { - r.Put(options.BaseURL+"/api/v1/games/{id}", wrapper.UpdateGame) + r.Put(options.BaseURL+"/api/v1/games/{uuid}", wrapper.UpdateGame) }) r.Group(func(r chi.Router) { r.Get(options.BaseURL+"/api/v1/results", wrapper.ListResults) @@ -1232,7 +1233,7 @@ func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handl r.Post(options.BaseURL+"/api/v1/results", wrapper.CreateResult) }) r.Group(func(r chi.Router) { - r.Get(options.BaseURL+"/api/v1/results/{id}", wrapper.GetResultById) + r.Get(options.BaseURL+"/api/v1/results/{uuid}", wrapper.GetResultById) }) r.Group(func(r chi.Router) { r.Get(options.BaseURL+"/api/v1/services", wrapper.ListServices) @@ -1241,13 +1242,13 @@ func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handl r.Post(options.BaseURL+"/api/v1/services", wrapper.CreateService) }) r.Group(func(r chi.Router) { - r.Delete(options.BaseURL+"/api/v1/services/{id}", wrapper.DeleteService) + r.Delete(options.BaseURL+"/api/v1/services/{uuid}", wrapper.DeleteService) }) r.Group(func(r chi.Router) { - r.Get(options.BaseURL+"/api/v1/services/{id}", wrapper.GetServiceById) + r.Get(options.BaseURL+"/api/v1/services/{uuid}", wrapper.GetServiceById) }) r.Group(func(r chi.Router) { - r.Put(options.BaseURL+"/api/v1/services/{id}", wrapper.UpdateService) + r.Put(options.BaseURL+"/api/v1/services/{uuid}", wrapper.UpdateService) }) r.Group(func(r chi.Router) { r.Get(options.BaseURL+"/api/v1/teams", wrapper.ListTeams) @@ -1256,13 +1257,13 @@ func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handl r.Post(options.BaseURL+"/api/v1/teams", wrapper.CreateTeam) }) r.Group(func(r chi.Router) { - r.Delete(options.BaseURL+"/api/v1/teams/{id}", wrapper.DeleteTeam) + r.Delete(options.BaseURL+"/api/v1/teams/{uuid}", wrapper.DeleteTeam) }) r.Group(func(r chi.Router) { - r.Get(options.BaseURL+"/api/v1/teams/{id}", wrapper.GetTeamById) + r.Get(options.BaseURL+"/api/v1/teams/{uuid}", wrapper.GetTeamById) }) r.Group(func(r chi.Router) { - r.Put(options.BaseURL+"/api/v1/teams/{id}", wrapper.UpdateTeam) + r.Put(options.BaseURL+"/api/v1/teams/{uuid}", wrapper.UpdateTeam) }) r.Group(func(r chi.Router) { r.Get(options.BaseURL+"/api/v1/universities", wrapper.GetApiV1Universities) @@ -1274,13 +1275,13 @@ func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handl r.Post(options.BaseURL+"/api/v1/users", wrapper.CreateUser) }) r.Group(func(r chi.Router) { - r.Delete(options.BaseURL+"/api/v1/users/{id}", wrapper.DeleteUser) + r.Delete(options.BaseURL+"/api/v1/users/{uuid}", wrapper.DeleteUser) }) r.Group(func(r chi.Router) { - r.Get(options.BaseURL+"/api/v1/users/{id}", wrapper.GetUserById) + r.Get(options.BaseURL+"/api/v1/users/{uuid}", wrapper.GetUserById) }) r.Group(func(r chi.Router) { - r.Put(options.BaseURL+"/api/v1/users/{id}", wrapper.UpdateUser) + r.Put(options.BaseURL+"/api/v1/users/{uuid}", wrapper.UpdateUser) }) return r diff --git a/internal/app/view/game.go b/internal/app/view/game.go index fad2672..e5212c5 100644 --- a/internal/app/view/game.go +++ b/internal/app/view/game.go @@ -3,33 +3,35 @@ package view import ( "ctf01d/internal/app/db" "time" + + openapi_types "github.com/oapi-codegen/runtime/types" ) type Game struct { - Id int `json:"id"` - StartTime time.Time `json:"start_time"` - EndTime time.Time `json:"end_time"` - Description string `json:"description,omitempty"` + Id openapi_types.UUID `json:"id"` + StartTime time.Time `json:"start_time"` + EndTime time.Time `json:"end_time"` + Description string `json:"description,omitempty"` } type GameDetails struct { - Id int `json:"id"` - StartTime time.Time `json:"start_time"` - EndTime time.Time `json:"end_time"` - Description string `json:"description,omitempty"` - Teams []TeamDetails `json:"team_details,omitempty"` + Id openapi_types.UUID `json:"id"` + StartTime time.Time `json:"start_time"` + EndTime time.Time `json:"end_time"` + Description string `json:"description,omitempty"` + Teams []TeamDetails `json:"team_details,omitempty"` } type TeamDetails struct { - Id int `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Members []Member `json:"members"` + Id openapi_types.UUID `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Members []Member `json:"members"` } type Member struct { - Id int `json:"id"` - UserName string `json:"user_name"` + Id openapi_types.UUID `json:"id"` + UserName string `json:"user_name"` } func NewGameFromModel(m *db.Game) *Game {