Skip to content

Commit 7c44339

Browse files
authored
Merge pull request #24 from felix1251/develop
Develop
2 parents 17a78c3 + 38feccf commit 7c44339

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/routes/auth/handlers.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct SignInParams {
3535
pub struct InvalidCredentials {
3636
#[schema(example = 404)]
3737
pub status: u16,
38-
#[schema(example = "Invalid credentials")]
38+
#[schema(example = "INVALID_CREDENTIALS")]
3939
pub message: String,
4040
}
4141

@@ -45,9 +45,10 @@ pub struct InvalidCredentials {
4545
tag = "Auth",
4646
path = "/auth/sign_in",
4747
responses(
48-
(status = 200, description = "Token Response", body = AuthTokens),
49-
(status = 404, description = "Invalid Credentials", body = InvalidCredentials),
50-
(status = 500, description = "Internal Server Error", body = InternalErrorSchema),
48+
(status = 200, description = "Token response", body = AuthTokens),
49+
(status = 404, description = "Invalid credentials", body = InvalidCredentials),
50+
(status = 422, description = "Request body validation errors", body = ValidationErrorSchema),
51+
(status = 500, description = "Internal server error", body = InternalErrorSchema),
5152
)
5253
)]
5354
pub async fn sign_in(
@@ -65,18 +66,16 @@ pub async fn sign_in(
6566
.filter(users::Column::Email.eq(sign_in_params.email))
6667
.one(&db)
6768
.await
68-
.map_err(|_err| {
69-
AppError::new(StatusCode::INTERNAL_SERVER_ERROR, "INTERNAL_SERVER_ERROR")
70-
})?;
69+
.map_err(|_err| AppError::new(StatusCode::NOT_FOUND, "INVALID_CREDENTIALS"))?;
7170

7271
if let Some(user) = db_user {
7372
if !verify_password(sign_in_params.password, &user.encrypted_password)? {
74-
return Err(AppError::new(StatusCode::NOT_FOUND, "Invalid Credentials"));
73+
return Err(AppError::new(StatusCode::NOT_FOUND, "INVALID_CREDENTIALS"));
7574
}
7675
let token = create_jwt(user.id)?;
7776
return Ok(Json(token));
7877
}
79-
return Err(AppError::new(StatusCode::NOT_FOUND, "Invalid Credentials"));
78+
return Err(AppError::new(StatusCode::NOT_FOUND, "INVALID_CREDENTIALS"));
8079
}
8180

8281
#[derive(Serialize, Deserialize, Validate, ToSchema)]
@@ -101,8 +100,8 @@ pub struct SignUpParams {
101100
path = "/auth/sign_up",
102101
responses(
103102
(status = 201, description = "User created with token response", body = AuthTokens),
104-
(status = 422, description = "Validation Errors", body = ValidationErrorSchema),
105-
(status = 500, description = "Internal Server Error", body = InternalErrorSchema),
103+
(status = 422, description = "Request body validation errors", body = ValidationErrorSchema),
104+
(status = 500, description = "Internal server error", body = InternalErrorSchema),
106105
)
107106
)]
108107
pub async fn sign_up(
@@ -188,9 +187,9 @@ pub struct CurrentUser {
188187
tag = "Auth",
189188
path = "/auth/me",
190189
responses(
191-
(status = 200, description = "Current user", body = CurrentUser),
190+
(status = 200, description = "Current user info", body = CurrentUser),
192191
(status = 401, description = "Unauthenticated", body = UnauthorizedSchema),
193-
(status = 500, description = "Internal Server Error", body = InternalErrorSchema),
192+
(status = 500, description = "Internal server error", body = InternalErrorSchema),
194193
),
195194
security(("bearer_auth" = []))
196195
)]

0 commit comments

Comments
 (0)