Skip to content

Commit

Permalink
Programmati Units Update
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnakamura committed Sep 27, 2023
1 parent dbdba9b commit 980fdef
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 29 deletions.
44 changes: 44 additions & 0 deletions src/Contracts/Resources/RealEstateDevelopments/UnitContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Bildvitta\IssProduto\Contracts\Resources\RealEstateDevelopments;

use Illuminate\Http\Client\RequestException;

interface UnitContract
{
/**
* @const string
*/
public const ENDPOINT_PREFIX = '/real-estate-developments/%s';

/**
* @const string
*/
public const ENDPOINT_INDEX = self::ENDPOINT_PREFIX.'/units';

/**
* @const string
*/
public const ENDPOINT_UPDATE = self::ENDPOINT_PREFIX.'/units/%s';

/**
* @param string $realEstateDevelopment
* @param array $query
*
* @return object
*
* @throws RequestException
*/
public function get(string $realEstateDevelopment, array $query = []): object;

/**
* @param string $realEstateDevelopment
* @param string $unit
* @param array $query
*
* @return object
*
* @throws RequestException
*/
public function update(string $realEstateDevelopment, string $unit, array $data = []): object;
}
52 changes: 52 additions & 0 deletions src/Resources/RealEstateDevelopments/UnitResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Bildvitta\IssProduto\Resources\RealEstateDevelopments;

use Bildvitta\IssProduto\Contracts\Resources\RealEstateDevelopments\UnitContract;
use Illuminate\Http\Client\RequestException;

class UnitResource extends BaseResource implements UnitContract
{
/**
* @param string $realEstateDevelopment
* @param array $query
*
* @return object
*
* @throws RequestException
*/
public function get(string $realEstateDevelopment, array $query = []): object
{
$endpoint = self::ENDPOINT_INDEX;
if ($this->issProduto->getProgrammatic()) {
$endpoint = '/programmatic' . $endpoint;
}

return $this->issProduto->request
->get(vsprintf($endpoint, [$realEstateDevelopment]), $query)
->throw()
->object();
}

/**
* @param string $realEstateDevelopment
* @param string $unit
* @param array $query
*
* @return object
*
* @throws RequestException
*/
public function update(string $realEstateDevelopment, string $unit, array $data = []): object
{
$endpoint = self::ENDPOINT_UPDATE;
if ($this->issProduto->getProgrammatic()) {
$endpoint = '/programmatic' . $endpoint;
}

return $this->issProduto->request
->put(vsprintf($endpoint, [$realEstateDevelopment, $unit]), $data)
->throw()
->object();
}
}
38 changes: 9 additions & 29 deletions src/Resources/RealStateDevelopmentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Bildvitta\IssProduto\Contracts\Resources\RealStateDevelopmentContract;
use Bildvitta\IssProduto\IssProduto;
use Bildvitta\IssProduto\Resources\RealEstateDevelopments\BlueprintResource;
use Bildvitta\IssProduto\Resources\RealEstateDevelopments\UnitResource;
use Bildvitta\IssProduto\Resources\RealEstateDevelopments\CharacteristicResource;
use Bildvitta\IssProduto\Resources\RealEstateDevelopments\MirrorResource;
use Bildvitta\IssProduto\Resources\RealEstateDevelopments\StageResource;
Expand Down Expand Up @@ -73,6 +74,14 @@ public function blueprints(): BlueprintResource
return new BlueprintResource($this->issProduto);
}

/**
* @return UnitResource
*/
public function units(): UnitResource
{
return new UnitResource($this->issProduto);
}

/**
* @param array $query
* @param array $body
Expand Down Expand Up @@ -119,33 +128,4 @@ public function update(string $uuid, array $data = []): object
{
return $this->issProduto->request->put(vsprintf(self::ENDPOINT_FIND_BY_UUID, [$uuid]), $data)->throw()->object();
}

/**
* @param string $uuid
* @param array $query
*
* @return object
*
* @throws RequestException
*/
public function unities(string $uuid, array $query = [])
{
return $this->issProduto->request->get(vsprintf(self::ENDPOINT_UNIT_PREFIX, [$uuid]), $query)->throw()->object();
}

/**
* @param string $realEstateDevelopment
* @param array $data
*
* @return object
*
* @throws RequestException
*/
public function updateUnit(string $realEstateDevelopment, array $data = [])
{
return $this->issProduto->request->put(
vsprintf(self::ENDPOINT_UNIT_PREFIX, [$realEstateDevelopment]),
['data' => $data]
)->throw()->object();
}
}

0 comments on commit 980fdef

Please sign in to comment.