From 06b7d92efefaaf90b26bba91fde59d8c9d2356f9 Mon Sep 17 00:00:00 2001 From: HyoBin Yang <50162252+HyoBN@users.noreply.github.com> Date: Wed, 13 Sep 2023 16:12:27 +0900 Subject: [PATCH] =?UTF-8?q?Feature/91=E2=9C=A8=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=84=A0=ED=98=B8=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20API=20(#124)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :recycle: [Refactor] 회원가입 시, 주소 직접 입력 삭제 * :bug: [Fix] 회원가입 시, birth가 Null로 저장되는 에러 해결 * :art: 파일명 전달하지 않게 재변경 * :art: 회원가입 시 image 제거, 음료 카테고리 이미지 전달 추가 * :sparkles: 사용자 선호 음료 카테고리 조회 API * :memo: API 명세 작성 * :sparkles: 유저 선호 카테고리 수정 API --- .../server/repository/CategoryRepository.java | 3 +++ .../PreferCategoryRepository.java | 2 ++ .../server/service/MemberService.java | 2 ++ .../serviceImpl/MemberServiceImpl.java | 20 +++++++++++++++++++ .../web/controller/MemberRestController.java | 15 ++++++++++++++ .../web/dto/requestDto/MemberRequestDto.java | 7 +++++++ 6 files changed, 49 insertions(+) diff --git a/src/main/java/zipdabang/server/repository/CategoryRepository.java b/src/main/java/zipdabang/server/repository/CategoryRepository.java index 34dd66a..305e698 100644 --- a/src/main/java/zipdabang/server/repository/CategoryRepository.java +++ b/src/main/java/zipdabang/server/repository/CategoryRepository.java @@ -3,6 +3,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import zipdabang.server.domain.Category; +import java.util.Optional; + public interface CategoryRepository extends JpaRepository { + Optional findByName(String name); } diff --git a/src/main/java/zipdabang/server/repository/memberRepositories/PreferCategoryRepository.java b/src/main/java/zipdabang/server/repository/memberRepositories/PreferCategoryRepository.java index 62428d3..179d77a 100644 --- a/src/main/java/zipdabang/server/repository/memberRepositories/PreferCategoryRepository.java +++ b/src/main/java/zipdabang/server/repository/memberRepositories/PreferCategoryRepository.java @@ -8,4 +8,6 @@ public interface PreferCategoryRepository extends JpaRepository { List findByMember(Member member); + + void deleteByMember(Member member); } diff --git a/src/main/java/zipdabang/server/service/MemberService.java b/src/main/java/zipdabang/server/service/MemberService.java index 4c988c0..bc6b6e7 100644 --- a/src/main/java/zipdabang/server/service/MemberService.java +++ b/src/main/java/zipdabang/server/service/MemberService.java @@ -23,6 +23,8 @@ public interface MemberService { OAuthJoin.OAuthJoinDto joinInfoComplete(MemberRequestDto.MemberInfoDto request, String type); public List findMemberPreferCategories(Member member); + public void deletePreferCategoryByMember(Member member); + public void updateMemberPreferCategory(Member member, MemberRequestDto.changeCategoryDto request); public String updateMemberProfileImage(Member member, MemberRequestDto.changeProfileDto profileDto) throws IOException; public void updateMemberBasicInfo(Member member, MemberResponseDto.MemberBasicInfoDto memberBasicInfoDto); diff --git a/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java index c2d1a77..9b6513a 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java @@ -112,6 +112,26 @@ public void existByPhoneNumber(String phoneNum) { } + @Override + public void deletePreferCategoryByMember(Member member) { + preferCategoryRepository.deleteByMember(member); + } + @Override + @Transactional + public void updateMemberPreferCategory(Member member, MemberRequestDto.changeCategoryDto request) { + deletePreferCategoryByMember(member); + for (String categoryName : request.getCategories()) { + Category category = categoryRepository.findByName(categoryName).get(); + preferCategoryRepository.save(MemberPreferCategory.builder() + .member(member) + .category(category) + .build() + ); + } + } + + + @Override @Transactional public String updateMemberProfileImage(Member member, MemberRequestDto.changeProfileDto profileDto) throws IOException { diff --git a/src/main/java/zipdabang/server/web/controller/MemberRestController.java b/src/main/java/zipdabang/server/web/controller/MemberRestController.java index c8bded5..8196f6f 100644 --- a/src/main/java/zipdabang/server/web/controller/MemberRestController.java +++ b/src/main/java/zipdabang/server/web/controller/MemberRestController.java @@ -174,6 +174,8 @@ public ResponseDto showMyProfile(@AuthMember return null; } + + // 내 선호 음료 조회 @Operation(summary = "[figma 더보기 - 즐겨마시는 음료 종류 1] 유저 선호 카테고리 조회 API ✔️", description = "유저 선호 카테고리 조회 API입니다.") @Parameters({ @@ -186,6 +188,19 @@ public ResponseDto memberPreferCatego return ResponseDto.of(MemberConverter.toMemberPreferCategoryDto(categories)); } + // 내 선호 음료 카테고리 수정 + @Operation(summary = "[figma 더보기 - 즐겨마시는 음료 종류 1] 유저 선호 카테고리 수정 API ✔️", description = "유저 선호 카테고리 수정 API입니다. 카테고리명(커피, 차 등)을 넣으시면 됩니다.") + @Parameters({ + @Parameter(name = "member", hidden = true), + }) + @PatchMapping("/members/category") + public ResponseDto updatePreferCategories(@AuthMember Member member, @RequestBody MemberRequestDto.changeCategoryDto request) { + List categories = request.getCategories(); + memberService.updateMemberPreferCategory(member, request); + return ResponseDto.of(MemberConverter.toMemberStatusDto(member.getMemberId(),"updatePreferCategories")); + } + + // 회원정보 조회 및 수정 APIs diff --git a/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java b/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java index c2398b4..ace3ee2 100644 --- a/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java +++ b/src/main/java/zipdabang/server/web/dto/requestDto/MemberRequestDto.java @@ -6,6 +6,7 @@ import java.util.List; import org.springframework.web.multipart.MultipartFile; +import zipdabang.server.web.dto.responseDto.MemberResponseDto; public class MemberRequestDto { @@ -126,6 +127,12 @@ public String toString() { private MultipartFile profileImage; } + @Getter + @Setter + public static class changeCategoryDto { + List categories; + } + @Getter @Setter public static class changeNicknameDto{ String nickname;