Compare commits

..

2 Commits

Author SHA1 Message Date
Rob Loranger 57610d69dc
fix pre-commit filename typo 2023-10-19 17:44:01 -07:00
Rob Loranger 39868563af
add formatting doc and pre-commit 2023-10-19 17:39:57 -07:00
4 changed files with 89 additions and 312 deletions

30
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,30 @@
# Contribution Guidelines
## Code Formatting
We format all Rust code using edition 2021 rules. This edition is defined in our Cargo.toml and most methods below will pick this up automatically.
### Manual Method
The most editor agnostic way to format your Rust code is by manually running cargo's fmt sub command.
To check if your code is formatted without making changes, run `cargo fmt --check`. Then if you want to format your code you can run just `cargo fmt`.
### VScode
We recommend the meta extension Rust, which includes rust-analyzer. Then to set your editor to format on save:
* In Visual Studio Code, press Control + Shift + P or Command + Shift + P (Mac) to open the command palette and type setting and then select Preferences: Open User Settings option.
* Search for format on save setting and check the checkbox.
You can also set language specific settings as outlined [here](https://code.visualstudio.com/docs/getstarted/settings#_language-specific-editor-settings). You will again want to then search for format on save and check the checkbox.
### Other Editors
You will first need to [install rust-analyzer](https://rust-analyzer.github.io/manual.html#installation), then configure your editor and install any needed plugins or extensions as outlined on that page.
### Pre Commit Hook
If you want to think about formatting your code less and just have git yell at you whe you try to commit code that is not properly formatted, you can use a simple pre-commit hook.
After cloning the repo, the file `pre-commit` to `.git/hooks/pre-commit`. That's it.

108
MODELS.md
View File

@ -185,6 +185,7 @@ struct Track {
is_available: bool, is_available: bool,
preview_source: Option<String>, preview_source: Option<String>,
source: String, source: String,
price: Option<rusty_money::Money>,
created_by: PersonId, created_by: PersonId,
created_at: chrono::DateTime, created_at: chrono::DateTime,
modified_by: PersonId, modified_by: PersonId,
@ -217,6 +218,7 @@ struct Album {
is_available: bool, is_available: bool,
preview_source: Option<String>, preview_source: Option<String>,
source: String, source: String,
price: Option<rusty_money::Money>,
created_by: PersonId, created_by: PersonId,
created_at: chrono::DateTime, created_at: chrono::DateTime,
modified_by: PersonId, modified_by: PersonId,
@ -287,14 +289,23 @@ struct Article {
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
enum CommentTarget { enum CommentTargetType {
Label(LabelId), Label,
Artist(ArtistId), Artist,
Album(AlbumId), Album,
Track(TrackId), Track,
Playlist(PlaylistId), Playlist,
Article(ArticleId), Article,
Comment(CommentId), Comment,
}
struct CommentTargetId {
label_id: Option<LabelId>,
artist_id: Option<ArtistId>,
album_id: Option<AlbumId>,
track_id: Option<TrackId>,
playlist_id: Option<PlaylistId>,
article_id: Option<ArticleId>,
comment_id: Option<CommentId>,
} }
struct CommentId { struct CommentId {
id: String, id: String,
@ -302,7 +313,8 @@ struct CommentId {
struct Comment { struct Comment {
id: CommentId, id: CommentId,
body: String, body: String,
target: CommentTarget, target_type: CommentTargetType,
target_id: CommentTargetId,
created_by: PersonId, created_by: PersonId,
created_at: chrono::DateTime, created_at: chrono::DateTime,
modified_by: Option<PersonId>, modified_by: Option<PersonId>,
@ -372,14 +384,9 @@ struct Video {
# Collection # Collection
A Collection represents one or more Albums, Tracks, and/or OtherProducts that are offered together as a package for Purchase A Collection represents one or more Albums and/or Tracks that are offered together as a package for Purchase
``` rust ``` rust
enum CollectionItem {
Album(AlbumId),
Track(TrackId),
OtherProduct(OtherProductId),
}
struct CollectionId { struct CollectionId {
id: String, id: String,
} }
@ -395,7 +402,10 @@ struct Collection {
is_available: bool, is_available: bool,
deleted_by: Option<PersonId>, deleted_by: Option<PersonId>,
deleted_at: Option<chrono::DateTime>, deleted_at: Option<chrono::DateTime>,
collection_items: Option<Vec<CollectionMember>>, albums: Option<Vec<Album>>,
tracks: Option<Vec<Track>>,
other_products: Option<Vec<OtherProduct>>,
price: Option<rusty_money::Money>,
} }
``` ```
@ -419,20 +429,20 @@ struct OtherProduct {
is_available: bool, is_available: bool,
deleted_by: Option<PersonId>, deleted_by: Option<PersonId>,
deleted_at: Option<chrono::DateTime>, deleted_at: Option<chrono::DateTime>,
requires_shipping: bool, price: Option<rusty_money::Money>
} }
``` ```
# Purchase # Purchase
A Purchase represents one or more Tracks, Albums, Collections, and/or OtherProducts 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
enum PurchaseItemType { enum PurchaseItemType {
Album(AlbumId), Album,
Track(TrackId), Track,
Collection(CollectionId), Collection,
OtherProduct(OtherProductId), OtherProduct,
} }
struct PurchaseItemId { struct PurchaseItemId {
id: String, id: String,
@ -442,16 +452,18 @@ struct SkuId {
} }
struct Sku { struct Sku {
id: SkuId, id: SkuId,
item: PurchaseItemType, album_id: Option<AlbumId>,
track_id: Option<TrackId>,
collection_id: Option<CollectionId>,
other_product_id: Option<OtherProductId>,
variant: Option<String>, variant: Option<String>,
description: Option<String>, discount_percentage: Option<f64>,
price: rusty_money::Money, discount_flatrate: Option<rusty_money::Money>,
requires_shipping: bool,
shipping_charge: Option<rusty_money::Money>,
} }
struct LineItem { struct PurchaseItem {
id: LineItemId, id: PurchaseItemId,
sku: SkuId, type: PurchaseItemType,
sku: Option<SkuId>,
quantity: usize, quantity: usize,
} }
enum PurchaseState { enum PurchaseState {
@ -465,41 +477,9 @@ enum PurchaseState {
} }
struct Purchase { struct Purchase {
id: String, id: String,
items: Vec<LineItem>, items: Vec<PurchaseItem>,
state: PurchaseState, state: PurchaseState,
purchased_by: Option<Person>, purchased_by: Person,
purchased_at: Option<chrono::DateTime>, purchased_at: Option<chrono::DateTime>,
fulfilled_by: Option<Person>,
fulfilled_at: Option<chrono::DateTime>,
coupons_applied: Option<Vec<CouponCodeId>>,
total_charge: rusty_money::Money,
}
```
# CouponCode
A CouponCode represents a code a Person can enter to receive a discount on a PurchateItem or on a Purchase.
``` rust
struct CouponCodeId {
id: String,
}
struct CouponCode {
id: CouponCodeId,
name: String,
code: String,
uses: usize,
max_uses: usize,
expiration: Option<chrono::DateTime>,
discount_flat: Option<rusty_money::Money>,
discount_percentage: Option<f32>,
skus: Option<Vec<SkuId>>,
is_active: bool,
created_by: PersonId,
created_at: chrono::DateTime,
modified_by: PersonId,
modified_at: chrono::DateTime,
deleted_by: Option<PersonId>,
deleted_at: Option<chrono::DateTime>,
} }
``` ```

260
SCHEMA.md
View File

@ -705,262 +705,26 @@ CREATE INDEX ArticleComments_article_id_IDX ON ArticleComments (article_id);
CREATE INDEX ArticleComments_comment_id_IDX ON ArticleComments (comment_id); CREATE INDEX ArticleComments_comment_id_IDX ON ArticleComments (comment_id);
``` ```
# OtherProducts # LabelImages
The OtherProducts table will contain products for sale that are not Albums nor Tracks nor Collections.
``` sql # LabelVideos
CREATE TABLE OtherProducts (
id TEXT(36),
name TEXT,
description TEXT,
created_by TEXT(36),
created_at INTEGER,
modified_by TEXT(36),
modified_at INTEGER,
deleted_by TEXT(36),
deleted_at INTEGER,
is_public INTEGER DEFAULT (0),
is_available INTEGER DEFAULT (0),
requires_shipping INTEGER DEFAULT (0),
CONSTRAINT OtherProducts_PK PRIMARY KEY (id),
CONSTRAINT OtherProducts_FK FOREIGN KEY (created_by) REFERENCES Persons(id),
CONSTRAINT OtherProducts_FK_1 FOREIGN KEY (modified_by) REFERENCES Persons(id),
CONSTRAINT OtherProducts_FK_2 FOREIGN KEY (deleted_by) REFERENCES Persons(id)
);
CREATE INDEX OtherProducts_name_IDX ON OtherProducts (name);
CREATE INDEX OtherProducts_description_IDX ON OtherProducts (description);
CREATE INDEX OtherProducts_created_by_IDX ON OtherProducts (created_by);
CREATE INDEX OtherProducts_created_at_IDX ON OtherProducts (created_at);
CREATE INDEX OtherProducts_modified_by_IDX ON OtherProducts (modified_by);
CREATE INDEX OtherProducts_modified_at_IDX ON OtherProducts (modified_at);
CREATE INDEX OtherProducts_deleted_by_IDX ON OtherProducts (deleted_by);
CREATE INDEX OtherProducts_deleted_at_IDX ON OtherProducts (deleted_at);
CREATE INDEX OtherProducts_is_public_IDX ON OtherProducts (is_public);
CREATE INDEX OtherProducts_is_available_IDX ON OtherProducts (is_available);
CREATE INDEX OtherProducts_requires_shipping_IDX ON OtherProducts (requires_shipping);
```
# Collections # ArtistImages
The Collections table will contain Collections where each Collection is comprised of one or more Tracks, Albums, and/or OtherProducts packaged together for sale.
``` sql # ArtistVideos
CREATE TABLE Collections (
id TEXT(36),
name TEXT,
description TEXT,
created_by TEXT(36),
created_at INTEGER,
modified_by TEXT(36),
modified_at INTEGER,
deleted_by TEXT(36),
deleted_at INTEGER,
is_public INTEGER DEFAULT (0),
is_available INTEGER DEFAULT (0),
CONSTRAINT Collections_PK PRIMARY KEY (id),
CONSTRAINT Collections_FK FOREIGN KEY (created_by) REFERENCES Persons(id),
CONSTRAINT Collections_FK_1 FOREIGN KEY (modified_by) REFERENCES Persons(id),
CONSTRAINT Collections_FK_2 FOREIGN KEY (deleted_by) REFERENCES Persons(id)
);
CREATE INDEX Collections_name_IDX ON Collections (name);
CREATE INDEX Collections_description_IDX ON Collections (description);
CREATE INDEX Collections_created_by_IDX ON Collections (created_by);
CREATE INDEX Collections_created_at_IDX ON Collections (created_at);
CREATE INDEX Collections_modified_by_IDX ON Collections (modified_by);
CREATE INDEX Collections_modified_at_IDX ON Collections (modified_at);
CREATE INDEX Collections_deleted_by_IDX ON Collections (deleted_by);
CREATE INDEX Collections_deleted_at_IDX ON Collections (deleted_at);
CREATE INDEX Collections_is_public_IDX ON Collections (is_public);
CREATE INDEX Collections_is_available_IDX ON Collections (is_available);
```
# CollectionAlbums # AlbumImages
The CollectionAlbums table will relate a Collection to the Album(s) it contains.
``` sql # AlbumVideos
CREATE TABLE CollectionAlbums (
collection_id TEXT(36),
album_id TEXT(36),
CONSTRAINT CollectionAlbums_PK PRIMARY KEY (collection_id,album_id),
CONSTRAINT CollectionAlbums_FK FOREIGN KEY (collection_id) REFERENCES Collections(id) ON DELETE CASCADE,
CONSTRAINT CollectionAlbums_FK_1 FOREIGN KEY (album_id) REFERENCES Albums(id) ON DELETE CASCADE
);
CREATE INDEX CollectionAlbums_collection_id_IDX ON CollectionAlbums (collection_id);
CREATE INDEX CollectionAlbums_album_id_IDX ON CollectionAlbums (album_id);
```
# CollectionTracks # TrackImages
The CollectionTracks table will relate a Collection to the Track(s) it contains.
``` sql # TrackVideos
CREATE TABLE CollectionTracks (
collection_id TEXT(36),
track_id TEXT(36),
CONSTRAINT CollectionTracks_PK PRIMARY KEY (collection_id,track_id),
CONSTRAINT CollectionTracks_FK FOREIGN KEY (collection_id) REFERENCES Collections(id) ON DELETE CASCADE,
CONSTRAINT CollectionTracks_FK_1 FOREIGN KEY (track_id) REFERENCES Tracks(id) ON DELETE CASCADE
);
CREATE INDEX CollectionTracks_collection_id_IDX ON CollectionTracks (collection_id);
CREATE INDEX CollectionTracks_track_id_IDX ON CollectionTracks (track_id);
```
# CollectionOtherProducts # PlaylistImages
The CollectionOtherProducts table will relate a Collection to the OtherProduct(s) it contains.
``` sql # PlaylistVideos
CREATE TABLE CollectionOtherProducts (
collection_id TEXT(36),
other_product_id TEXT(36),
CONSTRAINT CollectionOtherProducts_PK PRIMARY KEY (collection_id,other_product_id),
CONSTRAINT CollectionOtherProducts_FK FOREIGN KEY (collection_id) REFERENCES Collections(id) ON DELETE CASCADE,
CONSTRAINT CollectionOtherProducts_FK_1 FOREIGN KEY (other_product_id) REFERENCES OtherProducts(id) ON DELETE CASCADE
);
CREATE INDEX CollectionOtherProducts_collection_id_IDX ON CollectionOtherProducts (collection_id);
CREATE INDEX CollectionOtherProducts_other_product_id_IDX ON CollectionOtherProducts (other_product_id);
```
# Skus # ArticleImages
The Skus table will contain SKUs () representing items available for Purchase through the server.
``` sql # ArticleVideos
CREATE TABLE Skus (
id TEXT(36),
item_type TEXT,
item_id TEXT(36),
variant TEXT,
description TEXT,
price NUMERIC DEFAULT (0.00),
requires_shipping INTEGER DEFAULT (0),
shipping_charge NUMERIC DEFAULT (0.00),
CONSTRAINT Skus_PK PRIMARY KEY (id)
);
CREATE INDEX Skus_item_type_IDX ON Skus (item_type);
CREATE INDEX Skus_item_id_IDX ON Skus (item_id);
CREATE INDEX Skus_variant_IDX ON Skus (variant);
CREATE INDEX Skus_description_IDX ON Skus (description);
CREATE INDEX Skus_price_IDX ON Skus (price);
CREATE INDEX Skus_requires_shipping_IDX ON Skus (requires_shipping);
CREATE INDEX Skus_shipping_charge_IDX ON Skus (shipping_charge);
```
# LineItems
The LineItems table will contain individual SKUs and their associated quantites as part of a Purchase.
``` sql
CREATE TABLE LineItems (
id TEXT(36),
sku_id TEXT(36),
quantity INTEGER DEFAULT (1),
CONSTRAINT LineItems_PK PRIMARY KEY (id),
CONSTRAINT LineItems_FK FOREIGN KEY (sku_id) REFERENCES Skus(id)
);
CREATE INDEX LineItems_sku_id_IDX ON LineItems (sku_id);
CREATE INDEX LineItems_quantity_IDX ON LineItems (quantity);
```
# CouponCodes
The CouponCodes table will contain coupon codes that can be redeemed for a discount, either by amount or percentage, on a Purchase.
``` sql
CREATE TABLE CouponCodes (
id TEXT(36),
name TEXT,
code TEXT,
uses INTEGER DEFAULT (0),
max_uses INTEGER DEFAULT (0),
expiration INTEGER,
discount_flat NUMERIC DEFAULT (0.00),
discount_percentage NUMERIC DEFAULT (0.00),
is_sku_specific INTEGER DEFAULT (0),
is_active INTEGER DEFAULT (0),
created_by TEXT(36),
created_at INTEGER,
modified_by TEXT(36),
modified_at INTEGER,
deleted_by TEXT(36),
deleted_at INTEGER,
CONSTRAINT CouponCodes_PK PRIMARY KEY (id),
CONSTRAINT CouponCodes_FK FOREIGN KEY (created_by) REFERENCES Persons(id),
CONSTRAINT CouponCodes_FK_1 FOREIGN KEY (modified_by) REFERENCES Persons(id),
CONSTRAINT CouponCodes_FK_2 FOREIGN KEY (deleted_by) REFERENCES Persons(id)
);
CREATE INDEX CouponCodes_name_IDX ON CouponCodes (name);
CREATE UNIQUE INDEX CouponCodes_code_IDX ON CouponCodes (code);
CREATE INDEX CouponCodes_uses_IDX ON CouponCodes (uses);
CREATE INDEX CouponCodes_max_uses_IDX ON CouponCodes (max_uses);
CREATE INDEX CouponCodes_expiration_IDX ON CouponCodes (expiration);
CREATE INDEX CouponCodes_is_sku_specific_IDX ON CouponCodes (is_sku_specific);
CREATE INDEX CouponCodes_is_active_IDX ON CouponCodes (is_active);
CREATE INDEX CouponCodes_created_by_IDX ON CouponCodes (created_by);
CREATE INDEX CouponCodes_created_at_IDX ON CouponCodes (created_at);
CREATE INDEX CouponCodes_modified_by_IDX ON CouponCodes (modified_by);
CREATE INDEX CouponCodes_modified_at_IDX ON CouponCodes (modified_at);
CREATE INDEX CouponCodes_deleted_by_IDX ON CouponCodes (deleted_by);
CREATE INDEX CouponCodes_deleted_at_IDX ON CouponCodes (deleted_at);
```
# CouponCodeSkus
The CouponCodeSkus table will relate a CouponCode to one or more Skus the CouponCode can be applied to, if CouponCode.is_sku_specific is true. (If CouponCode.is_sku_specific is false the CouponCode can be applied to an entire Purchase regardless of the Skus being purchased.)
``` sql
CREATE TABLE CouponCodeSkus (
coupon_code_id TEXT(36),
sku_id TEXT(36),
CONSTRAINT CouponCodeSkus_PK PRIMARY KEY (coupon_code_id,sku_id),
CONSTRAINT CouponCodeSkus_FK FOREIGN KEY (coupon_code_id) REFERENCES CouponCodes(id),
CONSTRAINT CouponCodeSkus_FK_1 FOREIGN KEY (sku_id) REFERENCES Skus(id)
);
```
# Purchases
The Purchases table will contain Purchases!
``` sql
CREATE TABLE Purchases (
id TEXT(36),
state TEXT,
purchased_by TEXT(36),
purchased_at INTEGER,
fulfilled_by TEXT(36),
fulfilled_at INTEGER,
total_charge NUMERIC DEFAULT (0.00),
CONSTRAINT Purchases_PK PRIMARY KEY (id),
CONSTRAINT Purchases_FK FOREIGN KEY (purchased_by) REFERENCES Persons(id),
CONSTRAINT Purchases_FK_1 FOREIGN KEY (fulfilled_by) REFERENCES Persons(id)
);
CREATE INDEX Purchases_state_IDX ON Purchases (state);
CREATE INDEX Purchases_purchased_by_IDX ON Purchases (purchased_by);
CREATE INDEX Purchases_purchased_at_IDX ON Purchases (purchased_at);
CREATE INDEX Purchases_fulfilled_by_IDX ON Purchases (fulfilled_by);
CREATE INDEX Purchases_fulfilled_at_IDX ON Purchases (fulfilled_at);
CREATE INDEX Purchases_total_charge_IDX ON Purchases (total_charge);
```
# PurchaseLineItems
The PurchaseLineItems table will relate a Purchase to one or more LineItems.
``` sql
CREATE TABLE PurchaseLineItems (
purchase_id TEXT(36),
line_item_id TEXT(36),
CONSTRAINT PurchaseLineItems_PK PRIMARY KEY (purchase_id,line_item_id),
CONSTRAINT PurchaseLineItems_FK FOREIGN KEY (purchase_id) REFERENCES Purchases(id),
CONSTRAINT PurchaseLineItems_FK_1 FOREIGN KEY (line_item_id) REFERENCES LineItems(id) ON DELETE CASCADE
);
CREATE INDEX PurchaseLineItems_purchase_id_IDX ON PurchaseLineItems (purchase_id);
CREATE INDEX PurchaseLineItems_line_item_id_IDX ON PurchaseLineItems (line_item_id);
```
# PurchaseCouponCodes
The PurchaseCouponCodes table will relate a Purchase to one or more CouponCodes that were successfully applied to the Purchase.
``` sql
CREATE TABLE PurchaseCouponCodes (
purchase_id TEXT(36),
coupon_code_id TEXT(36),
CONSTRAINT PurchaseCouponCodes_PK PRIMARY KEY (purchase_id,coupon_code_id),
CONSTRAINT PurchaseCouponCodes_FK FOREIGN KEY (purchase_id) REFERENCES Purchases(id),
CONSTRAINT PurchaseCouponCodes_FK_1 FOREIGN KEY (coupon_code_id) REFERENCES CouponCodes(id)
);
CREATE INDEX PurchaseCouponCodes_purchase_id_IDX ON PurchaseCouponCodes (purchase_id);
CREATE INDEX PurchaseCouponCodes_coupon_code_id_IDX ON PurchaseCouponCodes (coupon_code_id);
```

3
pre-commit Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
cargo fmt --check