|
4 | 4 |
|
5 | 5 | namespace PhpList\RestBundle\Controller;
|
6 | 6 |
|
| 7 | +use Symfony\Bridge\Doctrine\Attribute\MapEntity; |
7 | 8 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
8 | 9 | use PhpList\Core\Domain\Model\Subscription\Subscriber;
|
9 | 10 | use PhpList\Core\Domain\Repository\Subscription\SubscriberRepository;
|
|
15 | 16 | use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
16 | 17 | use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
17 | 18 | use Symfony\Component\Routing\Attribute\Route;
|
| 19 | +use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; |
18 | 20 | use Symfony\Component\Serializer\SerializerInterface;
|
19 | 21 | use OpenApi\Attributes as OA;
|
20 | 22 |
|
@@ -156,6 +158,88 @@ public function postAction(Request $request, SerializerInterface $serializer): J
|
156 | 158 | );
|
157 | 159 | }
|
158 | 160 |
|
| 161 | + #[Route('/subscribers/{subscriber}', name: 'get_subscriber_by_id', methods: ['GET'])] |
| 162 | + #[OA\Get( |
| 163 | + path: '/subscribers/{subscriber}', |
| 164 | + description: 'Get subscriber date by id.', |
| 165 | + summary: 'Get a subscriber', |
| 166 | + tags: ['subscribers'], |
| 167 | + parameters: [ |
| 168 | + new OA\Parameter( |
| 169 | + name: 'session', |
| 170 | + description: 'Session ID obtained from authentication', |
| 171 | + in: 'header', |
| 172 | + required: true, |
| 173 | + schema: new OA\Schema(type: 'string') |
| 174 | + ), |
| 175 | + new OA\Parameter( |
| 176 | + name: 'id', |
| 177 | + description: 'Subscriber ID', |
| 178 | + in: 'path', |
| 179 | + required: true, |
| 180 | + schema: new OA\Schema(type: 'string') |
| 181 | + ) |
| 182 | + ], |
| 183 | + responses: [ |
| 184 | + new OA\Response( |
| 185 | + response: 200, |
| 186 | + description: 'Success', |
| 187 | + content: new OA\JsonContent( |
| 188 | + properties: [ |
| 189 | + new OA\Property( |
| 190 | + property: 'creation_date', |
| 191 | + type: 'string', |
| 192 | + format: 'date-time', |
| 193 | + example: '2017-12-16T18:44:27+00:00' |
| 194 | + ), |
| 195 | + new OA\ Property(property: 'email', type: 'string', example: '[email protected]'), |
| 196 | + new OA\Property(property: 'confirmed', type: 'boolean', example: false), |
| 197 | + new OA\Property(property: 'blacklisted', type: 'boolean', example: false), |
| 198 | + new OA\Property(property: 'bounced', type: 'integer', example: 0), |
| 199 | + new OA\Property( |
| 200 | + property: 'unique_id', |
| 201 | + type: 'string', |
| 202 | + example: '69f4e92cf50eafca9627f35704f030f4' |
| 203 | + ), |
| 204 | + new OA\Property(property: 'html_email', type: 'boolean', example: false), |
| 205 | + new OA\Property(property: 'disabled', type: 'boolean', example: false), |
| 206 | + new OA\Property(property: 'id', type: 'integer', example: 1) |
| 207 | + ] |
| 208 | + ) |
| 209 | + ), |
| 210 | + new OA\Response( |
| 211 | + response: 403, |
| 212 | + description: 'Failure', |
| 213 | + content: new OA\JsonContent( |
| 214 | + properties: [ |
| 215 | + new OA\Property( |
| 216 | + property: 'message', |
| 217 | + type: 'string', |
| 218 | + example: 'No valid session key was provided as basic auth password.' |
| 219 | + ) |
| 220 | + ] |
| 221 | + ) |
| 222 | + ), |
| 223 | + new OA\Response( |
| 224 | + response: 404, |
| 225 | + description: 'Not Found', |
| 226 | + ) |
| 227 | + ] |
| 228 | + )] |
| 229 | + public function getAction( |
| 230 | + Request $request, |
| 231 | + #[MapEntity(mapping: ['id' => 'id'])] Subscriber $subscriber, |
| 232 | + SerializerInterface $serializer |
| 233 | + ): JsonResponse { |
| 234 | + $this->requireAuthentication($request); |
| 235 | + |
| 236 | + $json = $serializer->serialize($subscriber, 'json', [ |
| 237 | + AbstractNormalizer::GROUPS => 'SubscriberListMembers', |
| 238 | + ]); |
| 239 | + |
| 240 | + return new JsonResponse($json, Response::HTTP_OK, [], true); |
| 241 | + } |
| 242 | + |
159 | 243 | /**
|
160 | 244 | * @param Request $request
|
161 | 245 | *
|
|
0 commit comments