Skip to content

Commit

Permalink
create :: 도서 신청 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
ta2ye0n committed Apr 7, 2024
1 parent 953bf0b commit 761922e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
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,42 @@
package com.mindway.server.v2.domain.order.service.impl;

import com.mindway.server.v2.domain.order.entity.Orders;
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();
}

List<Orders> orders = ordersRepository.findAll();

return orders.stream()
.map(ordersConverter::toDto)
.collect(Collectors.toList());
}
}

0 comments on commit 761922e

Please sign in to comment.