Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - filter invalid pp #5

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Response/DTO/ParcelShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ParcelShop
* @var Openings[]
*/
private array $openings = [];
private Coordinates $coordinates;
private ?Coordinates $coordinates;
private ?string $holidayStarts;
private ?string $holidayEnds;

Expand All @@ -43,7 +43,7 @@ public function __construct(
?string $info,
Address $address,
array $openings,
Coordinates $coordinates,
?Coordinates $coordinates,
?string $holidayStarts,
?string $holidayEnds
) {
Expand All @@ -70,6 +70,12 @@ public function __construct(
*/
public static function fromRawParcelShop(RawParcelShop $rawParcelShop, array $openings): self
{
$coordinates = null;

if (null !== $rawParcelShop->geolat && null !== $rawParcelShop->geolng) {
$coordinates = new Coordinates((float) $rawParcelShop->geolat, (float) $rawParcelShop->geolng);
}

return new self(
$rawParcelShop->pclshopid,
$rawParcelShop->name,
Expand All @@ -84,7 +90,7 @@ public static function fromRawParcelShop(RawParcelShop $rawParcelShop, array $op
$rawParcelShop->info,
Address::fromRawParcelShop($rawParcelShop),
$openings,
new Coordinates((float) $rawParcelShop->geolat, (float) $rawParcelShop->geolng),
$coordinates,
$rawParcelShop->holidaystarts,
$rawParcelShop->holidayends
);
Expand Down Expand Up @@ -158,7 +164,7 @@ public function getOpenings(): array
return $this->openings;
}

public function getCoordinates(): Coordinates
public function getCoordinates(): ?Coordinates
{
return $this->coordinates;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Response/DTO/RawParcelShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class RawParcelShop
public ?string $iscodhandler;
public ?string $paybybankcard;
public ?string $dropoffpoint;
public string $geolat;
public string $geolng;
public ?string $geolat;
public ?string $geolng;
public string $owner;
public ?string $isparcellocker;
public ?string $vendor_url;
Expand Down
6 changes: 5 additions & 1 deletion src/Service/ParcelShopsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public function getParcelShopCollection(

$parcelShopCollection = [];
foreach ($rawParcelShopCollection as $rawParcelShop) {
$openings = $this->getOpenings($rawParcelShop->pclshopid);
try {
$openings = $this->getOpenings($rawParcelShop->pclshopid);
} catch (\Throwable $throwable) {
$openings = [];
}

$parcelShop = ParcelShop::fromRawParcelShop($rawParcelShop, $openings);
$parcelShopCollection[] = $parcelShop;
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/Service/ParcelShopsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function assertOfficeSame(array $parcelShops): void
'email' => $address->getEmail(),
],
'openings' => $actualOpenings,
'coordinates' => [
'coordinates' => null === $parcelShop->getCoordinates() ? null : [
'latitude' => $parcelShop->getCoordinates()->latitude,
'longitude' => $parcelShop->getCoordinates()->longitude,
],
Expand All @@ -134,6 +134,7 @@ private function getLogger(array $parcelShops = []): LoggerInterface
'[GLS_BUNDLE] Request - /psmap/psmap_getdata.php?action=getList&ctrcode=SI&pclshopin=1&parcellockin=1',
'[GLS_BUNDLE] Response - /psmap/psmap_getdata.php?action=getList&ctrcode=SI&pclshopin=1&parcellockin=1',
];

foreach ($parcelShops as $parcelShop) {
$expected[] = '[GLS_BUNDLE] Request - /psmap/psmap_getdata.php?action=getOpenings&pclshopid=' . $parcelShop['pclshopid'];
$expected[] = '[GLS_BUNDLE] Response - /psmap/psmap_getdata.php?action=getOpenings&pclshopid=' . $parcelShop['pclshopid'];
Expand Down
36 changes: 28 additions & 8 deletions tests/Integration/Service/data/parcelShops.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,37 @@
"name": "OMV SLOVENIJA D.O.O.",
"ctrcode": "SI",
"zipcode": "6000",

"city": "KOPER",
"address": "Istrska cesta 53",
"contact": null,
"phone": null,
"email": null,

"iscodhandler": "t",
"paybybankcard": "t",
"dropoffpoint": "t",

"geolat": "45.539",
"geolng": "13.7287",
"owner": "GLS",
"isparcellocker": "f",
"vendor_url": null,
"pcl_pickup_time": null,
"info": null,
"holidaystarts": null,
"holidayends": null
},
{
"pclshopid": "6000-OMV01",
"name": "OMV SLOVENIJA D.O.O.",
"ctrcode": "SI",
"zipcode": "6000",
"city": "KOPER",
"address": "Istrska cesta 53",
"contact": null,
"phone": null,
"email": null,
"iscodhandler": "t",
"paybybankcard": "t",
"dropoffpoint": "t",
"geolat": "45.539",
"geolng": "13.7287",
"owner": "GLS",
Expand All @@ -493,17 +513,17 @@
"city": "LJUBLJANA",
"address": "Litijska cesta 40",
"contact": null,
"phone": "01\/520-81-20",
"email": "[email protected]",
"phone": null,
"email": null,
"iscodhandler": null,
"paybybankcard": null,
"dropoffpoint": null,
"geolat": "46.0473",
"geolng": "14.5463",
"geolat": null,
"geolng": null,
"owner": "GLS",
"isparcellocker": null,
"vendor_url": null,
"pcl_pickup_time": "10:00",
"pcl_pickup_time": null,
"info": null,
"holidaystarts": null,
"holidayends": null
Expand Down
75 changes: 68 additions & 7 deletions tests/Integration/Service/data/parcelShops_expected_parcels.json
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,70 @@
"holidayStarts": null,
"holidayEnds": null
},
{
"shopId": "6000-OMV01",
"name": "OMV SLOVENIJA D.O.O.",
"countryCode": "SI",
"isCodHandler": true,
"payByBankCard": true,
"dropOffPoint": true,
"owner": "GLS",
"isParcelLocker": false,
"vendorUrl": null,
"pickupTime": null,
"info": null,
"address": {
"zipCode": "6000",
"city": "KOPER",
"place": "Istrska cesta 53",
"contact": null,
"phone": null,
"email": null
},
"openings": [
{
"day": "monday",
"open": "00:00-24:00",
"midbreak": ""
},
{
"day": "tuesday",
"open": "00:00-24:00",
"midbreak": ""
},
{
"day": "wednesday",
"open": "00:00-24:00",
"midbreak": ""
},
{
"day": "thursday",
"open": "00:00-24:00",
"midbreak": ""
},
{
"day": "friday",
"open": "00:00-24:00",
"midbreak": ""
},
{
"day": "saturday",
"open": "00:00-24:00",
"midbreak": ""
},
{
"day": "sunday",
"open": "00:00-24:00",
"midbreak": ""
}
],
"coordinates": {
"latitude": 45.539,
"longitude": 13.7287
},
"holidayStarts": null,
"holidayEnds": null
},
{
"shopId": "1000-OMV04",
"name": "PS OMV LJUBLJANA LITIJSKA",
Expand All @@ -1353,15 +1417,15 @@
"owner": "GLS",
"isParcelLocker": false,
"vendorUrl": null,
"pickupTime": "10:00",
"pickupTime": null,
"info": null,
"address": {
"zipCode": "1000",
"city": "LJUBLJANA",
"place": "Litijska cesta 40",
"contact": null,
"phone": "01\/520-81-20",
"email": "[email protected]"
"phone": null,
"email": null
},
"openings": [
{
Expand Down Expand Up @@ -1400,10 +1464,7 @@
"midbreak": ""
}
],
"coordinates": {
"latitude": 46.0473,
"longitude": 14.5463
},
"coordinates": null,
"holidayStarts": null,
"holidayEnds": null
}
Expand Down
Loading