Skip to content

Commit

Permalink
Updated OpenAPI spec
Browse files Browse the repository at this point in the history
  • Loading branch information
cikzh committed Feb 10, 2025
1 parent 1e170a2 commit 5936788
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
81 changes: 81 additions & 0 deletions backend/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,69 @@
}
}
}
},
"/api/user/{user_id}": {
"put": {
"tags": [
"authentication"
],
"summary": "Update a user",
"operationId": "user_update",
"parameters": [
{
"name": "user_id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32",
"minimum": 0
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateUserRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "User updated",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
},
"404": {
"description": "User not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
},
"500": {
"description": "Internal server error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
}
}
}
},
"components": {
Expand Down Expand Up @@ -2429,6 +2492,24 @@
}
}
},
"UpdateUserRequest": {
"type": "object",
"required": [
"username",
"role"
],
"properties": {
"fullname": {
"type": "string"
},
"role": {
"$ref": "#/components/schemas/Role"
},
"username": {
"type": "string"
}
}
},
"User": {
"type": "object",
"description": "User object, corresponds to a row in the users table",
Expand Down
2 changes: 2 additions & 0 deletions backend/src/authentication/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ pub struct UpdateUserRequest {
#[utoipa::path(
post,
path = "/api/user",
request_body = CreateUserRequest,
responses(
(status = 201, description = "User created", body = User),
(status = 500, description = "Internal server error", body = ErrorResponse),
Expand All @@ -343,6 +344,7 @@ pub async fn user_create(
#[utoipa::path(
put,
path = "/api/user/{user_id}",
request_body = UpdateUserRequest,
responses(
(status = 200, description = "User updated", body = User),
(status = 404, description = "User not found", body = ErrorResponse),
Expand Down
3 changes: 3 additions & 0 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub fn create_openapi() -> utoipa::openapi::OpenApi {
authentication::change_password,
authentication::user_list,
authentication::user_create,
authentication::user_update,
election::election_list,
election::election_create,
election::election_details,
Expand Down Expand Up @@ -192,6 +193,8 @@ pub fn create_openapi() -> utoipa::openapi::OpenApi {
authentication::LoginResponse,
authentication::ChangePasswordRequest,
authentication::UserListResponse,
authentication::UpdateUserRequest,
authentication::CreateUserRequest,
data_entry::CandidateVotes,
data_entry::DataEntry,
data_entry::SaveDataEntryResponse,
Expand Down
13 changes: 13 additions & 0 deletions frontend/lib/api/gen/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ export type LOGOUT_REQUEST_PATH = `/api/user/logout`;
export type WHOAMI_REQUEST_PARAMS = Record<string, never>;
export type WHOAMI_REQUEST_PATH = `/api/user/whoami`;

// /api/user/{user_id}
export interface USER_UPDATE_REQUEST_PARAMS {
user_id: number;
}
export type USER_UPDATE_REQUEST_PATH = `/api/user/${number}`;
export type USER_UPDATE_REQUEST_BODY = UpdateUserRequest;

/** TYPES **/

/**
Expand Down Expand Up @@ -537,6 +544,12 @@ export interface SummaryDifferencesCounts {
unreturned_ballots_count: SumCount;
}

export interface UpdateUserRequest {
fullname?: string;
role: Role;
username: string;
}

/**
* User object, corresponds to a row in the users table
*/
Expand Down

0 comments on commit 5936788

Please sign in to comment.