1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use serde::{Deserialize, Serialize};
use uuid::Uuid;
pub mod campaign;
pub mod location;
pub mod map;
pub mod npc;
#[cfg_attr(feature = "diesel", derive(Queryable, Insertable))]
#[cfg_attr(feature = "diesel", diesel(table_name = "worlds"))]
#[derive(Serialize, Deserialize, Debug)]
pub struct World {
pub id: String,
pub name: String,
pub description: String,
}
impl World {
pub fn new(name: String, description: String) -> Self {
Self {
id: Uuid::new_v4().to_string(),
name,
description,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct WorldRequest {
pub name: Option<String>,
pub description: Option<String>,
}
impl WorldRequest {
pub fn to_world(&self) -> Option<World> {
match &self.name {
Some(name) => Some(World::new(
name.to_string(),
self.description.clone().expect("no description provided"),
)),
None => None,
}
}
}