-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Review routes
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ jobs: | |
postgres: | ||
image: postgres | ||
env: | ||
POSTGRES_HOST: postgres | ||
POSTGRES_PASSWORD: mysecretpassword | ||
options: >- | ||
--health-cmd pg_isready | ||
|
@@ -37,9 +38,20 @@ jobs: | |
- 5432:5432 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build and run API | ||
- uses: dtolnay/rust-toolchain@stable | ||
- name: Migrate Database | ||
env: | ||
DATABASE_URL: postgres://postgres:mysecretpassword@localhost:5432 | ||
run: | | ||
cd backend | ||
cargo install sqlx-cli --features postgres | ||
sqlx migrate run | ||
- name: Build and run API | ||
env: | ||
DATABASE_URL: postgres://postgres:[email protected]:5432 | ||
run: | | ||
cd backend | ||
cargo run & cargo test | ||
cargo build | ||
cargo sqlx prepare | ||
cargo run & | ||
cargo test |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,10 @@ authors = ["Valentin Vareskic <[email protected]>"] | |
|
||
[dependencies] | ||
axum = "0.7.5" | ||
reqwest = "0.12.3" | ||
reqwest = { version = "0.12.3", features = ["json"] } | ||
serde = { version = "1.0.197", features = ["derive"] } | ||
tokio = { version = "1.37.0", features = ["full"] } | ||
tracing = "0.1.40" | ||
tracing-subscriber = "0.3.18" | ||
sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-native-tls", "any", "postgres" , "migrate" , "chrono"] } | ||
serde_json = "1.0.117" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use axum::http::StatusCode; | ||
use axum::response::IntoResponse; | ||
use axum::Json; | ||
use serde_json::json; | ||
|
||
#[derive(Debug)] | ||
pub enum AppError { | ||
InternalServerError, | ||
BodyParsingError(String), | ||
MissingResource(String), | ||
} | ||
|
||
pub fn internal_error<E>(_err: E) -> AppError { | ||
AppError::InternalServerError | ||
} | ||
|
||
impl IntoResponse for AppError { | ||
fn into_response(self) -> axum::response::Response { | ||
let (status, err_msg) = match self { | ||
Self::InternalServerError => ( | ||
StatusCode::INTERNAL_SERVER_ERROR, | ||
String::from("Internal Server Error"), | ||
), | ||
Self::BodyParsingError(message) => ( | ||
StatusCode::BAD_REQUEST, | ||
format!("Bad request error: {}", message), | ||
), | ||
Self::MissingResource(message) => ( | ||
StatusCode::NOT_FOUND, | ||
format!("Resource can't be found: {}", message), | ||
), | ||
}; | ||
(status, Json(json!({ "message": err_msg }))).into_response() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod error; | ||
pub mod routes; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod reviews; |