-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/main/java/com/mindway/server/v2/domain/order/service/GetBookOrdersService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/mindway/server/v2/domain/order/service/impl/GetBookOrdersServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |