-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] 요청 목록 조회 API 생성 #65
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
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.dto.BaseResponse | ||
import com.psr.psr.global.exception.BaseResponseCode | ||
import com.psr.psr.global.jwt.UserAccount | ||
import com.psr.psr.order.dto.OrderListRes | ||
import com.psr.psr.order.dto.OrderReq | ||
import com.psr.psr.order.dto.OrderRes | ||
import com.psr.psr.order.service.OrderService | ||
|
@@ -12,18 +16,25 @@ import org.springframework.web.bind.annotation.* | |
@RestController | ||
@RequestMapping("/orders") | ||
class OrderController( | ||
private val orderService: OrderService | ||
private val orderService: OrderService | ||
) { | ||
// 요청하기 | ||
@PostMapping | ||
fun makeOrder (@AuthenticationPrincipal userAccount: UserAccount, @RequestBody @Valid orderReq: OrderReq) : BaseResponse<Unit> { | ||
if (orderReq.websiteUrl.isNullOrBlank()) orderReq.websiteUrl = null | ||
return BaseResponse(orderService.makeOrder(userAccount.getUser(), orderReq)) | ||
} | ||
// 요청하기 | ||
@PostMapping | ||
fun makeOrder(@AuthenticationPrincipal userAccount: UserAccount, @RequestBody @Valid orderReq: OrderReq): BaseResponse<Unit> { | ||
if (orderReq.websiteUrl.isNullOrBlank()) orderReq.websiteUrl = null | ||
return BaseResponse(orderService.makeOrder(userAccount.getUser(), orderReq)) | ||
} | ||
|
||
// 요청 상세 조회 | ||
@GetMapping("/{orderId}") | ||
fun getOrderDetail (@AuthenticationPrincipal userAccount: UserAccount, @PathVariable orderId: Long) : BaseResponse<OrderRes> { | ||
return BaseResponse(orderService.getOrderDetail(userAccount.getUser(), orderId)) | ||
} | ||
// 요청 상세 조회 | ||
@GetMapping("/{orderId}") | ||
fun getOrderDetail(@AuthenticationPrincipal userAccount: UserAccount,@PathVariable orderId: Long): BaseResponse<OrderRes> { | ||
return BaseResponse(orderService.getOrderDetail(userAccount.getUser(), orderId)) | ||
} | ||
|
||
// 요청 목록 조회 | ||
@GetMapping | ||
fun getOrderList(@AuthenticationPrincipal userAccount: UserAccount, type: String, status: String): BaseResponse<OrderListRes> { | ||
if (type !in listOf(SELL, ORDER)) return BaseResponse(BaseResponseCode.INVALID_ORDER_TYPE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 옹 이렇게 간편하게 예외처리 할 수 잇군여 !!!! |
||
return BaseResponse(orderService.getOrderList(userAccount.getUser(), type, status)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.psr.psr.order.dto | ||
|
||
data class OrderListComp ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comp는 어떤 줄임말인가용 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. component인데 orderRes가 이미 있어서 이렇게 지어봤습니당 |
||
val orderId: Long, | ||
val orderDate: String, | ||
val userName: String, | ||
val productId: Long, | ||
val productName: String, | ||
val isReviewed: Boolean | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.psr.psr.order.dto | ||
|
||
data class OrderListRes ( | ||
val orders: List<OrderListComp>? | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
package com.psr.psr.order.entity | ||
|
||
enum class OrderStatus(val value: String) { | ||
import com.psr.psr.global.exception.BaseException | ||
import com.psr.psr.global.exception.BaseResponseCode | ||
|
||
enum class OrderStatus(val statusName: String) { | ||
ORDER_WAITING("요청대기"), | ||
PROGRESSING("진행중"), | ||
COMPLETED("진행완료"), | ||
CANCELED("요청취소") | ||
CANCELED("요청취소"); | ||
|
||
companion object { | ||
fun findByName(statusName: String): OrderStatus { | ||
return OrderStatus.values().find { it.statusName == statusName } | ||
?: throw BaseException(BaseResponseCode.INVALID_ORDER_STATUS) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package com.psr.psr.order.repository | ||
|
||
import com.psr.psr.order.entity.Order | ||
import com.psr.psr.order.entity.OrderStatus | ||
import com.psr.psr.user.entity.User | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface OrderRepository: JpaRepository<Order, Long> { | ||
fun findByIdAndStatus(orderId: Long, status: String): Order? | ||
fun findByUserAndOrderStatusAndStatus(orderer: User, orderStatus: OrderStatus, status: String): List<Order> | ||
fun findByProductUserAndOrderStatusAndStatus(seller: User, orderStatus: OrderStatus, status: String): List<Order> | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고냥 QA로 취직하자 ㅎㅅㅎ