-
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
37 book order #38
37 book order #38
Changes from all commits
2b5055e
31b2420
e2851f7
afbf58f
ecdfb89
ecd26fe
514c8b0
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.mindway.server.v2.domain.order.entity; | ||
|
||
public enum BookType { | ||
NOVEL, | ||
ESSAY | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.mindway.server.v2.domain.order.presentation; | ||
|
||
import com.mindway.server.v2.domain.order.entity.BookType; | ||
import com.mindway.server.v2.domain.order.presentation.dto.request.OrderRequest; | ||
import com.mindway.server.v2.domain.order.service.BookRequestService; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v2/order") | ||
public class OrdersController { | ||
private final BookRequestService bookRequestService; | ||
|
||
@PostMapping() | ||
public ResponseEntity<Void> bookRequest | ||
(@RequestParam BookType type, @RequestBody @Valid OrderRequest bookRequest) { | ||
bookRequestService.execute(type, bookRequest); | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
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. μ μ²μ΄ μμ±λμλ€λ μλ―Έλ‘ createλ μ΄λ€κ°μ?? 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. κΈ°λ₯μ΄ μ± μ μ μ²νλκ±°λΌμ λλ¬Έμ requestκ° λ μ§κ΄μ μΌλ‘ μ μ μμκ±° κ°λ€κ³ μκ°ν΄μ requestλ₯Ό μ¬μ©νμ΅λλ€ 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. μ κ·Έ λΆλΆ λ§κ³ HttpStatusλΆλΆ λ§νκ±°μμ 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. μ κ·ΈλΌ createκ° λ λ«κ² λ€μ μμ ν κ²μ 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. μμ νμ΅λλ€ |
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mindway.server.v2.domain.order.presentation.dto.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
public class OrderRequest { | ||
private String title; | ||
private String author; | ||
private String book_url; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.mindway.server.v2.domain.order.service; | ||
|
||
import com.mindway.server.v2.domain.order.entity.BookType; | ||
import com.mindway.server.v2.domain.order.presentation.dto.request.OrderRequest; | ||
|
||
public interface BookRequestService { | ||
void execute(BookType bookType, OrderRequest bookRequest); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.mindway.server.v2.domain.order.service.impl; | ||
|
||
import com.mindway.server.v2.domain.order.entity.BookType; | ||
import com.mindway.server.v2.domain.order.entity.Orders; | ||
import com.mindway.server.v2.domain.order.presentation.dto.request.OrderRequest; | ||
import com.mindway.server.v2.domain.order.repository.OrdersRepository; | ||
import com.mindway.server.v2.domain.order.service.BookRequestService; | ||
import com.mindway.server.v2.domain.order.util.OrdersConverter; | ||
import com.mindway.server.v2.domain.user.entity.User; | ||
import com.mindway.server.v2.domain.user.util.UserUtil; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(rollbackFor = {Exception.class}) | ||
public class BookRequestServiceImpl implements BookRequestService { | ||
|
||
private final UserUtil userUtil; | ||
private final OrdersRepository ordersRepository; | ||
private final OrdersConverter ordersConverter; | ||
|
||
@Override | ||
public void execute(BookType bookType, OrderRequest bookRequest) { | ||
User user = userUtil.getCurrentUser(); | ||
|
||
Orders order = ordersConverter.toEntity(bookRequest, user, bookType); | ||
ordersRepository.save(order); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.mindway.server.v2.domain.order.util; | ||
|
||
import com.mindway.server.v2.domain.order.entity.BookType; | ||
import com.mindway.server.v2.domain.order.entity.Orders; | ||
import com.mindway.server.v2.domain.order.presentation.dto.request.OrderRequest; | ||
import com.mindway.server.v2.domain.user.entity.User; | ||
|
||
public interface OrdersConverter { | ||
Orders toEntity (OrderRequest bookRequest, User user, BookType bookType); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.mindway.server.v2.domain.order.util.impl; | ||
|
||
import com.mindway.server.v2.domain.order.entity.BookType; | ||
import com.mindway.server.v2.domain.order.entity.Orders; | ||
import com.mindway.server.v2.domain.order.presentation.dto.request.OrderRequest; | ||
import com.mindway.server.v2.domain.order.util.OrdersConverter; | ||
import com.mindway.server.v2.domain.user.entity.User; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class OrdersConverterImpl implements OrdersConverter { | ||
@Override | ||
public Orders toEntity(OrderRequest bookRequest, User user, BookType bookType) { | ||
return Orders.builder() | ||
.title(bookRequest.getTitle()) | ||
.author(bookRequest.getAuthor()) | ||
.bookURL(bookRequest.getBook_url()) | ||
.bookType(bookType) | ||
.user(user) | ||
.build(); | ||
} | ||
} |
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.
λͺ μΈμλ₯Ό νμΈν΄λ³΄λκΉ orderμμλ postμμ²μ΄ νλλ°μ μλ κ±° κ°μλ° μλν¬μΈνΈλ₯Ό μ€μ νμ μ΄μ κ° μλμ?
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.
ecd26fe
λ€λ₯Έ λΆλΆ λͺ μΈμλ νΌλλμ μλͺ»μ΄κ±°κ°μμ μμ νμ΅λλ€