Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,819 changes: 1,819 additions & 0 deletions openapi.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/api/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod auth;
pub mod projects;
pub mod tags;
pub mod testimonials;
32 changes: 32 additions & 0 deletions src/api/v1/tags/dto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use rapina::schemars::{self, JsonSchema};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, JsonSchema)]
pub struct CreateTagRequest {
pub name: String,
pub color: Option<String>,
}

#[derive(Deserialize, JsonSchema)]
pub struct UpdateTagRequest {
pub name: Option<String>,
pub color: Option<String>,
}

#[derive(Clone, Serialize, JsonSchema)]
pub struct TagResponse {
pub id: String,
pub project_id: String,
pub name: String,
pub color: Option<String>,
}

#[derive(Deserialize, JsonSchema)]
pub struct SetTestimonialTagsRequest {
pub tag_ids: Vec<String>,
}

#[derive(Serialize, JsonSchema)]
pub struct TestimonialTagsResponse {
pub tags: Vec<TagResponse>,
}
55 changes: 55 additions & 0 deletions src/api/v1/tags/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use rapina::database::DbError;
use rapina::prelude::*;

pub enum TagError {
DbError(DbError),
NotFound,
Forbidden,
NameTaken,
}

impl IntoApiError for TagError {
fn into_api_error(self) -> Error {
match self {
TagError::DbError(e) => e.into_api_error(),
TagError::NotFound => Error::not_found("tag not found"),
TagError::Forbidden => Error::forbidden("you do not own this project"),
TagError::NameTaken => {
Error::conflict("a tag with this name already exists in this project")
}
}
}
}

impl DocumentedError for TagError {
fn error_variants() -> Vec<ErrorVariant> {
vec![
ErrorVariant {
status: 404,
code: "NOT_FOUND",
description: "Tag not found",
},
ErrorVariant {
status: 403,
code: "FORBIDDEN",
description: "User does not own this project",
},
ErrorVariant {
status: 409,
code: "CONFLICT",
description: "Tag name already exists in this project",
},
ErrorVariant {
status: 500,
code: "INTERNAL_ERROR",
description: "Internal server error",
},
]
}
}

impl From<DbError> for TagError {
fn from(e: DbError) -> Self {
TagError::DbError(e)
}
}
Loading