refactor: add content type to response definitions for consistency across controllers

This commit is contained in:
Mika 2025-06-17 17:16:41 +02:00
parent af67204060
commit 09f4ddc3a4
6 changed files with 45 additions and 45 deletions

View file

@ -32,7 +32,7 @@ pub fn setup(cfg: &mut ServiceConfig) {
description = "Authenticate a user with username and password", description = "Authenticate a user with username and password",
request_body = LoginRequest, request_body = LoginRequest,
responses( 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 = 400, description = "Invalid credentials"),
(status = 409, description = "User already logged in"), (status = 409, description = "User already logged in"),
(status = 500, description = "Internal server error") (status = 500, description = "Internal server error")
@ -66,7 +66,7 @@ pub async fn login(
summary = "User logout", summary = "User logout",
description = "Log out the currently authenticated user and clear session", description = "Log out the currently authenticated user and clear session",
responses( 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") (status = 500, description = "Internal server error")
) )
)] )]

View file

@ -15,7 +15,7 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
summary = "Get all classes (Not Implemented)", summary = "Get all classes (Not Implemented)",
description = "Retrieve a list of all classes - currently not implemented", description = "Retrieve a list of all classes - currently not implemented",
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[get("")] #[get("")]
@ -33,7 +33,7 @@ async fn get_classes() -> impl Responder {
("id" = String, Path, description = "Class ID") ("id" = String, Path, description = "Class ID")
), ),
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[get("/{id}")] #[get("/{id}")]
@ -48,7 +48,7 @@ async fn get_class() -> impl Responder {
summary = "Create class (Not Implemented)", summary = "Create class (Not Implemented)",
description = "Create a new class - currently not implemented", description = "Create a new class - currently not implemented",
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[post("")] #[post("")]
@ -63,7 +63,7 @@ async fn create_class() -> impl Responder {
summary = "Update class (Not Implemented)", summary = "Update class (Not Implemented)",
description = "Update an existing class - currently not implemented", description = "Update an existing class - currently not implemented",
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[put("")] #[put("")]
@ -81,7 +81,7 @@ async fn update_class() -> impl Responder {
("id" = String, Path, description = "Class ID to delete") ("id" = String, Path, description = "Class ID to delete")
), ),
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[delete("/{id}")] #[delete("/{id}")]

View file

@ -15,7 +15,7 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
summary = "Get all groups (Not Implemented)", summary = "Get all groups (Not Implemented)",
description = "Retrieve a list of all groups - currently not implemented", description = "Retrieve a list of all groups - currently not implemented",
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[get("")] #[get("")]
@ -33,7 +33,7 @@ async fn get_groups() -> impl Responder {
("project" = String, Path, description = "Project ID") ("project" = String, Path, description = "Project ID")
), ),
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[get("/{project}")] #[get("/{project}")]
@ -48,7 +48,7 @@ async fn get_groups_for_project() -> impl Responder {
summary = "Create group (Not Implemented)", summary = "Create group (Not Implemented)",
description = "Create a new group - currently not implemented", description = "Create a new group - currently not implemented",
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[post("")] #[post("")]
@ -63,7 +63,7 @@ async fn create_group() -> impl Responder {
summary = "Update group (Not Implemented)", summary = "Update group (Not Implemented)",
description = "Update an existing group - currently not implemented", description = "Update an existing group - currently not implemented",
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[put("")] #[put("")]
@ -81,7 +81,7 @@ async fn update_group() -> impl Responder {
("id" = String, Path, description = "Group ID to delete") ("id" = String, Path, description = "Group ID to delete")
), ),
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[delete("/{id}")] #[delete("/{id}")]

View file

@ -22,8 +22,8 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
summary = "Get all projects", summary = "Get all projects",
description = "Retrieve a list of all projects", description = "Retrieve a list of all projects",
responses( responses(
(status = 200, description = "List of projects retrieved successfully", body = Vec<entity::project::Model>), (status = 200, description = "List of projects retrieved successfully", body = Vec<entity::project::Model>, content_type = "application/json"),
(status = 500, description = "Internal server error", body = String) (status = 500, description = "Internal server error", body = String, content_type = "application/json")
) )
)] )]
#[get("")] #[get("")]
@ -45,9 +45,9 @@ async fn get_projects(
("id" = String, Path, description = "Project ID") ("id" = String, Path, description = "Project ID")
), ),
responses( responses(
(status = 200, description = "Project retrieved successfully", body = entity::project::Model), (status = 200, description = "Project retrieved successfully", body = entity::project::Model, content_type = "application/json"),
(status = 404, description = "Project not found", body = String), (status = 404, description = "Project not found", body = String, content_type = "application/json"),
(status = 500, description = "Internal server error", body = String) (status = 500, description = "Internal server error", body = String, content_type = "application/json")
) )
)] )]
#[get("/{id}")] #[get("/{id}")]
@ -70,9 +70,9 @@ async fn get_project(
description = "Create a new project with the provided details", description = "Create a new project with the provided details",
request_body = CreateProject, request_body = CreateProject,
responses( responses(
(status = 200, description = "Project created successfully", body = entity::project::Model), (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), (status = 400, description = "Invalid request data or validation error", body = String, content_type = "application/json"),
(status = 500, description = "Internal server error", body = String) (status = 500, description = "Internal server error", body = String, content_type = "application/json")
) )
)] )]
#[post("")] #[post("")]
@ -97,10 +97,10 @@ async fn create_project(
), ),
request_body = CreateProject, request_body = CreateProject,
responses( responses(
(status = 200, description = "Project updated successfully", body = entity::project::Model), (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), (status = 400, description = "Invalid request data or validation error", body = String, content_type = "application/json"),
(status = 404, description = "Project not found", body = String), (status = 404, description = "Project not found", body = String, content_type = "application/json"),
(status = 500, description = "Internal server error", body = String) (status = 500, description = "Internal server error", body = String, content_type = "application/json")
) )
)] )]
#[put("/{id}")] #[put("/{id}")]
@ -126,9 +126,9 @@ async fn update_project(
("id" = String, Path, description = "Project ID to delete") ("id" = String, Path, description = "Project ID to delete")
), ),
responses( responses(
(status = 200, description = "Project deleted successfully", body = String), (status = 200, description = "Project deleted successfully", body = String, content_type = "application/json"),
(status = 404, description = "Project not found", body = String), (status = 404, description = "Project not found", body = String, content_type = "application/json"),
(status = 500, description = "Internal server error", body = String) (status = 500, description = "Internal server error", body = String, content_type = "application/json")
) )
)] )]
#[delete("/{id}")] #[delete("/{id}")]

