Skip to content

Commit

Permalink
feat: Ability to retrieve company info via auth code without auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Co-7 committed Aug 7, 2023
1 parent 35d3c2a commit 0fb4dfd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ security:
- { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI docs
- { path: ^/auth, roles: PUBLIC_ACCESS }
- { path: ^/admin/login, roles: PUBLIC_ACCESS }
- { path: ^/api/companybyauthcode, roles: PUBLIC_ACCESS }
- { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
Expand Down
30 changes: 30 additions & 0 deletions src/Controller/CompanyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Controller;

use App\Entity\Company;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Serializer\SerializerInterface;

class CompanyController extends AbstractController
{
#[Route("/api/companybyauthcode/{auth_code}", name: 'company_by_code', methods: ['GET'])]
public function getCompanyByAuthCode(string $auth_code, SerializerInterface $serializer, EntityManagerInterface $em)
{
$company = $em->getRepository(Company::class)->findOneBy(['auth_code' => $auth_code]);

if (!$company) {
return new JsonResponse(['code' => "NOT_AUTHORIZED", 'message' => 'You are not authorized to obtain company information', 'content' => []], JsonResponse::HTTP_NOT_FOUND);
}

$companyName = $company->getName();
$companyLogo = $company->getLogo();

$jsonResponse = $serializer->serialize(['name' => $companyName, 'logo' => $companyLogo], 'json');

return new JsonResponse($jsonResponse, JsonResponse::HTTP_OK, [], true);
}
}

0 comments on commit 0fb4dfd

Please sign in to comment.