Add rating delete endpoint
This commit is contained in:
parent
eac85a9045
commit
a8133b3233
2 changed files with 59 additions and 3 deletions
|
|
@ -32,7 +32,7 @@ class RatingController extends AbstractController
|
||||||
],
|
],
|
||||||
$repo->findAll()
|
$repo->findAll()
|
||||||
),
|
),
|
||||||
]));
|
]), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/api/ratings', methods: ['POST'])]
|
#[Route('/api/ratings', methods: ['POST'])]
|
||||||
|
|
@ -88,6 +88,27 @@ class RatingController extends AbstractController
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
return $this->json(null, 201);
|
return $this->json(null, 202);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/api/ratings/{id}', methods: ['DELETE'])]
|
||||||
|
public function delete(
|
||||||
|
int $id,
|
||||||
|
EntityManagerInterface $em,
|
||||||
|
OutputService $output,
|
||||||
|
RatingRepository $ratingRepository,
|
||||||
|
): JsonResponse {
|
||||||
|
$rating = $ratingRepository->findById($id);
|
||||||
|
|
||||||
|
if ($rating === null) {
|
||||||
|
return $this->json(
|
||||||
|
$output->error(["UNKNOWN_RATING"])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$em->remove($rating);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $this->json(null, 204);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ class RatingControllerTest extends WebTestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertResponseIsSuccessful();
|
$this->assertResponseIsSuccessful();
|
||||||
$this->assertResponseStatusCodeSame(201);
|
$this->assertResponseStatusCodeSame(202);
|
||||||
|
|
||||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||||
$em->clear();
|
$em->clear();
|
||||||
|
|
@ -115,4 +115,39 @@ class RatingControllerTest extends WebTestCase
|
||||||
$this->assertSame(8, $updated->getScore());
|
$this->assertSame(8, $updated->getScore());
|
||||||
$this->assertSame('Other note', $updated->getNote());
|
$this->assertSame('Other note', $updated->getNote());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDelete(): void
|
||||||
|
{
|
||||||
|
$client = static::createClient();
|
||||||
|
|
||||||
|
$user = UserFactory::createOne();
|
||||||
|
$client->loginUser($user);
|
||||||
|
|
||||||
|
$subject = RestaurantFactory::createOne([
|
||||||
|
'createdBy' => $user,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$rating = RatingFactory::createOne([
|
||||||
|
'subject' => $subject,
|
||||||
|
'score' => 0,
|
||||||
|
'note' => 'first note',
|
||||||
|
]);
|
||||||
|
$id = $rating->getId();
|
||||||
|
|
||||||
|
$client->request(
|
||||||
|
'DELETE',
|
||||||
|
'/api/ratings/' . $id,
|
||||||
|
server: ['CONTENT_TYPE' => 'application/json'],
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertResponseIsSuccessful();
|
||||||
|
$this->assertResponseStatusCodeSame(204);
|
||||||
|
|
||||||
|
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||||
|
$em->clear();
|
||||||
|
|
||||||
|
$this->assertNull(
|
||||||
|
$em->getRepository(Rating::class)->find($id)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue