Update bookable room field types from float to int (
bc stripes use int) Change-Id: I15d3d9be2e46f9fd253feda94fbedf1db975948d
This commit is contained in:
parent
61eab29443
commit
5d209e8a36
@ -28,7 +28,7 @@ final class SummitRoomReservationValidationRulesFactory
|
||||
|
||||
return [
|
||||
'currency' => 'required|string|currency_iso',
|
||||
'amount' => 'required|integer',
|
||||
'amount' => 'required|integer|greater_than:0',
|
||||
'start_datetime' => 'required|date_format:U',
|
||||
'end_datetime' => 'required|date_format:U|after:start_datetime',
|
||||
];
|
||||
|
@ -29,7 +29,7 @@ final class SummitVenueBookableRoomValidationRulesFactory
|
||||
|
||||
return array_merge([
|
||||
'capacity' => 'required|integer:min:0',
|
||||
'time_slot_cost' => 'required|numeric',
|
||||
'time_slot_cost' => 'required|integer|greater_than:0',
|
||||
'currency' => 'required|string|currency_iso',
|
||||
], $rules);
|
||||
}
|
||||
|
@ -962,7 +962,7 @@ trait SummitBookableVenueRoomApi
|
||||
if(!Request::isJson()) return $this->error400();
|
||||
$payload = Input::json()->all();
|
||||
$rules = [
|
||||
'amount' => 'required|numeric',
|
||||
'amount' => 'required|integer|greater_than:0',
|
||||
];
|
||||
|
||||
// Creates a Validator instance and validates the data.
|
||||
|
@ -21,7 +21,7 @@ use ModelSerializers\SerializerRegistry;
|
||||
class SummitBookableVenueRoomSerializer extends SummitVenueRoomSerializer
|
||||
{
|
||||
protected static $array_mappings = [
|
||||
'TimeSlotCost' => 'time_slot_cost:json_float',
|
||||
'TimeSlotCost' => 'time_slot_cost:json_int',
|
||||
'Currency' => 'currency:json_string',
|
||||
];
|
||||
|
||||
|
@ -240,7 +240,7 @@ final class SummitLocationFactory
|
||||
self::populateSummitVenueRoom($room, $data);
|
||||
|
||||
if(isset($data['time_slot_cost']))
|
||||
$room->setTimeSlotCost(floatval($data['time_slot_cost']));
|
||||
$room->setTimeSlotCost(intval($data['time_slot_cost']));
|
||||
|
||||
if(isset($data['currency']))
|
||||
$room->setCurrency(trim($data['currency']));
|
||||
|
@ -11,7 +11,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use Eluceo\iCal\Component\Timezone;
|
||||
use models\summit\Summit;
|
||||
use models\summit\SummitRoomReservation;
|
||||
@ -33,10 +32,10 @@ final class SummitRoomReservationFactory
|
||||
if(isset($data['currency']))
|
||||
$reservation->setCurrency(trim($data['currency']));
|
||||
if(isset($data['amount']))
|
||||
$reservation->setAmount(floatval($data['amount']));
|
||||
$reservation->setAmount(intval($data['amount']));
|
||||
|
||||
// dates ( they came on local time epoch , so must be converted to utc using
|
||||
// summit timezone
|
||||
// summit timezonefloatval
|
||||
if(isset($data['start_datetime'])) {
|
||||
$val = intval($data['start_datetime']);
|
||||
$val = new \DateTime("@$val");
|
||||
|
@ -27,8 +27,8 @@ class SummitBookableVenueRoom extends SummitVenueRoom
|
||||
const ClassName = 'SummitBookableVenueRoom';
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="TimeSlotCost", type="decimal")
|
||||
* @var float
|
||||
* @ORM\Column(name="TimeSlotCost", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $time_slot_cost;
|
||||
|
||||
@ -159,17 +159,17 @@ class SummitBookableVenueRoom extends SummitVenueRoom
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
* @return int
|
||||
*/
|
||||
public function getTimeSlotCost(): float
|
||||
public function getTimeSlotCost(): int
|
||||
{
|
||||
return floatval($this->time_slot_cost);
|
||||
return $this->time_slot_cost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $time_slot_cost
|
||||
* @param int $time_slot_cost
|
||||
*/
|
||||
public function setTimeSlotCost(float $time_slot_cost): void
|
||||
public function setTimeSlotCost(int $time_slot_cost): void
|
||||
{
|
||||
$this->time_slot_cost = $time_slot_cost;
|
||||
}
|
||||
|
@ -77,13 +77,13 @@ class SummitRoomReservation extends SilverstripeBaseModel
|
||||
|
||||
/**
|
||||
* @var float
|
||||
* @ORM\Column(name="Amount", type="float")
|
||||
* @ORM\Column(name="Amount", type="integer")
|
||||
*/
|
||||
private $amount;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
* @ORM\Column(name="RefundedAmount", type="float")
|
||||
* @ORM\Column(name="RefundedAmount", type="integer")
|
||||
*/
|
||||
private $refunded_amount;
|
||||
|
||||
@ -126,9 +126,9 @@ class SummitRoomReservation extends SilverstripeBaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amount
|
||||
* @param int $amount
|
||||
*/
|
||||
public function refund(float $amount){
|
||||
public function refund(int $amount){
|
||||
$this->status = self::RefundedStatus;
|
||||
$this->refunded_amount = $amount;
|
||||
Event::fire(new BookableRoomReservationRefundAccepted($this->getId()));
|
||||
@ -271,17 +271,17 @@ class SummitRoomReservation extends SilverstripeBaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
* @return int
|
||||
*/
|
||||
public function getAmount(): float
|
||||
public function getAmount(): int
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amount
|
||||
* @param int $amount
|
||||
*/
|
||||
public function setAmount(float $amount): void
|
||||
public function setAmount(int $amount): void
|
||||
{
|
||||
$this->amount = $amount;
|
||||
}
|
||||
@ -289,7 +289,8 @@ class SummitRoomReservation extends SilverstripeBaseModel
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->amount = 0.0;
|
||||
$this->amount = 0;
|
||||
$this->refunded_amount = 0;
|
||||
$this->status = self::ReservedStatus;
|
||||
}
|
||||
|
||||
@ -356,19 +357,11 @@ class SummitRoomReservation extends SilverstripeBaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
* @return int
|
||||
*/
|
||||
public function getRefundedAmount(): float
|
||||
public function getRefundedAmount(): int
|
||||
{
|
||||
return $this->refunded_amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $refunded_amount
|
||||
*/
|
||||
public function setRefundedAmount(float $refunded_amount): void
|
||||
{
|
||||
$this->refunded_amount = $refunded_amount;
|
||||
}
|
||||
|
||||
}
|
@ -614,10 +614,12 @@ class AppServiceProvider extends ServiceProvider
|
||||
$value = trim($value);
|
||||
return isset($currencies[$value]);
|
||||
});
|
||||
|
||||
Validator::extend('greater_than', function ($attribute, $value, $otherValue) {
|
||||
return intval($value) > intval($otherValue[0]);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
* @return void
|
||||
|
@ -1717,13 +1717,30 @@ final class SummitLocationService
|
||||
$currency = trim($payload['currency']);
|
||||
|
||||
if($room->getCurrency() != $currency){
|
||||
throw new ValidationException(sprintf("currency set %s is not allowed for room %s", $currency, $room->getId()));
|
||||
throw new ValidationException
|
||||
(
|
||||
sprintf
|
||||
(
|
||||
"currency set %s is not allowed for room %s",
|
||||
$currency,
|
||||
$room->getId()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$amount = floatval($payload['amount']);
|
||||
$amount = intval($payload['amount']);
|
||||
|
||||
if($room->getTimeSlotCost() != $amount){
|
||||
throw new ValidationException(sprintf("amount set %s does not match with time slot cost %s for room %s", $currency, $room->getTimeSlotCost(), $room->getId()));
|
||||
throw new ValidationException
|
||||
(
|
||||
sprintf
|
||||
(
|
||||
"amount set %s does not match with time slot cost %s for room %s",
|
||||
$amount,
|
||||
$room->getTimeSlotCost(),
|
||||
$room->getId()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$reservation = SummitRoomReservationFactory::build($summit, $payload);
|
||||
|
54
database/migrations/model/Version20190629222739.php
Normal file
54
database/migrations/model/Version20190629222739.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php namespace Database\Migrations\Model;
|
||||
/**
|
||||
* Copyright 2019 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema as Schema;
|
||||
use LaravelDoctrine\Migrations\Schema\Table;
|
||||
use LaravelDoctrine\Migrations\Schema\Builder;
|
||||
|
||||
/**
|
||||
* Class Version20190629222739
|
||||
* @package Database\Migrations\Model
|
||||
*/
|
||||
final class Version20190629222739 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
$builder = new Builder($schema);
|
||||
if($schema->hasTable("SummitRoomReservation")) {
|
||||
$builder->table('SummitRoomReservation', function (Table $table) {
|
||||
$table->dropColumn('RefundedAmount');
|
||||
$table->integer("RefundedAmount")->setDefault(0)->setNotnull(true);
|
||||
$table->dropColumn('Amount');
|
||||
$table->integer("Amount")->setDefault(0)->setNotnull(true);
|
||||
});
|
||||
}
|
||||
if($schema->hasTable("SummitBookableVenueRoom")) {
|
||||
$builder->table('SummitBookableVenueRoom', function (Table $table) {
|
||||
$table->dropColumn('TimeSlotCost');
|
||||
$table->integer("TimeSlotCost")->setDefault(0)->setNotnull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1429,15 +1429,16 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest
|
||||
* @param int $start_date
|
||||
* @return mixed
|
||||
*/
|
||||
public function testBookableRoomReservation($summit_id =27, $room_id = 922, $start_date = 1572919200, $end_date = 1572922800){
|
||||
public function testBookableRoomReservation($summit_id =27, $start_date = 1572919200, $end_date = 1572922800){
|
||||
$bookable_room = $this->testAddBookableRoom($summit_id);
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'room_id' => $room_id,
|
||||
'room_id' => $bookable_room->id,
|
||||
];
|
||||
|
||||
$data = [
|
||||
'currency' => 'USD',
|
||||
'amount' => 325,
|
||||
'amount' => 200,
|
||||
'start_datetime' => $start_date,
|
||||
'end_datetime' => $end_date,
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user