Skip to content

Commit

Permalink
Add new API Structure
Browse files Browse the repository at this point in the history
  • Loading branch information
isiko committed May 10, 2024
1 parent eff68b9 commit 1ff9cf4
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 65 deletions.
270 changes: 206 additions & 64 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["app", "metro-scrape", "backend", "foodlib", "cli-client"]
members = ["app", "metro-scrape", "backend", "foodlib", "cli-client", "api" ]
default-members = ["app", "backend", "foodlib"]

[workspace.dependencies]
Expand Down
13 changes: 13 additions & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "api"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = "0.7.5"
dotenv.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json = "1.0.117"
tokio = { workspace = true, features = ["full"] }
41 changes: 41 additions & 0 deletions api/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use axum::{http::StatusCode, response::IntoResponse, routing::{delete, get, post, put}, Router};

pub fn router() -> Router {
Router::new()
.route("/", get(list))
.route("/", post(update_event))
.route("/:event_id/", get(show_event))
.route("/:event_id/", delete(delete_event))
.route("/:event_id/", post(update_event))
.route("/:event_id/meals/", put(meal_add))
.route("/:event_id/meals/", delete(meal_delete))
.route("/:event_id/meals/", post(meal_update))
}

async fn list() -> impl IntoResponse {
StatusCode::OK
}

async fn show_event() -> impl IntoResponse {
StatusCode::OK
}

async fn delete_event() -> impl IntoResponse {
StatusCode::OK
}

async fn update_event() -> impl IntoResponse {
StatusCode::OK
}

async fn meal_add() -> impl IntoResponse {
StatusCode::OK
}

async fn meal_delete() -> impl IntoResponse {
StatusCode::OK
}

async fn meal_update() -> impl IntoResponse {
StatusCode::OK
}
26 changes: 26 additions & 0 deletions api/src/ingredients.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use axum::{http::StatusCode, response::IntoResponse, routing::{delete, get, post, put}, Router};

pub fn router() -> Router {
Router::new()
.route("/", get(list))
.route("/", put(add))
.route("/:ingredient_id/", get(show_ingredient))
.route("/:ingredient_id/", delete(delete_ingredient))
.route("/:ingredient_id/", post(show_ingredient))
}

async fn add() -> impl IntoResponse {
StatusCode::OK
}

async fn list() -> impl IntoResponse {
StatusCode::OK
}

async fn show_ingredient() -> impl IntoResponse {
StatusCode::OK
}

async fn delete_ingredient() -> impl IntoResponse {
StatusCode::OK
}
23 changes: 23 additions & 0 deletions api/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use axum::Router;
use tokio::net::TcpListener;

mod events;
mod ingredients;
mod places;
mod reciepes;

#[tokio::main]
async fn main() {
let app = Router::new()
.nest("/events", events::router())
.nest("/ingredients", ingredients::router())
.nest("/places", places::router())
.nest("/reciepes", reciepes::router());

println!("Server started successfully at 0.0.0.0:8080");

let listener = TcpListener::bind("0.0.0.0:8080").await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.unwrap();
}
30 changes: 30 additions & 0 deletions api/src/places.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use axum::{http::StatusCode, response::IntoResponse, routing::{delete, get, post, put}, Router};

pub fn router() -> Router {
Router::new()
.route("/", get(list_places))
.route("/", put(add_places))
.route("/:place_id", get(get_place))
.route("/:place_id", post(update_place))
.route("/:place_id", delete(delete_place))
}

async fn list_places() -> impl IntoResponse {
StatusCode::OK
}

async fn add_places() -> impl IntoResponse {
StatusCode::OK
}

async fn get_place() -> impl IntoResponse {
StatusCode::OK
}

async fn update_place() -> impl IntoResponse {
StatusCode::OK
}

async fn delete_place() -> impl IntoResponse {
StatusCode::OK
}
30 changes: 30 additions & 0 deletions api/src/reciepes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use axum::{http::StatusCode, response::IntoResponse, routing::{delete, get, post, put}, Router};

pub fn router() -> Router {
Router::new()
.route("/", get(list_reciepes))
.route("/", put(add_reciepe))
.route("/:recipe_id/", get(calc_reciepe))
.route("/:recipe_id/", post(update_reciepe))
.route("/:recipe_id/", delete(update_reciepe))
.route("/:recipe_id/steps/", get(update_reciepe))
.route("/:recipe_id/steps/", post(update_reciepe))
.route("/:recipe_id/ingredients/", get(calc_reciepe))
.route("/:recipe_id/ingredients/", post(calc_reciepe))
}

async fn list_reciepes() -> impl IntoResponse {
StatusCode::OK
}

async fn add_reciepe() -> impl IntoResponse {
StatusCode::OK
}

async fn calc_reciepe() -> impl IntoResponse {
StatusCode::OK
}

async fn update_reciepe() -> impl IntoResponse {
StatusCode::OK
}

0 comments on commit 1ff9cf4

Please sign in to comment.