View file

@ -15,7 +15,7 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
summary = "Get all templates (Not Implemented)", summary = "Get all templates (Not Implemented)",
description = "Retrieve a list of all templates - currently not implemented", description = "Retrieve a list of all templates - currently not implemented",
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[get("")] #[get("")]
@ -33,7 +33,7 @@ async fn get_templates() -> impl Responder {
("id" = String, Path, description = "Template ID") ("id" = String, Path, description = "Template ID")
), ),
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[get("/{id}")] #[get("/{id}")]
@ -48,7 +48,7 @@ async fn get_template() -> impl Responder {
summary = "Create template (Not Implemented)", summary = "Create template (Not Implemented)",
description = "Create a new template - currently not implemented", description = "Create a new template - currently not implemented",
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[post("")] #[post("")]
@ -63,7 +63,7 @@ async fn create_template() -> impl Responder {
summary = "Update template (Not Implemented)", summary = "Update template (Not Implemented)",
description = "Update an existing template - currently not implemented", description = "Update an existing template - currently not implemented",
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[put("")] #[put("")]
@ -81,7 +81,7 @@ async fn update_template() -> impl Responder {
("id" = String, Path, description = "Template ID to delete") ("id" = String, Path, description = "Template ID to delete")
), ),
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[delete("/{id}")] #[delete("/{id}")]

View file

@ -1,8 +1,8 @@
use crate::{Database, entity, error::ApiError}; use crate::{Database, entity, error::ApiError};
use actix_web::{Responder, delete, get, post, put, web}; use actix_web::{Responder, delete, get, post, put, web};
use serde::Deserialize; use serde::Deserialize;
use validator::Validate;
use utoipa::ToSchema; use utoipa::ToSchema;
use validator::Validate;
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
cfg.service(get_users) cfg.service(get_users)
@ -30,8 +30,8 @@ pub struct CreateUser {
summary = "Get all users", summary = "Get all users",
description = "Retrieve a list of all users", description = "Retrieve a list of all users",
responses( responses(
(status = 200, description = "List of users retrieved successfully", body = Vec<entity::user::Model>), (status = 200, description = "List of users retrieved successfully", body = Vec<entity::user::Model>, content_type = "application/json"),
(status = 500, description = "Internal server error", body = String) (status = 500, description = "Internal server error", body = String, content_type = "application/json")
) )
)] )]
#[get("")] #[get("")]
@ -52,9 +52,9 @@ async fn get_users(
("id" = String, Path, description = "User ID") ("id" = String, Path, description = "User ID")
), ),
responses( responses(
(status = 200, description = "User retrieved successfully", body = entity::user::Model), (status = 200, description = "User retrieved successfully", body = entity::user::Model, content_type = "application/json"),
(status = 404, description = "User not found", body = String), (status = 404, description = "User not found", body = String, content_type = "application/json"),
(status = 500, description = "Internal server error", body = String) (status = 500, description = "Internal server error", body = String, content_type = "application/json")
) )
)] )]
#[get("/{id}")] #[get("/{id}")]
@ -75,9 +75,9 @@ async fn get_user(
description = "Create a new user with username, name, and password", description = "Create a new user with username, name, and password",
request_body = CreateUser, request_body = CreateUser,
responses( responses(
(status = 200, description = "User created successfully", body = entity::user::Model), (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), (status = 400, description = "Invalid request data or validation error", body = String, content_type = "application/json"),
(status = 500, description = "Internal server error", body = String) (status = 500, description = "Internal server error", body = String, content_type = "application/json")
) )
)] )]
#[post("")] #[post("")]
@ -100,7 +100,7 @@ async fn create_user(
summary = "Update user (Not Implemented)", summary = "Update user (Not Implemented)",
description = "Update user information - currently not implemented", description = "Update user information - currently not implemented",
responses( responses(
(status = 501, description = "Not implemented", body = String) (status = 501, description = "Not implemented", body = String, content_type = "application/json")
) )
)] )]
#[put("")] #[put("")]
@ -118,9 +118,9 @@ async fn update_user() -> impl Responder {
("id" = String, Path, description = "User ID to delete") ("id" = String, Path, description = "User ID to delete")
), ),
responses( responses(
(status = 200, description = "User deleted successfully", 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), (status = 404, description = "User not found", body = String, content_type = "application/json"),
(status = 500, description = "Internal server error", body = String) (status = 500, description = "Internal server error", body = String, content_type = "application/json")
) )
)] )]
#[delete("/{id}")] #[delete("/{id}")]