feat: clerks endpoint
This commit is contained in:
parent
0a2b71082b
commit
c26872edb8
2 changed files with 57 additions and 1 deletions
|
@ -128,6 +128,13 @@ async fn update_booking(
|
||||||
Ok(StatusCode::NO_CONTENT)
|
Ok(StatusCode::NO_CONTENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn clerks(
|
||||||
|
Extension(service): Extension<Service>,
|
||||||
|
) -> Result<impl IntoResponse, ServiceError> {
|
||||||
|
let clerks = service.get_clerks().await?;
|
||||||
|
Ok(Json(clerks))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn routes() -> Router<BoxRoute> {
|
pub fn routes() -> Router<BoxRoute> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/rooms", get(rooms))
|
.route("/rooms", get(rooms))
|
||||||
|
@ -139,5 +146,6 @@ pub fn routes() -> Router<BoxRoute> {
|
||||||
.route("/bookings/:id/rooms/:roomid", put(add_booking_room).delete(delete_booking_room))
|
.route("/bookings/:id/rooms/:roomid", put(add_booking_room).delete(delete_booking_room))
|
||||||
.route("/bookings/:id/guests", get(booking_guests))
|
.route("/bookings/:id/guests", get(booking_guests))
|
||||||
.route("/bookings/:id/guests/:personid", put(add_booking_guest).delete(delete_booking_guest))
|
.route("/bookings/:id/guests/:personid", put(add_booking_guest).delete(delete_booking_guest))
|
||||||
|
.route("/clerks", get(clerks))
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
50
src/sql.rs
50
src/sql.rs
|
@ -1,6 +1,6 @@
|
||||||
use hyper::StatusCode;
|
use hyper::StatusCode;
|
||||||
|
|
||||||
use crate::{ServiceInner, model::{Room, Booking, Person, Address, BookingBody, CleaningPlan}, error::ServiceError};
|
use crate::{ServiceInner, model::{Room, Booking, Person, Address, BookingBody, CleaningPlan, Clerk}, error::ServiceError};
|
||||||
|
|
||||||
impl ServiceInner {
|
impl ServiceInner {
|
||||||
|
|
||||||
|
@ -383,4 +383,52 @@ impl ServiceInner {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_clerks(&self) -> Result<Vec<Clerk>, ServiceError> {
|
||||||
|
let session = self.pool.get_session().await?;
|
||||||
|
let stmt = session.prepare("
|
||||||
|
SELECT
|
||||||
|
c.staff,
|
||||||
|
c.salary,
|
||||||
|
p.personId,
|
||||||
|
p.name,
|
||||||
|
p.lastName,
|
||||||
|
p.age,
|
||||||
|
ad.street,
|
||||||
|
ad.houseNumber,
|
||||||
|
ad.postalCode,
|
||||||
|
ad.city,
|
||||||
|
ad.country
|
||||||
|
FROM Clerk c
|
||||||
|
INNER JOIN Person p ON p.personId = c.personId
|
||||||
|
INNER JOIN Address ad ON p.addressId = ad.addressId
|
||||||
|
").await?;
|
||||||
|
|
||||||
|
let rows = stmt.query("").await?;
|
||||||
|
|
||||||
|
let mut clerks: Vec<Clerk> = vec![];
|
||||||
|
|
||||||
|
while let Some(row) = rows.next().await? {
|
||||||
|
let clerk = Clerk {
|
||||||
|
staff_number: row.get(0)?,
|
||||||
|
salary: row.get(1)?,
|
||||||
|
person_data: Person {
|
||||||
|
id: row.get(2)?,
|
||||||
|
first_name: row.get(3)?,
|
||||||
|
last_name: row.get(4)?,
|
||||||
|
age: row.get(5)?,
|
||||||
|
address: Address {
|
||||||
|
street: row.get(6)?,
|
||||||
|
house_number: row.get(7)?,
|
||||||
|
postal_code: row.get(8)?,
|
||||||
|
city: row.get(9)?,
|
||||||
|
country: row.get(10)?,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
clerks.push(clerk);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(clerks)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue