Skip to content

Commit

Permalink
add openapi to album
Browse files Browse the repository at this point in the history
  • Loading branch information
NexVeridian committed Jan 15, 2025
1 parent 862a848 commit eb00e80
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/controllers/album.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::unnecessary_struct_initialization)]
#![allow(clippy::unused_async)]
use loco_rs::prelude::*;
use axum::debug_handler;
use loco_rs::prelude::*;
use serde::Serialize;

#[derive(Serialize, Debug, ToSchema)]
pub struct Album {
title: String,
rating: u32,
}

/// Get album
///
/// Returns a title and rating
#[utoipa::path(
get,
path = "/api/album/get_album",
tags = ["album"],
responses(
(status = 200, description = "Album found", body = Album),
),
)]
#[debug_handler]
pub async fn index(State(_ctx): State<AppContext>) -> Result<Response> {
format::empty()
pub async fn get_album(State(_ctx): State<AppContext>) -> Result<Response> {
format::json(Album {
title: "VH II".to_string(),
rating: 10,
})
}

pub fn routes() -> Routes {
Routes::new()
.prefix("api/albums/")
.add("/", get(index))
.prefix("api/album/")
.add("/get_album", routes!(get_album))
}

0 comments on commit eb00e80

Please # to comment.