feat: initial API and docs
This commit is contained in:
parent
79be4eb543
commit
5d709d658b
16 changed files with 3169 additions and 342 deletions
38
src/entities/book.rs
Normal file
38
src/entities/book.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, utoipa::ToSchema)]
|
||||
#[sea_orm(table_name = "Book")]
|
||||
#[schema(title="Book", as=entities::Book)]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = true)]
|
||||
pub id: u32,
|
||||
pub ean: String,
|
||||
pub title: String,
|
||||
pub author: String
|
||||
}
|
||||
|
||||
impl Default for Model {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
id: 0,
|
||||
ean: "".to_string(),
|
||||
title: "".to_string(),
|
||||
author: "".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::book_instance::Entity")]
|
||||
BookInstance,
|
||||
}
|
||||
|
||||
impl Related<super::book_instance::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::BookInstance.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
57
src/entities/book_instance.rs
Normal file
57
src/entities/book_instance.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, utoipa::ToSchema)]
|
||||
#[sea_orm(table_name = "BookInstances")]
|
||||
#[schema(title="BookInstance", as=entities::BookInstance)]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = true)]
|
||||
pub id: u32,
|
||||
pub price: i32,
|
||||
pub sold_price: Option<i32>,
|
||||
pub status: BookStatus,
|
||||
pub book_id: u32,
|
||||
pub owner_id: u32
|
||||
}
|
||||
// Missing: Bal
|
||||
|
||||
#[derive(EnumIter, DeriveActiveEnum, PartialEq, Eq ,Deserialize, Serialize, Clone, Copy, Debug, utoipa::ToSchema)]
|
||||
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(1))")]
|
||||
pub enum BookStatus {
|
||||
#[sea_orm(string_value = "A")]
|
||||
Available,
|
||||
#[sea_orm(string_value = "S")]
|
||||
Sold,
|
||||
#[sea_orm(string_value = "D")]
|
||||
Damaged
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::book::Entity",
|
||||
from = "Column::BookId",
|
||||
to = "super::book::Column::Id"
|
||||
)]
|
||||
Book,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::owner::Entity",
|
||||
from = "Column::OwnerId",
|
||||
to = "super::owner::Column::Id"
|
||||
)]
|
||||
Owner,
|
||||
}
|
||||
|
||||
impl Related<super::book::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Book.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::owner::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Owner.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
6
src/entities/mod.rs
Normal file
6
src/entities/mod.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
pub mod prelude;
|
||||
|
||||
pub mod book;
|
||||
pub mod book_instance;
|
||||
pub mod owner;
|
||||
|
||||
27
src/entities/owner.rs
Normal file
27
src/entities/owner.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
#[sea_orm(table_name = "Owners")]
|
||||
#[schema(title="Owner", as=entities::Owner)]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = true)]
|
||||
pub id: u32,
|
||||
pub first_name: String,
|
||||
pub last_name: String,
|
||||
pub contact: String
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::book_instance::Entity")]
|
||||
BookInstance
|
||||
}
|
||||
|
||||
impl Related<super::book_instance::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::BookInstance.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
4
src/entities/prelude.rs
Normal file
4
src/entities/prelude.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
pub use super::book::Entity as Book;
|
||||
pub use super::book_instance::Entity as BookInstance;
|
||||
pub use super::owner::Entity as Owner;
|
||||
Reference in a new issue