@@ -6,8 +6,6 @@ use crate::util::errors::AppResult;
66use crate :: views:: EncodableKeyword ;
77use axum:: Json ;
88use axum:: extract:: { FromRequestParts , Path , Query } ;
9- use axum_extra:: json;
10- use axum_extra:: response:: ErasedJson ;
119use diesel:: prelude:: * ;
1210use http:: request:: Parts ;
1311
@@ -72,6 +70,11 @@ pub async fn list_keywords(
7270 Ok ( Json ( ListResponse { keywords, meta } ) )
7371}
7472
73+ #[ derive( Debug , Serialize , utoipa:: ToSchema ) ]
74+ pub struct GetResponse {
75+ pub keyword : EncodableKeyword ,
76+ }
77+
7578/// Get keyword metadata.
7679#[ utoipa:: path(
7780 get,
@@ -80,11 +83,14 @@ pub async fn list_keywords(
8083 ( "keyword" = String , Path , description = "The keyword to find" ) ,
8184 ) ,
8285 tag = "keywords" ,
83- responses( ( status = 200 , description = "Successful Response" ) ) ,
86+ responses( ( status = 200 , description = "Successful Response" , body = inline ( GetResponse ) ) ) ,
8487) ]
85- pub async fn find_keyword ( Path ( name) : Path < String > , state : AppState ) -> AppResult < ErasedJson > {
88+ pub async fn find_keyword (
89+ Path ( name) : Path < String > ,
90+ state : AppState ,
91+ ) -> AppResult < Json < GetResponse > > {
8692 let mut conn = state. db_read ( ) . await ?;
8793 let kw = Keyword :: find_by_keyword ( & mut conn, & name) . await ?;
88-
89- Ok ( json ! ( { " keyword" : EncodableKeyword :: from ( kw ) } ) )
94+ let keyword = EncodableKeyword :: from ( kw ) ;
95+ Ok ( Json ( GetResponse { keyword } ) )
9096}
0 commit comments