@@ -8,17 +8,18 @@ use crate::models::response::OkResponse;
88pub fn init ( cfg : & mut web:: ServiceConfig ) {
99 cfg. service (
1010 web:: scope ( "/settings" )
11- . service (
12- web:: resource ( "" )
13- . route ( web:: get ( ) . to ( get_settings) )
14- . route ( web:: post ( ) . to ( update_settings_handler) ) ,
15- )
16- . service ( web:: resource ( "/name" ) . route ( web:: get ( ) . to ( get_site_name) ) )
17- . service ( web:: resource ( "/public" ) . route ( web:: get ( ) . to ( get_public_settings) ) ) ,
11+ . service ( web:: resource ( "" ) . route ( web:: get ( ) . to ( get) ) . route ( web:: post ( ) . to ( update) ) )
12+ . service ( web:: resource ( "/name" ) . route ( web:: get ( ) . to ( site_name) ) )
13+ . service ( web:: resource ( "/public" ) . route ( web:: get ( ) . to ( get_public) ) ) ,
1814 ) ;
1915}
2016
21- pub async fn get_settings ( req : HttpRequest , app_data : WebAppData ) -> ServiceResult < impl Responder > {
17+ /// Get Settings
18+ ///
19+ /// # Errors
20+ ///
21+ /// This function will return an error if unable to get user from database.
22+ pub async fn get ( req : HttpRequest , app_data : WebAppData ) -> ServiceResult < impl Responder > {
2223 // check for user
2324 let user = app_data. auth . get_user_compact_from_request ( & req) . await ?;
2425
@@ -32,13 +33,23 @@ pub async fn get_settings(req: HttpRequest, app_data: WebAppData) -> ServiceResu
3233 Ok ( HttpResponse :: Ok ( ) . json ( OkResponse { data : & * settings } ) )
3334}
3435
35- pub async fn get_public_settings ( app_data : WebAppData ) -> ServiceResult < impl Responder > {
36+ /// Get Public Settings
37+ ///
38+ /// # Errors
39+ ///
40+ /// This function should not return an error.
41+ pub async fn get_public ( app_data : WebAppData ) -> ServiceResult < impl Responder > {
3642 let public_settings = app_data. cfg . get_public ( ) . await ;
3743
3844 Ok ( HttpResponse :: Ok ( ) . json ( OkResponse { data : public_settings } ) )
3945}
4046
41- pub async fn get_site_name ( app_data : WebAppData ) -> ServiceResult < impl Responder > {
47+ /// Get Name of Website
48+ ///
49+ /// # Errors
50+ ///
51+ /// This function should not return an error.
52+ pub async fn site_name ( app_data : WebAppData ) -> ServiceResult < impl Responder > {
4253 let settings = app_data. cfg . settings . read ( ) . await ;
4354
4455 Ok ( HttpResponse :: Ok ( ) . json ( OkResponse {
@@ -55,7 +66,7 @@ pub async fn get_site_name(app_data: WebAppData) -> ServiceResult<impl Responder
5566/// - There is no logged-in user.
5667/// - The user is not an administrator.
5768/// - The settings could not be updated because they were loaded from env vars.
58- pub async fn update_settings_handler (
69+ pub async fn update (
5970 req : HttpRequest ,
6071 payload : web:: Json < config:: TorrustBackend > ,
6172 app_data : WebAppData ,
0 commit comments