refactor: implement fetchall with generic type
This commit is contained in:
26
sdgb-api/src/title/methods/api_ext/mod.rs
Normal file
26
sdgb-api/src/title/methods/api_ext/mod.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use crate::title::methods::{APIExt, APIMethod};
|
||||
|
||||
#[crabtime::function]
|
||||
fn api_implement(api_names: Vec<String>) {
|
||||
for api_name in api_names {
|
||||
crabtime::output!(
|
||||
pub struct {{api_name}};
|
||||
|
||||
impl APIExt for {{api_name}} {
|
||||
const METHOD: APIMethod = APIMethod::{{api_name}};
|
||||
type Payload = crate::title::model::{{api_name}};
|
||||
type Response = crate::title::model::{{api_name}}Resp;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
api_implement!([
|
||||
"Ping",
|
||||
"UserLoginApi",
|
||||
"UserLogoutApi",
|
||||
"GetUserDataApi",
|
||||
"GetUserPreviewApi",
|
||||
"GetUserRatingApi",
|
||||
"GetUserMusicApi",
|
||||
]);
|
||||
21
sdgb-api/src/title/methods/has_uid/mod.rs
Normal file
21
sdgb-api/src/title/methods/has_uid/mod.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use crate::title::methods::HasUid;
|
||||
|
||||
#[crabtime::function]
|
||||
fn uid_get_impl(api_names: Vec<String>) {
|
||||
for api_name in api_names {
|
||||
crabtime::output!(
|
||||
impl HasUid for crate::title::model::{{api_name}}Resp {
|
||||
fn get_uid(&self) -> u32 {
|
||||
self.user_id
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
uid_get_impl!([
|
||||
"GetUserDataApi",
|
||||
"GetUserMusicApi",
|
||||
"GetUserPreviewApi",
|
||||
"GetUserRatingApi"
|
||||
]);
|
||||
@@ -53,31 +53,13 @@ pub trait APIExt {
|
||||
type Response: for<'de> Deserialize<'de>;
|
||||
}
|
||||
|
||||
#[crabtime::function]
|
||||
fn api_implement(api_names: Vec<String>) {
|
||||
for api_name in api_names {
|
||||
let api_name = api_name;
|
||||
crabtime::output!(
|
||||
pub struct {{api_name}};
|
||||
|
||||
impl APIExt for {{api_name}} {
|
||||
const METHOD: APIMethod = APIMethod::{{api_name}};
|
||||
type Payload = crate::title::model::{{api_name}};
|
||||
type Response = crate::title::model::{{api_name}}Resp;
|
||||
}
|
||||
);
|
||||
}
|
||||
pub trait HasUid {
|
||||
fn get_uid(&self) -> u32;
|
||||
}
|
||||
|
||||
api_implement!([
|
||||
"Ping",
|
||||
"UserLoginApi",
|
||||
"UserLogoutApi",
|
||||
"GetUserDataApi",
|
||||
"GetUserPreviewApi",
|
||||
"GetUserRatingApi",
|
||||
"GetUserMusicApi",
|
||||
]);
|
||||
mod api_ext;
|
||||
mod has_uid;
|
||||
pub use api_ext::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod _test {
|
||||
|
||||
@@ -9,6 +9,12 @@ pub struct GetUserPreviewApi {
|
||||
pub user_id: u32,
|
||||
}
|
||||
|
||||
impl From<u32> for GetUserPreviewApi {
|
||||
fn from(user_id: u32) -> Self {
|
||||
Self { user_id }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GetUserPreviewApiResp {
|
||||
|
||||
Reference in New Issue
Block a user