Skip to content

Commit

Permalink
feat!(routes): GET x and GET xyz now return entities (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: Ray Redondo <rdredond@lcdev.xyz>
  • Loading branch information
rdrpenguin04 and Ray Redondo authored Jul 14, 2024
1 parent 0f6806d commit b2ba10f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ fn get_docs() -> SwaggerUIConfig {
async fn main() -> Result<(), rocket::Error> {
initialize().await;


let cors = CorsOptions::default()
.allowed_origins(AllowedOrigins::all())
.allowed_methods(
Expand Down
8 changes: 4 additions & 4 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use uuid::Uuid;

#[openapi]
#[get("/<collection>")]
pub async fn get_x(collection: &str) -> Json<Vec<Uuid>> {
pub async fn get_x(collection: &str) -> Json<Vec<Entity>> {
let connection = &mut establish_connection().await;

Json({
use crate::schema::entities::dsl::*;
entities
.filter(ty.eq(collection))
.select(id)
.select(Entity::as_select())
.load(connection)
.await
.expect("error loading entities")
Expand All @@ -43,7 +43,7 @@ pub async fn get_xy(collection: &str, item: Uuid) -> Json<Entity> {

#[openapi]
#[get("/<super_collection>/<parent>/<collection>")]
pub async fn get_xyz(super_collection: &str, parent: Uuid, collection: &str) -> Json<Vec<Uuid>> {
pub async fn get_xyz(super_collection: &str, parent: Uuid, collection: &str) -> Json<Vec<Entity>> {
let _ = super_collection; // :) deal with it later
let connection = &mut establish_connection().await;

Expand All @@ -52,7 +52,7 @@ pub async fn get_xyz(super_collection: &str, parent: Uuid, collection: &str) ->
entities
.filter(ty.eq(collection))
.filter(parent_id.eq(parent))
.select(id)
.select(Entity::as_select())
.load(connection)
.await
.expect("error loading entities")
Expand Down

0 comments on commit b2ba10f

Please sign in to comment.