-
Notifications
You must be signed in to change notification settings - Fork 0
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
root
authored and
root
committed
Jan 31, 2024
1 parent
bc076b4
commit 4cf7d01
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod routes_login; | ||
pub mod routes_tickets; | ||
|
||
pub const AUTH_TOKEN: &str = "auth-token"; |
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,41 @@ | ||
use axum::{ | ||
extract::{Path, State}, | ||
routing::{delete, post}, | ||
Json, Router, | ||
}; | ||
|
||
use crate::{ | ||
model::{ModelController, Ticket, TicketForCreate}, | ||
Result, | ||
}; | ||
|
||
async fn create_ticket( | ||
State(mc): State<ModelController>, | ||
Json(ticket_fc): Json<TicketForCreate>, | ||
) -> Result<Json<Ticket>> { | ||
let ticket = mc.create_ticket(ticket_fc).await?; | ||
|
||
Ok(Json(ticket)) | ||
} | ||
|
||
async fn list_tickets(State(mc): State<ModelController>) -> Result<Json<Vec<Ticket>>> { | ||
let tickets = mc.list_tickets().await?; | ||
|
||
Ok(Json(tickets)) | ||
} | ||
|
||
async fn delete_ticket( | ||
State(mc): State<ModelController>, | ||
Path(id): Path<u64>, | ||
) -> Result<Json<Ticket>> { | ||
let ticket = mc.delete_ticket(id).await?; | ||
|
||
Ok(Json(ticket)) | ||
} | ||
|
||
pub fn routes(mc: ModelController) -> Router { | ||
Router::new() | ||
.route("/tickets", post(create_ticket).get(list_tickets)) | ||
.route("/tickets/:id", delete(delete_ticket)) | ||
.with_state(mc) | ||
} |
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