use of io.gravitee.rest.api.model.NewRatingAnswerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiRatingAnswersResource method createApiRatingAnswer.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.API_RATING_ANSWER, acls = RolePermissionAction.CREATE) })
public Response createApiRatingAnswer(@PathParam("apiId") String apiId, @PathParam("ratingId") String ratingId, @Valid RatingAnswerInput ratingAnswerInput) {
if (ratingAnswerInput == 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))) {
RatingEntity ratingEntity = ratingService.findById(ratingId);
if (ratingEntity != null && ratingEntity.getApi().equals(apiId)) {
NewRatingAnswerEntity ratingAnswerEntity = new NewRatingAnswerEntity();
ratingAnswerEntity.setComment(ratingAnswerInput.getComment());
ratingAnswerEntity.setRatingId(ratingId);
RatingEntity updatedRating = ratingService.createAnswer(ratingAnswerEntity);
return Response.status(Status.CREATED).entity(ratingMapper.convert(updatedRating, uriInfo)).build();
}
throw new RatingNotFoundException(ratingId, apiId);
}
throw new ApiNotFoundException(apiId);
}
Aggregations