welcome back to dyb-tech

This commit is contained in:
Daniel Guzman
2024-05-18 02:28:01 +02:00
parent 9513cdba09
commit 9f30bc98c7
6149 changed files with 668407 additions and 0 deletions
View File
+78
View File
@@ -0,0 +1,78 @@
<?php
namespace DMD\LaLigaApi\Controller;
use DMD\LaLigaApi\Service\League\acceptJoinLeagueRequest\HandleAcceptJoinLeagueRequest;
use DMD\LaLigaApi\Service\League\createLeague\HandleCreateLeague;
use DMD\LaLigaApi\Service\League\declineJoinLeagueRequest\HandleDeclineJoinLeagueRequest;
use DMD\LaLigaApi\Service\League\getAllLeagues\HandleGetAllLeagues;
use DMD\LaLigaApi\Service\League\getLeagueById\HandleGetLeagueById;
use DMD\LaLigaApi\Service\League\newJoinLeagueRequest\HandleNewJoinLeagueRequest;
use DMD\LaLigaApi\Service\League\joinTeam\HandleCaptainRequest;
use DMD\LaLigaApi\Service\League\updateLeague\HandleUpdateLeague;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Routing\Annotation\Route;
class LeagueController extends AbstractController
{
#[Route('/api/league/new', name: 'app_league', methods: ['POST'])]
public function createLeague(Request $request, HandleCreateLeague $handleCreateLeague): JsonResponse
{
return $handleCreateLeague($request);
}
#[Route('/api/league/{$leagueId}', name: 'app_update_league', methods: ['PUT'])]
public function updateLeague(Request $request, HandleUpdateLeague $handleUpdateLeague, int $leagueId): JsonResponse
{
return $handleUpdateLeague($request, $leagueId);
}
#[Route('/api/league/{leagueId}/join', name: 'app_join_league', methods: ['PUT'])]
public function joinLeague(Request $request, HandleNewJoinLeagueRequest $handleJoinLeague, int $leagueId): JsonResponse
{
return $handleJoinLeague($request, $leagueId);
}
/**
* @throws TransportExceptionInterface
*/
#[Route('/api/league/{leagueId}/team/{teamId}', name: 'app_join_team', methods: ['PUT'])]
public function joinTeam(Request $request, HandleCaptainRequest $handleCaptainRequest, int $leagueId, int $teamId): JsonResponse
{
return $handleCaptainRequest($request, $leagueId, $teamId);
}
#[Route('/api/league/{leagueId}', name: 'app_get_league', methods: ['GET'])]
public function getLeagueById(Request $request, HandleGetLeagueById $handleGetLeagueById, int $leagueId): JsonResponse
{
return $handleGetLeagueById($request, $leagueId);
}
#[Route('/api/public/league', name: 'app_get_all_leagues', methods: ['GET'])]
public function getAllLeagues(HandleGetAllLeagues $handleGetAllLeagues): JsonResponse
{
return $handleGetAllLeagues();
}
/**
* @throws TransportExceptionInterface
*/
#[Route('api/league/{leagueId}/user/{userId}/accept', name: 'app_accept_join_request', methods: ['GET'])]
public function acceptJoinRequest(
Request $request,
HandleAcceptJoinLeagueRequest $handleAcceptJoinLeagueRequest,
int $leagueId,
int $userId
): JsonResponse
{
return $handleAcceptJoinLeagueRequest($request, $leagueId, $userId);
}
#[Route('api/league/{leagueId}/decline/{captainId}', name: 'app_decline_join_request', methods: ['GET'])]
public function declineJoinRequest(Request $request, HandleDeclineJoinLeagueRequest $handleDeclineJoinRequest, int $leagueId, int $captainId): JsonResponse
{
return $handleDeclineJoinRequest($request, $leagueId, $captainId);
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace DMD\LaLigaApi\Controller;
use DMD\LaLigaApi\Service\User\Handlers\getNotifications\HandleGetNotifications;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class NotificationController extends AbstractController
{
#[Route('/api/notifications', name: 'app_get_notifications')]
public function getAllNotifications(HandleGetNotifications $handleGetNotifications): Response
{
return $handleGetNotifications();
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace DMD\LaLigaApi\Controller;
use DMD\LaLigaApi\Service\Season\addTeam\HandleAddTeam;
use DMD\LaLigaApi\Service\Season\createGameCalendar\HandleCreateGameCalendarRequest;
use DMD\LaLigaApi\Service\Season\createSeason\HandleCreateSeason;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class SeasonController extends AbstractController
{
#[Route('/api/league/{leagueId}/season/create', name: 'app_add_season', methods: ['POST'])]
public function addSeason(Request $request, HandleCreateSeason $handleCreateSeason, int $leagueId): JsonResponse
{
return $handleCreateSeason($request, $leagueId);
}
#[Route('/api/league/{leagueId}/season/{seasonId}/team', name: 'app_add_team', methods: ['POST'])]
public function addTeam(Request $request, HandleAddTeam $handleAddTeam, int $leagueId, int $seasonId): JsonResponse
{
return $handleAddTeam($request, $leagueId, $seasonId);
}
#[Route('/api/league/{leagueId}/season/{seasonId}/calendar', name: 'app_create_calendar', methods: ['POST'])]
public function createCalendar(Request $request, HandleCreateGameCalendarRequest $handleCreateGameCalendarRequest, int $leagueId, int $seasonId): JsonResponse
{
return $handleCreateGameCalendarRequest($request, $leagueId, $seasonId);
}
}
+64
View File
@@ -0,0 +1,64 @@
<?php
namespace DMD\LaLigaApi\Controller;
use DMD\LaLigaApi\Repository\UserRepository;
use DMD\LaLigaApi\Service\User\Handlers\delete\HandleDeleteUser;
use DMD\LaLigaApi\Service\User\Handlers\update\HandleUpdateUser;
use DMD\LaLigaApi\Service\User\Handlers\register\HandleRegistration;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
class UserController extends AbstractController
{
#[Route('/api/register', name: 'app_user_register', methods: ['POST'])]
public function createUser(Request $request, HandleRegistration $handleRegistration): JsonResponse
{
return $handleRegistration($request);
}
#[Route('/api/user/', name: 'app_user_delete', methods: ['DELETE'])]
public function deleteUser(Request $request, HandleDeleteUser $handleDeleteUser): JsonResponse
{
return $handleDeleteUser($request);
}
#[Route('/api/user/edit', name: 'app_update_user', methods: ['PUT'])]
public function updateUser(Request $request, HandleUpdateUser $handleUpdateUser): JsonResponse
{
return $handleUpdateUser($request);
}
#[Route('/api/user/password', name: 'app_user_change_password', methods: ['PUT'])]
public function changePassword(
Request $request,
UserRepository $userRepository,
UserPasswordHasherInterface $passwordHasher,
EntityManagerInterface $entityManager
): JsonResponse
{
$user = $userRepository->findOneBy([
'email' => ($request->toArray())['username']
]);
if (is_null($user))
{
throw new HttpException(
Response::HTTP_NOT_FOUND,
'User not found.'
);
}
$hashedPassword = $passwordHasher->hashPassword($user, ($request->toArray())['newPassword']);
$user->setPassword($hashedPassword);
$entityManager->persist($user);
$entityManager->flush($user);
$entityManager->clear();
return new JsonResponse([
'success' => true
]);
}
}