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

๐Ÿ”€ :: ๋‚ด๊ฐ€ ์‹ ์ฒญํ•œ ๋„์„œ ๋ชฉ๋ก ๋ถˆ๋Ÿฌ์˜ค๊ธฐ #36

Merged
merged 5 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,11 @@
package com.mindway.server.v2.domain.order.repository;

import com.mindway.server.v2.domain.order.entity.Orders;
import com.mindway.server.v2.domain.user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface OrdersRepository extends JpaRepository<Orders, Long> {
List<Orders> findByUser(User user);
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
package com.mindway.server.v2.domain.user.presentation;

import com.mindway.server.v2.domain.user.presentation.dto.response.UserInfoResponse;
import com.mindway.server.v2.domain.user.presentation.dto.response.MyOrdersResponse;
import com.mindway.server.v2.domain.user.service.GetMyOrdersService;
import com.mindway.server.v2.domain.user.service.UserInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v2/my")
public class UserController {

private final UserInfoService userInfoService;
private final GetMyOrdersService getMyOrdersService;

@GetMapping
public ResponseEntity<UserInfoResponse> getUserInfo() {
UserInfoResponse userInfoResponse = userInfoService.execute();
return ResponseEntity.ok(userInfoResponse);
}

@GetMapping("/book")
public ResponseEntity<List<MyOrdersResponse>> getMyOrders() {
List<MyOrdersResponse> responses = getMyOrdersService.execute();
return ResponseEntity.ok(responses);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mindway.server.v2.domain.user.presentation.dto.response;

import lombok.Builder;
import lombok.Getter;

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

import com.mindway.server.v2.domain.user.presentation.dto.response.MyOrdersResponse;

import java.util.List;

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

import com.mindway.server.v2.domain.order.entity.Orders;
import com.mindway.server.v2.domain.order.repository.OrdersRepository;
import com.mindway.server.v2.domain.user.entity.User;
import com.mindway.server.v2.domain.user.presentation.dto.response.MyOrdersResponse;
import com.mindway.server.v2.domain.user.service.GetMyOrdersService;
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 GetMyOrdersServiceImpl implements GetMyOrdersService {

private final UserUtil userUtil;
private final OrdersRepository ordersRepository;

public List<MyOrdersResponse> execute() {
User user = userUtil.getCurrentUser();
List<Orders> ordersList = ordersRepository.findByUser(user);

return ordersList.stream()
.map(orders -> MyOrdersResponse.builder()
.title(orders.getTitle())
.author(orders.getAuthor())
.build())
.collect(Collectors.toList());
}
}
Loading