90 lines
2.9 KiB
Rust
90 lines
2.9 KiB
Rust
use crate::{ApiResponse, error::ApiError};
|
|
use actix_web::{HttpResponse, Result, web};
|
|
use service::AppService;
|
|
use service::project::message_favorite::{
|
|
ProjectMessageFavoriteQuery, ProjectMessageFavoriteResponse,
|
|
};
|
|
use session::Session;
|
|
use uuid::Uuid;
|
|
|
|
#[utoipa::path(
|
|
get,
|
|
path = "/api/projects/{project_name}/message-favorites",
|
|
params(
|
|
("project_name" = String, Path),
|
|
ProjectMessageFavoriteQuery,
|
|
),
|
|
responses(
|
|
(status = 200, description = "List current user's project message favorites", body = ApiResponse<ProjectMessageFavoriteResponse>),
|
|
(status = 401, description = "Unauthorized"),
|
|
(status = 403, description = "Forbidden"),
|
|
(status = 404, description = "Not found"),
|
|
),
|
|
tag = "Project"
|
|
)]
|
|
pub async fn project_message_favorites(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
path: web::Path<String>,
|
|
query: web::Query<ProjectMessageFavoriteQuery>,
|
|
) -> Result<HttpResponse, ApiError> {
|
|
let resp = service
|
|
.project_message_favorites(&session, path.into_inner(), query.into_inner())
|
|
.await?;
|
|
Ok(ApiResponse::ok(resp).to_response())
|
|
}
|
|
|
|
#[utoipa::path(
|
|
post,
|
|
path = "/api/projects/{project_name}/messages/{message_id}/favorite",
|
|
params(
|
|
("project_name" = String, Path),
|
|
("message_id" = Uuid, Path),
|
|
),
|
|
responses(
|
|
(status = 200, description = "Favorite a project message", body = ApiResponse<service::project::message_favorite::ProjectMessageFavoriteItem>),
|
|
(status = 401, description = "Unauthorized"),
|
|
(status = 403, description = "Forbidden"),
|
|
(status = 404, description = "Not found"),
|
|
),
|
|
tag = "Project"
|
|
)]
|
|
pub async fn project_message_favorite_add(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
path: web::Path<(String, Uuid)>,
|
|
) -> Result<HttpResponse, ApiError> {
|
|
let (project_name, message_id) = path.into_inner();
|
|
let resp = service
|
|
.project_message_favorite_add(&session, project_name, message_id)
|
|
.await?;
|
|
Ok(ApiResponse::ok(resp).to_response())
|
|
}
|
|
|
|
#[utoipa::path(
|
|
delete,
|
|
path = "/api/projects/{project_name}/messages/{message_id}/favorite",
|
|
params(
|
|
("project_name" = String, Path),
|
|
("message_id" = Uuid, Path),
|
|
),
|
|
responses(
|
|
(status = 200, description = "Remove a project message favorite"),
|
|
(status = 401, description = "Unauthorized"),
|
|
(status = 403, description = "Forbidden"),
|
|
(status = 404, description = "Not found"),
|
|
),
|
|
tag = "Project"
|
|
)]
|
|
pub async fn project_message_favorite_remove(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
path: web::Path<(String, Uuid)>,
|
|
) -> Result<HttpResponse, ApiError> {
|
|
let (project_name, message_id) = path.into_inner();
|
|
service
|
|
.project_message_favorite_remove(&session, project_name, message_id)
|
|
.await?;
|
|
Ok(crate::api_success())
|
|
}
|