updates models, makes them more accurate and rusty

This commit is contained in:
cascode _ 2023-10-18 10:25:54 -04:00 committed by cascode
parent 8c6998085e
commit 25dc8413dd
1 changed files with 150 additions and 32 deletions

182
MODELS.md
View File

@ -12,10 +12,22 @@ Representations in this document are in application context; for database struct
A Person represents a person! Specifically, a Person is a person who is using/has used the web application. Many applications call this entity a "User". We call them a Person. A Person represents a person! Specifically, a Person is a person who is using/has used the web application. Many applications call this entity a "User". We call them a Person.
``` rust ``` rust
struct Person { struct PersonId {
id: String, id: String,
}
struct Person {
id: PersonId,
remote_id: String, remote_id: String,
name: String, name: String,
handle: Option<String>,
email: Option<Vec<String>>,
is_active: bool,
created_at: chrono::DateTime,
modified_at: chrono::DateTime,
modified_by: PersonId,
deleted_at: Option<chrono::DateTime>,
deleted_by: Option<PersonId>,
last_seen: chrono::DateTime,
} }
``` ```
@ -24,8 +36,12 @@ struct Person {
A Tag is a classification label that a Person wants to associate to a Label, an Artist, an Album, a Track, or a Playlist, used as a way of grouping entities together via some commonality the context of which is not programmatically relevant. A Tag is a classification label that a Person wants to associate to a Label, an Artist, an Album, a Track, or a Playlist, used as a way of grouping entities together via some commonality the context of which is not programmatically relevant.
``` rust ``` rust
struct Tag { struct TagId {
host: String,
id: String, id: String,
}
struct Tag {
id: TagId,
name: String, name: String,
} }
``` ```
@ -35,14 +51,17 @@ struct Tag {
A Label represents a record label (a group of people who handle promotion and/or distribution for one or more Artists). A Label represents a record label (a group of people who handle promotion and/or distribution for one or more Artists).
``` rust ``` rust
struct Label { struct LabelId {
id: String, id: String,
}
struct Label {
id: LabelId,
name: String, name: String,
description: String, description: String,
website: String, website: String,
artists: HashMap<Artist>, artists: HashMap<Artist>,
tags: HashMap<Tag>, tags: Option<Vec<Tag>>,
comments: HashMap<Comment>, comments: Option<Vec<Comment>>,
} }
``` ```
@ -51,13 +70,16 @@ struct Label {
An Artist represents a musical artist. An Artist represents a musical artist.
``` rust ``` rust
struct Artist { struct ArtistId {
id: String, id: String,
}
struct Artist {
id: ArtistId,
name: String, name: String,
bio: String, bio: String,
website: String, website: String,
tags: HashMap<Tag>, tags: Option<Vec<Tag>>,
comments: HashMap<Comment>, comments: Option<Vec<Comment>>,
} }
``` ```
@ -66,23 +88,30 @@ struct Artist {
A Track represents a single piece of work by an Artist that is contained in an audio file. A Track represents a single piece of work by an Artist that is contained in an audio file.
``` rust ``` rust
struct Track { struct TrackId {
id: String, id: String,
}
struct Track {
id: TrackId,
title: String, title: String,
description: String, description: String,
duration: chrono::Duration, duration: chrono::Duration,
artists: HashMap<Artist>, artists: HashMap<Artist>,
created_by: String, is_public: bool,
preview_source: Option<String>,
source: String,
price: Option<rusty_money::Money>,
created_by: PersonId,
created_at: chrono::DateTime, created_at: chrono::DateTime,
modified_by: String, modified_by: PersonId,
modified_at: chrono::DateTime, modified_at: chrono::DateTime,
deleted_by: Option<String>, deleted_by: Option<PersonId>,
deleted_at: Option<chrono::DateTime>, deleted_at: Option<chrono::DateTime>,
tags: HashMap<Tag>, tags: Option<Vec<Tag>>,
comments: HashMap<Comment>, comments: Option<Vec<Comment>>,
lyrics: String, lyrics: Option<String>,
cover: String, cover: Option<String>,
images: HashMap<String>, images: Option<Vec<String>>,
} }
``` ```
@ -91,22 +120,29 @@ struct Track {
An Album represents a work by an Artist that contains one or more Tracks. An Album represents a work by an Artist that contains one or more Tracks.
``` rust ``` rust
struct Album { struct AlbumId {
id: String, id: String,
}
struct Album {
id: AlbumId,
title: String, title: String,
description: String, description: String,
artists: HashMap<Artist>, artists: HashMap<Artist>,
tracks: HashMap<Track>, tracks: HashMap<Track>,
created_by: String, is_public: bool,
preview_source: Option<String>,
source: String,
price: Option<rusty_money::Money>,
created_by: PersonId,
created_at: chrono::DateTime, created_at: chrono::DateTime,
modified_by: String, modified_by: PersonId,
modified_at: chrono::DateTime, modified_at: chrono::DateTime,
deleted_by: Option<String>, deleted_by: Option<PersonId>,
deleted_at: Option<chrono::DateTime>, deleted_at: Option<chrono::DateTime>,
tags: HashMap<Tag>, tags: Option<Vec<Tag>>,
comments: HashMap<Comment>, comments: Option<Vec<Comment>>,
cover: String, cover: Option<String>,
images: HashMap<String>, images: Option<Vec<String>>,
} }
``` ```
@ -115,8 +151,11 @@ struct Album {
A Playlist represents an ordered collection of Tracks assembled by a Person. A Playlist represents an ordered collection of Tracks assembled by a Person.
``` rust ``` rust
struct Playlist { struct PlaylistId {
id: String, id: String,
}
struct Playlist {
id: PlaylistId,
title: String, title: String,
description: String, description: String,
created_by: String, created_by: String,
@ -124,10 +163,36 @@ struct Playlist {
modified_at: chrono::DateTime, modified_at: chrono::DateTime,
deleted_at: Option<chrono::DateTime> deleted_at: Option<chrono::DateTime>
is_public: bool, is_public: bool,
cover: String, cover: Option<String>,
tracks: HashMap<Track>, tracks: Vec<Track>,
tags: HashMap<Tag>, tags: Option<Vec<Tag>>,
comments: HashMap<Comment>, comments: Option<Vec<Comment>>,
}
```
# Article
An Article represents a "blog post" style article written by a Person.
``` rust
struct ArticleId {
id: String,
}
struct Article {
id: ArticleId,
title: String,
body: String,
description: Option<String>,
created_by: PersonId,
created_at: chrono::DateTime,
modified_at: chrono::DateTime,
deleted_at: Option<chrono::DateTime>
is_public: bool,
cover: Option<String>,
images: Option<Vec<String>>,
tracks: Option<Vec<Track>>,
tags: Option<Vec<Tag>>,
comments: Option<Vec<Comment>>,
} }
``` ```
@ -136,9 +201,35 @@ struct Playlist {
A Comment represents a textual comment that a Person wants to attach contextually to an Artist, an Album, a Track, or a Playlist. A Comment represents a textual comment that a Person wants to attach contextually to an Artist, an Album, a Track, or a Playlist.
``` rust ``` rust
struct Comment { enum CommentTargetType {
Label,
Artist,
Album,
Track,
Playlist,
Comment,
}
struct CommentTargetId {
label_id: Option<LabelId>,
artist_id: Option<ArtistId>,
album_id: Option<AlbumId>,
track_id: Option<TrackId>,
playlist_id: Option<PlaylistId>,
comment_id: Option<CommentId>,
}
struct CommentId {
id: String, id: String,
}
struct Comment {
id: CommentId,
body: String, body: String,
target_type: CommentTargetType,
target_id: CommentTargetId,
created_by: PersonId,
created_at: chrono::DateTime,
modified_at: chrono::DateTime,
deleted_at: Option<chrono::DateTime>
is_public: bool,
} }
``` ```
@ -147,7 +238,34 @@ struct Comment {
A Purchase represents one or more Tracks or Albums that a Person purchases from an Artist or Label through the server. A Purchase represents one or more Tracks or Albums that a Person purchases from an Artist or Label through the server.
``` rust ``` rust
struct Purchase { enum PurchaseItemType {
Album,
Track,
Collection,
OtherProduct,
}
struct PurchaseItemId {
id: String, id: String,
} }
struct SkuId {
id: String,
}
struct Sku {
id: SkuId,
album_id: Option<AlbumId>,
track_id: Option<TrackId>,
collection_id: Option<CollectionId>,
other_product_id: Option<OtherProductId>,
}
struct PurchaseItem {
id: PurchaseItemId,
type: PurchaseItemType,
sku: SkuId,
quantity: usize,
discount_percentage: usize,
}
struct Purchase {
id: String,
}
``` ```