@@ -9,17 +9,17 @@ mod test_helpers;
99
1010use crate :: database:: {
1111 create_ticket, create_user, delete_ticket, edit_ticket, filter_tickets_in_database,
12- get_all_tickets, get_single_ticket, get_user_by_email, remove_session_from_db,
12+ get_all_tickets, get_all_users , get_single_ticket, get_user_by_email, remove_session_from_db,
1313 write_session_to_db, DataBase ,
1414} ;
1515use crate :: middleware:: validator;
1616use crate :: models:: { NewSession , NewUser , Ticket , TokenClaims } ;
1717use crate :: payloads:: { FilterPayload , LoginPayload , TicketPayload } ;
1818use crate :: status_messages:: {
1919 CANNOT_LOGOUT , ERROR_COULD_NOT_CREATE_TICKET , ERROR_COULD_NOT_CREATE_USER ,
20- ERROR_COULD_NOT_DELETE , ERROR_COULD_NOT_GET , ERROR_COULD_NOT_UPDATE , ERROR_INCORRECT_PASSWORD ,
21- ERROR_INVALID_ID , ERROR_NOT_FOUND , ERROR_NOT_LOGGED_IN , ERROR_NO_USER_FOUND ,
22- ERROR_USER_ALREADY_EXISTS , SUCCESS_LOGOUT ,
20+ ERROR_COULD_NOT_DELETE , ERROR_COULD_NOT_GET , ERROR_COULD_NOT_RETRIEVE_USERS ,
21+ ERROR_COULD_NOT_UPDATE , ERROR_INCORRECT_PASSWORD , ERROR_INVALID_ID , ERROR_NOT_FOUND ,
22+ ERROR_NOT_LOGGED_IN , ERROR_NO_USER_FOUND , ERROR_USER_ALREADY_EXISTS , SUCCESS_LOGOUT ,
2323} ;
2424use actix_cors:: Cors ;
2525use actix_web:: cookie:: time:: { Duration , OffsetDateTime } ;
@@ -54,7 +54,8 @@ async fn main() -> Result<()> {
5454 . service ( delete)
5555 . service ( edit)
5656 . service ( filter_tickets)
57- . service ( logout) ,
57+ . service ( logout)
58+ . service ( get_users) ,
5859 ) ,
5960 )
6061 } )
@@ -258,6 +259,16 @@ async fn login(payload: Json<LoginPayload>) -> impl Responder {
258259 }
259260}
260261
262+ #[ get( "/users" ) ]
263+ async fn get_users ( ) -> impl Responder {
264+ let mut database = DataBase :: new ( ) ;
265+
266+ match get_all_users ( & mut database. connection ) {
267+ Ok ( all_users) => HttpResponse :: Ok ( ) . json ( all_users) ,
268+ Err ( _) => HttpResponse :: InternalServerError ( ) . json ( ERROR_COULD_NOT_RETRIEVE_USERS ) ,
269+ }
270+ }
271+
261272/*
262273* To fully understand the tests and the test data,
263274* have a look at the setup_database function in test_helpers.rs.
0 commit comments