Skip to content

Commit

Permalink
Merge pull request #179 from PSR-Co/fix/#178-qa-fix
Browse files Browse the repository at this point in the history
[fix] 1차 QA 수정사항 변경
  • Loading branch information
psyeon1120 authored Sep 17, 2023
2 parents 56c7de1 + 544e535 commit ba00a8b
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 35 deletions.
5 changes: 3 additions & 2 deletions src/main/kotlin/com/psr/psr/global/Constant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ class Constant {
}
}

class OrderType{
companion object OrderType{
class Order{
companion object Order{
const val SELL = "sell"
const val ORDER = "order"
const val STATUS = "status"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ enum class BaseResponseCode(status: HttpStatus, message: String) {

// report
INVALID_REPORT_CATEGORY(HttpStatus.BAD_REQUEST, "올바르지 않은 신고 카테고리입니다."),
REPORT_ALREADY_COMPLETE(HttpStatus.CONFLICT, "이미 신고 완료된 리뷰입니다."),
REPORT_ALREADY_COMPLETE(HttpStatus.CONFLICT, "이미 신고 완료되었습니다."),
NULL_REPORT_CATEGORY(HttpStatus.BAD_REQUEST, "신고 카테고리를 입력해주세요."),
VALID_REVIEW_USER(HttpStatus.UNAUTHORIZED, "본인이 작성한 리뷰는 신고할 수 없습니다."),

// inquiry
NOT_FOUND_INQUIRY(HttpStatus.NOT_FOUND, "해당 문의를 찾을 수 없습니다."),
Expand All @@ -65,6 +66,7 @@ enum class BaseResponseCode(status: HttpStatus, message: String) {
NOT_FOUND_ORDER(HttpStatus.NOT_FOUND, "해당 요청을 찾을 수 없습니다."),
INVALID_ORDER_STATUS(HttpStatus.BAD_REQUEST, "올바르지 않은 요청 상태입니다."),
INVALID_ORDER_TYPE(HttpStatus.BAD_REQUEST, "올바르지 않은 요청 타입입니다."),
NULL_ORDER_STATUS(HttpStatus.BAD_REQUEST, "요청 상태를 입력해주세요."),

// review
REVIEW_ALREADY_COMPLETE(HttpStatus.CONFLICT, "이미 리뷰 완료된 요청입니다."),
Expand Down
24 changes: 18 additions & 6 deletions src/main/kotlin/com/psr/psr/order/controller/OrderController.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.psr.psr.order.controller

import com.psr.psr.global.Constant.OrderType.OrderType.ORDER
import com.psr.psr.global.Constant.OrderType.OrderType.SELL
import com.psr.psr.global.Constant
import com.psr.psr.global.Constant.Order.Order.ORDER
import com.psr.psr.global.Constant.Order.Order.SELL
import com.psr.psr.global.Constant.Order.Order.STATUS
import com.psr.psr.global.dto.BaseResponse
import com.psr.psr.global.exception.BaseResponseCode
import com.psr.psr.global.jwt.UserAccount
Expand Down Expand Up @@ -64,10 +66,20 @@ class OrderController(
fun editOrder(
@AuthenticationPrincipal userAccount: UserAccount,
@PathVariable orderId: Long,
@RequestBody(required = false) @Valid orderReq: OrderReq?,
@RequestParam(required = false) status: String?
@RequestBody @Valid orderReq: OrderReq
): BaseResponse<Unit> {
if (orderReq.websiteUrl.isNullOrBlank()) orderReq.websiteUrl = null
return BaseResponse(orderService.editOrder(userAccount.getUser(), orderReq, orderId))
}

// 요청 상태 수정
@PatchMapping("/{orderId}/status")
fun editOrderStatus(
@AuthenticationPrincipal userAccount: UserAccount,
@PathVariable orderId: Long,
@RequestBody status: Map<String, String>
): BaseResponse<Unit> {
if (orderReq != null && orderReq.websiteUrl.isNullOrBlank()) orderReq.websiteUrl = null
return BaseResponse(orderService.editOrder(userAccount.getUser(), orderReq, status, orderId))
status[Constant.Order.STATUS] ?: return BaseResponse(BaseResponseCode.NULL_ORDER_STATUS)
return BaseResponse(orderService.editOrderStatus(userAccount.getUser(), status[STATUS]!!, orderId))
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/psr/psr/order/dto/OrderListRes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data class OrderListRes (
companion object {
fun toListDto(order: Order, type: String): OrderListRes {
val userName =
if (type == Constant.OrderType.SELL) order.ordererName
if (type == Constant.Order.SELL) order.ordererName
else order.product.user.nickname

return OrderListRes(
Expand Down
19 changes: 9 additions & 10 deletions src/main/kotlin/com/psr/psr/order/entity/Order.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@ data class Order(
var review: Review? = null

) : BaseEntity() {
fun editOrder(orderReq: OrderReq?, orderStatus: OrderStatus?) {
if (orderReq != null) {
this.ordererName = orderReq.ordererName
this.websiteUrl = orderReq.websiteUrl
this.inquiry = orderReq.inquiry
this.description = orderReq.description
}
if (orderStatus != null) {
this.orderStatus = orderStatus
}
fun editOrder(orderReq: OrderReq) {
this.ordererName = orderReq.ordererName
this.websiteUrl = orderReq.websiteUrl
this.inquiry = orderReq.inquiry
this.description = orderReq.description
}

fun editOrderStatus(orderStatus: OrderStatus) {
this.orderStatus = orderStatus
}

fun setReview(review: Review?): Order {
Expand Down
26 changes: 17 additions & 9 deletions src/main/kotlin/com/psr/psr/order/service/OrderService.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.psr.psr.order.service

import com.psr.psr.global.Constant.OrderType.OrderType.SELL
import com.psr.psr.global.Constant.Order.Order.SELL
import com.psr.psr.global.Constant.UserStatus.UserStatus.ACTIVE_STATUS
import com.psr.psr.global.exception.BaseException
import com.psr.psr.global.exception.BaseResponseCode
Expand Down Expand Up @@ -69,21 +69,29 @@ class OrderService(
return orderList.map { order: Order -> OrderListRes.toListDto(order, type) }
}

// 요청 수정
fun editOrder(user: User, orderReq: OrderReq?, status: String?, orderId: Long) {
// 요청 수정(요청자만 수정 가능)
fun editOrder(user: User, orderReq: OrderReq, orderId: Long) {
val order: Order = orderRepository.findByIdAndStatus(orderId, ACTIVE_STATUS)
?: throw BaseException(BaseResponseCode.NOT_FOUND_ORDER)
if (order.user.id != user.id) throw BaseException(BaseResponseCode.NO_PERMISSION)

var orderStatus: OrderStatus? = null
if (status != null) orderStatus = OrderStatus.findByValue(status)
order.editOrder(orderReq)
orderRepository.save(order)
}

// 요청 상태 수정(판매자만 수정 가능)
fun editOrderStatus(user: User, status: String, orderId: Long) {
val order: Order = orderRepository.findByIdAndStatus(orderId, ACTIVE_STATUS)
?: throw BaseException(BaseResponseCode.NOT_FOUND_ORDER)
if (order.product.user.id != user.id) throw BaseException(BaseResponseCode.NO_PERMISSION)

val orderStatus = OrderStatus.findByValue(status)

order.editOrder(orderReq, orderStatus)
order.editOrderStatus(orderStatus)
val saveOrder = orderRepository.save(order)

// 요청 상태 변경 시 알림 전송
if (status != null)
notificationService.sendChangeOrderStatusNoti(order.product.name, order.product.user, saveOrder.orderStatus, order.id!!)
// 요청 상태 변경 알림 전송
notificationService.sendChangeOrderStatusNoti(order.product.name, order.product.user, saveOrder.orderStatus, order.id!!)
}

// 2달 뒤 요청상태 입력 요망 알림(오후 1시마다 실행)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ class ReviewController(
// 상품별 리뷰 목록 조회
@GetMapping("/products/{productId}/reviews")
fun getProductReviews(
@AuthenticationPrincipal userAccount: UserAccount,
@PathVariable productId: Long,
@PageableDefault(size = 8, sort = ["id"], direction = Sort.Direction.DESC) pageable: Pageable
): BaseResponse<Page<ReviewListRes>> {
return BaseResponse(reviewService.getProductReviews(productId, pageable))
return BaseResponse(reviewService.getProductReviews(userAccount.getUser(), productId, pageable))
}

// 리뷰 개별 조회
Expand Down
9 changes: 6 additions & 3 deletions src/main/kotlin/com/psr/psr/review/dto/ReviewListRes.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.psr.psr.review.dto

import com.psr.psr.review.entity.Review
import com.psr.psr.user.entity.User
import java.time.format.DateTimeFormatter

data class ReviewListRes(
Expand All @@ -10,10 +11,11 @@ data class ReviewListRes(
val imgList: List<String>?,
val reviewedDate: String,
val nickName: String,
val profileImgUrl: String?
val profileImgUrl: String?,
val isMyReview: Boolean
) {
companion object {
fun toDto(review: Review): ReviewListRes {
fun toDto(review: Review, user: User): ReviewListRes {
val reviewImgs =
if (review.imgs.isNotEmpty()) review.imgs.map { img -> img.imgUrl }
else null
Expand All @@ -24,7 +26,8 @@ data class ReviewListRes(
imgList = reviewImgs,
reviewedDate = review.createdAt.format(DateTimeFormatter.ISO_DATE),
nickName = review.order.user.nickname,
profileImgUrl = review.order.user.imgUrl
profileImgUrl = review.order.user.imgUrl,
isMyReview = review.order.user == user
)
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/psr/psr/review/service/ReviewService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ class ReviewService(
}

// 상품별 리뷰 목록 조회
fun getProductReviews(productId: Long, pageable: Pageable): Page<ReviewListRes> {
fun getProductReviews(user: User, productId: Long, pageable: Pageable): Page<ReviewListRes> {
val product: Product = productRepository.findByIdAndStatus(productId, ACTIVE_STATUS)
?: throw BaseException(BaseResponseCode.NOT_FOUND_PRODUCT)

return reviewRepository.findByProductAndStatus(product, ACTIVE_STATUS, pageable)
.map { review -> ReviewListRes.toDto(review) }
.map { review -> ReviewListRes.toDto(review, user) }
}

// 리뷰 개별 조회
Expand All @@ -119,6 +119,7 @@ class ReviewService(

val review: Review = reviewRepository.findByIdAndStatus(reviewId, ACTIVE_STATUS)
?: throw BaseException(BaseResponseCode.NOT_FOUND_REVIEW)
if (review.order.user == user) throw BaseException(BaseResponseCode.VALID_REVIEW_USER)
if (reviewReportRepository.findByReviewAndUserAndStatus(review, user, ACTIVE_STATUS) != null)
throw BaseException(BaseResponseCode.REPORT_ALREADY_COMPLETE)

Expand Down

0 comments on commit ba00a8b

Please sign in to comment.