From 09f4ddc3a430d0af7fa5607d92dd531af17cf224 Mon Sep 17 00:00:00 2001 From: Mika Date: Tue, 17 Jun 2025 17:16:41 +0200 Subject: [PATCH] refactor: add content type to response definitions for consistency across controllers --- crates/backend/src/controller/auth.rs | 4 +-- crates/backend/src/controller/class.rs | 10 ++++---- crates/backend/src/controller/group.rs | 10 ++++---- crates/backend/src/controller/project.rs | 30 +++++++++++------------ crates/backend/src/controller/template.rs | 10 ++++---- crates/backend/src/controller/user.rs | 26 ++++++++++---------- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/crates/backend/src/controller/auth.rs b/crates/backend/src/controller/auth.rs index 12158b2..79f902b 100644 --- a/crates/backend/src/controller/auth.rs +++ b/crates/backend/src/controller/auth.rs @@ -32,7 +32,7 @@ pub fn setup(cfg: &mut ServiceConfig) { description = "Authenticate a user with username and password", request_body = LoginRequest, responses( - (status = 200, description = "Login successful", body = MessageResponse), + (status = 200, description = "Login successful", body = MessageResponse, content_type = "application/json"), (status = 400, description = "Invalid credentials"), (status = 409, description = "User already logged in"), (status = 500, description = "Internal server error") @@ -66,7 +66,7 @@ pub async fn login( summary = "User logout", description = "Log out the currently authenticated user and clear session", responses( - (status = 200, description = "Logout successful", body = MessageResponse), + (status = 200, description = "Logout successful", body = MessageResponse, content_type = "application/json"), (status = 500, description = "Internal server error") ) )] diff --git a/crates/backend/src/controller/class.rs b/crates/backend/src/controller/class.rs index 3eedc5d..9f9343c 100644 --- a/crates/backend/src/controller/class.rs +++ b/crates/backend/src/controller/class.rs @@ -15,7 +15,7 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { summary = "Get all classes (Not Implemented)", description = "Retrieve a list of all classes - currently not implemented", responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[get("")] @@ -33,7 +33,7 @@ async fn get_classes() -> impl Responder { ("id" = String, Path, description = "Class ID") ), responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[get("/{id}")] @@ -48,7 +48,7 @@ async fn get_class() -> impl Responder { summary = "Create class (Not Implemented)", description = "Create a new class - currently not implemented", responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[post("")] @@ -63,7 +63,7 @@ async fn create_class() -> impl Responder { summary = "Update class (Not Implemented)", description = "Update an existing class - currently not implemented", responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[put("")] @@ -81,7 +81,7 @@ async fn update_class() -> impl Responder { ("id" = String, Path, description = "Class ID to delete") ), responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[delete("/{id}")] diff --git a/crates/backend/src/controller/group.rs b/crates/backend/src/controller/group.rs index 1999bdc..e125764 100644 --- a/crates/backend/src/controller/group.rs +++ b/crates/backend/src/controller/group.rs @@ -15,7 +15,7 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { summary = "Get all groups (Not Implemented)", description = "Retrieve a list of all groups - currently not implemented", responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[get("")] @@ -33,7 +33,7 @@ async fn get_groups() -> impl Responder { ("project" = String, Path, description = "Project ID") ), responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[get("/{project}")] @@ -48,7 +48,7 @@ async fn get_groups_for_project() -> impl Responder { summary = "Create group (Not Implemented)", description = "Create a new group - currently not implemented", responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[post("")] @@ -63,7 +63,7 @@ async fn create_group() -> impl Responder { summary = "Update group (Not Implemented)", description = "Update an existing group - currently not implemented", responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[put("")] @@ -81,7 +81,7 @@ async fn update_group() -> impl Responder { ("id" = String, Path, description = "Group ID to delete") ), responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[delete("/{id}")] diff --git a/crates/backend/src/controller/project.rs b/crates/backend/src/controller/project.rs index 6fa4f02..476e954 100644 --- a/crates/backend/src/controller/project.rs +++ b/crates/backend/src/controller/project.rs @@ -22,8 +22,8 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { summary = "Get all projects", description = "Retrieve a list of all projects", responses( - (status = 200, description = "List of projects retrieved successfully", body = Vec), - (status = 500, description = "Internal server error", body = String) + (status = 200, description = "List of projects retrieved successfully", body = Vec, content_type = "application/json"), + (status = 500, description = "Internal server error", body = String, content_type = "application/json") ) )] #[get("")] @@ -45,9 +45,9 @@ async fn get_projects( ("id" = String, Path, description = "Project ID") ), responses( - (status = 200, description = "Project retrieved successfully", body = entity::project::Model), - (status = 404, description = "Project not found", body = String), - (status = 500, description = "Internal server error", body = String) + (status = 200, description = "Project retrieved successfully", body = entity::project::Model, content_type = "application/json"), + (status = 404, description = "Project not found", body = String, content_type = "application/json"), + (status = 500, description = "Internal server error", body = String, content_type = "application/json") ) )] #[get("/{id}")] @@ -70,9 +70,9 @@ async fn get_project( description = "Create a new project with the provided details", request_body = CreateProject, responses( - (status = 200, description = "Project created successfully", body = entity::project::Model), - (status = 400, description = "Invalid request data or validation error", body = String), - (status = 500, description = "Internal server error", body = String) + (status = 200, description = "Project created successfully", body = entity::project::Model, content_type = "application/json"), + (status = 400, description = "Invalid request data or validation error", body = String, content_type = "application/json"), + (status = 500, description = "Internal server error", body = String, content_type = "application/json") ) )] #[post("")] @@ -97,10 +97,10 @@ async fn create_project( ), request_body = CreateProject, responses( - (status = 200, description = "Project updated successfully", body = entity::project::Model), - (status = 400, description = "Invalid request data or validation error", body = String), - (status = 404, description = "Project not found", body = String), - (status = 500, description = "Internal server error", body = String) + (status = 200, description = "Project updated successfully", body = entity::project::Model, content_type = "application/json"), + (status = 400, description = "Invalid request data or validation error", body = String, content_type = "application/json"), + (status = 404, description = "Project not found", body = String, content_type = "application/json"), + (status = 500, description = "Internal server error", body = String, content_type = "application/json") ) )] #[put("/{id}")] @@ -126,9 +126,9 @@ async fn update_project( ("id" = String, Path, description = "Project ID to delete") ), responses( - (status = 200, description = "Project deleted successfully", body = String), - (status = 404, description = "Project not found", body = String), - (status = 500, description = "Internal server error", body = String) + (status = 200, description = "Project deleted successfully", body = String, content_type = "application/json"), + (status = 404, description = "Project not found", body = String, content_type = "application/json"), + (status = 500, description = "Internal server error", body = String, content_type = "application/json") ) )] #[delete("/{id}")] diff --git a/crates/backend/src/controller/template.rs b/crates/backend/src/controller/template.rs index ab24bc1..61b138d 100644 --- a/crates/backend/src/controller/template.rs +++ b/crates/backend/src/controller/template.rs @@ -15,7 +15,7 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { summary = "Get all templates (Not Implemented)", description = "Retrieve a list of all templates - currently not implemented", responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[get("")] @@ -33,7 +33,7 @@ async fn get_templates() -> impl Responder { ("id" = String, Path, description = "Template ID") ), responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[get("/{id}")] @@ -48,7 +48,7 @@ async fn get_template() -> impl Responder { summary = "Create template (Not Implemented)", description = "Create a new template - currently not implemented", responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[post("")] @@ -63,7 +63,7 @@ async fn create_template() -> impl Responder { summary = "Update template (Not Implemented)", description = "Update an existing template - currently not implemented", responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[put("")] @@ -81,7 +81,7 @@ async fn update_template() -> impl Responder { ("id" = String, Path, description = "Template ID to delete") ), responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[delete("/{id}")] diff --git a/crates/backend/src/controller/user.rs b/crates/backend/src/controller/user.rs index 6fe0775..5c4f5ae 100644 --- a/crates/backend/src/controller/user.rs +++ b/crates/backend/src/controller/user.rs @@ -1,8 +1,8 @@ use crate::{Database, entity, error::ApiError}; use actix_web::{Responder, delete, get, post, put, web}; use serde::Deserialize; -use validator::Validate; use utoipa::ToSchema; +use validator::Validate; pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { cfg.service(get_users) @@ -30,8 +30,8 @@ pub struct CreateUser { summary = "Get all users", description = "Retrieve a list of all users", responses( - (status = 200, description = "List of users retrieved successfully", body = Vec), - (status = 500, description = "Internal server error", body = String) + (status = 200, description = "List of users retrieved successfully", body = Vec, content_type = "application/json"), + (status = 500, description = "Internal server error", body = String, content_type = "application/json") ) )] #[get("")] @@ -52,9 +52,9 @@ async fn get_users( ("id" = String, Path, description = "User ID") ), responses( - (status = 200, description = "User retrieved successfully", body = entity::user::Model), - (status = 404, description = "User not found", body = String), - (status = 500, description = "Internal server error", body = String) + (status = 200, description = "User retrieved successfully", body = entity::user::Model, content_type = "application/json"), + (status = 404, description = "User not found", body = String, content_type = "application/json"), + (status = 500, description = "Internal server error", body = String, content_type = "application/json") ) )] #[get("/{id}")] @@ -75,9 +75,9 @@ async fn get_user( description = "Create a new user with username, name, and password", request_body = CreateUser, responses( - (status = 200, description = "User created successfully", body = entity::user::Model), - (status = 400, description = "Invalid request data or validation error", body = String), - (status = 500, description = "Internal server error", body = String) + (status = 200, description = "User created successfully", body = entity::user::Model, content_type = "application/json"), + (status = 400, description = "Invalid request data or validation error", body = String, content_type = "application/json"), + (status = 500, description = "Internal server error", body = String, content_type = "application/json") ) )] #[post("")] @@ -100,7 +100,7 @@ async fn create_user( summary = "Update user (Not Implemented)", description = "Update user information - currently not implemented", responses( - (status = 501, description = "Not implemented", body = String) + (status = 501, description = "Not implemented", body = String, content_type = "application/json") ) )] #[put("")] @@ -118,9 +118,9 @@ async fn update_user() -> impl Responder { ("id" = String, Path, description = "User ID to delete") ), responses( - (status = 200, description = "User deleted successfully", body = String), - (status = 404, description = "User not found", body = String), - (status = 500, description = "Internal server error", body = String) + (status = 200, description = "User deleted successfully", body = String, content_type = "application/json", example = "User 123e4567-e89b-12d3-a456-426614174000 deleted"), + (status = 404, description = "User not found", body = String, content_type = "application/json"), + (status = 500, description = "Internal server error", body = String, content_type = "application/json") ) )] #[delete("/{id}")]