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

feature: cash deliveries should have amount of money in the task info for the messenger (API) #4672

Merged
merged 40 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c16b3c6
bump database version
vladimir-8 Oct 1, 2024
0f571e4
WIP; return DTOs from `/api/me/tasks/*` endpoint instead of entities
vladimir-8 Oct 1, 2024
7372682
WIP; map more fields
vladimir-8 Oct 2, 2024
0fa47cd
Merge commit '1aa772f4f0374c386fdf14203ce8825d5d426f0b' into feature/…
vladimir-8 Oct 8, 2024
a02f22e
WIP: read more fields from the task object
vladimir-8 Oct 9, 2024
70a4e14
removed not needed logs
vladimir-8 Oct 9, 2024
614764e
added: more fields
vladimir-8 Oct 9, 2024
0182329
Merge branch 'master' into feature/4337-task-extra-info
vladimir-8 Oct 10, 2024
9f63c6d
WIP: handle tours
vladimir-8 Oct 10, 2024
8cac627
introduce /me/tasks/v2
vladimir-8 Oct 10, 2024
240b60e
remove deprecated fields
vladimir-8 Oct 10, 2024
98f88fb
filter out cancelled tasks
vladimir-8 Oct 10, 2024
c76394d
remove `hydra` view
vladimir-8 Oct 10, 2024
6a3c536
added: pickup packages and weight
vladimir-8 Oct 11, 2024
9dce435
flatten metadata
vladimir-8 Oct 11, 2024
1c0fc09
renamed: MyTaskListDto
vladimir-8 Oct 11, 2024
598ee1d
set output type
vladimir-8 Oct 11, 2024
53b40e5
wip: MyTaskDtoNormalizer
vladimir-8 Oct 11, 2024
b6d4dc2
Merge branch 'master' into feature/4337-task-extra-info
vladimir-8 Oct 14, 2024
aa037c1
maintain v1 response fields
vladimir-8 Oct 14, 2024
40ee2a2
added: has_loopeat_returns
vladimir-8 Oct 14, 2024
814d888
re-added: isZeroWaste
vladimir-8 Oct 15, 2024
5ba788d
updated normalization logic
vladimir-8 Oct 15, 2024
dda3660
skip optional has_loopeat_returns field
vladimir-8 Oct 16, 2024
f71a563
removed type
vladimir-8 Oct 16, 2024
1985ac4
fix: phpStan error
vladimir-8 Oct 16, 2024
4b48282
re-formatting
vladimir-8 Oct 16, 2024
3110bd3
Merge branch 'master' into feature/4337-task-extra-info
vladimir-8 Oct 17, 2024
3ebd5bc
updated: get payment method from the database
vladimir-8 Oct 17, 2024
c0e79e6
fix: create a task list if it does not exist yet
vladimir-8 Oct 17, 2024
1b86b27
fixed: task mapping
vladimir-8 Oct 17, 2024
5828338
publish MyTaskListDto in the Centrifugo event
vladimir-8 Oct 17, 2024
13d7fb1
fixed: make orgName optional
vladimir-8 Oct 17, 2024
5aa2035
extracted getPaymentMethod function
vladimir-8 Oct 17, 2024
04b5c8f
fixed: output format
vladimir-8 Oct 18, 2024
16094e4
Merge branch 'master' into feature/4337-task-extra-info
vladimir-8 Oct 18, 2024
002fb55
remove: unused fields
vladimir-8 Oct 18, 2024
a936c5e
removed: duplicate code
vladimir-8 Oct 18, 2024
70d5d6c
Merge branch 'master' into feature/4337-task-extra-info
vladimir-8 Oct 28, 2024
07fae57
move metadata generation into TaskListRepository
vladimir-8 Oct 28, 2024
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
4 changes: 3 additions & 1 deletion app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,15 @@ doctrine:
numrange: string
tsrange: string

# Tells Doctrine what database features are supported
# Make sure that your production database uses this version or higher.
# If you don't define this option and you haven't created your database yet,
# you may get PDOException errors because Doctrine will try to guess
# the database server version automatically and none is available.
# http://symfony.com/doc/current/reference/configuration/doctrine.html
# Should be fixed in next Doctrine version
# https://github.com/doctrine/dbal/pull/2671
server_version: 9.4
server_version: '13'

# Add a schema filter to avoid having PostGIS tables tiger.* & topology.* in migrations diff
# https://symfony.com/doc/master/bundles/DoctrineMigrationsBundle/index.html#manual-tables
Expand Down
2 changes: 2 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ services:
sylius.repository.order:
alias: AppBundle\Entity\Sylius\OrderRepository

AppBundle\Entity\TaskListRepository: ~

AppBundle\Entity\Task\RecurrenceRuleRepository: ~

AppBundle\Service\Routing\Osrm: ~
Expand Down
10 changes: 10 additions & 0 deletions app/config/services/serializer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ services:
- "@api_platform.jsonld.normalizer.item"
tags: [ { name: serializer.normalizer, priority: 128 } ]

