Fixed supporting company missing endpoints
Change-Id: Ice705593bee17382a3423d438b9ae99bb4ee4460 Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
parent
25f429082d
commit
bb98dd2da5
|
@ -185,15 +185,12 @@ class ProjectSponsorshipType extends SilverstripeBaseModel implements IOrderable
|
|||
self::recalculateOrderForSelectable($this->supporting_companies, $value, $new_order);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
* @return SupportingCompany|null
|
||||
*/
|
||||
public function addSupportingCompany(Company $company):?SupportingCompany {
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('company', $company));
|
||||
$supporting_company = $this->supporting_companies->matching($criteria)->first();
|
||||
if($supporting_company) return $supporting_company;
|
||||
$supporting_company = new SupportingCompany();
|
||||
$supporting_company->setCompany($company);
|
||||
$supporting_company->setSponsorshipType($this);
|
||||
|
@ -202,6 +199,17 @@ class ProjectSponsorshipType extends SilverstripeBaseModel implements IOrderable
|
|||
return $supporting_company;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
* @return SupportingCompany|null
|
||||
*/
|
||||
public function getSupportingCompanyByCompany(Company $company):?SupportingCompany {
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('company', $company));
|
||||
$supporting_company = $this->supporting_companies->matching($criteria)->first();
|
||||
return !$supporting_company ? null : $supporting_company;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
*/
|
||||
|
|
|
@ -227,6 +227,11 @@ final class SponsoredProjectService
|
|||
if(is_null($company) || !$company instanceof Company)
|
||||
throw new EntityNotFoundException(sprintf("company %s not found.", $payload['company_id']));
|
||||
|
||||
$oldSupportingCompany = $projectSponsorshipType->getSupportingCompanyByCompany($company);
|
||||
if(!is_null($oldSupportingCompany)){
|
||||
throw new ValidationException(sprintf("Company %s already is a supporting company.", $payload['company_id']));
|
||||
}
|
||||
|
||||
$supportingCompany = $projectSponsorshipType->addSupportingCompany($company);
|
||||
|
||||
if (isset($payload['order']) && intval($payload['order']) != $supportingCompany->getOrder()) {
|
||||
|
|
|
@ -6178,6 +6178,14 @@ class ApiEndpointsSeeder extends Seeder
|
|||
sprintf(SponsoredProjectScope::Read, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-sponsored-project-supporting-companies',
|
||||
'route' => '/api/v1/sponsored-projects/{id}/sponsorship-types/{sponsorship_type_id}/supporting-companies',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
sprintf(SponsoredProjectScope::Write, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-sponsored-project-supporting-companies',
|
||||
'route' => '/api/v1/sponsored-projects/{id}/sponsorship-types/{sponsorship_type_id}/supporting-companies/{company_id}',
|
||||
|
|
Loading…
Reference in New Issue