This repository was archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Add unimplemented API methods #35
Open
grahhnt
wants to merge
12
commits into
main
Choose a base branch
from
34-unimpl-api-methods
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
27be8d2
add city_projects GET, POST, PUT & DELETE
439d204
forgot permission checks for country usage
grahhnt bbd91e2
linting
grahhnt ff2f5c0
remove unused (probably test) api endpoint
grahhnt 3bbcf1a
Builders WIP
grahhnt af1d5b5
add uuid dependency
grahhnt d675f29
Change returned status codes
grahhnt 9e35efd
improvements
grahhnt 0e8c80a
Add country get endpoints
grahhnt fc7ba8c
FTP endpoint
grahhnt 0b27326
Move plots endpoints
grahhnt 2594295
move the rest of the plots endpoints
grahhnt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| use sea_orm::{DatabaseConnection, DbErr}; | ||
|
|
||
| use crate::entities::{prelude::*, *}; | ||
| use sea_orm::entity::*; | ||
| use uuid::Uuid; | ||
|
|
||
| pub async fn by_uuid( | ||
| db: &DatabaseConnection, | ||
| uuid: Uuid, | ||
| ) -> Result<Option<plotsystem_builders::Model>, DbErr> { | ||
| PlotsystemBuilders::find_by_id(uuid.as_hyphenated().to_string()) | ||
| .one(db) | ||
| .await | ||
| } | ||
|
|
||
| pub async fn all(db: &DatabaseConnection) -> Result<Vec<plotsystem_builders::Model>, DbErr> { | ||
| PlotsystemBuilders::find().all(db).await | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| use sea_orm::{DatabaseConnection, DbErr}; | ||
|
|
||
| use crate::entities::{prelude::*, *}; | ||
|
|
||
| use sea_orm::entity::*; | ||
|
|
||
| pub async fn by_id( | ||
| db: &DatabaseConnection, | ||
| id: i32, | ||
| ) -> Result<plotsystem_countries::Model, DbErr> { | ||
| match PlotsystemCountries::find_by_id(id).one(db).await? { | ||
| Some(cp) => Ok(cp), | ||
| None => Err(DbErr::RecordNotFound(format!( | ||
| "Country with id {} does not exists", | ||
| id | ||
| ))), | ||
| } | ||
| } | ||
|
|
||
| pub async fn all(db: &DatabaseConnection) -> Result<Vec<plotsystem_countries::Model>, DbErr> { | ||
| PlotsystemCountries::find().all(db).await | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||||||||||||||||||||||||
| use crate::auth::auth_preflag_request_guard::AuthPreflag; | ||||||||||||||||||||||||||||
| use crate::{db_get, entities::*, pool::Db}; | ||||||||||||||||||||||||||||
| use rocket::Request; | ||||||||||||||||||||||||||||
| use rocket::{http::Status, response, response::Responder, response::Response, serde::json::Json}; | ||||||||||||||||||||||||||||
| use sea_orm::{ActiveValue::*, EntityTrait}; | ||||||||||||||||||||||||||||
| use sea_orm_rocket::Connection; | ||||||||||||||||||||||||||||
| use serde::Deserialize; | ||||||||||||||||||||||||||||
| use uuid::Uuid; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| pub struct APIResponse<R>(pub Status, pub Option<R>); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| impl<'r, 'o: 'r, R: Responder<'r, 'o>> Responder<'r, 'o> for APIResponse<R> { | ||||||||||||||||||||||||||||
| fn respond_to(self, req: &'r Request<'_>) -> response::Result<'o> { | ||||||||||||||||||||||||||||
| let mut build = Response::build(); | ||||||||||||||||||||||||||||
| if let Some(responder) = self.1 { | ||||||||||||||||||||||||||||
| build.merge(responder.respond_to(req)?); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| build.status(self.0).ok() | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| #[get("/builders")] | ||||||||||||||||||||||||||||
| pub async fn builders_get_all( | ||||||||||||||||||||||||||||
| conn: Connection<'_, Db>, | ||||||||||||||||||||||||||||
| ) -> Result<Json<Vec<plotsystem_builders::Model>>, APIResponse<String>> { | ||||||||||||||||||||||||||||
| let db = conn.into_inner(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| match db_get::builder::all(db).await { | ||||||||||||||||||||||||||||
| Ok(builders) => Ok(Json(builders)), | ||||||||||||||||||||||||||||
| Err(e) => Err(APIResponse( | ||||||||||||||||||||||||||||
| Status::InternalServerError, | ||||||||||||||||||||||||||||
| Some(e.to_string()), | ||||||||||||||||||||||||||||
| )), | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| #[get("/builder/<uuid>")] | ||||||||||||||||||||||||||||
| pub async fn builders_get( | ||||||||||||||||||||||||||||
| conn: Connection<'_, Db>, | ||||||||||||||||||||||||||||
| uuid: String, | ||||||||||||||||||||||||||||
| ) -> Result<APIResponse<Json<plotsystem_builders::Model>>, APIResponse<String>> { | ||||||||||||||||||||||||||||
| let db = conn.into_inner(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| let parsed_uuid = Uuid::parse_str(&uuid); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if parsed_uuid.is_err() { | ||||||||||||||||||||||||||||
| return Err(APIResponse(Status::BadRequest, None)); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| match db_get::builder::by_uuid(db, parsed_uuid.unwrap()).await { | ||||||||||||||||||||||||||||
| Ok(builder) => { | ||||||||||||||||||||||||||||
| if (builder.is_none()) { | ||||||||||||||||||||||||||||
| Ok(APIResponse(Status::NotFound, None)) | ||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An unsucessful API request shouldnt return the Ok() Variant. Return an error instead.
Suggested change
|
||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| Ok(APIResponse(Status::Ok, Some(Json(builder.unwrap())))) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+53
to
+57
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use match syntax here instead.
Suggested change
|
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| Err(e) => Err(APIResponse( | ||||||||||||||||||||||||||||
| Status::InternalServerError, | ||||||||||||||||||||||||||||
| Some(e.to_string()), | ||||||||||||||||||||||||||||
| )), | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not return an APIResponse in both cases (like in function
builders_get) for more code consistency