This commit is contained in:
Benjamin Sherriff
2023-10-05 09:07:53 -04:00
parent ac17be838a
commit 1b41849115
54 changed files with 6473 additions and 129 deletions

View File

@@ -1,5 +1,4 @@
RUST_LOG=warn,service=info
COMPOSE_PROJECT_NAME=siren
DATABASE_USER=siren
DATABASE_PASSWORD=

View File

@@ -1 +1 @@
SIREN_VERSION=0.2.4
SIREN_VERSION=0.2.5

View File

@@ -1,6 +1,6 @@
[package]
name = "service"
version = "0.2.4"
version = "0.2.5"
edition = "2021"
authors = ["Ben Sherriff <hello@bensherriff.com>"]
repository = "https://github.com/bensherriff/siren"
@@ -14,6 +14,7 @@ path = "src/lib.rs"
[dependencies]
actix-web = "4.4.0"
actix-rt = "2.9.0"
actix-cors = "0.6.4"
actix-web-httpauth = "0.8.1"
chrono = { version = "0.4.31", features = ["serde"] }
dotenv = "0.15.0"

View File

@@ -5,12 +5,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 60,
"value": 60,
"unit": "feet"
},
"saving_throw": [
@@ -48,7 +48,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
@@ -67,7 +67,7 @@
"durations": [
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "round"
}
],
@@ -87,7 +87,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
@@ -95,7 +95,7 @@
},
"area": {
"type": "sphere",
"amount": 5,
"value": 5,
"unit": "feet"
},
"damage_inflict": [
@@ -111,7 +111,7 @@
"durations": [
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "round"
}
],
@@ -133,12 +133,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 120,
"value": 120,
"unit": "feet"
},
"damage_inflict": [
@@ -153,7 +153,7 @@
"durations": [
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "round"
}
],
@@ -176,17 +176,17 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 60,
"value": 60,
"unit": "feet"
},
"area": {
"type": "cube",
"amount": 5,
"value": 5,
"unit": "feet"
},
"components": {
@@ -200,7 +200,7 @@
},
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "hour"
}
],
@@ -231,17 +231,17 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 60,
"value": 60,
"unit": "feet"
},
"area": {
"type": "cube",
"amount": 5,
"value": 5,
"unit": "feet"
},
"components": {
@@ -252,7 +252,7 @@
"durations": [
{
"type": "concentration",
"amount": 1,
"value": 1,
"unit": "minutes"
}
],
@@ -275,12 +275,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 120,
"value": 120,
"unit": "feet"
},
"components": {
@@ -292,7 +292,7 @@
"durations": [
{
"type": "concentration",
"amount": 1,
"value": 1,
"unit": "minutes"
}
],
@@ -303,7 +303,7 @@
],
"description": {
"entries": [
"You create up to four torch-amountd lights within range, making them appear as torches, lanterns, or glowing orbs that hover in the air for the duration. You can also combine the four lights into one glowing vaguely humanoid form of Medium amount. Whichever form you choose, each light sheds dim light in a 10-foot radius.",
"You create up to four torch-valued lights within range, making them appear as torches, lanterns, or glowing orbs that hover in the air for the duration. You can also combine the four lights into one glowing vaguely humanoid form of Medium value. Whichever form you choose, each light sheds dim light in a 10-foot radius.",
"As a bonus action on your turn, you can move the lights up to 60 feet to a new spot within range. A light must be within 20 feet of another light created by this spell, and a light winks out if it exceeds the spell's range."
]
}
@@ -314,12 +314,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 30,
"value": 30,
"unit": "feet"
},
"components": {
@@ -358,12 +358,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 120,
"value": 120,
"unit": "feet"
},
"damage_inflict": [
@@ -398,7 +398,7 @@
"level": 0,
"ritual": true,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
@@ -412,7 +412,7 @@
"durations": [
{
"type": "timed",
"amount": 8,
"value": 8,
"unit": "hours"
}
],
@@ -434,12 +434,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 120,
"value": 120,
"unit": "feet"
},
"damage_inflict": [
@@ -474,7 +474,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
@@ -484,12 +484,12 @@
"verbal": false,
"somatic": true,
"material": true,
"materials_needed": "a small amount of makeup applied to the face as this spell is cast"
"materials_needed": "a small value of makeup applied to the face as this spell is cast"
},
"durations": [
{
"type": "concentration",
"amount": 1,
"value": 1,
"unit": "minutes"
}
],
@@ -510,12 +510,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 60,
"value": 60,
"unit": "feet"
},
"saving_throw": [
@@ -552,7 +552,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
@@ -560,7 +560,7 @@
},
"area": {
"type": "sphere",
"amount": 5,
"value": 5,
"unit": "feet"
},
"damage_inflict": [
@@ -596,7 +596,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
@@ -610,7 +610,7 @@
"durations": [
{
"type": "concentration",
"amount": 1,
"value": 1,
"unit": "minutes"
}
],
@@ -631,12 +631,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 30,
"value": 30,
"unit": "feet"
},
"components": {
@@ -674,12 +674,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 30,
"value": 30,
"unit": "feet"
},
"saving_throw": [
@@ -716,7 +716,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
@@ -724,7 +724,7 @@
},
"area": {
"type": "sphere",
"amount": 20,
"value": 20,
"unit": "feet"
},
"saving_throw": [
@@ -739,7 +739,7 @@
"durations": [
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "hour"
}
],
@@ -761,12 +761,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "self",
"amount": 15,
"value": 15,
"unit": "feet"
},
"saving_throw": [
@@ -803,12 +803,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 30,
"value": 30,
"unit": "feet"
},
"components": {
@@ -819,7 +819,7 @@
"durations": [
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "minutes"
}
],
@@ -842,7 +842,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "bonus"
},
"range": {
@@ -860,7 +860,7 @@
"durations": [
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "minutes"
}
],
@@ -881,7 +881,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "minutes"
},
"range": {
@@ -916,12 +916,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 120,
"value": 120,
"unit": "feet"
},
"components": {
@@ -933,7 +933,7 @@
"durations": [
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "round"
}
],
@@ -955,12 +955,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 60,
"value": 60,
"unit": "feet"
},
"saving_throw": [
@@ -996,12 +996,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 30,
"value": 30,
"unit": "feet"
},
"components": {
@@ -1013,7 +1013,7 @@
"durations": [
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "minutes"
}
],
@@ -1037,17 +1037,17 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 30,
"value": 30,
"unit": "feet"
},
"area": {
"type": "cube",
"amount": 5,
"value": 5,
"unit": "feet"
},
"components": {
@@ -1061,7 +1061,7 @@
},
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "hour"
}
],
@@ -1090,12 +1090,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 10,
"value": 10,
"unit": "feet"
},
"saving_throw": [
@@ -1134,11 +1134,11 @@
"ritual": false,
"casting_time": {
"unit": "action",
"amount": 1
"value": 1
},
"range": {
"type": "point",
"amount": 10,
"value": 10,
"unit": "feet"
},
"components": {
@@ -1149,7 +1149,7 @@
"durations": [
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "hour"
}
],
@@ -1183,7 +1183,7 @@
"ritual": false,
"casting_time": {
"unit": "action",
"amount": 1
"value": 1
},
"range": {
"type": "self"
@@ -1220,7 +1220,7 @@
"ritual": false,
"casting_time": {
"unit": "action",
"amount": 1
"value": 1
},
"range": {
"type": "self"
@@ -1237,7 +1237,7 @@
"durations": [
{
"type": "timed",
"amount": 10,
"value": 10,
"unit": "minutes"
}
],
@@ -1261,11 +1261,11 @@
"ritual": false,
"casting_time": {
"unit": "action",
"amount": 1
"value": 1
},
"range": {
"type": "point",
"amount": 60,
"value": 60,
"unit": "feet"
},
"damage_inflict": [
@@ -1301,7 +1301,7 @@
"ritual": false,
"casting_time": {
"unit": "action",
"amount": 1
"value": 1
},
"range": {
"type": "touch"
@@ -1315,7 +1315,7 @@
"durations": [
{
"type": "concentration",
"amount": 1,
"value": 1,
"unit": "round"
}
],
@@ -1336,12 +1336,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 60,
"value": 60,
"unit": "feet"
},
"saving_throw": [
@@ -1378,7 +1378,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"damage_inflict": [
@@ -1389,7 +1389,7 @@
],
"range": {
"type": "point",
"amount": 30,
"value": 30,
"unit": "feet"
},
"components": {
@@ -1419,17 +1419,17 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 30,
"value": 30,
"unit": "feet"
},
"area": {
"type": "cube",
"amount": 5,
"value": 5,
"unit": "feet"
},
"components": {
@@ -1443,7 +1443,7 @@
},
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "hour"
}
],
@@ -1473,7 +1473,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "bonus"
},
"range": {
@@ -1492,7 +1492,7 @@
"durations": [
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "minutes"
}
],
@@ -1513,7 +1513,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"damage_inflict": [
@@ -1551,7 +1551,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
@@ -1584,7 +1584,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"damage_inflict": [
@@ -1595,7 +1595,7 @@
],
"range": {
"type": "self",
"amount": 5,
"value": 5,
"unit": "feet"
},
"components": {
@@ -1625,12 +1625,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 30,
"value": 30,
"unit": "feet"
},
"components": {
@@ -1641,7 +1641,7 @@
"durations": [
{
"type": "timed",
"amount": 1,
"value": 1,
"unit": "minutes"
}
],
@@ -1674,7 +1674,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"damage_inflict": [
@@ -1683,7 +1683,7 @@
"attack_type": "melee",
"range": {
"type": "point",
"amount": 30,
"value": 30,
"unit": "feet"
},
"components": {
@@ -1715,7 +1715,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"damage_inflict": [
@@ -1726,7 +1726,7 @@
],
"range": {
"type": "point",
"amount": 5,
"value": 5,
"unit": "feet"
},
"components": {
@@ -1756,7 +1756,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"damage_inflict": [
@@ -1767,7 +1767,7 @@
],
"range": {
"type": "point",
"amount": 60,
"value": 60,
"unit": "feet"
},
"components": {
@@ -1797,12 +1797,12 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"range": {
"type": "point",
"amount": 30,
"value": 30,
"unit": "feet"
},
"components": {
@@ -1813,7 +1813,7 @@
"durations": [
{
"type": "concentration",
"amount": 1,
"value": 1,
"unit": "round"
}
],
@@ -1834,7 +1834,7 @@
"level": 0,
"ritual": false,
"casting_time": {
"amount": 1,
"value": 1,
"unit": "action"
},
"damage_inflict": [
@@ -1845,7 +1845,7 @@
],
"range": {
"type": "point",
"amount": 60,
"value": 60,
"unit": "feet"
},
"components": {
@@ -1877,7 +1877,7 @@
"ritual": false,
"casting_time": {
"unit": "action",
"amount": 1
"value": 1
},
"damage_inflict": [
"radiant"
@@ -1887,7 +1887,7 @@
],
"range": {
"type": "point",
"amount": 5,
"value": 5,
"unit": "feet"
},
"components": {

View File

@@ -1,5 +1,6 @@
version: '3.8'
name: siren
services:
service:
image: siren-service:${SIREN_VERSION:-latest}
@@ -14,7 +15,7 @@ services:
environment:
DATABASE_HOST: db
DATABASE_PORT: 5432
SERVICE_HOST: siren
SERVICE_HOST: service
SERVICE_PORT: 5000
ports:
- ${SERVICE_PORT:-5000}:5000

View File

@@ -6,7 +6,7 @@ use crate::db::{schema::spells::{self}, classes::AbilityType, conditions::Condit
use super::{SchoolType, CastingTime, CastingType, SpellAttackType, SpellDamageType, Range, Area, Components, Duration, Source, Description, DurationType};
#[derive(Queryable, QueryableByName)]
#[derive(Queryable, QueryableByName, Serialize, Deserialize)]
#[diesel(table_name = spells)]
pub struct QuerySpell {
pub id: i32,
@@ -191,6 +191,7 @@ impl InsertSpell {
#[derive(Debug, Serialize, Deserialize)]
pub struct Spell {
pub id: Option<i32>,
pub name: String,
pub school: SchoolType,
pub level: i32,
@@ -226,17 +227,18 @@ impl From<QuerySpell> for Spell {
Err(err) => {
log::error!("Failed to parse spell: {}", err);
Self {
id: None,
name: "".to_string(),
school: SchoolType::Abjuration,
level: 0,
ritual: false,
casting_time: CastingTime { amount: 0, casting_type: CastingType::Action },
casting_time: CastingTime { value: 0, casting_type: CastingType::Action },
saving_throw: None,
attack_type: None,
damage_inflict: None,
damage_resist: None,
conditions: None,
range: Range { range_type: "".to_string(), amount: None, unit: None },
range: Range { range_type: "".to_string(), value: None, unit: None },
area: None,
components: Components { verbal: false, somatic: false, material: false, materials_needed: None, materials_cost: None, materials_consumed: None },
durations: vec![],

View File

@@ -73,7 +73,7 @@ async fn get_all(req: HttpRequest) -> HttpResponse {
None => None
};
// Limit must be between 1 and 100
let limit = std::cmp::min(std::cmp::max(params.limit.unwrap_or(20), 1), 100);
let limit = std::cmp::min(std::cmp::max(params.limit.unwrap_or(100), 1), 100);
let total_count = QuerySpell::get_count(&filters).unwrap();
let max_page = std::cmp::max((total_count as f64 / limit as f64).ceil() as i32, 1);
// Page must be between 1 and max_page
@@ -82,8 +82,11 @@ async fn get_all(req: HttpRequest) -> HttpResponse {
match web::block(move || QuerySpell::get_all(&filters, limit, page)).await.unwrap() {
Ok(spells) => {
let mut response: Vec<Spell> = Vec::new();
for spell in spells {
response.push(Spell::from(spell));
for query_spell in spells {
let id = query_spell.id;
let mut spell = Spell::from(query_spell);
spell.id = Some(id);
response.push(spell);
}
HttpResponse::Ok().json(GetResponse {
data: response,
@@ -112,10 +115,15 @@ async fn get_by_id(id: web::Path<String>) -> HttpResponse {
})
};
match web::block(move || QuerySpell::get_by_id(id)).await.unwrap() {
Ok(spell) => HttpResponse::Ok().json(GetResponse {
data: Spell::from(spell),
metadata: None
}),
Ok(query_spell) => {
let id = query_spell.id;
let mut spell = Spell::from(query_spell);
spell.id = Some(id);
HttpResponse::Ok().json(GetResponse {
data: spell,
metadata: None
})
},
Err(err) => {
error!("{:?}", err.message);
ResponseError::error_response(&err)

View File

@@ -56,7 +56,7 @@ impl FromStr for SchoolType {
#[derive(Debug, Serialize, Deserialize)]
pub struct CastingTime {
pub amount: i32,
pub value: i32,
#[serde(rename = "unit")]
pub casting_type: CastingType
}
@@ -209,7 +209,7 @@ pub struct Range {
#[serde(rename = "type")]
pub range_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub amount: Option<i32>,
pub value: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub unit: Option<String>
}
@@ -219,7 +219,7 @@ pub struct Area {
#[serde(rename = "type")]
pub area_type: AreaType,
#[serde(skip_serializing_if = "Option::is_none")]
pub amount: Option<i32>,
pub value: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub unit: Option<String>
}
@@ -270,7 +270,7 @@ pub struct Duration {
#[serde(rename = "type")]
pub duration_type: DurationType,
#[serde(skip_serializing_if = "Option::is_none")]
pub amount: Option<i32>,
pub value: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub unit: Option<String>
}

View File

@@ -4,6 +4,7 @@ extern crate diesel_migrations;
use std::env;
use actix_cors::Cors;
use actix_web::{HttpServer, App};
use dotenv::dotenv;
@@ -22,9 +23,15 @@ async fn main() -> std::io::Result<()> {
let port = env::var("SERVICE_PORT").unwrap_or("5000".to_string());
match HttpServer::new(|| {
let cors = Cors::default()
.allow_any_origin()
.allow_any_method()
.allow_any_header()
.max_age(3600);
App::new()
.configure(db::messages::init_routes)
.configure(db::spells::init_routes)
.wrap(cors)
})
.bind(format!("{}:{}", host, port)) {
Ok(b) => {