diff --git a/src/main/java/aromanticcat/umcproject/controller/AddressBookController.java b/src/main/java/aromanticcat/umcproject/controller/AddressBookController.java deleted file mode 100644 index ec2bfc7..0000000 --- a/src/main/java/aromanticcat/umcproject/controller/AddressBookController.java +++ /dev/null @@ -1,24 +0,0 @@ -package aromanticcat.umcproject.controller; - - -import aromanticcat.umcproject.apiPayload.ApiResponse; -import aromanticcat.umcproject.service.AdressBookService.AddressBookQueryService; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/address-book") -@RequiredArgsConstructor -public class AddressBookController { - - private final AddressBookQueryService addressBookQueryService; - -// @GetMapping("/") -// @ApiOperation("주소록 조회") -// public ApiResponse<> - - -} diff --git a/src/main/java/aromanticcat/umcproject/converter/FriendConverter.java b/src/main/java/aromanticcat/umcproject/converter/FriendConverter.java new file mode 100644 index 0000000..ba2c87d --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/converter/FriendConverter.java @@ -0,0 +1,23 @@ +package aromanticcat.umcproject.converter; + +import aromanticcat.umcproject.web.dto.Friend.FriendResponseDTO; +import aromanticcat.umcproject.entity.Friend; +import org.springframework.data.domain.Page; + +import java.util.List; +import java.util.stream.Collectors; + +public class FriendConverter { + + // Friend 엔티티 -> DTO 생성 + public static FriendResponseDTO.FriendDTO toFriendDTO(Friend friend){ + + return FriendResponseDTO.FriendDTO.builder() + .friend_id(friend.getId()) + .friend_name(friend.getFriend_name()) + .are_we_friend(friend.isAre_we_friend()) + .are_we_close(friend.isAre_we_close()) + .build(); + } + +} diff --git a/src/main/java/aromanticcat/umcproject/dto/AddressBook/AddressBookRequestDTO.java b/src/main/java/aromanticcat/umcproject/dto/AddressBook/AddressBookRequestDTO.java deleted file mode 100644 index 714f3a0..0000000 --- a/src/main/java/aromanticcat/umcproject/dto/AddressBook/AddressBookRequestDTO.java +++ /dev/null @@ -1,5 +0,0 @@ -package aromanticcat.umcproject.dto.AddressBook; - - -public class AddressBookRequestDTO { -} diff --git a/src/main/java/aromanticcat/umcproject/dto/AddressBook/AddressBookRespondDTO.java b/src/main/java/aromanticcat/umcproject/dto/AddressBook/AddressBookRespondDTO.java deleted file mode 100644 index 11240c7..0000000 --- a/src/main/java/aromanticcat/umcproject/dto/AddressBook/AddressBookRespondDTO.java +++ /dev/null @@ -1,26 +0,0 @@ -package aromanticcat.umcproject.dto.AddressBook; - -import lombok.Getter; - -public class AddressBookRespondDTO { - - @Getter - public static class friendListDTO{ - -// List friends; - - } - - @Getter - public static class friendDTO{ - - Long friend_id; - - String friend_name; - - boolean are_we_friend; - - boolean are_we_close; - - } -} diff --git a/src/main/java/aromanticcat/umcproject/entity/Friend.java b/src/main/java/aromanticcat/umcproject/entity/Friend.java index 1a5043d..cabdd78 100644 --- a/src/main/java/aromanticcat/umcproject/entity/Friend.java +++ b/src/main/java/aromanticcat/umcproject/entity/Friend.java @@ -18,7 +18,7 @@ public class Friend extends BaseEntity { private String friend_name; - @JoinColumn(name = "to_user_id") + @JoinColumn(name = "member_id") @ManyToOne(fetch = FetchType.LAZY) private Member member; diff --git a/src/main/java/aromanticcat/umcproject/entity/Member.java b/src/main/java/aromanticcat/umcproject/entity/Member.java index 9be38f6..64fa847 100644 --- a/src/main/java/aromanticcat/umcproject/entity/Member.java +++ b/src/main/java/aromanticcat/umcproject/entity/Member.java @@ -15,6 +15,7 @@ public class Member extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "member_id") private Long id; private String nickname; diff --git a/src/main/java/aromanticcat/umcproject/repository/FriendRepository.java b/src/main/java/aromanticcat/umcproject/repository/FriendRepository.java new file mode 100644 index 0000000..95e6495 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/repository/FriendRepository.java @@ -0,0 +1,13 @@ +package aromanticcat.umcproject.repository; + +import aromanticcat.umcproject.entity.Friend; +import aromanticcat.umcproject.entity.Member; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FriendRepository extends JpaRepository { + + Page findByMember(Member member, Pageable pageable); +} diff --git a/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookCommandService.java b/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookCommandService.java deleted file mode 100644 index 7c0f793..0000000 --- a/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookCommandService.java +++ /dev/null @@ -1,4 +0,0 @@ -package aromanticcat.umcproject.service.AdressBookService; - -public interface AddressBookCommandService { -} diff --git a/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookCommandServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookCommandServiceImpl.java deleted file mode 100644 index a768a8a..0000000 --- a/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookCommandServiceImpl.java +++ /dev/null @@ -1,7 +0,0 @@ -package aromanticcat.umcproject.service.AdressBookService; - -import org.springframework.stereotype.Service; - -@Service -public class AddressBookCommandServiceImpl implements AddressBookCommandService{ -} diff --git a/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookQueryService.java b/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookQueryService.java deleted file mode 100644 index a2a05ae..0000000 --- a/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookQueryService.java +++ /dev/null @@ -1,4 +0,0 @@ -package aromanticcat.umcproject.service.AdressBookService; - -public interface AddressBookQueryService { -} diff --git a/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookQueryServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookQueryServiceImpl.java deleted file mode 100644 index dadc783..0000000 --- a/src/main/java/aromanticcat/umcproject/service/AdressBookService/AddressBookQueryServiceImpl.java +++ /dev/null @@ -1,7 +0,0 @@ -package aromanticcat.umcproject.service.AdressBookService; - -import org.springframework.stereotype.Service; - -@Service -public class AddressBookQueryServiceImpl implements AddressBookQueryService{ -} diff --git a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandService.java b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandService.java new file mode 100644 index 0000000..2bce938 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandService.java @@ -0,0 +1,4 @@ +package aromanticcat.umcproject.service.FriendService; + +public interface FriendCommandService { +} diff --git a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandServiceImpl.java new file mode 100644 index 0000000..d61fc9b --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandServiceImpl.java @@ -0,0 +1,7 @@ +package aromanticcat.umcproject.service.FriendService; + +import org.springframework.stereotype.Service; + +@Service +public class FriendCommandServiceImpl implements FriendCommandService { +} diff --git a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryService.java b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryService.java new file mode 100644 index 0000000..847cd4f --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryService.java @@ -0,0 +1,17 @@ +package aromanticcat.umcproject.service.FriendService; + +import aromanticcat.umcproject.entity.Friend; +import aromanticcat.umcproject.entity.Member; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.Optional; + +public interface FriendQueryService { + + Optional findMember(Long id); + + Page getFriendList(Long MemberId, Integer page); + + +} diff --git a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryServiceImpl.java new file mode 100644 index 0000000..2ce0778 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryServiceImpl.java @@ -0,0 +1,42 @@ +package aromanticcat.umcproject.service.FriendService; + +import aromanticcat.umcproject.entity.Friend; +import aromanticcat.umcproject.entity.Member; +import aromanticcat.umcproject.repository.FriendRepository; +import aromanticcat.umcproject.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +@Service +@RequiredArgsConstructor +@Transactional +public class FriendQueryServiceImpl implements FriendQueryService { + + private final MemberRepository memberRepository; + private final FriendRepository friendRepository; + + @Override + public Optional findMember(Long memberId) { + Optional member = memberRepository.findById(memberId); + return member; + } + + @Override + public Page getFriendList(Long MemberId, Integer page) { + + // page는 페이지의 번호, 12는 한 페이지에 보여줄 친구의 수 + Pageable pageable = PageRequest.of(page,12); + + Member member = memberRepository.findById(MemberId).get(); + + Page friendList = friendRepository.findByMember(member, pageable); + + return friendList; + } +} diff --git a/src/main/java/aromanticcat/umcproject/service/NangmanLetterService.java b/src/main/java/aromanticcat/umcproject/service/NangmanLetterService.java index 84e2df0..11e28e0 100644 --- a/src/main/java/aromanticcat/umcproject/service/NangmanLetterService.java +++ b/src/main/java/aromanticcat/umcproject/service/NangmanLetterService.java @@ -1,6 +1,6 @@ package aromanticcat.umcproject.service; -import aromanticcat.umcproject.dto.NangmanLetterDTO; +import aromanticcat.umcproject.web.dto.NangmanLetterDTO; public interface NangmanLetterService { diff --git a/src/main/java/aromanticcat/umcproject/service/NangmanLetterServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/NangmanLetterServiceImpl.java index 6dd28c0..1c83c3e 100644 --- a/src/main/java/aromanticcat/umcproject/service/NangmanLetterServiceImpl.java +++ b/src/main/java/aromanticcat/umcproject/service/NangmanLetterServiceImpl.java @@ -1,6 +1,6 @@ package aromanticcat.umcproject.service; -import aromanticcat.umcproject.dto.NangmanLetterDTO; +import aromanticcat.umcproject.web.dto.NangmanLetterDTO; import aromanticcat.umcproject.entity.NangmanLetter; import aromanticcat.umcproject.repository.MemberRepository; import aromanticcat.umcproject.repository.NangmanLetterRepository; diff --git a/src/main/java/aromanticcat/umcproject/web/controller/FriendController.java b/src/main/java/aromanticcat/umcproject/web/controller/FriendController.java new file mode 100644 index 0000000..5e46d0c --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/web/controller/FriendController.java @@ -0,0 +1,59 @@ +package aromanticcat.umcproject.web.controller; + + +import aromanticcat.umcproject.apiPayload.ApiResponse; +import aromanticcat.umcproject.converter.FriendConverter; +import aromanticcat.umcproject.entity.Friend; +import aromanticcat.umcproject.web.dto.Friend.FriendResponseDTO; +import aromanticcat.umcproject.service.FriendService.FriendQueryService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.stream.Collectors; + +@RestController +@RequestMapping("/address-book") +@RequiredArgsConstructor +public class FriendController { + + private final FriendQueryService friendQueryService; + + @GetMapping("/{member_id}") + @Operation(summary = "사용자의 주소록에 있는 친구들 조회 API", description = "페이징 포함을 포함합니다, query String으로 page 번호를 주세요.") +// @ApiResponses(value = { +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!", content = @Content(schema = @Schema(implementation = ApiResponse.class))), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), +// @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class))), +// }) + @Parameters({ + @Parameter(name = "memberId", description = "사용자의 아이디, path variable 입니다!"), + @Parameter(name = "page", description = "페이지 번호, 0번이 1번 페이지 입니다.") + }) + public ApiResponse> getFriendList(@PathVariable(name = "member_id") Long memberId, + @RequestParam(value = "page", defaultValue = "0") Integer page){ + try{ + // 페이지별 친구 목록 조회 + Page friendList = friendQueryService.getFriendList(memberId, page); + + // 친구 내용을 간략하게 변환 + List friendDTOList = friendList.stream() + .map(FriendConverter::toFriendDTO) + .collect(Collectors.toList()); + + // 성공 응답 생성 + return ApiResponse.onSuccess(friendDTOList); + + }catch (Exception e){ + return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null); + } + } + + +} diff --git a/src/main/java/aromanticcat/umcproject/controller/NangmanLetterController.java b/src/main/java/aromanticcat/umcproject/web/controller/NangmanLetterController.java similarity index 92% rename from src/main/java/aromanticcat/umcproject/controller/NangmanLetterController.java rename to src/main/java/aromanticcat/umcproject/web/controller/NangmanLetterController.java index 9224798..c7ff69f 100644 --- a/src/main/java/aromanticcat/umcproject/controller/NangmanLetterController.java +++ b/src/main/java/aromanticcat/umcproject/web/controller/NangmanLetterController.java @@ -1,7 +1,7 @@ -package aromanticcat.umcproject.controller; +package aromanticcat.umcproject.web.controller; import aromanticcat.umcproject.apiPayload.ApiResponse; -import aromanticcat.umcproject.dto.NangmanLetterDTO; +import aromanticcat.umcproject.web.dto.NangmanLetterDTO; import aromanticcat.umcproject.service.NangmanLetterService; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/aromanticcat/umcproject/web/dto/Friend/FriendRequestDTO.java b/src/main/java/aromanticcat/umcproject/web/dto/Friend/FriendRequestDTO.java new file mode 100644 index 0000000..f7ddb02 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/web/dto/Friend/FriendRequestDTO.java @@ -0,0 +1,5 @@ +package aromanticcat.umcproject.web.dto.Friend; + + +public class FriendRequestDTO { +} diff --git a/src/main/java/aromanticcat/umcproject/web/dto/Friend/FriendResponseDTO.java b/src/main/java/aromanticcat/umcproject/web/dto/Friend/FriendResponseDTO.java new file mode 100644 index 0000000..cb3b5c2 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/web/dto/Friend/FriendResponseDTO.java @@ -0,0 +1,18 @@ +package aromanticcat.umcproject.web.dto.Friend; + +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +public class FriendResponseDTO { + + @Getter + @Builder + public static class FriendDTO{ + Long friend_id; + String friend_name; + boolean are_we_friend; + boolean are_we_close; + } +} diff --git a/src/main/java/aromanticcat/umcproject/dto/NangmanLetterDTO.java b/src/main/java/aromanticcat/umcproject/web/dto/NangmanLetterDTO.java similarity index 95% rename from src/main/java/aromanticcat/umcproject/dto/NangmanLetterDTO.java rename to src/main/java/aromanticcat/umcproject/web/dto/NangmanLetterDTO.java index a161783..efffe9a 100644 --- a/src/main/java/aromanticcat/umcproject/dto/NangmanLetterDTO.java +++ b/src/main/java/aromanticcat/umcproject/web/dto/NangmanLetterDTO.java @@ -1,4 +1,4 @@ -package aromanticcat.umcproject.dto; +package aromanticcat.umcproject.web.dto; import lombok.AllArgsConstructor; import lombok.Builder;