From 8447335ecfd6f7f6552399a3bd0bf85a00a5b468 Mon Sep 17 00:00:00 2001 From: Igor Polyakov Date: Sun, 23 Jun 2024 09:58:14 +0300 Subject: [PATCH 1/2] Add a user profile and command history --- api/openapi.yaml | 104 ++++- .../app/database/update0015_update0016.go | 43 ++ internal/app/handlers/interface.go | 12 +- internal/app/handlers/teams.go | 10 + internal/app/repository/game.go | 2 +- internal/app/repository/user.go | 4 +- internal/app/server/server.gen.go | 418 +++++++++++------- 7 files changed, 404 insertions(+), 189 deletions(-) create mode 100644 internal/app/database/update0015_update0016.go diff --git a/api/openapi.yaml b/api/openapi.yaml index 8c45a1c..7d81d1b 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -160,14 +160,14 @@ paths: description: Bad request '500': description: Failed response - '/api/v1/users/{uuid}': + '/api/v1/users/{userId}': get: tags: - Users summary: Get a user by ID operationId: getUserById parameters: - - name: uuid + - name: userId in: path required: true style: simple @@ -193,7 +193,7 @@ paths: summary: Update a user operationId: updateUser parameters: - - name: uuid + - name: userId in: path required: true style: simple @@ -221,7 +221,7 @@ paths: summary: Delete a user operationId: deleteUser parameters: - - name: uuid + - name: userId in: path required: true style: simple @@ -276,14 +276,14 @@ paths: description: Bad request '500': description: Failed response - '/api/v1/games/{uuid}': + '/api/v1/games/{gameId}': get: tags: - Games summary: Get a game by ID operationId: getGameById parameters: - - name: uuid + - name: gameId in: path required: true style: simple @@ -309,7 +309,7 @@ paths: summary: Update a game operationId: updateGame parameters: - - name: uuid + - name: gameId in: path required: true style: simple @@ -343,7 +343,7 @@ paths: summary: Delete a game operationId: deleteGame parameters: - - name: uuid + - name: gameId in: path required: true style: simple @@ -411,14 +411,14 @@ paths: content: application/json: schema: {} - '/api/v1/teams/{uuid}': + '/api/v1/teams/{teamId}': get: tags: - Teams summary: Get a team by ID operationId: getTeamById parameters: - - name: uuid + - name: teamId in: path required: true style: simple @@ -440,7 +440,7 @@ paths: summary: Update a team operationId: updateTeam parameters: - - name: uuid + - name: teamId in: path required: true style: simple @@ -464,7 +464,7 @@ paths: summary: Delete a team operationId: deleteTeam parameters: - - name: uuid + - name: teamId in: path required: true style: simple @@ -476,6 +476,66 @@ paths: responses: '200': description: Team deleted successfully + /api/v1/teams/{teamId}/join/{userId}: + post: + tags: + - Teams + summary: Connect user with team + parameters: + - in: path + name: teamId + required: true + schema: + type: string + format: uuid + description: The ID of the team + - in: path + name: userId + required: true + schema: + type: string + format: uuid + description: The ID of the user + responses: + '200': + description: Connect successfully + content: + application/json: + schema: + type: object + properties: + message: + type: string + /api/v1/teams/{teamId}/leave/{userId}: + post: + tags: + - Teams + summary: Leave user from team + parameters: + - in: path + name: teamId + required: true + schema: + type: string + format: uuid + description: The ID of the team + - in: path + name: userId + required: true + schema: + type: string + format: uuid + description: The ID of the user + responses: + '200': + description: Left successfully + content: + application/json: + schema: + type: object + properties: + message: + type: string /api/v1/results: get: tags: @@ -508,14 +568,14 @@ paths: responses: '200': description: Result created successfully - '/api/v1/results/{uuid}': + '/api/v1/results/{resultId}': get: tags: - Results summary: Get a result by ID operationId: getResultById parameters: - - name: uuid + - name: resultId in: path required: true style: simple @@ -563,14 +623,14 @@ paths: responses: '200': description: Service created successfully - '/api/v1/services/{uuid}': + '/api/v1/services/{serviceId}': get: tags: - Services summary: Get a service by ID operationId: getServiceById parameters: - - name: uuid + - name: serviceId in: path required: true style: simple @@ -592,7 +652,7 @@ paths: summary: Update a service operationId: updateService parameters: - - name: uuid + - name: serviceId in: path required: true style: simple @@ -616,7 +676,7 @@ paths: summary: Delete a service operationId: deleteService parameters: - - name: uuid + - name: serviceId in: path required: true style: simple @@ -628,7 +688,7 @@ paths: responses: '200': description: Service deleted successfully - /api/v1/services/{uuid}/upload/checker: + /api/v1/services/{serviceId}/upload/checker: post: tags: - Services @@ -637,7 +697,7 @@ paths: Handler for upload zip-archive with checker parameters: - in: path - name: uuid + name: serviceId required: true schema: type: string @@ -659,7 +719,7 @@ paths: content: application/json: {} - /api/v1/services/{uuid}/upload/service: + /api/v1/services/{serviceId}/upload/service: post: summary: Upload zip service description: | @@ -668,7 +728,7 @@ paths: - Services parameters: - in: path - name: uuid + name: serviceId required: true schema: type: string diff --git a/internal/app/database/update0015_update0016.go b/internal/app/database/update0015_update0016.go new file mode 100644 index 0000000..da70d20 --- /dev/null +++ b/internal/app/database/update0015_update0016.go @@ -0,0 +1,43 @@ +package database + +import ( + "database/sql" + "log/slog" + "runtime" +) + +func DatabaseUpdate_update0015_update0016(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 := "Make profile table" + if getInfo { + return fromUpdateId, toUpdateId, description, nil + } + query := ` + BEGIN; + ALTER TABLE team_members RENAME TO profiles; + ALTER TABLE profiles RENAME COLUMN team_id TO current_team_id; + ALTER TABLE profiles ADD COLUMN created_at TIMESTAMP default now(); + ALTER TABLE profiles ADD COLUMN updated_at TIMESTAMP default now(); + ALTER TABLE profiles ADD COLUMN id UUID DEFAULT gen_random_uuid(); + + CREATE TABLE team_history ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + user_id UUID REFERENCES users(id), + team_id UUID REFERENCES teams(id), + joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + left_at TIMESTAMP + ); + COMMIT; + ` + _, err := db.Query(query) + if err != nil { + slog.Error("Problem with select, query: " + query + "\n error:" + err.Error()) + return fromUpdateId, toUpdateId, description, err + } + return fromUpdateId, toUpdateId, description, nil +} diff --git a/internal/app/handlers/interface.go b/internal/app/handlers/interface.go index 7a1b4b5..a22ccf8 100644 --- a/internal/app/handlers/interface.go +++ b/internal/app/handlers/interface.go @@ -124,10 +124,18 @@ func (siw *ServerInterfaceWrapper) UpdateUser(w http.ResponseWriter, r *http.Req siw.handlers.UpdateUser(w, r, id) } -func (siw *ServerInterfaceWrapper) PostApiV1ServicesUuidUploadChecker(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { +func (siw *ServerInterfaceWrapper) PostApiV1ServicesServiceIdUploadChecker(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.PostApiV1ServicesUuidUploadChecker(w, r, id) } -func (siw *ServerInterfaceWrapper) PostApiV1ServicesUuidUploadService(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { +func (siw *ServerInterfaceWrapper) PostApiV1ServicesServiceIdUploadService(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { siw.handlers.PostApiV1ServicesUuidUploadService(w, r, id) } + +func (siw *ServerInterfaceWrapper) PostApiV1TeamsTeamIdJoinUserId(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID, userId openapi_types.UUID) { + siw.handlers.PostApiV1TeamsTeamIdJoinUserId(w, r, teamId, userId) +} + +func (siw *ServerInterfaceWrapper) PostApiV1TeamsTeamIdLeaveUserId(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID, userId openapi_types.UUID) { + siw.handlers.PostApiV1TeamsTeamIdLeaveUserId(w, r, teamId, userId) +} diff --git a/internal/app/handlers/teams.go b/internal/app/handlers/teams.go index 914c7c5..8a1181d 100644 --- a/internal/app/handlers/teams.go +++ b/internal/app/handlers/teams.go @@ -93,3 +93,13 @@ func (h *Handlers) UpdateTeam(w http.ResponseWriter, r *http.Request, id openapi } api_helpers.RespondWithJSON(w, http.StatusOK, map[string]string{"data": "Team updated successfully"}) } + +func (h *Handlers) PostApiV1TeamsTeamIdJoinUserId(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID, userId openapi_types.UUID) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusNotImplemented) +} + +func (h *Handlers) PostApiV1TeamsTeamIdLeaveUserId(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID, userId openapi_types.UUID) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusNotImplemented) +} diff --git a/internal/app/repository/game.go b/internal/app/repository/game.go index b241fb2..085ae19 100644 --- a/internal/app/repository/game.go +++ b/internal/app/repository/game.go @@ -39,7 +39,7 @@ func (r *gameRepo) GetGameDetails(ctx context.Context, id openapi_types.UUID) (* FROM games g JOIN team_games tg ON g.id = tg.game_id JOIN teams t ON tg.team_id = t.id - JOIN team_members tm ON t.id = tm.team_id + JOIN profiles tm ON t.id = tm.team_id JOIN users u ON tm.user_id = u.id WHERE g.id = $1; ` diff --git a/internal/app/repository/user.go b/internal/app/repository/user.go index 40cc4f0..7de00c0 100644 --- a/internal/app/repository/user.go +++ b/internal/app/repository/user.go @@ -38,7 +38,7 @@ func (r *userRepo) Create(ctx context.Context, user *models.User) 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) + _, err := r.db.ExecContext(ctx, "INSERT INTO profiles (user_id, team_id) VALUES ($1, $2)", userId, teamId) if err != nil { return err } @@ -78,7 +78,7 @@ func (r *userRepo) Delete(ctx context.Context, id openapi_types.UUID) error { if err != nil { return err } - if _, err := tx.ExecContext(ctx, "DELETE FROM team_members WHERE user_id = $1", id); err != nil { + if _, err := tx.ExecContext(ctx, "DELETE FROM profiles WHERE user_id = $1", id); err != nil { err2 := tx.Rollback() if err2 != nil { return err2 diff --git a/internal/app/server/server.gen.go b/internal/app/server/server.gen.go index b928c4a..dc5f7bd 100644 --- a/internal/app/server/server.gen.go +++ b/internal/app/server/server.gen.go @@ -232,13 +232,13 @@ type PostApiV1AuthSigninJSONBody struct { UserName *string `json:"user_name,omitempty"` } -// PostApiV1ServicesUuidUploadCheckerMultipartBody defines parameters for PostApiV1ServicesUuidUploadChecker. -type PostApiV1ServicesUuidUploadCheckerMultipartBody struct { +// PostApiV1ServicesServiceIdUploadCheckerMultipartBody defines parameters for PostApiV1ServicesServiceIdUploadChecker. +type PostApiV1ServicesServiceIdUploadCheckerMultipartBody struct { File *openapi_types.File `json:"file,omitempty"` } -// PostApiV1ServicesUuidUploadServiceMultipartBody defines parameters for PostApiV1ServicesUuidUploadService. -type PostApiV1ServicesUuidUploadServiceMultipartBody struct { +// PostApiV1ServicesServiceIdUploadServiceMultipartBody defines parameters for PostApiV1ServicesServiceIdUploadService. +type PostApiV1ServicesServiceIdUploadServiceMultipartBody struct { File *openapi_types.File `json:"file,omitempty"` } @@ -266,11 +266,11 @@ type CreateServiceJSONRequestBody = ServiceRequest // UpdateServiceJSONRequestBody defines body for UpdateService for application/json ContentType. type UpdateServiceJSONRequestBody = ServiceRequest -// PostApiV1ServicesUuidUploadCheckerMultipartRequestBody defines body for PostApiV1ServicesUuidUploadChecker for multipart/form-data ContentType. -type PostApiV1ServicesUuidUploadCheckerMultipartRequestBody PostApiV1ServicesUuidUploadCheckerMultipartBody +// PostApiV1ServicesServiceIdUploadCheckerMultipartRequestBody defines body for PostApiV1ServicesServiceIdUploadChecker for multipart/form-data ContentType. +type PostApiV1ServicesServiceIdUploadCheckerMultipartRequestBody PostApiV1ServicesServiceIdUploadCheckerMultipartBody -// PostApiV1ServicesUuidUploadServiceMultipartRequestBody defines body for PostApiV1ServicesUuidUploadService for multipart/form-data ContentType. -type PostApiV1ServicesUuidUploadServiceMultipartRequestBody PostApiV1ServicesUuidUploadServiceMultipartBody +// PostApiV1ServicesServiceIdUploadServiceMultipartRequestBody defines body for PostApiV1ServicesServiceIdUploadService for multipart/form-data ContentType. +type PostApiV1ServicesServiceIdUploadServiceMultipartRequestBody PostApiV1ServicesServiceIdUploadServiceMultipartBody // CreateTeamJSONRequestBody defines body for CreateTeam for application/json ContentType. type CreateTeamJSONRequestBody = TeamRequest @@ -302,14 +302,14 @@ type ServerInterface interface { // (POST /api/v1/games) CreateGame(w http.ResponseWriter, r *http.Request) // Delete a game - // (DELETE /api/v1/games/{uuid}) - DeleteGame(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (DELETE /api/v1/games/{gameId}) + DeleteGame(w http.ResponseWriter, r *http.Request, gameId openapi_types.UUID) // Get a game by ID - // (GET /api/v1/games/{uuid}) - GetGameById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (GET /api/v1/games/{gameId}) + GetGameById(w http.ResponseWriter, r *http.Request, gameId openapi_types.UUID) // Update a game - // (PUT /api/v1/games/{uuid}) - UpdateGame(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (PUT /api/v1/games/{gameId}) + UpdateGame(w http.ResponseWriter, r *http.Request, gameId openapi_types.UUID) // List all results // (GET /api/v1/results) ListResults(w http.ResponseWriter, r *http.Request) @@ -317,8 +317,8 @@ type ServerInterface interface { // (POST /api/v1/results) CreateResult(w http.ResponseWriter, r *http.Request) // Get a result by ID - // (GET /api/v1/results/{uuid}) - GetResultById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (GET /api/v1/results/{resultId}) + GetResultById(w http.ResponseWriter, r *http.Request, resultId openapi_types.UUID) // List all services // (GET /api/v1/services) ListServices(w http.ResponseWriter, r *http.Request) @@ -326,20 +326,20 @@ type ServerInterface interface { // (POST /api/v1/services) CreateService(w http.ResponseWriter, r *http.Request) // Delete a service - // (DELETE /api/v1/services/{uuid}) - DeleteService(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (DELETE /api/v1/services/{serviceId}) + DeleteService(w http.ResponseWriter, r *http.Request, serviceId openapi_types.UUID) // Get a service by ID - // (GET /api/v1/services/{uuid}) - GetServiceById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (GET /api/v1/services/{serviceId}) + GetServiceById(w http.ResponseWriter, r *http.Request, serviceId openapi_types.UUID) // Update a service - // (PUT /api/v1/services/{uuid}) - UpdateService(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (PUT /api/v1/services/{serviceId}) + UpdateService(w http.ResponseWriter, r *http.Request, serviceId openapi_types.UUID) // Upload zip-archive - // (POST /api/v1/services/{uuid}/upload/checker) - PostApiV1ServicesUuidUploadChecker(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (POST /api/v1/services/{serviceId}/upload/checker) + PostApiV1ServicesServiceIdUploadChecker(w http.ResponseWriter, r *http.Request, serviceId openapi_types.UUID) // Upload zip service - // (POST /api/v1/services/{uuid}/upload/service) - PostApiV1ServicesUuidUploadService(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (POST /api/v1/services/{serviceId}/upload/service) + PostApiV1ServicesServiceIdUploadService(w http.ResponseWriter, r *http.Request, serviceId openapi_types.UUID) // List all teams // (GET /api/v1/teams) ListTeams(w http.ResponseWriter, r *http.Request) @@ -347,14 +347,20 @@ type ServerInterface interface { // (POST /api/v1/teams) CreateTeam(w http.ResponseWriter, r *http.Request) // Delete a team - // (DELETE /api/v1/teams/{uuid}) - DeleteTeam(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (DELETE /api/v1/teams/{teamId}) + DeleteTeam(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID) // Get a team by ID - // (GET /api/v1/teams/{uuid}) - GetTeamById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (GET /api/v1/teams/{teamId}) + GetTeamById(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID) // Update a team - // (PUT /api/v1/teams/{uuid}) - UpdateTeam(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (PUT /api/v1/teams/{teamId}) + UpdateTeam(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID) + // Connect user with team + // (POST /api/v1/teams/{teamId}/join/{userId}) + PostApiV1TeamsTeamIdJoinUserId(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID, userId openapi_types.UUID) + // Leave user from team + // (POST /api/v1/teams/{teamId}/leave/{userId}) + PostApiV1TeamsTeamIdLeaveUserId(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID, userId openapi_types.UUID) // Retrieves a list of universities // (GET /api/v1/universities) GetApiV1Universities(w http.ResponseWriter, r *http.Request, params GetApiV1UniversitiesParams) @@ -365,14 +371,14 @@ type ServerInterface interface { // (POST /api/v1/users) CreateUser(w http.ResponseWriter, r *http.Request) // Delete a user - // (DELETE /api/v1/users/{uuid}) - DeleteUser(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (DELETE /api/v1/users/{userId}) + DeleteUser(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID) // Get a user by ID - // (GET /api/v1/users/{uuid}) - GetUserById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (GET /api/v1/users/{userId}) + GetUserById(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID) // Update a user - // (PUT /api/v1/users/{uuid}) - UpdateUser(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) + // (PUT /api/v1/users/{userId}) + UpdateUser(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID) } // Unimplemented server implementation that returns http.StatusNotImplemented for each endpoint. @@ -410,20 +416,20 @@ func (_ Unimplemented) CreateGame(w http.ResponseWriter, r *http.Request) { } // Delete a game -// (DELETE /api/v1/games/{uuid}) -func (_ Unimplemented) DeleteGame(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (DELETE /api/v1/games/{gameId}) +func (_ Unimplemented) DeleteGame(w http.ResponseWriter, r *http.Request, gameId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Get a game by ID -// (GET /api/v1/games/{uuid}) -func (_ Unimplemented) GetGameById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (GET /api/v1/games/{gameId}) +func (_ Unimplemented) GetGameById(w http.ResponseWriter, r *http.Request, gameId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Update a game -// (PUT /api/v1/games/{uuid}) -func (_ Unimplemented) UpdateGame(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (PUT /api/v1/games/{gameId}) +func (_ Unimplemented) UpdateGame(w http.ResponseWriter, r *http.Request, gameId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } @@ -440,8 +446,8 @@ func (_ Unimplemented) CreateResult(w http.ResponseWriter, r *http.Request) { } // Get a result by ID -// (GET /api/v1/results/{uuid}) -func (_ Unimplemented) GetResultById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (GET /api/v1/results/{resultId}) +func (_ Unimplemented) GetResultById(w http.ResponseWriter, r *http.Request, resultId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } @@ -458,32 +464,32 @@ func (_ Unimplemented) CreateService(w http.ResponseWriter, r *http.Request) { } // Delete a service -// (DELETE /api/v1/services/{uuid}) -func (_ Unimplemented) DeleteService(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (DELETE /api/v1/services/{serviceId}) +func (_ Unimplemented) DeleteService(w http.ResponseWriter, r *http.Request, serviceId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Get a service by ID -// (GET /api/v1/services/{uuid}) -func (_ Unimplemented) GetServiceById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (GET /api/v1/services/{serviceId}) +func (_ Unimplemented) GetServiceById(w http.ResponseWriter, r *http.Request, serviceId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Update a service -// (PUT /api/v1/services/{uuid}) -func (_ Unimplemented) UpdateService(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (PUT /api/v1/services/{serviceId}) +func (_ Unimplemented) UpdateService(w http.ResponseWriter, r *http.Request, serviceId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Upload zip-archive -// (POST /api/v1/services/{uuid}/upload/checker) -func (_ Unimplemented) PostApiV1ServicesUuidUploadChecker(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (POST /api/v1/services/{serviceId}/upload/checker) +func (_ Unimplemented) PostApiV1ServicesServiceIdUploadChecker(w http.ResponseWriter, r *http.Request, serviceId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Upload zip service -// (POST /api/v1/services/{uuid}/upload/service) -func (_ Unimplemented) PostApiV1ServicesUuidUploadService(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (POST /api/v1/services/{serviceId}/upload/service) +func (_ Unimplemented) PostApiV1ServicesServiceIdUploadService(w http.ResponseWriter, r *http.Request, serviceId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } @@ -500,20 +506,32 @@ func (_ Unimplemented) CreateTeam(w http.ResponseWriter, r *http.Request) { } // Delete a team -// (DELETE /api/v1/teams/{uuid}) -func (_ Unimplemented) DeleteTeam(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (DELETE /api/v1/teams/{teamId}) +func (_ Unimplemented) DeleteTeam(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Get a team by ID -// (GET /api/v1/teams/{uuid}) -func (_ Unimplemented) GetTeamById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (GET /api/v1/teams/{teamId}) +func (_ Unimplemented) GetTeamById(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Update a team -// (PUT /api/v1/teams/{uuid}) -func (_ Unimplemented) UpdateTeam(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (PUT /api/v1/teams/{teamId}) +func (_ Unimplemented) UpdateTeam(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID) { + w.WriteHeader(http.StatusNotImplemented) +} + +// Connect user with team +// (POST /api/v1/teams/{teamId}/join/{userId}) +func (_ Unimplemented) PostApiV1TeamsTeamIdJoinUserId(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID, userId openapi_types.UUID) { + w.WriteHeader(http.StatusNotImplemented) +} + +// Leave user from team +// (POST /api/v1/teams/{teamId}/leave/{userId}) +func (_ Unimplemented) PostApiV1TeamsTeamIdLeaveUserId(w http.ResponseWriter, r *http.Request, teamId openapi_types.UUID, userId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } @@ -536,20 +554,20 @@ func (_ Unimplemented) CreateUser(w http.ResponseWriter, r *http.Request) { } // Delete a user -// (DELETE /api/v1/users/{uuid}) -func (_ Unimplemented) DeleteUser(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (DELETE /api/v1/users/{userId}) +func (_ Unimplemented) DeleteUser(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Get a user by ID -// (GET /api/v1/users/{uuid}) -func (_ Unimplemented) GetUserById(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (GET /api/v1/users/{userId}) +func (_ Unimplemented) GetUserById(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } // Update a user -// (PUT /api/v1/users/{uuid}) -func (_ Unimplemented) UpdateUser(w http.ResponseWriter, r *http.Request, uuid openapi_types.UUID) { +// (PUT /api/v1/users/{userId}) +func (_ Unimplemented) UpdateUser(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID) { w.WriteHeader(http.StatusNotImplemented) } @@ -643,17 +661,17 @@ func (siw *ServerInterfaceWrapper) DeleteGame(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "gameId" ------------- + var gameId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "gameId", chi.URLParam(r, "gameId"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "gameId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.DeleteGame(w, r, uuid) + siw.Handler.DeleteGame(w, r, gameId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -669,17 +687,17 @@ func (siw *ServerInterfaceWrapper) GetGameById(w http.ResponseWriter, r *http.Re var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "gameId" ------------- + var gameId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "gameId", chi.URLParam(r, "gameId"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "gameId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetGameById(w, r, uuid) + siw.Handler.GetGameById(w, r, gameId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -695,17 +713,17 @@ func (siw *ServerInterfaceWrapper) UpdateGame(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "gameId" ------------- + var gameId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "gameId", chi.URLParam(r, "gameId"), &gameId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "gameId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.UpdateGame(w, r, uuid) + siw.Handler.UpdateGame(w, r, gameId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -751,17 +769,17 @@ func (siw *ServerInterfaceWrapper) GetResultById(w http.ResponseWriter, r *http. var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "resultId" ------------- + var resultId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "resultId", chi.URLParam(r, "resultId"), &resultId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "resultId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetResultById(w, r, uuid) + siw.Handler.GetResultById(w, r, resultId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -807,17 +825,17 @@ func (siw *ServerInterfaceWrapper) DeleteService(w http.ResponseWriter, r *http. var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "serviceId" ------------- + var serviceId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "serviceId", chi.URLParam(r, "serviceId"), &serviceId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "serviceId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.DeleteService(w, r, uuid) + siw.Handler.DeleteService(w, r, serviceId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -833,17 +851,17 @@ func (siw *ServerInterfaceWrapper) GetServiceById(w http.ResponseWriter, r *http var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "serviceId" ------------- + var serviceId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "serviceId", chi.URLParam(r, "serviceId"), &serviceId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "serviceId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetServiceById(w, r, uuid) + siw.Handler.GetServiceById(w, r, serviceId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -859,17 +877,17 @@ func (siw *ServerInterfaceWrapper) UpdateService(w http.ResponseWriter, r *http. var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "serviceId" ------------- + var serviceId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "serviceId", chi.URLParam(r, "serviceId"), &serviceId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "serviceId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.UpdateService(w, r, uuid) + siw.Handler.UpdateService(w, r, serviceId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -879,23 +897,23 @@ func (siw *ServerInterfaceWrapper) UpdateService(w http.ResponseWriter, r *http. handler.ServeHTTP(w, r.WithContext(ctx)) } -// PostApiV1ServicesUuidUploadChecker operation middleware -func (siw *ServerInterfaceWrapper) PostApiV1ServicesUuidUploadChecker(w http.ResponseWriter, r *http.Request) { +// PostApiV1ServicesServiceIdUploadChecker operation middleware +func (siw *ServerInterfaceWrapper) PostApiV1ServicesServiceIdUploadChecker(w http.ResponseWriter, r *http.Request) { ctx := r.Context() var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "serviceId" ------------- + var serviceId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "serviceId", chi.URLParam(r, "serviceId"), &serviceId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "serviceId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.PostApiV1ServicesUuidUploadChecker(w, r, uuid) + siw.Handler.PostApiV1ServicesServiceIdUploadChecker(w, r, serviceId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -905,23 +923,23 @@ func (siw *ServerInterfaceWrapper) PostApiV1ServicesUuidUploadChecker(w http.Res handler.ServeHTTP(w, r.WithContext(ctx)) } -// PostApiV1ServicesUuidUploadService operation middleware -func (siw *ServerInterfaceWrapper) PostApiV1ServicesUuidUploadService(w http.ResponseWriter, r *http.Request) { +// PostApiV1ServicesServiceIdUploadService operation middleware +func (siw *ServerInterfaceWrapper) PostApiV1ServicesServiceIdUploadService(w http.ResponseWriter, r *http.Request) { ctx := r.Context() var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "serviceId" ------------- + var serviceId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "serviceId", chi.URLParam(r, "serviceId"), &serviceId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "serviceId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.PostApiV1ServicesUuidUploadService(w, r, uuid) + siw.Handler.PostApiV1ServicesServiceIdUploadService(w, r, serviceId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -967,17 +985,17 @@ func (siw *ServerInterfaceWrapper) DeleteTeam(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "teamId" ------------- + var teamId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "teamId", chi.URLParam(r, "teamId"), &teamId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "teamId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.DeleteTeam(w, r, uuid) + siw.Handler.DeleteTeam(w, r, teamId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -993,17 +1011,17 @@ func (siw *ServerInterfaceWrapper) GetTeamById(w http.ResponseWriter, r *http.Re var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "teamId" ------------- + var teamId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "teamId", chi.URLParam(r, "teamId"), &teamId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "teamId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetTeamById(w, r, uuid) + siw.Handler.GetTeamById(w, r, teamId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -1019,17 +1037,87 @@ func (siw *ServerInterfaceWrapper) UpdateTeam(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "teamId" ------------- + var teamId openapi_types.UUID + + err = runtime.BindStyledParameterWithOptions("simple", "teamId", chi.URLParam(r, "teamId"), &teamId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "teamId", Err: err}) + return + } + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.UpdateTeam(w, r, teamId) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r.WithContext(ctx)) +} + +// PostApiV1TeamsTeamIdJoinUserId operation middleware +func (siw *ServerInterfaceWrapper) PostApiV1TeamsTeamIdJoinUserId(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + var err error + + // ------------- Path parameter "teamId" ------------- + var teamId openapi_types.UUID + + err = runtime.BindStyledParameterWithOptions("simple", "teamId", chi.URLParam(r, "teamId"), &teamId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "teamId", Err: err}) + return + } + + // ------------- Path parameter "userId" ------------- + var userId openapi_types.UUID + + err = runtime.BindStyledParameterWithOptions("simple", "userId", chi.URLParam(r, "userId"), &userId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "userId", Err: err}) + return + } + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.PostApiV1TeamsTeamIdJoinUserId(w, r, teamId, userId) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r.WithContext(ctx)) +} + +// PostApiV1TeamsTeamIdLeaveUserId operation middleware +func (siw *ServerInterfaceWrapper) PostApiV1TeamsTeamIdLeaveUserId(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + var err error + + // ------------- Path parameter "teamId" ------------- + var teamId openapi_types.UUID + + err = runtime.BindStyledParameterWithOptions("simple", "teamId", chi.URLParam(r, "teamId"), &teamId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "teamId", Err: err}) + return + } + + // ------------- Path parameter "userId" ------------- + var userId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "userId", chi.URLParam(r, "userId"), &userId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "userId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.UpdateTeam(w, r, uuid) + siw.Handler.PostApiV1TeamsTeamIdLeaveUserId(w, r, teamId, userId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -1103,17 +1191,17 @@ func (siw *ServerInterfaceWrapper) DeleteUser(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "userId" ------------- + var userId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "userId", chi.URLParam(r, "userId"), &userId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "userId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.DeleteUser(w, r, uuid) + siw.Handler.DeleteUser(w, r, userId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -1129,17 +1217,17 @@ func (siw *ServerInterfaceWrapper) GetUserById(w http.ResponseWriter, r *http.Re var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "userId" ------------- + var userId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "userId", chi.URLParam(r, "userId"), &userId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "userId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.GetUserById(w, r, uuid) + siw.Handler.GetUserById(w, r, userId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -1155,17 +1243,17 @@ func (siw *ServerInterfaceWrapper) UpdateUser(w http.ResponseWriter, r *http.Req var err error - // ------------- Path parameter "uuid" ------------- - var uuid openapi_types.UUID + // ------------- Path parameter "userId" ------------- + var userId openapi_types.UUID - err = runtime.BindStyledParameterWithOptions("simple", "uuid", chi.URLParam(r, "uuid"), &uuid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "userId", chi.URLParam(r, "userId"), &userId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { - siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "uuid", Err: err}) + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "userId", Err: err}) return } handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.UpdateUser(w, r, uuid) + siw.Handler.UpdateUser(w, r, userId) })) for _, middleware := range siw.HandlerMiddlewares { @@ -1304,13 +1392,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/{uuid}", wrapper.DeleteGame) + r.Delete(options.BaseURL+"/api/v1/games/{gameId}", wrapper.DeleteGame) }) r.Group(func(r chi.Router) { - r.Get(options.BaseURL+"/api/v1/games/{uuid}", wrapper.GetGameById) + r.Get(options.BaseURL+"/api/v1/games/{gameId}", wrapper.GetGameById) }) r.Group(func(r chi.Router) { - r.Put(options.BaseURL+"/api/v1/games/{uuid}", wrapper.UpdateGame) + r.Put(options.BaseURL+"/api/v1/games/{gameId}", wrapper.UpdateGame) }) r.Group(func(r chi.Router) { r.Get(options.BaseURL+"/api/v1/results", wrapper.ListResults) @@ -1319,7 +1407,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/{uuid}", wrapper.GetResultById) + r.Get(options.BaseURL+"/api/v1/results/{resultId}", wrapper.GetResultById) }) r.Group(func(r chi.Router) { r.Get(options.BaseURL+"/api/v1/services", wrapper.ListServices) @@ -1328,19 +1416,19 @@ 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/{uuid}", wrapper.DeleteService) + r.Delete(options.BaseURL+"/api/v1/services/{serviceId}", wrapper.DeleteService) }) r.Group(func(r chi.Router) { - r.Get(options.BaseURL+"/api/v1/services/{uuid}", wrapper.GetServiceById) + r.Get(options.BaseURL+"/api/v1/services/{serviceId}", wrapper.GetServiceById) }) r.Group(func(r chi.Router) { - r.Put(options.BaseURL+"/api/v1/services/{uuid}", wrapper.UpdateService) + r.Put(options.BaseURL+"/api/v1/services/{serviceId}", wrapper.UpdateService) }) r.Group(func(r chi.Router) { - r.Post(options.BaseURL+"/api/v1/services/{uuid}/upload/checker", wrapper.PostApiV1ServicesUuidUploadChecker) + r.Post(options.BaseURL+"/api/v1/services/{serviceId}/upload/checker", wrapper.PostApiV1ServicesServiceIdUploadChecker) }) r.Group(func(r chi.Router) { - r.Post(options.BaseURL+"/api/v1/services/{uuid}/upload/service", wrapper.PostApiV1ServicesUuidUploadService) + r.Post(options.BaseURL+"/api/v1/services/{serviceId}/upload/service", wrapper.PostApiV1ServicesServiceIdUploadService) }) r.Group(func(r chi.Router) { r.Get(options.BaseURL+"/api/v1/teams", wrapper.ListTeams) @@ -1349,13 +1437,19 @@ 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/{uuid}", wrapper.DeleteTeam) + r.Delete(options.BaseURL+"/api/v1/teams/{teamId}", wrapper.DeleteTeam) + }) + r.Group(func(r chi.Router) { + r.Get(options.BaseURL+"/api/v1/teams/{teamId}", wrapper.GetTeamById) + }) + r.Group(func(r chi.Router) { + r.Put(options.BaseURL+"/api/v1/teams/{teamId}", wrapper.UpdateTeam) }) r.Group(func(r chi.Router) { - r.Get(options.BaseURL+"/api/v1/teams/{uuid}", wrapper.GetTeamById) + r.Post(options.BaseURL+"/api/v1/teams/{teamId}/join/{userId}", wrapper.PostApiV1TeamsTeamIdJoinUserId) }) r.Group(func(r chi.Router) { - r.Put(options.BaseURL+"/api/v1/teams/{uuid}", wrapper.UpdateTeam) + r.Post(options.BaseURL+"/api/v1/teams/{teamId}/leave/{userId}", wrapper.PostApiV1TeamsTeamIdLeaveUserId) }) r.Group(func(r chi.Router) { r.Get(options.BaseURL+"/api/v1/universities", wrapper.GetApiV1Universities) @@ -1367,13 +1461,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/{uuid}", wrapper.DeleteUser) + r.Delete(options.BaseURL+"/api/v1/users/{userId}", wrapper.DeleteUser) }) r.Group(func(r chi.Router) { - r.Get(options.BaseURL+"/api/v1/users/{uuid}", wrapper.GetUserById) + r.Get(options.BaseURL+"/api/v1/users/{userId}", wrapper.GetUserById) }) r.Group(func(r chi.Router) { - r.Put(options.BaseURL+"/api/v1/users/{uuid}", wrapper.UpdateUser) + r.Put(options.BaseURL+"/api/v1/users/{userId}", wrapper.UpdateUser) }) return r From 3de582e7abba1119dd31816017258c9a398af434 Mon Sep 17 00:00:00 2001 From: IgorPolyakov Date: Fri, 5 Jul 2024 01:19:33 +0300 Subject: [PATCH 2/2] profile & team history work now --- api/openapi.yaml | 79 ++++++++++++++++++- internal/app/database/struct_updater.go | 2 + .../database/update0016_update0016testdata.go | 32 ++++++++ internal/app/db/profile.go | 22 ++++++ internal/app/handlers/interface.go | 4 + internal/app/handlers/users.go | 11 +++ internal/app/repository/game.go | 2 +- internal/app/repository/user.go | 37 +++++++++ internal/app/server/server.gen.go | 68 ++++++++++++++++ internal/app/view/profile.go | 28 +++++++ internal/app/view/user.go | 9 --- 11 files changed, 280 insertions(+), 14 deletions(-) create mode 100644 internal/app/database/update0016_update0016testdata.go create mode 100644 internal/app/db/profile.go create mode 100644 internal/app/view/profile.go diff --git a/api/openapi.yaml b/api/openapi.yaml index 7d81d1b..c6a2909 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -238,6 +238,33 @@ paths: content: application/json: schema: {} + '/api/v1/users/{userId}/profile': + get: + tags: + - Users + summary: Get a profile by user ID + operationId: getProfileById + parameters: + - name: userId + in: path + required: true + style: simple + explode: false + schema: + type: string + format: uuid + example: 81e17cb6-5c46-4934-b6d5-5c8356712cb6 + responses: + '200': + description: Detailed information of a profile + content: + application/json: + schema: + $ref: '#/components/schemas/ProfileResponse' + '400': + description: Bad request + '500': + description: Failed response /api/v1/games: get: tags: @@ -807,6 +834,50 @@ components: format: uuid example: 81e17cb6-5c46-4934-b6d5-5c8356712cb6 description: Unique identifier for the result entry + ProfileResponse: + type: object + description: The response schema for a user's profile, including id, timestamps, team name, and team history. + properties: + id: + type: string + format: uuid + description: The unique identifier for the user. + created_at: + type: string + format: date-time + description: The timestamp when the user profile was created. + updated_at: + type: string + format: date-time + description: The timestamp when the user profile was last updated. + team_name: + type: string + description: The current name of the user's team. + team_history: + type: array + description: The list of teams the user has been part of, including the periods of membership. + items: + $ref: '#/components/schemas/TeamHistory' + TeamHistory: + required: + - name + - join + type: object + description: The schema for recording the history of teams a user has joined and left. + properties: + name: + type: string + description: The name of the team. + join: + type: string + format: date-time + description: The timestamp when the user joined the team. + example: '2024-01-23T04:56:07.000Z' + left: + type: string + format: date-time + description: The timestamp when the user left the team. + example: '2024-01-23T04:56:07.000Z' UserResponse: type: object properties: @@ -844,12 +915,12 @@ components: type: string description: The start time of the game format: date-time - example: '2000-01-23T04:56:07.000Z' + example: '2024-01-23T04:56:07.000Z' end_time: type: string description: The end time of the game format: date-time - example: '2000-01-24T04:56:07.000Z' + example: '2024-01-24T04:56:07.000Z' description: type: string description: A brief description of the game @@ -868,12 +939,12 @@ components: type: string description: The start time of the game format: date-time - example: '2000-01-23T04:56:07.000Z' + example: '2024-01-23T04:56:07.000Z' end_time: type: string description: The end time of the game format: date-time - example: '2000-01-24T04:56:07.000Z' + example: '2024-01-24T04:56:07.000Z' description: type: string description: A brief description of the game diff --git a/internal/app/database/struct_updater.go b/internal/app/database/struct_updater.go index d345c97..d9d9935 100644 --- a/internal/app/database/struct_updater.go +++ b/internal/app/database/struct_updater.go @@ -41,6 +41,8 @@ func RegisterAllUpdates() map[string][]DatabaseUpdateFunc { allUpdates = RegisterDatabaseUpdate(allUpdates, DatabaseUpdate_update0014_update0014fix1) allUpdates = RegisterDatabaseUpdate(allUpdates, DatabaseUpdate_update0014_update0015) allUpdates = RegisterDatabaseUpdate(allUpdates, DatabaseUpdate_update0015_update0015testdata) + allUpdates = RegisterDatabaseUpdate(allUpdates, DatabaseUpdate_update0015_update0016) + allUpdates = RegisterDatabaseUpdate(allUpdates, DatabaseUpdate_update0016_update0016testdata) return allUpdates } diff --git a/internal/app/database/update0016_update0016testdata.go b/internal/app/database/update0016_update0016testdata.go new file mode 100644 index 0000000..1ee7a09 --- /dev/null +++ b/internal/app/database/update0016_update0016testdata.go @@ -0,0 +1,32 @@ +package database + +import ( + "database/sql" + "log/slog" + "runtime" +) + +func DatabaseUpdate_update0016_update0016testdata(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 := "Flush team_history table" + if getInfo { + return fromUpdateId, toUpdateId, description, nil + } + + query := ` + INSERT INTO team_history (user_id, team_id, joined_at) + SELECT user_id, current_team_id, created_at + FROM profiles + ` + _, err := db.Query(query) + if err != nil { + slog.Error("Problem with select, query: " + query + "\n error:" + err.Error()) + return fromUpdateId, toUpdateId, description, err + } + return fromUpdateId, toUpdateId, description, nil +} diff --git a/internal/app/db/profile.go b/internal/app/db/profile.go new file mode 100644 index 0000000..ce72465 --- /dev/null +++ b/internal/app/db/profile.go @@ -0,0 +1,22 @@ +package db + +import ( + "time" +) + +type Profile struct { + CurrentTeam string `db:"name"` + CreatedAt time.Time `db:"created_at"` + UpdatedAt time.Time `db:"created_at"` +} + +type ProfileTeams struct { + JoinedAt time.Time `db:"joined_at"` + LeftAt *time.Time `db:"left_at"` + Name string `db:"name"` +} + +type ProfileWithHistory struct { + Profile Profile + History []ProfileTeams +} diff --git a/internal/app/handlers/interface.go b/internal/app/handlers/interface.go index a22ccf8..8122488 100644 --- a/internal/app/handlers/interface.go +++ b/internal/app/handlers/interface.go @@ -120,6 +120,10 @@ func (siw *ServerInterfaceWrapper) GetUserById(w http.ResponseWriter, r *http.Re siw.handlers.GetUserById(w, r, id) } +func (siw *ServerInterfaceWrapper) GetProfileById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { + siw.handlers.GetProfileById(w, r, id) +} + 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/users.go b/internal/app/handlers/users.go index 6f959b0..82c1efb 100644 --- a/internal/app/handlers/users.go +++ b/internal/app/handlers/users.go @@ -73,6 +73,17 @@ func (h *Handlers) GetUserById(w http.ResponseWriter, r *http.Request, id openap api_helpers.RespondWithJSON(w, http.StatusOK, view.NewUserFromModel(user)) } +func (h *Handlers) GetProfileById(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) { + repo := repository.NewUserRepository(h.DB) + userProfile, err := repo.GetProfileWithHistory(r.Context(), id) + if err != nil { + slog.Warn(err.Error(), "handler", "GetProfileByIdHandler") + api_helpers.RespondWithJSON(w, http.StatusInternalServerError, map[string]string{"error": "Failed to fetch user"}) + return + } + api_helpers.RespondWithJSON(w, http.StatusOK, view.NewProfileFromModel(userProfile)) +} + func (h *Handlers) ListUsers(w http.ResponseWriter, r *http.Request) { repo := repository.NewUserRepository(h.DB) users, err := repo.List(r.Context()) diff --git a/internal/app/repository/game.go b/internal/app/repository/game.go index 085ae19..1e4ac95 100644 --- a/internal/app/repository/game.go +++ b/internal/app/repository/game.go @@ -39,7 +39,7 @@ func (r *gameRepo) GetGameDetails(ctx context.Context, id openapi_types.UUID) (* FROM games g JOIN team_games tg ON g.id = tg.game_id JOIN teams t ON tg.team_id = t.id - JOIN profiles tm ON t.id = tm.team_id + JOIN profiles tm ON t.id = tm.current_team_id JOIN users u ON tm.user_id = u.id WHERE g.id = $1; ` diff --git a/internal/app/repository/user.go b/internal/app/repository/user.go index 7de00c0..114ee3b 100644 --- a/internal/app/repository/user.go +++ b/internal/app/repository/user.go @@ -12,6 +12,7 @@ type UserRepository interface { Create(ctx context.Context, user *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) + GetProfileWithHistory(ctx context.Context, id openapi_types.UUID) (*models.ProfileWithHistory, error) GetByUserName(ctx context.Context, id string) (*models.User, error) Update(ctx context.Context, user *models.User) error Delete(ctx context.Context, id openapi_types.UUID) error @@ -47,6 +48,42 @@ func (r *userRepo) AddUserToTeams(ctx context.Context, userId openapi_types.UUID return nil } +func (r *userRepo) GetProfileWithHistory(ctx context.Context, id openapi_types.UUID) (*models.ProfileWithHistory, error) { + query := ` + SELECT teams.name, created_at, updated_at + FROM profiles JOIN teams on profiles.current_team_id=teams.id + WHERE profiles.user_id = $1 + ` + profile := models.Profile{} + err := r.db.QueryRowContext(ctx, query, id).Scan(&profile.CurrentTeam, &profile.CreatedAt, &profile.UpdatedAt) + if err != nil { + return nil, err + } + query = ` + SELECT joined_at, left_at, name + FROM team_history + JOIN teams ON teams.id = team_history.team_id + WHERE user_id = $1 + ` + rows, err := r.db.QueryContext(ctx, query, id) + var history []models.ProfileTeams + for rows.Next() { + var team models.ProfileTeams + err := rows.Scan(&team.JoinedAt, &team.LeftAt, &team.Name) + if err != nil { + return nil, err + } + history = append(history, team) + } + if err != nil { + return nil, err + } + return &models.ProfileWithHistory{ + Profile: profile, + History: history, + }, nil +} + 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{} diff --git a/internal/app/server/server.gen.go b/internal/app/server/server.gen.go index dc5f7bd..d665b8d 100644 --- a/internal/app/server/server.gen.go +++ b/internal/app/server/server.gen.go @@ -54,6 +54,24 @@ type GameResponse struct { StartTime time.Time `json:"start_time"` } +// ProfileResponse The response schema for a user's profile, including id, timestamps, team name, and team history. +type ProfileResponse struct { + // CreatedAt The timestamp when the user profile was created. + CreatedAt *time.Time `json:"created_at,omitempty"` + + // Id The unique identifier for the user. + Id *openapi_types.UUID `json:"id,omitempty"` + + // TeamHistory The list of teams the user has been part of, including the periods of membership. + TeamHistory *[]TeamHistory `json:"team_history,omitempty"` + + // TeamName The current name of the user's team. + TeamName *string `json:"team_name,omitempty"` + + // UpdatedAt The timestamp when the user profile was last updated. + UpdatedAt *time.Time `json:"updated_at,omitempty"` +} + // ResultRequest defines model for ResultRequest. type ResultRequest struct { // GameId Identifier of the game this result is for @@ -126,6 +144,18 @@ type ServiceResponse struct { Name string `json:"name"` } +// TeamHistory The schema for recording the history of teams a user has joined and left. +type TeamHistory struct { + // Join The timestamp when the user joined the team. + Join time.Time `json:"join"` + + // Left The timestamp when the user left the team. + Left *time.Time `json:"left,omitempty"` + + // Name The name of the team. + Name string `json:"name"` +} + // TeamRequest defines model for TeamRequest. type TeamRequest struct { // AvatarUrl URL to the team's avatar @@ -379,6 +409,9 @@ type ServerInterface interface { // Update a user // (PUT /api/v1/users/{userId}) UpdateUser(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID) + // Get a profile by user ID + // (GET /api/v1/users/{userId}/profile) + GetProfileById(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID) } // Unimplemented server implementation that returns http.StatusNotImplemented for each endpoint. @@ -571,6 +604,12 @@ func (_ Unimplemented) UpdateUser(w http.ResponseWriter, r *http.Request, userId w.WriteHeader(http.StatusNotImplemented) } +// Get a profile by user ID +// (GET /api/v1/users/{userId}/profile) +func (_ Unimplemented) GetProfileById(w http.ResponseWriter, r *http.Request, userId openapi_types.UUID) { + w.WriteHeader(http.StatusNotImplemented) +} + // ServerInterfaceWrapper converts contexts to parameters. type ServerInterfaceWrapper struct { Handler ServerInterface @@ -1263,6 +1302,32 @@ func (siw *ServerInterfaceWrapper) UpdateUser(w http.ResponseWriter, r *http.Req handler.ServeHTTP(w, r.WithContext(ctx)) } +// GetProfileById operation middleware +func (siw *ServerInterfaceWrapper) GetProfileById(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + var err error + + // ------------- Path parameter "userId" ------------- + var userId openapi_types.UUID + + err = runtime.BindStyledParameterWithOptions("simple", "userId", chi.URLParam(r, "userId"), &userId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "userId", Err: err}) + return + } + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.GetProfileById(w, r, userId) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r.WithContext(ctx)) +} + type UnescapedCookieParamError struct { ParamName string Err error @@ -1469,6 +1534,9 @@ func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handl r.Group(func(r chi.Router) { r.Put(options.BaseURL+"/api/v1/users/{userId}", wrapper.UpdateUser) }) + r.Group(func(r chi.Router) { + r.Get(options.BaseURL+"/api/v1/users/{userId}/profile", wrapper.GetProfileById) + }) return r } diff --git a/internal/app/view/profile.go b/internal/app/view/profile.go new file mode 100644 index 0000000..afeee2a --- /dev/null +++ b/internal/app/view/profile.go @@ -0,0 +1,28 @@ +package view + +import ( + "ctf01d/internal/app/server" + + "ctf01d/internal/app/db" +) + +func NewProfileFromModel(p *db.ProfileWithHistory) *server.ProfileResponse { + return &server.ProfileResponse{ + CreatedAt: &p.Profile.CreatedAt, + UpdatedAt: &p.Profile.UpdatedAt, + TeamName: &p.Profile.CurrentTeam, + TeamHistory: makeTeamHistory(p.History), + } +} + +func makeTeamHistory(tms []db.ProfileTeams) *[]server.TeamHistory { + out := []server.TeamHistory{} + for _, tm := range tms { + out = append(out, server.TeamHistory{ + Join: tm.JoinedAt, + Left: tm.LeftAt, + Name: tm.Name, + }) + } + return &out +} diff --git a/internal/app/view/user.go b/internal/app/view/user.go index fd7cb10..fc92e05 100644 --- a/internal/app/view/user.go +++ b/internal/app/view/user.go @@ -7,15 +7,6 @@ import ( helpers "ctf01d/internal/app/utils" ) -type User struct { - Id int `json:"id"` - DisplayName string `json:"display_name"` - Username string `json:"user_name"` - Role string `json:"role,omitempty"` - AvatarUrl string `json:"avatar_url,omitempty"` - Status string `json:"status,omitempty"` -} - func NewUserFromModel(u *db.User) *server.UserResponse { userRole := helpers.ConvertUserRequestRoleToUserResponseRole(u.Role) return &server.UserResponse{