Skip to content
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

Merged
merged 7 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -24,6 +24,8 @@ public class Orders {

private String bookURL;

private BookType bookType;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
Expand Down
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λͺ…μ„Έμ„œλ₯Ό ν™•μΈν•΄λ³΄λ‹ˆκΉŒ orderμ—μ„œλŠ” postμš”μ²­μ΄ ν•˜λ‚˜λ°–μ— μ—†λŠ” κ±° 같은데 μ—”λ“œν¬μΈνŠΈλ₯Ό μ„€μ •ν•˜μ‹  μ΄μœ κ°€ μžˆλ‚˜μš”?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ecd26fe

λ‹€λ₯Έ λΆ€λΆ„ λͺ…μ„Έμ„œλž‘ ν˜Όλ™λ˜μ„œ 잘λͺ»μ“΄κ±°κ°™μ•„μš” μˆ˜μ •ν–ˆμŠ΅λ‹ˆλ‹€

bookRequestService.execute(type, bookRequest);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

신청이 μƒμ„±λ˜μ—ˆλ‹€λŠ” 의미둜 createλŠ” μ–΄λ–€κ°€μš”??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

κΈ°λŠ₯이 책을 μ‹ μ²­ν•˜λŠ”κ±°λΌμ„œ λ•Œλ¬Έμ— requestκ°€ 더 μ§κ΄€μ μœΌλ‘œ μ•Œ 수 μžˆμ„κ±° κ°™λ‹€κ³  μƒκ°ν•΄μ„œ requestλ₯Ό μ‚¬μš©ν–ˆμŠ΅λ‹ˆλ‹€

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ•„ κ·Έ λΆ€λΆ„ 말고 HttpStatusλΆ€λΆ„ λ§ν•œκ±°μ—μš”

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ•„ 그럼 createκ°€ 더 λ‚«κ² λ„€μš” μˆ˜μ •ν• κ²Œμš”

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ecd26fe

μˆ˜μ •ν–ˆμŠ΅λ‹ˆλ‹€


}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// user
.requestMatchers(HttpMethod.GET, "/api/v2/my").authenticated()

// orders
.requestMatchers(HttpMethod.POST, "/api/v2/order").authenticated()

.anyRequest().authenticated()
)

Expand Down
Loading