Creates or updates a preference for a given user.
public setPreference ( |
||
$user | The user to set the preference for | |
$key | string | The key to set |
$value | string | The value to set |
return | The user preference |
/** * Retrieves a collection of resources. * * @param Request $request * * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable * @throws \Exception If the format is invalid * * @throws RuntimeException|RootNodeNotFoundException */ public function __invoke(Request $request) { $user = $this->userService->getUser(); $data = json_decode($request->getContent()); if (property_exists($data, "preferenceKey") && property_exists($data, "preferenceValue")) { $preference = $this->userPreferenceService->setPreference($user, $data->preferenceKey, $data->preferenceValue); } else { throw new \Exception("Invalid format"); } list($resourceType) = $this->extractAttributes($request); /** * @var ResourceInterface $resourceType */ $serializedData = $this->serializer->normalize($preference, 'json', $resourceType->getNormalizationContext()); return new JsonResponse($serializedData); }