use derive_builder::Builder;
use serde::Serialize;
use uuid::Uuid;
use crate::{
schema::{NoData, PaginationQuery},
Result,
};
use crate::schema::list::*;
#[derive(Debug, Serialize, Clone, Builder)]
pub struct CreateCustomList<'a> {
pub name: &'a str,
#[builder(default = "CustomListVisibility::Private")]
pub visibility: CustomListVisibility,
#[builder(setter(each = "add_manga"))]
pub manga: Vec<&'a Uuid>,
pub version: i32,
}
impl_endpoint! {
POST "/list",
#[body auth] CreateCustomList<'_>,
#[flatten_result] CustomListResponse
}
#[derive(Debug, Clone)]
pub struct GetCustomList<'a> {
id: &'a Uuid,
}
impl_endpoint! {
GET ("/list/{:x}", id),
#[no_data] GetCustomList<'_>,
#[flatten_result] CustomListResponse
}
#[derive(Debug, Serialize, Clone, Builder)]
pub struct UpdateCustomList<'a> {
#[serde(skip)]
pub id: &'a Uuid,
pub name: &'a str,
pub visibility: CustomListVisibility,
#[builder(setter(each = "add_manga"))]
pub manga: Vec<&'a Uuid>,
pub version: i32,
}
impl_endpoint! {
PUT ("/list/{:x}", id),
#[body auth] UpdateCustomList<'_>,
#[flatten_result] CustomListResponse
}
#[derive(Debug, Clone)]
pub struct DeleteCustomList<'a> {
pub id: &'a Uuid,
}
impl_endpoint! {
DELETE ("/list/{:x}", id),
#[no_data auth] DeleteCustomList<'_>,
#[discard_result] Result<NoData>
}
#[derive(Debug, Clone)]
pub struct AddMangaToCustomList<'a> {
pub manga_id: &'a Uuid,
pub list_id: &'a Uuid,
}
impl_endpoint! {
POST ("/manga/{:x}/list/{:x}", manga_id, list_id),
#[no_data auth] AddMangaToCustomList<'_>,
#[discard_result] Result<NoData>
}
#[derive(Debug, Clone)]
pub struct RemoveMangaFromCustomList<'a> {
pub manga_id: &'a Uuid,
pub list_id: &'a Uuid,
}
impl_endpoint! {
DELETE ("/manga/{:x}/list/{:x}", manga_id, list_id),
#[no_data auth] RemoveMangaFromCustomList<'_>,
#[discard_result] Result<NoData>
}
#[derive(Debug, Serialize, Clone)]
pub struct GetLoggedUserCustomLists {
#[serde(flatten)]
pub pagination: PaginationQuery,
}
impl_endpoint! {
GET "/user/list",
#[query auth] GetLoggedUserCustomLists,
CustomListList
}
#[derive(Debug, Serialize, Clone)]
pub struct GetUserCustomLists<'a> {
#[serde(skip)]
pub user_id: &'a Uuid,
#[serde(flatten)]
pub pagination: PaginationQuery,
}
impl_endpoint! {
GET ("/user/{:x}/list", user_id),
#[query auth] GetUserCustomLists<'_>,
CustomListList
}