mirror of
https://github.com/standardebooks/web.git
synced 2025-07-20 22:33:57 -04:00
Allow editing of projects
This commit is contained in:
parent
e21f411191
commit
b2191d1219
16 changed files with 191 additions and 75 deletions
|
@ -4,6 +4,7 @@ try{
|
|||
session_start();
|
||||
|
||||
$httpMethod = HttpInput::ValidateRequestMethod([Enums\HttpMethod::Post, Enums\HttpMethod::Patch, Enums\HttpMethod::Put]);
|
||||
$exceptionRedirectUrl = '/projects/new';
|
||||
|
||||
if(Session::$User === null){
|
||||
throw new Exceptions\LoginRequiredException();
|
||||
|
@ -26,6 +27,20 @@ try{
|
|||
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||
header('Location: /projects');
|
||||
}
|
||||
|
||||
// PUTing a `Project`.
|
||||
if($httpMethod == Enums\HttpMethod::Put){
|
||||
$project = Project::Get(HttpInput::Int(GET, 'project-id'));
|
||||
$exceptionRedirectUrl = $project->EditUrl;
|
||||
|
||||
$project->FillFromHttpPost();
|
||||
|
||||
$project->Save();
|
||||
|
||||
$_SESSION['is-project-saved'] = true;
|
||||
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||
header('Location: ' . $project->Ebook->Url);
|
||||
}
|
||||
}
|
||||
catch(Exceptions\EbookNotFoundException){
|
||||
Template::ExitWithCode(Enums\HttpCode::NotFound);
|
||||
|
@ -41,5 +56,5 @@ catch(Exceptions\InvalidProjectException | Exceptions\ProjectExistsException | E
|
|||
$_SESSION['exception'] = $ex;
|
||||
|
||||
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||
header('Location: /projects/new');
|
||||
header('Location: ' . $exceptionRedirectUrl);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue