Backend: Created info table in database. Created README instructions for psql. Boilerplate for Rust.
This commit is contained in:
parent
f1384a6a78
commit
8d748b56e6
6 changed files with 109 additions and 6 deletions
|
@ -10,6 +10,7 @@ axum = { version = "0.6.20", features = ["form"] }
|
|||
axum-error = "0.2.0"
|
||||
dotenv = "0.15.0"
|
||||
serde = { version = "1.0.192", features = ["derive"] }
|
||||
sqlx = { version = "0.7.2", features = ["runtime-tokio", "tls-rustls", "sqlite"] }
|
||||
sqlx = { version = "0.7.2", features = ["runtime-tokio", "tls-rustls", "postgres", "chrono"] }
|
||||
tokio = { version = "1.34.0", features = ["full"] }
|
||||
tower-http = { version = "0.4.4", features = ["cors"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
33
backend/README.md
Normal file
33
backend/README.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
# Creation of the Database
|
||||
|
||||
`[name]` being the username you created in postgres\
|
||||
`[pwd]` being its password
|
||||
|
||||
```
|
||||
sudo dnf install postgresql postgresql-client postgresql-server postgresql-contrib
|
||||
sudo -u postgres createdb --owner=name cv
|
||||
sudo service postgresql restart
|
||||
```
|
||||
|
||||
## Importing `.sql` files
|
||||
|
||||
Idk for now (xd)
|
||||
|
||||
## ⚠️ Be sure to modify your config file to access the postgres database ⚠️
|
||||
|
||||
```
|
||||
sudo nano /var/lib/pgsql/data/pg_hba.conf
|
||||
```
|
||||
Check if those lines are correct :
|
||||
```
|
||||
# IPv4 local connections:
|
||||
host all all 127.0.0.1/32 md5
|
||||
# IPv6 local connections:
|
||||
host all all ::1/128 md5
|
||||
```
|
||||
|
||||
# Env file configuration
|
||||
|
||||
```
|
||||
DATABASE_URL=postgres://[name]:[pwd]@localhost/cv
|
||||
```
|
16
backend/db/info.sql
Normal file
16
backend/db/info.sql
Normal file
|
@ -0,0 +1,16 @@
|
|||
-- public.info definition
|
||||
|
||||
-- Drop table
|
||||
|
||||
-- DROP TABLE public.info;
|
||||
|
||||
CREATE TABLE public.info (
|
||||
birth_year date NULL,
|
||||
id serial4 NOT NULL,
|
||||
full_name text NULL,
|
||||
phone_number varchar NULL,
|
||||
email varchar NULL,
|
||||
softskills text NULL,
|
||||
interests text NULL,
|
||||
CONSTRAINT info_pkey PRIMARY KEY (id)
|
||||
);
|
|
@ -1,3 +1,58 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
routing::{get, post},
|
||||
Form, Json, Router,
|
||||
};
|
||||
use axum_error::Result;
|
||||
use dotenv::dotenv;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{
|
||||
postgres::{PgPool, PgPoolOptions},
|
||||
types::chrono::NaiveDate,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
use tower_http::cors::CorsLayer;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// Environnement table + pool connection
|
||||
dotenv().ok();
|
||||
let url = std::env::var("DATABASE_URL")?;
|
||||
let pool = PgPoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect(&url)
|
||||
.await?;
|
||||
|
||||
// Creating a router
|
||||
let router = Router::new()
|
||||
.route("/info", get(info))
|
||||
.with_state(pool)
|
||||
.layer(CorsLayer::very_permissive());
|
||||
|
||||
// Server
|
||||
let address = SocketAddr::from(([0, 0, 0, 0], 8000));
|
||||
Ok(axum::Server::bind(&address)
|
||||
.serve(router.into_make_service())
|
||||
.await?)
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct Info {
|
||||
id: i64,
|
||||
full_name: Option<String>,
|
||||
phone_number: Option<String>,
|
||||
email: Option<String>,
|
||||
softskills: Option<String>,
|
||||
interests: Option<String>,
|
||||
birth_year: Option<NaiveDate>,
|
||||
}
|
||||
|
||||
async fn info(State(pool): State<PgPool>) -> Result<Json<Vec<Info>>> {
|
||||
let infos = sqlx::query_as!(
|
||||
Info,
|
||||
"SELECT id, full_name, phone_number, email, softskills, interests, birth_year FROM public.info"
|
||||
)
|
||||
.fetch_all(&pool)
|
||||
.await?;
|
||||
Ok(Json(infos))
|
||||
}
|
||||
|
|
2
frontend/.svelte-kit/ambient.d.ts
vendored
2
frontend/.svelte-kit/ambient.d.ts
vendored
|
@ -109,7 +109,6 @@ declare module '$env/static/private' {
|
|||
export const npm_node_execpath: string;
|
||||
export const npm_config_engine_strict: string;
|
||||
export const GIO_LAUNCHED_DESKTOP_FILE: string;
|
||||
export const OLDPWD: string;
|
||||
export const TERM_PROGRAM: string;
|
||||
export const NODE_ENV: string;
|
||||
}
|
||||
|
@ -224,7 +223,6 @@ declare module '$env/dynamic/private' {
|
|||
npm_node_execpath: string;
|
||||
npm_config_engine_strict: string;
|
||||
GIO_LAUNCHED_DESKTOP_FILE: string;
|
||||
OLDPWD: string;
|
||||
TERM_PROGRAM: string;
|
||||
NODE_ENV: string;
|
||||
[key: `PUBLIC_${string}`]: undefined;
|
||||
|
|
|
@ -20,7 +20,7 @@ export const options = {
|
|||
app: ({ head, body, assets, nonce, env }) => "<!DOCTYPE html>\n<html lang=\"en\" class=\"dark\">\n\t<head>\n\t\t<meta charset=\"utf-8\" />\n\t\t<link rel=\"icon\" href=\"" + assets + "/favicon.png\" />\n\t\t<meta name=\"viewport\" content=\"width=device-width\" />\n\t\t" + head + "\n\t</head>\n\t<body data-sveltekit-preload-data=\"hover\" data-theme=\"crimson\">\n\t\t<div style=\"display: contents\">" + body + "</div>\n\t</body>\n</html>\n",
|
||||
error: ({ status, message }) => "<!DOCTYPE html>\n<html lang=\"en\">\n\t<head>\n\t\t<meta charset=\"utf-8\" />\n\t\t<title>" + message + "</title>\n\n\t\t<style>\n\t\t\tbody {\n\t\t\t\t--bg: white;\n\t\t\t\t--fg: #222;\n\t\t\t\t--divider: #ccc;\n\t\t\t\tbackground: var(--bg);\n\t\t\t\tcolor: var(--fg);\n\t\t\t\tfont-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,\n\t\t\t\t\tUbuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t\tjustify-content: center;\n\t\t\t\theight: 100vh;\n\t\t\t\tmargin: 0;\n\t\t\t}\n\n\t\t\t.error {\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t\tmax-width: 32rem;\n\t\t\t\tmargin: 0 1rem;\n\t\t\t}\n\n\t\t\t.status {\n\t\t\t\tfont-weight: 200;\n\t\t\t\tfont-size: 3rem;\n\t\t\t\tline-height: 1;\n\t\t\t\tposition: relative;\n\t\t\t\ttop: -0.05rem;\n\t\t\t}\n\n\t\t\t.message {\n\t\t\t\tborder-left: 1px solid var(--divider);\n\t\t\t\tpadding: 0 0 0 1rem;\n\t\t\t\tmargin: 0 0 0 1rem;\n\t\t\t\tmin-height: 2.5rem;\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t}\n\n\t\t\t.message h1 {\n\t\t\t\tfont-weight: 400;\n\t\t\t\tfont-size: 1em;\n\t\t\t\tmargin: 0;\n\t\t\t}\n\n\t\t\t@media (prefers-color-scheme: dark) {\n\t\t\t\tbody {\n\t\t\t\t\t--bg: #222;\n\t\t\t\t\t--fg: #ddd;\n\t\t\t\t\t--divider: #666;\n\t\t\t\t}\n\t\t\t}\n\t\t</style>\n\t</head>\n\t<body>\n\t\t<div class=\"error\">\n\t\t\t<span class=\"status\">" + status + "</span>\n\t\t\t<div class=\"message\">\n\t\t\t\t<h1>" + message + "</h1>\n\t\t\t</div>\n\t\t</div>\n\t</body>\n</html>\n"
|
||||
},
|
||||
version_hash: "1sncic5"
|
||||
version_hash: "gzttwb"
|
||||
};
|
||||
|
||||
export function get_hooks() {
|
||||
|
|
Loading…
Add table
Reference in a new issue