got into a heated debate about the correctness of this logic that i wrote
#[post("")]
async fn sign_up(
db: Data<mongodb::Database>,
http_client: Data<reqwest::Client>,
payload: Json<SignUpPayload>,
) -> Response {
let SignUpPayload {
username,
password,
email,
captcha_tokens,
} = &payload.0;
if !captcha::are_tokens_valid(&http_client, captcha_tokens).await? {
unauthorized!();
}
if User::exists_with_username(&db, username).await? {
forbidden!("username is being used");
}
if User::exists_with_email(&db, email).await? {
forbidden!("email is being used");
}
QueuedRegistration::builder()
.username(username)
.hashed_password(&hash::apply(password)?)
.email(email)
.build(&db)
.await?;
ok!();
}
User & QueuedRegistration being database models, and the post request handler being the controller
according to the guy i was arguing with, he claimed that the logic that i'm handling inside of the controller shouldn't be in the controller since it makes it "unmaintainable" and i was left pretty dumbfounded.
it may just be me, but this seems pretty damn maintainable?
just looking for some second opinions here