Skip to content

Commit

Permalink
[SERVER] BookingService: return rating's ID on createNewRating
Browse files Browse the repository at this point in the history
  • Loading branch information
Huynh Thanh Binh committed Aug 29, 2020
1 parent 10724ad commit 14a0c92
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions api/booking-api/src/main/proto/Booking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ service BookingService {
* ++ bookingId: uuid of booking
* ++ rating: rating star (min = 1, max = 5)
* ++ comment: can be an empty string or a comment string
* + response: Empty value if succeed, otherwise, throw exception */
rpc createBookingRating (CreateBookingRatingRequest) returns (google.protobuf.Empty);
* + response: new booking rating's ID if succeed, otherwise, throw exception */
rpc createBookingRating (CreateBookingRatingRequest) returns (google.protobuf.Int64Value);

/** PUBLIC - for customer only
* use-case: customer get existed rating of a finished booking to parking lot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,13 @@ public void getCustomerOnGoingBooking(Empty request, StreamObserver<Booking> res
}

@Override
public void createBookingRating(CreateBookingRatingRequest request, StreamObserver<Empty> responseObserver) {
public void createBookingRating(CreateBookingRatingRequest request, StreamObserver<Int64Value> responseObserver) {
Long customerId = serverInterceptor.getUserIdContext().get();
try {
serverInterceptor.validateUserRole("CUSTOMER");
bookingService.createBookingRating(customerId, request.getBookingId(), request.getRating(), request.getComment());
Long newRatingId = bookingService.createBookingRating(customerId, request.getBookingId(), request.getRating(), request.getComment());

responseObserver.onNext(Empty.getDefaultInstance());
responseObserver.onNext(Int64Value.of(newRatingId));
responseObserver.onCompleted();

LoggingUtil.log(Level.INFO, "SERVICE", "Success",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Map<Tuple, String> getAllRatingsOfParkingLot(@NotNull Long parkingLotId,

Map<Integer, Long> getParkingLotRatingCountGroupByRating(@NotNull Long parkingLotId);

void createBookingRating(@NotNull Long customerId,
Long createBookingRating(@NotNull Long customerId,
@NotEmpty String bookingUuidString,
@NotNull Integer rating,
@NotEmpty String comment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public Map<Integer, Long> getParkingLotRatingCountGroupByRating(@NotNull Long pa
}

@Override
public void createBookingRating(@NotNull Long customerId,
public Long createBookingRating(@NotNull Long customerId,
@NotNull String bookingUuidString,
@NotNull Integer rating,
@NotEmpty String comment) {
Expand All @@ -297,9 +297,7 @@ public void createBookingRating(@NotNull Long customerId,
.rating(rating.shortValue())
.comment(comment)
.build();

bookingRatingRepository.saveAndFlush(bookingRatingEntity);
return;
return bookingRatingRepository.saveAndFlush(bookingRatingEntity).getId();
}
throw new BookingAlreadyRatedException();
}
Expand Down

0 comments on commit 14a0c92

Please sign in to comment.