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

도서 신청 조회 api #45

Merged
merged 5 commits into from
Apr 7, 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
Expand Up @@ -3,22 +3,27 @@
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.presentation.dto.request.OrderUpdateRequest;
import com.mindway.server.v2.domain.order.presentation.dto.response.OrdersResponse;
import com.mindway.server.v2.domain.order.service.BookRequestService;
import com.mindway.server.v2.domain.order.service.DeleteBookOrderService;
import com.mindway.server.v2.domain.order.service.GetBookOrdersService;
import com.mindway.server.v2.domain.order.service.UpdateBookOrderService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v2/order")
public class OrdersController {
private final BookRequestService bookRequestService;
private final DeleteBookOrderService deleteBookOrderService;
private final UpdateBookOrderService updateBookOrderService;
private final GetBookOrdersService getBookOrdersService;

@PostMapping()
public ResponseEntity<Void> bookRequest
Expand All @@ -40,4 +45,10 @@ public ResponseEntity<Void> deleteBook (@PathVariable(value = "order_id") Long i
return ResponseEntity.noContent().build();
}

@GetMapping
public ResponseEntity<List<OrdersResponse>> getBookOrders () {
List<OrdersResponse> orders = getBookOrdersService.execute();
return ResponseEntity.ok(orders);
}
Copy link
Member

Choose a reason for hiding this comment

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

bookOrders라는 메서드만 봐서는 무슨 역할을 하는 메서드인지 모르겠어요..
이름 다시 생각해보시는게 좋을거같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0837399

신청도서 불러오는거라 getBookOrders로 바꿨는데 이건 어떤거 같나요??

Copy link
Member

Choose a reason for hiding this comment

The 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.response;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class OrdersResponse {
private String title;
private String author;
private String book_url;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mindway.server.v2.domain.order.service;

import com.mindway.server.v2.domain.order.presentation.dto.response.OrdersResponse;

import java.util.List;

public interface GetBookOrdersService {
List<OrdersResponse> execute();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mindway.server.v2.domain.order.service.impl;

import com.mindway.server.v2.domain.order.exception.NotAccessStudentException;
import com.mindway.server.v2.domain.order.presentation.dto.response.OrdersResponse;
import com.mindway.server.v2.domain.order.repository.OrdersRepository;
import com.mindway.server.v2.domain.order.service.GetBookOrdersService;
import com.mindway.server.v2.domain.order.util.OrdersConverter;
import com.mindway.server.v2.domain.user.entity.Authority;
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;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true, rollbackFor = {Exception.class})
public class GetBookOrdersServiceImpl implements GetBookOrdersService {
private final UserUtil userUtil;
private final OrdersRepository ordersRepository;
private final OrdersConverter ordersConverter;

@Override
public List<OrdersResponse> execute() {
User user = userUtil.getCurrentUser();

if (user.getAuthority() != Authority.ROLE_TEACHER
&& user.getAuthority() != Authority.ROLE_HELPER) {
throw new NotAccessStudentException();
}

return ordersRepository.findAll().stream()
.map(ordersConverter::toDto)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
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.presentation.dto.response.OrdersResponse;
import com.mindway.server.v2.domain.user.entity.User;

public interface OrdersConverter {
Orders toEntity (OrderRequest bookRequest, User user, BookType bookType);

OrdersResponse toDto (Orders orders);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.presentation.dto.response.OrdersResponse;
import com.mindway.server.v2.domain.order.util.OrdersConverter;
import com.mindway.server.v2.domain.user.entity.User;
import org.springframework.stereotype.Component;
Expand All @@ -19,4 +20,13 @@ public Orders toEntity(OrderRequest bookRequest, User user, BookType bookType) {
.user(user)
.build();
}

@Override
public OrdersResponse toDto(Orders orders) {
return OrdersResponse.builder()
.title(orders.getTitle())
.author(orders.getAuthor())
.book_url(orders.getBookURL())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(HttpMethod.POST, "/api/v2/order").authenticated()
.requestMatchers(HttpMethod.DELETE, "/api/v2/order/{order_id}").authenticated()
.requestMatchers(HttpMethod.PATCH, "api/v2/order/{order_id}").authenticated()
.requestMatchers(HttpMethod.GET, "api/v2/order").authenticated()

.anyRequest().authenticated()
)
Expand Down
Loading