Skip to content

Commit 1b8d9b9

Browse files
committed
chg: Renamed some structs
1 parent 9a8c4f5 commit 1b8d9b9

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

actix/src/auth.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,29 @@ use crate::config::Config;
1313

1414
// Define JSON struct for error response
1515
#[derive(Serialize)]
16-
pub struct APIResponse {
16+
pub struct APIVerification {
1717
pub success: bool,
1818
pub error: bool,
1919
reason: String,
2020
pass: bool,
2121
}
2222

2323
// If the api_key environment variable exists
24-
pub fn is_api_ok(http: HttpRequest, config: &Config) -> APIResponse {
24+
pub fn is_api_ok(http: HttpRequest, config: &Config) -> APIVerification {
2525
// If the api_key environment variable exists
2626
if config.api_key.is_some() {
2727
// If the header exists
2828
if let Some(header) = get_api_header(&http) {
2929
// If the header is correct
3030
if is_key_valid(header, config) {
31-
APIResponse {
31+
APIVerification {
3232
success: true,
3333
error: false,
3434
reason: "Correct API key".to_string(),
3535
pass: false,
3636
}
3737
} else {
38-
APIResponse {
38+
APIVerification {
3939
success: false,
4040
error: true,
4141
reason: "Incorrect API key".to_string(),
@@ -46,7 +46,7 @@ pub fn is_api_ok(http: HttpRequest, config: &Config) -> APIResponse {
4646
// Further authentication checks will be conducted in services.rs
4747
} else {
4848
// Due to the implementation of this result in services.rs, this JSON object will not be outputted.
49-
APIResponse {
49+
APIVerification {
5050
success: false,
5151
error: false,
5252
reason: "No valid authentication was found".to_string(),
@@ -56,14 +56,14 @@ pub fn is_api_ok(http: HttpRequest, config: &Config) -> APIResponse {
5656
} else {
5757
// If the API key isn't set, but an API Key header is provided
5858
if get_api_header(&http).is_some() {
59-
APIResponse {
59+
APIVerification {
6060
success: false,
6161
error: true,
6262
reason: "An API key was provided, but the 'api_key' environment variable is not configured in the Chhoto URL instance".to_string(),
6363
pass: false
6464
}
6565
} else {
66-
APIResponse {
66+
APIVerification {
6767
success: false,
6868
error: false,
6969
reason: "".to_string(),

actix/src/services.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum ChhotoError {
3131

3232
// Define JSON struct for returning success/error data
3333
#[derive(Serialize)]
34-
struct Response {
34+
struct JSONResponse {
3535
success: bool,
3636
error: bool,
3737
reason: String,
@@ -115,15 +115,15 @@ pub async fn add_link(
115115
HttpResponse::Created().json(response)
116116
}
117117
Err(ServerError) => {
118-
let response = Response {
118+
let response = JSONResponse {
119119
success: false,
120120
error: true,
121121
reason: "Something went wrong when adding the link.".to_string(),
122122
};
123123
HttpResponse::InternalServerError().json(response)
124124
}
125125
Err(ClientError { reason }) => {
126-
let response = Response {
126+
let response = JSONResponse {
127127
success: false,
128128
error: true,
129129
reason,
@@ -192,15 +192,15 @@ pub async fn expand(req: String, data: web::Data<AppState>, http: HttpRequest) -
192192
HttpResponse::Ok().json(body)
193193
}
194194
Err(ServerError) => {
195-
let body = Response {
195+
let body = JSONResponse {
196196
success: false,
197197
error: true,
198198
reason: "Something went wrong when finding the link.".to_string(),
199199
};
200200
HttpResponse::BadRequest().json(body)
201201
}
202202
Err(ClientError { reason }) => {
203-
let body = Response {
203+
let body = JSONResponse {
204204
success: false,
205205
error: true,
206206
reason,
@@ -226,23 +226,23 @@ pub async fn edit_link(
226226
if result.success || is_session_valid(session, config) {
227227
match utils::edit_link(&req, &data.db, config) {
228228
Ok(()) => {
229-
let body = Response {
229+
let body = JSONResponse {
230230
success: true,
231231
error: false,
232232
reason: String::from("Edit was successful."),
233233
};
234234
HttpResponse::Created().json(body)
235235
}
236236
Err(ServerError) => {
237-
let body = Response {
237+
let body = JSONResponse {
238238
success: false,
239239
error: true,
240240
reason: "Something went wrong when editing the link.".to_string(),
241241
};
242242
HttpResponse::InternalServerError().json(body)
243243
}
244244
Err(ClientError { reason }) => {
245-
let body = Response {
245+
let body = JSONResponse {
246246
success: false,
247247
error: true,
248248
reason,
@@ -377,7 +377,7 @@ pub async fn login(req: String, session: Session, data: web::Data<AppState>) ->
377377
if let Some(valid_pass) = authorized {
378378
if !valid_pass {
379379
warn!("Failed login attempt!");
380-
let response = Response {
380+
let response = JSONResponse {
381381
success: false,
382382
error: true,
383383
reason: "Wrong password!".to_string(),
@@ -390,7 +390,7 @@ pub async fn login(req: String, session: Session, data: web::Data<AppState>) ->
390390
.insert("chhoto-url-auth", auth::gen_token())
391391
.expect("Error inserting auth token.");
392392

393-
let response = Response {
393+
let response = JSONResponse {
394394
success: true,
395395
error: false,
396396
reason: "Correct password!".to_string(),
@@ -442,23 +442,23 @@ pub async fn delete_link(
442442
if result.success {
443443
match utils::delete_link(&shortlink, &data.db, data.config.allow_capital_letters) {
444444
Ok(()) => {
445-
let response = Response {
445+
let response = JSONResponse {
446446
success: true,
447447
error: false,
448448
reason: format!("Deleted {shortlink}"),
449449
};
450450
HttpResponse::Ok().json(response)
451451
}
452452
Err(ServerError) => {
453-
let response = Response {
453+
let response = JSONResponse {
454454
success: false,
455455
error: true,
456456
reason: "Something went wrong when deleting the link.".to_string(),
457457
};
458458
HttpResponse::InternalServerError().json(response)
459459
}
460460
Err(ClientError { reason }) => {
461-
let response = Response {
461+
let response = JSONResponse {
462462
success: false,
463463
error: true,
464464
reason,

0 commit comments

Comments
 (0)