features, cleanup and bug fixes #26

Merged
ben merged 30 commits from ben/Jobboerse:main into main 2022-06-09 17:36:55 +02:00
5 changed files with 89 additions and 80 deletions
Showing only changes of commit c33b855568 - Show all commits

refactor some route-handlers in separate and better named files

Bennet Bleßmann 2022-05-30 22:44:42 +02:00 committed by Bennet Bleßmann
Signed by: ben
GPG key ID: 3BE1A1A3CBC3CF99

View file

@ -21,13 +21,16 @@ use tempfile::NamedTempFile;
use tokio::sync::{Mutex, RwLock, RwLockMappedWriteGuard, RwLockReadGuard, RwLockWriteGuard};
use toml::value::{Datetime, Offset};
use crate::auth::User;
use crate::error::PresentationError;
use crate::job_offers::error::SaveError;
use crate::route::{JOBOFFER_ATTACHMENT_ROUTE, PREVIEW_ATTACHMENT_ROUTE};
use crate::route::{JOBOFFER_DELETION_ROUTE, JOBOFFER_PUBLISH_ROUTE, JOBOFFER_UNPUBLISH_ROUTE};
use crate::util::{toml_date_to_chrono_date, toml_datetime_to_chrono_datetime};
use crate::ServerConfig;
use crate::{
auth::User,
error::PresentationError,
job_offers::error::SaveError,
route::JOBOFFER_DELETION_ROUTE,
route::{JOBOFFER_ATTACHMENT_ROUTE, PREVIEW_ATTACHMENT_ROUTE},
route::{JOBOFFER_PUBLISH_ROUTE, JOBOFFER_UNPUBLISH_ROUTE},
util::{toml_date_to_chrono_date, toml_datetime_to_chrono_datetime},
ServerConfig,
};
pub(crate) mod error;
@ -593,7 +596,7 @@ impl JobOffer<PathBuf> {
.attachments
.iter()
.map(|attachment| {
let location = match (is_preview, confirmation_token) {
let location = match (is_preview && !self.is_published(), confirmation_token) {
(false, _) => req
.url_for(
JOBOFFER_ATTACHMENT_ROUTE,

View file

@ -16,15 +16,15 @@ mod license;
pub(crate) use auth::{LOGIN_ROUTE, LOGOUT_ROUTE};
pub(crate) use job_offer::{
action::{JOBOFFER_DELETION_ROUTE, JOBOFFER_PUBLISH_ROUTE, JOBOFFER_UNPUBLISH_ROUTE},
create::JOBOFFER_CREATION_ROUTE,
delete::{JOBOFFER_BULK_DELETE_ROUTE, JOBOFFER_DELETE_EXPIRED_ROUTE, JOBOFFER_DELETION_ROUTE},
review::{JOBOFFER_PUBLISH_ROUTE, JOBOFFER_UNPUBLISH_ROUTE},
JOBOFFER_ATTACHMENT_ROUTE, JOBOFFER_OVERVIEW_ROUTE, JOBOFFER_SUMMARY_ROUTE,
JOBOFFER_SYNC_ROUTE, PREVIEW_ATTACHMENT_ROUTE,
};
pub(crate) use license::{LICENSES_ROUTE, LICENSE_BUNDLE};
use crate::error::PresentationError;
use crate::route::job_offer::action::{JOBOFFER_BULK_DELETE_ROUTE, JOBOFFER_DELETE_EXPIRED_ROUTE};
use crate::server_config::OperationMode;
use crate::server_config::ServerConfig;

View file

@ -9,10 +9,11 @@ use http::header::CONTENT_TYPE;
use serde::Deserialize;
use serde_json::json;
pub(crate) mod action;
pub(crate) mod confirmation;
pub(crate) mod create;
pub(crate) mod delete;
pub(crate) mod error;
pub(crate) mod review;
use crate::auth::User;
use crate::error::PresentationError;
@ -31,11 +32,11 @@ pub fn configure(service: &mut ServiceConfig) {
.service(confirmation::confirm_joboffer_get)
.service(confirmation::confirm_joboffer_post)
.service(confirmation::reject_joboffer_post)
.service(action::delete_joboffer)
.service(action::bulk_delete)
.service(action::delete_expired_joboffers)
.service(action::review_joboffer)
.service(action::unpublish_joboffer)
.service(delete::delete_joboffer)
.service(delete::bulk_delete)
.service(delete::delete_expired_joboffers)
.service(review::review_joboffer)
.service(review::unpublish_joboffer)
.service(job_offer_attachment)
.service(preview_attachment)
.service(sync);

View file

@ -1,16 +1,15 @@
use crate::auth::User;
use crate::error::PresentationError;
use crate::route::job_offer::error::DeletionResponseError;
use crate::route::{HTML_CONTENT, JOBOFFER_OVERVIEW_ROUTE};
use crate::{auth, get, template, JobOffers, ServerConfig};
use actix_session::Session;
use actix_web::{get, http, post, web, HttpRequest, HttpResponse};
use actix_web::{post, web, HttpRequest, HttpResponse};
use handlebars::Handlebars;
use log::debug;
use serde::{Deserialize, Deserializer};
use serde_json::json;
use crate::auth::User;
use crate::error::PresentationError;
use crate::route::job_offer::error::{DeletionResponseError, StateChangeResponseError};
use crate::route::{HTML_CONTENT, JOBOFFER_OVERVIEW_ROUTE};
use crate::{auth, template, JobOffers, ServerConfig};
pub(crate) const JOBOFFER_DELETION_ROUTE: &str = "joboffer_delete";
#[post("/{id}/delete", name = "joboffer_delete")]
@ -147,60 +146,3 @@ pub(crate) async fn bulk_delete(
.insert_header((http::header::LOCATION, dest.to_string()))
.finish())
}
pub(crate) const JOBOFFER_PUBLISH_ROUTE: &str = "review_offer";
#[post("/{id}/review", name = "review_offer")]
pub(crate) async fn review_joboffer(
req: HttpRequest,
path: web::Path<String>,
session: Session,
config: web::Data<ServerConfig>,
offers: web::Data<JobOffers>,
) -> actix_web::Result<HttpResponse, StateChangeResponseError> {
// TODO return the user to a page where they are asked to confirm publishing
// aka. the get variant of this route
let _user = auth::User::current(&session)?;
let id = path.into_inner();
if let Some(mut entry) = offers.get_offer_mut(&id, &config).await {
entry.mark_as_reviewed();
entry.try_clean().await?;
}
let dest = req.url_for_static(JOBOFFER_OVERVIEW_ROUTE)?;
Ok(HttpResponse::SeeOther()
.insert_header((http::header::LOCATION, dest.to_string()))
.finish())
}
pub(crate) const JOBOFFER_UNPUBLISH_ROUTE: &str = "unreview_offer";
#[post("/{id}/unreview", name = "unreview_offer")]
pub(crate) async fn unpublish_joboffer(
req: HttpRequest,
path: web::Path<String>,
session: Session,
config: web::Data<ServerConfig>,
offers: web::Data<JobOffers>,
) -> actix_web::Result<HttpResponse, StateChangeResponseError> {
// TODO return the user to a page where they are asked to confirm un-publishing
// aka. the get variant of this route
let _user = auth::User::current(&session)?;
let id = path.into_inner();
if let Some(mut entry) = offers.get_offer_mut(&id, &config).await {
entry.unmark_as_reviewed();
entry.try_clean().await?;
}
let dest = req
.url_for_static(JOBOFFER_OVERVIEW_ROUTE)
.expect("overview exists");
Ok(HttpResponse::SeeOther()
.insert_header((http::header::LOCATION, dest.to_string()))
.finish())
}

View file

@ -0,0 +1,63 @@
use actix_session::Session;
use actix_web::{http, post, web, HttpRequest, HttpResponse};
use crate::route::job_offer::error::StateChangeResponseError;
use crate::route::JOBOFFER_OVERVIEW_ROUTE;
use crate::{auth, JobOffers, ServerConfig};
pub(crate) const JOBOFFER_PUBLISH_ROUTE: &str = "review_offer";
#[post("/{id}/review", name = "review_offer")]
pub(crate) async fn review_joboffer(
req: HttpRequest,
path: web::Path<String>,
session: Session,
config: web::Data<ServerConfig>,
offers: web::Data<JobOffers>,
) -> actix_web::Result<HttpResponse, StateChangeResponseError> {
// TODO return the user to a page where they are asked to confirm publishing
// aka. the get variant of this route
let _user = auth::User::current(&session)?;
let id = path.into_inner();
if let Some(mut entry) = offers.get_offer_mut(&id, &config).await {
entry.mark_as_reviewed();
entry.try_clean().await?;
}
let dest = req.url_for_static(JOBOFFER_OVERVIEW_ROUTE)?;
Ok(HttpResponse::SeeOther()
.insert_header((http::header::LOCATION, dest.to_string()))
.finish())
}
pub(crate) const JOBOFFER_UNPUBLISH_ROUTE: &str = "unreview_offer";
#[post("/{id}/unreview", name = "unreview_offer")]
pub(crate) async fn unpublish_joboffer(
req: HttpRequest,
path: web::Path<String>,
session: Session,
config: web::Data<ServerConfig>,
offers: web::Data<JobOffers>,
) -> actix_web::Result<HttpResponse, StateChangeResponseError> {
// TODO return the user to a page where they are asked to confirm un-publishing
// aka. the get variant of this route
let _user = auth::User::current(&session)?;
let id = path.into_inner();
if let Some(mut entry) = offers.get_offer_mut(&id, &config).await {
entry.unmark_as_reviewed();
entry.try_clean().await?;
}
let dest = req
.url_for_static(JOBOFFER_OVERVIEW_ROUTE)
.expect("overview exists");
Ok(HttpResponse::SeeOther()
.insert_header((http::header::LOCATION, dest.to_string()))
.finish())
}