Symfony Api Platform – Not filtered duration

  Kiến thức lập trình

I’m currently on a Symfony Api Platform project and i need to know how to filter a duration
There is my object simplified

<?php

namespace AppEntity;

use DoctrineORMMapping as ORM;
use DoctrineDBALTypesTypes;
use ApiPlatformMetadataApiResource;
use ApiPlatformMetadataGetCollection;
use ApiPlatformMetadataApiFilter;
use SymfonyComponentSerializerAnnotationContext;
use AppRepositoryVideoRepository;

#[ORMTable(name: 'videos')]
#[ORMEntity(repositoryClass: VideoRepository::class)]
#[ApiResource(
    operations: [
        new GetCollection()
    ]
)]
#[ApiFilter(
    filterClass: RangeFilter::class,
    properties: [
        'duration',
    ],
)]
class Video
{

    #[ORMId]
    #[ORMGeneratedValue]
    #[ORMColumn(name: 'ID', type: Types::INTEGER)]
    private string $id;

    #[ORMColumn(name: 'DURATION', type: Types::TIME_MUTABLE, nullable: true)]
    #[Context([DateTimeNormalizer::FORMAT_KEY => 'H:i:s'])]
    private ?DateTime $duration;

    // Other properties ...
    // Getter and Setter ...

}

This is the BDD data for example:

id | duration
1  | 00:05:12
2  | 00:03:00
3  | 00:00:41

Then i try this call: GET {base_url}/videos?duration[gt]=00:03:00
I should have 1 result, but then i try i have the 3 result like the filter don’t work

What is missing ? What is wrong ?
Why isn’t the time passed understood as time?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT