-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74dd8ff
commit adae5da
Showing
3 changed files
with
99 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use actix_session::Session; | ||
use actix_web::{post, web, HttpResponse, Responder}; | ||
use utoipa::OpenApi; | ||
|
||
use crate::api::ApiResult; | ||
|
||
#[derive(OpenApi)] | ||
#[openapi( | ||
tags((name = "users/me/renew")), | ||
paths(post_renew) | ||
)] | ||
struct ApiDoc; | ||
|
||
pub fn openapi() -> utoipa::openapi::OpenApi { | ||
ApiDoc::openapi() | ||
} | ||
|
||
pub fn configure(cfg: &mut web::ServiceConfig) { | ||
cfg.service(post_renew); | ||
} | ||
|
||
#[utoipa::path( | ||
tag = "users/me/renew", | ||
get, | ||
path = "/api/users/me/renew", | ||
responses( | ||
(status = 200, description = "Successfully renewed", body = String), | ||
(status = 400, description = "Not logged in"), | ||
) | ||
)] | ||
#[post("/api/users/me/renew")] | ||
async fn post_renew(session: Session) -> ApiResult<impl Responder> { | ||
let Ok(Some(username)) = session.get::<String>("username") else { | ||
return Ok(HttpResponse::BadRequest().finish()); | ||
}; | ||
|
||
session.renew(); | ||
|
||
Ok(HttpResponse::Ok().json(username)) | ||
} |