-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
513 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/main/java/com/Optimart/controllers/ReviewController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,91 @@ | ||
package com.Optimart.controllers; | ||
|
||
import com.Optimart.annotations.SecuredSwaggerOperation; | ||
import com.Optimart.constants.Endpoint; | ||
import com.Optimart.dto.Product.CreateProductDTO; | ||
import com.Optimart.dto.Review.DeleteMultiReviewDTO; | ||
import com.Optimart.dto.Review.UpdateReviewDTO; | ||
import com.Optimart.dto.Review.WriteReviewDTO; | ||
import com.Optimart.models.Product; | ||
import com.Optimart.models.Review; | ||
import com.Optimart.responses.APIResponse; | ||
import com.Optimart.responses.Review.ReviewResponse; | ||
import com.Optimart.services.Review.ReviewService; | ||
import com.Optimart.utils.LocalizationUtils; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@RestController | ||
@Tag(name = "Review", description = "Everything about reviews") | ||
@RequestMapping(Endpoint.Reivew.BASE) | ||
public class ReviewController { | ||
private final LocalizationUtils localizationUtils; | ||
private final ReviewService reviewService; | ||
|
||
@ApiResponse(responseCode = "201", description = "CREATED", content = @Content(schema = @Schema(implementation = Object.class), mediaType = "application/json")) | ||
@SecuredSwaggerOperation(summary = "Write a new review") | ||
@PostMapping | ||
public ResponseEntity<APIResponse<ReviewResponse>> createNewReview(@RequestBody WriteReviewDTO writeReviewDTO){ | ||
return ResponseEntity.ok(reviewService.writeNewReview(writeReviewDTO)); | ||
} | ||
|
||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = Product.class), mediaType = "application/json")) | ||
@SecuredSwaggerOperation(summary = "Update a review") | ||
@PutMapping(Endpoint.Reivew.ID) | ||
public ResponseEntity<?> updateReview(@PathVariable String reviewId, @RequestBody UpdateReviewDTO updateReviewDTO) { | ||
return ResponseEntity.ok(reviewService.updateReview(updateReviewDTO, reviewId)); | ||
} | ||
|
||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = Product.class), mediaType = "application/json")) | ||
@SecuredSwaggerOperation(summary = "Update a review by me") | ||
@PutMapping(Endpoint.Reivew.ID_ME) | ||
public ResponseEntity<?> updateReviewByMe(@PathVariable String reviewId, @RequestBody UpdateReviewDTO updateReviewDTO) { | ||
return ResponseEntity.ok(reviewService.updateReview(updateReviewDTO, reviewId)); | ||
} | ||
|
||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = Product.class), mediaType = "application/json")) | ||
@SecuredSwaggerOperation(summary = "Get a existing review by id") | ||
@GetMapping(Endpoint.Reivew.ID) | ||
public ResponseEntity<?> getOneReview(@PathVariable String reviewId) { | ||
return ResponseEntity.ok(reviewService.getOneReview(reviewId)); | ||
} | ||
|
||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = Product.class), mediaType = "application/json")) | ||
@SecuredSwaggerOperation(summary = "Get all reviews") | ||
@GetMapping | ||
public ResponseEntity<?> getAllReview(@RequestParam Map<Object, String> filters) { | ||
return ResponseEntity.ok(reviewService.getAllReview(filters)); | ||
} | ||
|
||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = Product.class), mediaType = "application/json")) | ||
@SecuredSwaggerOperation(summary = "Delete a existing review by id") | ||
@DeleteMapping(Endpoint.Reivew.ID) | ||
public ResponseEntity<?> deleteOneReview(@PathVariable String reviewId) { | ||
return ResponseEntity.ok(reviewService.deleteOneReview(reviewId)); | ||
} | ||
|
||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = Product.class), mediaType = "application/json")) | ||
@SecuredSwaggerOperation(summary = "Delete a existing review by me") | ||
@DeleteMapping(Endpoint.Reivew.ID_ME) | ||
public ResponseEntity<?> deleteOneReviewByMe(@PathVariable String reviewId) { | ||
return ResponseEntity.ok(reviewService.deleteOneReview(reviewId)); | ||
} | ||
|
||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = Product.class), mediaType = "application/json")) | ||
@SecuredSwaggerOperation(summary = "Delete multiple review") | ||
@DeleteMapping(Endpoint.Reivew.DELETE_MANY) | ||
public ResponseEntity<?> deleteMultiReview(@RequestBody DeleteMultiReviewDTO deleteMultiReviewDTO) { | ||
return ResponseEntity.ok(reviewService.deleteMultiReview(deleteMultiReviewDTO)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/Optimart/dto/Review/DeleteMultiReviewDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.Optimart.dto.Review; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Setter | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class DeleteMultiReviewDTO { | ||
List<String> reviewIds; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/Optimart/dto/Review/UpdateReviewDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.Optimart.dto.Review; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Setter | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class UpdateReviewDTO { | ||
private String id; | ||
private String content; | ||
private double star; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.Optimart.dto.Review; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Setter | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class WriteReviewDTO { | ||
@JsonProperty("product") | ||
private String productId; | ||
@JsonProperty("user") | ||
private String userId; | ||
private String content; | ||
private double star; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/Optimart/repositories/ReviewRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.Optimart.repositories; | ||
|
||
import com.Optimart.models.Review; | ||
import com.Optimart.models.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
|
||
import java.util.UUID; | ||
|
||
public interface ReviewRepository extends JpaRepository<Review, UUID>, JpaSpecificationExecutor<Review> { | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/Optimart/repositories/Specification/ReviewSpecification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.Optimart.repositories.Specification; | ||
|
||
import com.Optimart.models.Review; | ||
import com.Optimart.models.User; | ||
import jakarta.persistence.criteria.Join; | ||
import jakarta.persistence.criteria.JoinType; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
public class ReviewSpecification { | ||
public static Specification<Review> searchByKeyword(String search) { | ||
return (root, query, criteriaBuilder) -> { | ||
if (search == null || search.isEmpty()) { | ||
return criteriaBuilder.conjunction(); | ||
} | ||
Join<Review, User> userJoin = root.join("user", JoinType.INNER); | ||
return criteriaBuilder.or( | ||
criteriaBuilder.like(criteriaBuilder.lower(root.get("content")), "%" + search.toLowerCase() + "%"), | ||
criteriaBuilder.like(criteriaBuilder.lower(userJoin.get("fullName")), "%" + search.toLowerCase() + "%") | ||
); | ||
}; | ||
} | ||
public static Specification<Review> filterReviews(String search) { | ||
return Specification.where(searchByKeyword(search)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/Optimart/responses/Product/BaseProductResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.Optimart.responses.Product; | ||
|
||
import lombok.*; | ||
|
||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class BaseProductResponse { | ||
private UUID id; | ||
private String name; | ||
private String slug; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/com/Optimart/responses/Review/ReviewResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.Optimart.responses.Review; | ||
|
||
import com.Optimart.responses.Product.BaseProductResponse; | ||
import com.Optimart.responses.User.BaseUserResponse; | ||
import lombok.*; | ||
|
||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class ReviewResponse { | ||
private UUID id; | ||
private String content; | ||
private double star; | ||
private BaseProductResponse product; | ||
private BaseUserResponse user; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/Optimart/responses/User/BaseUserResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.Optimart.responses.User; | ||
|
||
import lombok.*; | ||
|
||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class BaseUserResponse { | ||
private UUID id; | ||
private String fullName; | ||
private String firstName; | ||
private String middleName; | ||
private String lastName; | ||
private String imageUrl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.