AppBundle\Serializer\MyTaskDtoNormalizer:
arguments:
- "@api_platform.jsonld.normalizer.item"
tags: [ { name: serializer.normalizer, priority: 128 } ]

AppBundle\Serializer\MyTaskListDtoNormalizer:
arguments:
- "@api_platform.jsonld.normalizer.object"
tags: [ { name: serializer.normalizer, priority: 128 } ]

AppBundle\Serializer\TaskImageNormalizer:
arguments:
$normalizer: '@api_platform.jsonld.normalizer.item'
Expand Down
2 changes: 1 addition & 1 deletion src/Action/MyTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function loadExisting(\DateTime $date): ?TaskList

// reset array index to 0 with array_values, otherwise you might get weird stuff in the serializer
$notCancelled = array_values(
array_filter(array_filter($taskList->getTasks(), function (Task $task) {
array_filter(array_filter($taskList->getTasks(), function (Task $task) {
return !$task->isCancelled();
}))
);
Expand Down
57 changes: 57 additions & 0 deletions src/Action/MyTasks2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace AppBundle\Action;

use AppBundle\Entity\TaskListRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use AppBundle\Action\Utils\TokenStorageTrait;
use AppBundle\Entity\TaskList;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

final class MyTasks2
{
use TokenStorageTrait;

/**
* @var TaskListRepository
*/
private readonly EntityRepository $taskListRepository;

public function __construct(
TokenStorageInterface $tokenStorage,
private readonly EntityManagerInterface $entityManager)
{
$this->tokenStorage = $tokenStorage;
$this->taskListRepository = $this->entityManager->getRepository(TaskList::class);

Check failure on line 28 in src/Action/MyTasks2.php

View workflow job for this annotation

GitHub Actions / Lint PHP (8.2)

Property AppBundle\Action\MyTasks2::$taskListRepository (AppBundle\Entity\TaskListRepository) does not accept Doctrine\ORM\EntityRepository<AppBundle\Entity\TaskList>.

Check failure on line 28 in src/Action/MyTasks2.php

View workflow job for this annotation

GitHub Actions / Lint PHP (8.3)

Property AppBundle\Action\MyTasks2::$taskListRepository (AppBundle\Entity\TaskListRepository) does not accept Doctrine\ORM\EntityRepository<AppBundle\Entity\TaskList>.
}

public function __invoke(Request $request)
{
$user = $this->getUser();
$date = new \DateTime($request->get('date'));

$taskListDto = $this->taskListRepository->findMyTaskListAsDto($user, $date);

if (null === $taskListDto) {

$taskList = new TaskList();
$taskList->setCourier($user);
$taskList->setDate($date);

try {
$this->entityManager->persist($taskList);
$this->entityManager->flush();
} catch (UniqueConstraintViolationException $e) {
// If 2 requests are received at the very same time,
// we can have a race condition
// @see https://github.com/coopcycle/coopcycle-app/issues/1265
$taskListDto = $this->taskListRepository->findMyTaskListAsDto($user, $date);
}
}

return $taskListDto;
}
}
120 changes: 120 additions & 0 deletions src/Api/Dto/MyTaskDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace AppBundle\Api\Dto;

use AppBundle\Entity\Address;
use DateTime;
use Symfony\Component\Serializer\Annotation\Groups;

final class MyTaskDto
{
#[Groups(["task"])]
public readonly int $id;

#[Groups(["task"])]
public readonly DateTime $createdAt;

#[Groups(["task"])]
public readonly DateTime $updatedAt;

#[Groups(["task"])]
public readonly string $orgName;

#[Groups(["task"])]
public readonly string $type;

#[Groups(["task"])]
public readonly string $status;

#[Groups(["task"])]
public readonly Address $address;

#[Groups(["task"])]
public readonly DateTime $after;

#[Groups(["task"])]
public readonly DateTime $before;

#[Groups(["task"])]
public readonly ?int $previous;

#[Groups(["task"])]
public readonly ?int $next;

#[Groups(["task"])]
public readonly array $tags;

#[Groups(["task"])]
public readonly bool $doorstep;

#[Groups(["task"])]
public readonly ?string $comment;

#[Groups(["task"])]
public readonly array $packages;

#[Groups(["task"])]
public readonly ?int $weight;

#[Groups(["task"])]
public readonly bool $hasIncidents;

#[Groups(["task"])]
public readonly ?int $delivery_position;

#[Groups(["task"])]
public readonly ?string $order_number;

#[Groups(["task"])]
public readonly ?string $payment_method;

#[Groups(["task"])]
public readonly ?int $order_total;

public function __construct(
int $id,
DateTime $createdAt,
DateTime $updatedAt,
string $type,
string $status,
Address $address,
DateTime $after,
DateTime $before,
?int $previous,
?int $next,
array $tags,
bool $doorstep,
?string $comment,
array $packages,
?int $weight,
bool $hasIncidents,
string $orgName,
?int $deliveryPosition,
?string $orderNumber,
?string $paymentMethod,
?int $orderTotal
)
{
$this->id = $id;
$this->createdAt = $createdAt;
$this->updatedAt = $updatedAt;
$this->type = $type;
$this->status = $status;
$this->address = $address;
$this->after = $after;
$this->before = $before;
$this->previous = $previous;
$this->next = $next;
$this->tags = $tags;
$this->doorstep = $doorstep;
$this->comment = $comment;
$this->packages = $packages;
$this->weight = $weight;
$this->hasIncidents = $hasIncidents;
$this->orgName = $orgName;
$this->delivery_position = $deliveryPosition;
$this->order_number = $orderNumber;
$this->payment_method = $paymentMethod;
$this->order_total = $orderTotal;
}
}
88 changes: 88 additions & 0 deletions src/Api/Dto/MyTaskListDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace AppBundle\Api\Dto;

use AppBundle\Entity\Trailer;
use AppBundle\Entity\Vehicle;
use DateTime;
use Symfony\Component\Serializer\Annotation\Groups;

class MyTaskListDto
{
#[Groups(["task_list"])]
public readonly int $id;

#[Groups(["task_list"])]
public readonly DateTime $createdAt;

#[Groups(["task_list"])]
public readonly DateTime $updatedAt;

#[Groups(["task_list"])]
public readonly DateTime $date;

#[Groups(["task_list"])]
public readonly string $username;

/**
* @var MyTaskDto[]
*/
#[Groups(["task_list"])]
public readonly array $items;

#[Groups(["task_list"])]
public readonly int $distance;

#[Groups(["task_list"])]
public readonly int $duration;

#[Groups(["task_list"])]
public readonly string $polyline;

//TODO
#[Groups(["task_list"])]
public readonly ?Vehicle $vehicle;

//TODO
#[Groups(["task_list"])]
public readonly ?Trailer $trailer;

/**
* @param int $id
* @param DateTime $createdAt
* @param DateTime $updatedAt
* @param DateTime $date
* @param string $username
* @param MyTaskDto[] $items
* @param int $distance
* @param int $duration
* @param string $polyline
* @param Vehicle|null $vehicle
* @param Trailer|null $trailer
*/
public function __construct(
int $id,
DateTime $createdAt,
DateTime $updatedAt,
DateTime $date,
string $username,
array $items,
int $distance,
int $duration,
string $polyline,
?Vehicle $vehicle,
?Trailer $trailer)
{
$this->id = $id;
$this->createdAt = $createdAt;
$this->updatedAt = $updatedAt;
$this->date = $date;
$this->username = $username;
$this->items = $items;
$this->distance = $distance;
$this->duration = $duration;
$this->polyline = $polyline;
$this->vehicle = $vehicle;
$this->trailer = $trailer;
}
}
32 changes: 32 additions & 0 deletions src/Api/Dto/TaskPackageDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace AppBundle\Api\Dto;

use Symfony\Component\Serializer\Annotation\Groups;

class TaskPackageDto
{
#[Groups(["task"])]
public readonly string $shortCode;

#[Groups(["task"])]
public readonly string $name;

#[Groups(["task"])]
public readonly int $averageVolumeUnits;

#[Groups(["task"])]
public readonly int $quantity;

public function __construct(
string $shortCode,
string $name,
int $averageVolumeUnits,
int $quantity)
{
$this->shortCode = $shortCode;
$this->name = $name;
$this->averageVolumeUnits = $averageVolumeUnits;
$this->quantity = $quantity;
}
}
22 changes: 22 additions & 0 deletions src/Entity/TaskList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace AppBundle\Entity;

use AppBundle\Action\MyTasks as MyTasksController;
use AppBundle\Action\MyTasks2 as MyTasksController2;
use AppBundle\Action\TaskList\Create as CreateTaskListController;
use AppBundle\Action\TaskList\Optimize as OptimizeController;
use AppBundle\Action\TaskList\SetItems as SetTaskListItemsController;
use AppBundle\Entity\Task\CollectionInterface as TaskCollectionInterface;
use AppBundle\Api\Dto\MyTaskListDto;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use AppBundle\Api\Filter\DateFilter;
Expand Down Expand Up @@ -82,6 +84,26 @@
* }}
* }
* },
* "my_tasks_v2"={
* "method"="GET",
* "path"="/me/tasks/v2/{date}",
* "controller"=MyTasksController2::class,
* "access_control"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COURIER')",
* "output"=MyTaskListDto::class,
* "read"=false,
* "write"=false,
* "normalization_context"={"groups"={"task_list", "task", "delivery", "address"}},
* "openapi_context"={
* "summary"="Retrieves the collection of Task resources assigned to the authenticated token.",
* "parameters"={{
* "in"="path",
* "name"="date",
* "required"=true,
* "type"="string",
* "format"="date"
* }}
* }
* },
* "optimize"={
* "method"="GET",
* "path"="/task_lists/{id}/optimize",
Expand Down
Loading
Loading