Skip to content

Commit 0fb4dfd

Browse files
committed
feat: Ability to retrieve company info via auth code without auth
1 parent 35d3c2a commit 0fb4dfd

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

config/packages/security.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ security:
5353
- { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI docs
5454
- { path: ^/auth, roles: PUBLIC_ACCESS }
5555
- { path: ^/admin/login, roles: PUBLIC_ACCESS }
56+
- { path: ^/api/companybyauthcode, roles: PUBLIC_ACCESS }
5657
- { path: ^/admin, roles: ROLE_ADMIN }
5758
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
5859
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }

src/Controller/CompanyController.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Controller;
4+
5+
use App\Entity\Company;
6+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7+
use Symfony\Component\HttpFoundation\JsonResponse;
8+
use Symfony\Component\Routing\Annotation\Route;
9+
use Doctrine\ORM\EntityManagerInterface;
10+
use Symfony\Component\Serializer\SerializerInterface;
11+
12+
class CompanyController extends AbstractController
13+
{
14+
#[Route("/api/companybyauthcode/{auth_code}", name: 'company_by_code', methods: ['GET'])]
15+
public function getCompanyByAuthCode(string $auth_code, SerializerInterface $serializer, EntityManagerInterface $em)
16+
{
17+
$company = $em->getRepository(Company::class)->findOneBy(['auth_code' => $auth_code]);
18+
19+
if (!$company) {
20+
return new JsonResponse(['code' => "NOT_AUTHORIZED", 'message' => 'You are not authorized to obtain company information', 'content' => []], JsonResponse::HTTP_NOT_FOUND);
21+
}
22+
23+
$companyName = $company->getName();
24+
$companyLogo = $company->getLogo();
25+
26+
$jsonResponse = $serializer->serialize(['name' => $companyName, 'logo' => $companyLogo], 'json');
27+
28+
return new JsonResponse($jsonResponse, JsonResponse::HTTP_OK, [], true);
29+
}
30+
}

0 commit comments

Comments
 (0)