refactor (v2): better arch
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
10
crates/api-types/Cargo.toml
Normal file
10
crates/api-types/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "api-types"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
serde = { workspace = true }
|
||||
uuid = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
utoipa = { version = "5", features = ["axum_extras", "uuid", "chrono"] }
|
||||
29
crates/api-types/src/auth.rs
Normal file
29
crates/api-types/src/auth.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct LoginRequest {
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct RegisterRequest {
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct UserResponse {
|
||||
pub id: Uuid,
|
||||
pub email: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
/// Returned after a successful login or register.
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct AuthResponse {
|
||||
pub user: UserResponse,
|
||||
pub access_token: String,
|
||||
}
|
||||
18
crates/api-types/src/backup.rs
Normal file
18
crates/api-types/src/backup.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A note in portable backup format (no IDs — uses names and content only).
|
||||
#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
|
||||
pub struct BackupNote {
|
||||
pub title: Option<String>,
|
||||
pub content: String,
|
||||
pub color: String,
|
||||
pub is_pinned: bool,
|
||||
pub is_archived: bool,
|
||||
/// Tag names associated with this note.
|
||||
pub tags: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
|
||||
pub struct BackupData {
|
||||
pub notes: Vec<BackupNote>,
|
||||
}
|
||||
6
crates/api-types/src/config.rs
Normal file
6
crates/api-types/src/config.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct ConfigResponse {
|
||||
pub allow_registration: bool,
|
||||
}
|
||||
36
crates/api-types/src/errors.rs
Normal file
36
crates/api-types/src/errors.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct ErrorResponse {
|
||||
pub code: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl ErrorResponse {
|
||||
pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self {
|
||||
Self {
|
||||
code: code.into(),
|
||||
message: message.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn not_found(message: impl Into<String>) -> Self {
|
||||
Self::new("NOT_FOUND", message)
|
||||
}
|
||||
|
||||
pub fn forbidden(message: impl Into<String>) -> Self {
|
||||
Self::new("FORBIDDEN", message)
|
||||
}
|
||||
|
||||
pub fn conflict(message: impl Into<String>) -> Self {
|
||||
Self::new("CONFLICT", message)
|
||||
}
|
||||
|
||||
pub fn validation(message: impl Into<String>) -> Self {
|
||||
Self::new("VALIDATION_ERROR", message)
|
||||
}
|
||||
|
||||
pub fn internal(message: impl Into<String>) -> Self {
|
||||
Self::new("INTERNAL_ERROR", message)
|
||||
}
|
||||
}
|
||||
6
crates/api-types/src/lib.rs
Normal file
6
crates/api-types/src/lib.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
pub mod auth;
|
||||
pub mod backup;
|
||||
pub mod config;
|
||||
pub mod errors;
|
||||
pub mod notes;
|
||||
pub mod tags;
|
||||
82
crates/api-types/src/notes.rs
Normal file
82
crates/api-types/src/notes.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::tags::TagResponse;
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct CreateNoteRequest {
|
||||
pub title: Option<String>,
|
||||
#[serde(default)]
|
||||
pub content: String,
|
||||
pub color: Option<String>,
|
||||
#[serde(default)]
|
||||
pub is_pinned: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdateNoteRequest {
|
||||
pub title: Option<String>,
|
||||
pub content: Option<String>,
|
||||
pub color: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Default, utoipa::IntoParams)]
|
||||
pub struct ListNotesParams {
|
||||
pub pinned: Option<bool>,
|
||||
pub archived: Option<bool>,
|
||||
/// Filter by tag name.
|
||||
pub tag: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::IntoParams)]
|
||||
pub struct SearchParams {
|
||||
pub q: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct AddTagRequest {
|
||||
pub tag_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct PinRequest {
|
||||
pub pinned: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct ArchiveRequest {
|
||||
pub archived: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct NoteResponse {
|
||||
pub id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub title: Option<String>,
|
||||
pub content: String,
|
||||
pub color: String,
|
||||
pub is_pinned: bool,
|
||||
pub is_archived: bool,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub tags: Vec<TagResponse>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct NoteVersionResponse {
|
||||
pub id: Uuid,
|
||||
pub note_id: Uuid,
|
||||
pub title: Option<String>,
|
||||
pub content: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct NoteLinkResponse {
|
||||
pub source_id: Uuid,
|
||||
pub target_id: Uuid,
|
||||
/// Cosine similarity score in [0.0, 1.0].
|
||||
pub score: f32,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
18
crates/api-types/src/tags.rs
Normal file
18
crates/api-types/src/tags.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct CreateTagRequest {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct RenameTagRequest {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct TagResponse {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
}
|
||||
Reference in New Issue
Block a user