Skip to content

Commit a652f1a

Browse files
committed
docker setup
1 parent 8acb88c commit a652f1a

File tree

6 files changed

+216
-1
lines changed

6 files changed

+216
-1
lines changed

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Use a Rust base image
2+
FROM rust:latest
3+
4+
# Set the working directory inside the container
5+
WORKDIR /usr/src/palworld-api
6+
7+
# Copy the dependency manifest
8+
COPY Cargo.toml Cargo.lock ./
9+
COPY . .
10+
COPY .env .
11+
12+
# Build the application
13+
RUN cargo build --release
14+
15+
# Specify the command to run your application
16+
CMD ["target/release/palworld-api"]

README.Docker.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### Building and running your application
2+
3+
When you're ready, start your application by running:
4+
`docker compose up --build`.
5+
6+
Your application will be available at http://localhost:3000.
7+
8+
### Deploying your application to the cloud
9+
10+
First, build your image, e.g.: `docker build -t myapp .`.
11+
If your cloud uses a different CPU architecture than your development
12+
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
13+
you'll want to build the image for that platform, e.g.:
14+
`docker build --platform=linux/amd64 -t myapp .`.
15+
16+
Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.
17+
18+
Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/)
19+
docs for more detail on building and pushing.
20+
21+
### References
22+
* [Docker's Rust guide](https://docs.docker.com/language/rust/)

doc/created.rid

Whitespace-only changes.

src/exceptions.rs

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
use std::collections::HashMap;
2+
3+
pub struct ExceptionMap {
4+
exceptions: HashMap<(String, String), String>,
5+
}
6+
impl ExceptionMap {
7+
pub fn new() -> Self {
8+
let mut exceptions: HashMap<(String, String), String> = HashMap::new();
9+
exceptions.insert(
10+
("Relaxaurus".to_string(), "Sparkit".to_string()),
11+
"Relaxaurus Lux".to_string(),
12+
);
13+
exceptions.insert(
14+
("Incineram".to_string(), "Maraith".to_string()),
15+
"Incineram Noct".to_string(),
16+
);
17+
exceptions.insert(
18+
("Mau".to_string(), "Pengullet".to_string()),
19+
"Mau Cryst".to_string(),
20+
);
21+
exceptions.insert(
22+
("Vanwyrm".to_string(), "Foxcicle".to_string()),
23+
"Vanwyrm Cryst".to_string(),
24+
);
25+
exceptions.insert(
26+
("Eikthyrdeer".to_string(), "Hangyu".to_string()),
27+
"Eikthyrdeer Terra".to_string(),
28+
);
29+
exceptions.insert(
30+
("Ephidran".to_string(), "Surfent".to_string()),
31+
"Elphidran Aqua".to_string(),
32+
);
33+
exceptions.insert(
34+
("Pyrin".to_string(), "Katress".to_string()),
35+
"Pyrin Noct".to_string(),
36+
);
37+
exceptions.insert(
38+
("Mammorest".to_string(), "Wumpo".to_string()),
39+
"Mammorest Cryst".to_string(),
40+
);
41+
exceptions.insert(
42+
("Mossanda".to_string(), "Grizzbolt".to_string()),
43+
"Mossanda Lux".to_string(),
44+
);
45+
exceptions.insert(
46+
("Dinossum".to_string(), "Rayhound".to_string()),
47+
"Dinossom Lux".to_string(),
48+
);
49+
exceptions.insert(
50+
("Jolthog".to_string(), "Pengullet".to_string()),
51+
"Jolthog Cryst".to_string(),
52+
);
53+
exceptions.insert(
54+
("Frostallion".to_string(), "Helzephyr".to_string()),
55+
"Frostallion Noct".to_string(),
56+
);
57+
exceptions.insert(
58+
("Kingpaca".to_string(), "Reindrix".to_string()),
59+
"Ice Kingpaca".to_string(),
60+
);
61+
exceptions.insert(
62+
("Lyleen".to_string(), "Menasting".to_string()),
63+
"Lyleen Noct".to_string(),
64+
);
65+
exceptions.insert(
66+
("Leezpunk".to_string(), "Flambelle".to_string()),
67+
"Leezpunk Ignis".to_string(),
68+
);
69+
exceptions.insert(
70+
("Blazehowl".to_string(), "Felbat".to_string()),
71+
"Blazehowl Noct".to_string(),
72+
);
73+
exceptions.insert(
74+
("Robinquill".to_string(), "Fuddler".to_string()),
75+
"Robinquill Terra".to_string(),
76+
);
77+
exceptions.insert(
78+
("Broncherry".to_string(), "Fuack".to_string()),
79+
"Broncherry Aqua".to_string(),
80+
);
81+
exceptions.insert(
82+
("Surfent".to_string(), "Dumud".to_string()),
83+
"Surfent Terra".to_string(),
84+
);
85+
exceptions.insert(
86+
("Gobfin".to_string(), "Rooby".to_string()),
87+
"Gobfin Ignus".to_string(),
88+
);
89+
exceptions.insert(
90+
("Suzaku".to_string(), "Jormuntide".to_string()),
91+
"Suzaku Aqua".to_string(),
92+
);
93+
exceptions.insert(
94+
("Reptyro".to_string(), "Foxcicle".to_string()),
95+
"Ice Reptyro".to_string(),
96+
);
97+
exceptions.insert(
98+
("Hangyu".to_string(), "Swee".to_string()),
99+
"Hangyu Cryst".to_string(),
100+
);
101+
exceptions.insert(
102+
("Mossanda".to_string(), "Petallia".to_string()),
103+
"Lyleen".to_string(),
104+
);
105+
exceptions.insert(
106+
("Vanwyrm".to_string(), "Anubis".to_string()),
107+
"Faleris".to_string(),
108+
);
109+
exceptions.insert(
110+
("Mossanda".to_string(), "Rayhound".to_string()),
111+
"Grizzbolt".to_string(),
112+
);
113+
exceptions.insert(
114+
("Grizzbolt".to_string(), "Relaxaurus".to_string()),
115+
"Oserk".to_string(),
116+
);
117+
exceptions.insert(
118+
("Kitsun".to_string(), "Astegon".to_string()),
119+
"Shadowbeak".to_string(),
120+
);
121+
exceptions.insert(
122+
("Frostallion".to_string(), "Frostallion".to_string()),
123+
"Frostallion".to_string(),
124+
);
125+
exceptions.insert(
126+
("Jetragon".to_string(), "Jetragon".to_string()),
127+
"Jetragon".to_string(),
128+
);
129+
exceptions.insert(
130+
("Paladius".to_string(), "Paladius".to_string()),
131+
"Paladius".to_string(),
132+
);
133+
exceptions.insert(
134+
("Necromus".to_string(), "Necromus".to_string()),
135+
"Necromus".to_string(),
136+
);
137+
exceptions.insert(
138+
(
139+
"Jormuntide Ignis".to_string(),
140+
"Jormuntide Ignis".to_string(),
141+
),
142+
"Jormuntide Ignis".to_string(),
143+
);
144+
Self { exceptions }
145+
}
146+
147+
pub fn parents_exist(&self, parents: (&str, &str)) -> Option<&str> {
148+
let (father, mother) = parents;
149+
if let Some(child) = self
150+
.exceptions
151+
.get(&(father.to_string(), mother.to_string()))
152+
{
153+
Some(child)
154+
} else {
155+
None
156+
}
157+
}
158+
}

src/handler.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ pub async fn breeding_calc_handler(
5050
State(data): State<Arc<AppState>>,
5151
Json(body): Json<BreedData>,
5252
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
53+
if let Some(child) = &data
54+
.breed_exceptions
55+
.parents_exist((&body.father, &body.mother))
56+
{
57+
let response = serde_json::json!({"status": "success","data": serde_json::json!({
58+
"pal":child
59+
})});
60+
return Ok(Json(response));
61+
}
62+
5363
let pal_breeding_record = sqlx::query_as::<_, PalBreeding>(
5464
r#"SELECT * FROM public.pal_breeding ORDER BY ABS(breeding_power -
5565
(SELECT CAST ( FLOOR(AVG(breeding_power)) AS INT4) FROM public.pal_breeding WHERE name = $1 OR name = $1)) LIMIT 1;"#,

src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod exceptions;
12
mod handler;
23
mod model;
34
mod route;
@@ -7,13 +8,15 @@ use axum::http::{
78
};
89
mod body_schema;
910
use dotenv::dotenv;
11+
use exceptions::ExceptionMap;
1012
use route::create_router;
1113
use sqlx::postgres::{PgPool, PgPoolOptions};
1214
use std::sync::Arc;
1315
use tower_http::cors::CorsLayer;
1416

1517
pub struct AppState {
1618
db: PgPool,
19+
breed_exceptions: ExceptionMap,
1720
}
1821

1922
#[tokio::main]
@@ -40,8 +43,14 @@ async fn main() {
4043
.allow_methods([Method::GET])
4144
.allow_credentials(true)
4245
.allow_headers([AUTHORIZATION, ACCEPT, CONTENT_TYPE]);
46+
let exception_map = ExceptionMap::new();
47+
48+
let app = create_router(Arc::new(AppState {
49+
db: pool.clone(),
50+
breed_exceptions: exception_map,
51+
}))
52+
.layer(cors);
4353

44-
let app = create_router(Arc::new(AppState { db: pool.clone() })).layer(cors);
4554
println!("Server started");
4655
let listener = tokio::net::TcpListener::bind("0.0.0.0:8000").await.unwrap();
4756
axum::serve(listener, app).await.unwrap();

0 commit comments

Comments
 (0)