Skip to content

Commit

Permalink
add all services
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Jan 14, 2024
1 parent e648477 commit e8c0f81
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
axum = "0.7"
axum-macros = "0.4"
libaccount = { version = "0.1", git = "https://github.com/subitlab-buf/libaccount.git", branch = "tags" }
dmds = "0.2"
dmds-tokio-fs = "0.2"
Expand Down
6 changes: 4 additions & 2 deletions src/handle/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct NotifyReq {
/// "id": 19,
/// }
/// ```
#[derive(Serialize)]
pub struct NotifyRes {
/// Id of the notification.
pub id: u64,
Expand All @@ -78,14 +79,14 @@ pub async fn notify<Io: IoHandle>(
auth: Auth,
State(Global { worlds, .. }): State<Global<Io>>,
Json(NotifyReq { title, body, time }): Json<NotifyReq>,
) -> Result<NotifyRes, Error> {
) -> Result<Json<NotifyRes>, Error> {
let select = sd!(worlds.account, auth.account);
va!(auth, select => ManageNotifications);

let notification = Notification::new(title, body, time, auth.account);
let id = notification.id();
worlds.notification.insert(notification).await?;
Ok(NotifyRes { id })
Ok(Json(NotifyRes { id }))
}

/// Request URL query parameters for filtering notifications.
Expand Down Expand Up @@ -243,6 +244,7 @@ pub async fn get_info<Io: IoHandle>(
}))
}

#[derive(Deserialize)]
pub struct BulkGetInfoReq {
pub notifications: Box<[u64]>,
}
Expand Down
1 change: 1 addition & 0 deletions src/handle/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub async fn new_session<Io: IoHandle>(
}

/// Response body for [`upload`].
#[derive(Serialize)]
pub struct UploadRes {
/// Id of the resource.
pub id: u64,
Expand Down
40 changes: 39 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ pub mod routes {
pub const REVIEW_POST: &str = "/post/review/:id";
pub const DELETE_POST: &str = "/post/delete/:id";
pub const BULK_DELETE_POST: &str = "/post/bulk-delete";

pub const NEW_UPLOAD_SESSION: &str = "/resource/new-session";
pub const UPLOAD_RESOURCE: &str = "/resource/upload/:id";
pub const GET_RESOURCE_PAYLOAD: &str = "/resource/payload/:id";
pub const GET_RESOURCE_INFO: &str = "/resource/get/:id";
pub const BULK_GET_RESOURCE_INFO: &str = "/resource/bulk-get";

pub const NOTIFY: &str = "/notification/new";
pub const FILTER_NOTIFICATIONS: &str = "/notification/filter";
pub const GET_NOTIFICATION: &str = "/notification/get/:id";
pub const BULK_GET_NOTIFICATION: &str = "/notification/bulk-get";
pub const DELETE_NOTIFICATION: &str = "/notification/delete/:id";
pub const BULK_DELETE_NOTIFICATION: &str = "/notification/bulk-delete";
pub const MODIFY_NOTIFICATION: &str = "/notification/modify/:id";
}

#[derive(Debug)]
Expand Down Expand Up @@ -177,11 +191,12 @@ impl<Io: IoHandle> axum::extract::FromRequestParts<Global<Io>> for Auth {
}
}

fn routing<Io: IoHandle + 'static>(mut router: Router<Global<Io>>) -> Router<Global<Io>> {
fn routing<Io: IoHandle + 'static>(router: Router<Global<Io>>) -> Router<Global<Io>> {
use axum::routing::{delete, get, patch, post, put};
use routes::*;

router
// account serivces
.route(SEND_CAPTCHA, post(handle::account::send_captcha))
.route(REGISTER, put(handle::account::register))
.route(LOGIN, post(handle::account::login))
Expand All @@ -204,6 +219,29 @@ fn routing<Io: IoHandle + 'static>(mut router: Router<Global<Io>>) -> Router<Glo
.route(REVIEW_POST, patch(handle::post::review))
.route(DELETE_POST, delete(handle::post::remove))
.route(BULK_DELETE_POST, delete(handle::post::bulk_remove))
// resource services
.route(NEW_UPLOAD_SESSION, put(handle::resource::new_session))
.route(UPLOAD_RESOURCE, put(handle::resource::upload))
.route(GET_RESOURCE_PAYLOAD, get(handle::resource::get_payload))
.route(GET_RESOURCE_INFO, get(handle::resource::get_info))
.route(
BULK_GET_RESOURCE_INFO,
post(handle::resource::bulk_get_info),
)
// notification services
.route(NOTIFY, put(handle::notification::notify))
.route(FILTER_NOTIFICATIONS, get(handle::notification::filter))
.route(GET_NOTIFICATION, get(handle::notification::get_info))
.route(
BULK_GET_NOTIFICATION,
post(handle::notification::bulk_get_info),
)
.route(DELETE_NOTIFICATION, delete(handle::notification::remove))
.route(
BULK_DELETE_NOTIFICATION,
delete(handle::notification::bulk_remove),
)
.route(MODIFY_NOTIFICATION, patch(handle::notification::modify))
}

#[cfg(test)]
Expand Down

0 comments on commit e8c0f81

Please sign in to comment.