Commit 53020f82 authored by i.vasilenko@iq-adv.ru's avatar i.vasilenko@iq-adv.ru
Browse files

load & delete user image

parent cc616af1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,3 +2,4 @@
/.vscode/

.env
/app/public/uploads/
+12 −0
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ parameters:
    confirm_type: '%env(CONFIRM_TYPE)%'
    code_ttl: '%env(CODE_TTL)%'
    from_email: '%env(MAILER_ADDRESS)%'
    # Директория сохранения файлов
    images_directory: '%kernel.project_dir%/public/uploads/user_images'

services:
    # default configuration for services in *this* file
@@ -48,6 +50,14 @@ services:

    App\Service\Action\ActionServiceInterface $resetEmailService: '@App\Service\Action\Classes\ResetEmail'

    App\Service\Action\ActionServiceInterface $deleteImageService: '@App\Service\Action\Classes\DeleteImage'

    App\Service\Action\ActionServiceInterface $saveImageService: '@App\Service\Action\Classes\SaveImage'

    App\Service\Action\Classes\SaveImage:
        arguments:
            $targetDirectory: '%images_directory%'

    App\Service\Action\ActionServiceInterface: '@App\Service\Action\Classes\None'


@@ -66,6 +76,8 @@ services:

    App\Service\Dto\DtoServiceInterface $recoveryDto: '@App\Service\Dto\Classes\RecoveryDto'

    App\Service\Dto\DtoServiceInterface $imageDto: '@App\Service\Dto\Classes\ImageDto'

    App\Service\Dto\DtoServiceInterface: '@App\Service\Dto\Classes\NoneDto'


+34 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace App\Controller;

use App\Service\Action\ActionServiceInterface;
use App\Service\Dto\Classes\ChangeProfileDto;
use App\Service\Dto\Classes\ImageDto;
use App\Service\Dto\Classes\RecoveryCodeDto;
use App\Service\Dto\Classes\RecoveryDto;
use App\Service\Response\Classes\ProfileResponse;
@@ -116,4 +117,37 @@ class ProfileController extends AbstractController
    {
        return $resetEmailService->getResponse();
    }

    #[Route('/profile/image', name: 'profile_image', methods: ['POST'])]
    #[OA\RequestBody(
        content: new OA\JsonContent(ref: new Model(type: ImageDto::class))
    )]
    #[OA\Response(
        response: 200,
        description: 'Ответ',
        content: new OA\JsonContent(
            ref: new Model(type: Response::class, groups: ["message"])
        )
    )]
    public function saveImage(
        ActionServiceInterface $saveImageService,
    ): JsonResponse
    {
        return $saveImageService->getResponse();
    }

    #[Route('/profile/image/delete', name: 'profile_image_delete', methods: ['GET'])]
    #[OA\Response(
        response: 200,
        description: 'Ответ',
        content: new OA\JsonContent(
            ref: new Model(type: Response::class, groups: ["message"])
        )
    )]
    public function deleteImage(
        ActionServiceInterface $deleteImageService,
    ): JsonResponse
    {
        return $deleteImageService->getResponse();
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -363,7 +363,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
                new ReflectionExtractor()
            );
            $serializer = new Serializer(
                [$normalizer, new DateTimeNormalizer()],
                [new DateTimeNormalizer(), $normalizer],
                [new JsonEncoder()]
            );
            return $serializer->deserialize(
@@ -388,7 +388,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
            null,
            new ReflectionExtractor()
        );
        $serializer = new Serializer([$normalizer], [new JsonEncoder()]);
        $serializer = new Serializer([new DateTimeNormalizer(), $normalizer], [new JsonEncoder()]);
        $data = $serializer->serialize($this, 'json', ['groups' => $groups]);
        $array = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
        return self::createByArray($array, $groups);
+13 −0
Original line number Diff line number Diff line
@@ -129,6 +129,19 @@ class UserHistory
        $type = $this->getType();

        switch ($field = $this->getField()) {
            case 'image':
                switch ($type) {
                    case self::TYPE_CREATE:
                        $text = 'Изображение загружено';
                        break;
                    case self::TYPE_UPDATE:
                        $text = 'Изображение обновлено';
                        break;
                    case self::TYPE_DELETE:
                        $text = 'Изображение удалено';
                        break;
                }
                break;
            case 'confirm':
                switch ($type) {
                    case self::TYPE_CREATE:
Loading