diff --git a/core/src/errors.rs b/core/src/errors.rs index 07fde48..bdb9e11 100644 --- a/core/src/errors.rs +++ b/core/src/errors.rs @@ -7,6 +7,8 @@ pub mod boards; pub mod messages; pub mod threads; +pub mod marks; + pub mod auth; pub mod authors; pub mod files; diff --git a/core/src/errors/marks.rs b/core/src/errors/marks.rs new file mode 100644 index 0000000..71c6c5a --- /dev/null +++ b/core/src/errors/marks.rs @@ -0,0 +1,10 @@ +use eva::data; + +#[data] +pub struct NoSuchTag {} + +#[data] +pub struct NoSuchGenre {} + +#[data] +pub struct NoSuchBadge {} diff --git a/core/src/requests/games.rs b/core/src/requests/games.rs index 0a4acc3..b67984c 100644 --- a/core/src/requests/games.rs +++ b/core/src/requests/games.rs @@ -1,6 +1,6 @@ use crate::{ errors, - types::{Patch, True, author, file, game}, + types::{Patch, True, author, file, game, mark}, }; use std::collections::HashMap; @@ -23,9 +23,9 @@ pub mod update { pub description: Patch>, pub slug: Patch, pub thumbnail: Patch>, - pub genres: Patch, - pub badges: Patch, - pub tags: Patch, + pub genres: Patch, + pub badges: Patch, + pub tags: Patch, pub screenshots: Patch, pub published: Patch, } @@ -53,9 +53,9 @@ pub mod search { #[data] #[derive(Default)] pub struct Marks { - pub tags: Logic, - pub genres: Logic, - pub badges: Logic, + pub tags: Logic, + pub genres: Logic, + pub badges: Logic, } type SortKey = (K, game::Id); @@ -141,6 +141,10 @@ pub mod create { pub description: Option, pub thumbnail: Option, pub author: author::Id, + #[serde(default)] + pub tags: mark::Tags, + #[serde(default)] + pub genres: mark::Genres, pub slug: Option, pub vndb: Option, pub release_date: Option, @@ -165,8 +169,8 @@ pub mod get { #[data] pub struct Marks { - pub tags: HashMap, - pub badges: HashMap, + pub tags: HashMap, + pub badges: HashMap, } #[data] diff --git a/core/src/requests/marks.rs b/core/src/requests/marks.rs index 964d58d..8bc40df 100644 --- a/core/src/requests/marks.rs +++ b/core/src/requests/marks.rs @@ -1,4 +1,4 @@ -use crate::types::game; +use crate::types::mark; use eva::{array, data, str}; @@ -18,7 +18,7 @@ pub mod add_tag { #[data] pub struct Ok { - pub id: game::Tag, + pub id: mark::Tag, } #[data(error, display("_"))] @@ -35,7 +35,7 @@ pub mod add_badge { #[data] pub struct Ok { - pub id: game::Badge, + pub id: mark::Badge, } #[data(error, display("_"))] @@ -52,7 +52,7 @@ pub mod list_genres { #[data] pub struct Ok { - pub genres: array::ImmutableHeap, + pub genres: array::ImmutableHeap, } #[data(error, display("_"))] @@ -69,7 +69,7 @@ pub mod list_badges { #[data] pub struct Ok { - pub badges: Vec>, + pub badges: Vec>, } #[data(error, display("_"))] @@ -86,7 +86,7 @@ pub mod list_tags { #[data] pub struct Ok { - pub tags: Vec>, + pub tags: Vec>, } #[data(error, display("_"))] diff --git a/core/src/types/game.rs b/core/src/types/game.rs index 4b3173b..a618a8e 100644 --- a/core/src/types/game.rs +++ b/core/src/types/game.rs @@ -1,18 +1,6 @@ use eva::{array, data, int, str, str::CompactString, time::Date}; -use crate::types::{author, entity::define_eid, file, slug, user}; - -#[data] -#[derive(Default)] -pub struct Tags(pub array::ImmutableHeap); - -#[data] -#[derive(Default)] -pub struct Genres(pub array::ImmutableHeap); - -#[data] -#[derive(Default)] -pub struct Badges(pub array::ImmutableHeap); +use crate::types::{author, entity::define_eid, file, mark, slug, user}; #[data] #[derive(Default)] @@ -100,9 +88,9 @@ pub struct Game { pub publication: Option, pub screenshots: Screenshots, - pub tags: Tags, - pub genres: Genres, - pub badges: Badges, + pub tags: mark::Tags, + pub genres: mark::Genres, + pub badges: mark::Badges, } #[data(copy)] @@ -129,17 +117,8 @@ pub struct Votes(pub u32); define_eid! { /// ID of the game. pub struct Id(Game); - - /// ID of the tag. - pub struct Tag(Tag); - - /// Game badge. - pub struct Badge(Badge); } -#[str(newtype, copy)] -pub struct Genre(pub slug::LowerSlug<15>); - /// Estimated time to read. #[int(u8, 0..=100)] pub enum TimeToReadHours {} diff --git a/core/src/types/mark.rs b/core/src/types/mark.rs new file mode 100644 index 0000000..4adf478 --- /dev/null +++ b/core/src/types/mark.rs @@ -0,0 +1,26 @@ +use eva::{array, data, str}; + +use crate::types::{entity, slug}; + +#[data] +#[derive(Default)] +pub struct Tags(pub array::ImmutableHeap); + +#[data] +#[derive(Default)] +pub struct Genres(pub array::ImmutableHeap); + +#[data] +#[derive(Default)] +pub struct Badges(pub array::ImmutableHeap); + +#[str(newtype, copy)] +pub struct Genre(pub slug::LowerSlug<15>); + +entity::define_eid! { + /// ID of the tag. + pub struct Tag(Tag); + + /// Game badge. + pub struct Badge(Badge); +} diff --git a/core/src/types/mod.rs b/core/src/types/mod.rs index a3dc5eb..414ea29 100644 --- a/core/src/types/mod.rs +++ b/core/src/types/mod.rs @@ -6,6 +6,8 @@ pub mod board; pub mod message; pub mod thread; +pub mod mark; + pub mod author; pub mod user;