Update bookable room field types from float to int (

bc stripes use int)

Change-Id: I15d3d9be2e46f9fd253feda94fbedf1db975948d
This commit is contained in:
smarcet 2019-06-30 14:49:36 -03:00
parent 61eab29443
commit 5d209e8a36
12 changed files with 108 additions and 42 deletions

View File

@ -28,7 +28,7 @@ final class SummitRoomReservationValidationRulesFactory
return [ return [
'currency' => 'required|string|currency_iso', 'currency' => 'required|string|currency_iso',
'amount' => 'required|integer', 'amount' => 'required|integer|greater_than:0',
'start_datetime' => 'required|date_format:U', 'start_datetime' => 'required|date_format:U',
'end_datetime' => 'required|date_format:U|after:start_datetime', 'end_datetime' => 'required|date_format:U|after:start_datetime',
]; ];

View File

@ -29,7 +29,7 @@ final class SummitVenueBookableRoomValidationRulesFactory
return array_merge([ return array_merge([
'capacity' => 'required|integer:min:0', 'capacity' => 'required|integer:min:0',
'time_slot_cost' => 'required|numeric', 'time_slot_cost' => 'required|integer|greater_than:0',
'currency' => 'required|string|currency_iso', 'currency' => 'required|string|currency_iso',
], $rules); ], $rules);
} }

View File

@ -962,7 +962,7 @@ trait SummitBookableVenueRoomApi
if(!Request::isJson()) return $this->error400(); if(!Request::isJson()) return $this->error400();
$payload = Input::json()->all(); $payload = Input::json()->all();
$rules = [ $rules = [
'amount' => 'required|numeric', 'amount' => 'required|integer|greater_than:0',
]; ];
// Creates a Validator instance and validates the data. // Creates a Validator instance and validates the data.

View File

@ -21,7 +21,7 @@ use ModelSerializers\SerializerRegistry;
class SummitBookableVenueRoomSerializer extends SummitVenueRoomSerializer class SummitBookableVenueRoomSerializer extends SummitVenueRoomSerializer
{ {
protected static $array_mappings = [ protected static $array_mappings = [
'TimeSlotCost' => 'time_slot_cost:json_float', 'TimeSlotCost' => 'time_slot_cost:json_int',
'Currency' => 'currency:json_string', 'Currency' => 'currency:json_string',
]; ];

View File

@ -240,7 +240,7 @@ final class SummitLocationFactory
self::populateSummitVenueRoom($room, $data); self::populateSummitVenueRoom($room, $data);
if(isset($data['time_slot_cost'])) if(isset($data['time_slot_cost']))
$room->setTimeSlotCost(floatval($data['time_slot_cost'])); $room->setTimeSlotCost(intval($data['time_slot_cost']));
if(isset($data['currency'])) if(isset($data['currency']))
$room->setCurrency(trim($data['currency'])); $room->setCurrency(trim($data['currency']));

View File

@ -11,7 +11,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
use Eluceo\iCal\Component\Timezone; use Eluceo\iCal\Component\Timezone;
use models\summit\Summit; use models\summit\Summit;
use models\summit\SummitRoomReservation; use models\summit\SummitRoomReservation;
@ -33,10 +32,10 @@ final class SummitRoomReservationFactory
if(isset($data['currency'])) if(isset($data['currency']))
$reservation->setCurrency(trim($data['currency'])); $reservation->setCurrency(trim($data['currency']));
if(isset($data['amount'])) 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 // dates ( they came on local time epoch , so must be converted to utc using
// summit timezone // summit timezonefloatval
if(isset($data['start_datetime'])) { if(isset($data['start_datetime'])) {
$val = intval($data['start_datetime']); $val = intval($data['start_datetime']);
$val = new \DateTime("@$val"); $val = new \DateTime("@$val");

View File

@ -27,8 +27,8 @@ class SummitBookableVenueRoom extends SummitVenueRoom
const ClassName = 'SummitBookableVenueRoom'; const ClassName = 'SummitBookableVenueRoom';
/** /**
* @ORM\Column(name="TimeSlotCost", type="decimal") * @ORM\Column(name="TimeSlotCost", type="integer")
* @var float * @var int
*/ */
private $time_slot_cost; 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; $this->time_slot_cost = $time_slot_cost;
} }

View File

@ -77,13 +77,13 @@ class SummitRoomReservation extends SilverstripeBaseModel
/** /**
* @var float * @var float
* @ORM\Column(name="Amount", type="float") * @ORM\Column(name="Amount", type="integer")
*/ */
private $amount; private $amount;
/** /**
* @var float * @var float
* @ORM\Column(name="RefundedAmount", type="float") * @ORM\Column(name="RefundedAmount", type="integer")
*/ */
private $refunded_amount; 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->status = self::RefundedStatus;
$this->refunded_amount = $amount; $this->refunded_amount = $amount;
Event::fire(new BookableRoomReservationRefundAccepted($this->getId())); 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; return $this->amount;
} }
/** /**
* @param float $amount * @param int $amount
*/ */
public function setAmount(float $amount): void public function setAmount(int $amount): void
{ {
$this->amount = $amount; $this->amount = $amount;
} }
@ -289,7 +289,8 @@ class SummitRoomReservation extends SilverstripeBaseModel
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
$this->amount = 0.0; $this->amount = 0;
$this->refunded_amount = 0;
$this->status = self::ReservedStatus; $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; return $this->refunded_amount;
} }
/**
* @param float $refunded_amount
*/
public function setRefundedAmount(float $refunded_amount): void
{
$this->refunded_amount = $refunded_amount;
}
} }

View File

@ -614,10 +614,12 @@ class AppServiceProvider extends ServiceProvider
$value = trim($value); $value = trim($value);
return isset($currencies[$value]); return isset($currencies[$value]);
}); });
Validator::extend('greater_than', function ($attribute, $value, $otherValue) {
return intval($value) > intval($otherValue[0]);
});
} }
/** /**
* Register any application services. * Register any application services.
* @return void * @return void

View File

@ -1717,13 +1717,30 @@ final class SummitLocationService
$currency = trim($payload['currency']); $currency = trim($payload['currency']);
if($room->getCurrency() != $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){ 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); $reservation = SummitRoomReservationFactory::build($summit, $payload);

View 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)
{
}
}

View File

@ -1429,15 +1429,16 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest
* @param int $start_date * @param int $start_date
* @return mixed * @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 = [ $params = [
'id' => $summit_id, 'id' => $summit_id,
'room_id' => $room_id, 'room_id' => $bookable_room->id,
]; ];
$data = [ $data = [
'currency' => 'USD', 'currency' => 'USD',
'amount' => 325, 'amount' => 200,
'start_datetime' => $start_date, 'start_datetime' => $start_date,
'end_datetime' => $end_date, 'end_datetime' => $end_date,
]; ];