use of io.gravitee.rest.api.model.NewRatingEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiRatingsResource method createApiRating.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.API_RATING, acls = RolePermissionAction.CREATE) })
public Response createApiRating(@PathParam("apiId") String apiId, @Valid RatingInput ratingInput) {
if (ratingInput == null) {
throw new BadRequestException("Input must not be null.");
}
final ApiQuery apiQuery = new ApiQuery();
apiQuery.setIds(Collections.singletonList(apiId));
Collection<ApiEntity> userApis = apiService.findPublishedByUser(getAuthenticatedUserOrNull(), apiQuery);
if (userApis.stream().anyMatch(a -> a.getId().equals(apiId))) {
NewRatingEntity rating = new NewRatingEntity();
rating.setApi(apiId);
rating.setComment(ratingInput.getComment());
rating.setTitle(ratingInput.getTitle());
rating.setRate(ratingInput.getValue().byteValue());
RatingEntity createdRating = ratingService.create(rating);
return Response.status(Status.CREATED).entity(ratingMapper.convert(createdRating, uriInfo)).build();
}
throw new ApiNotFoundException(apiId);
}
Aggregations