From 9e3460d34ae0fd6ae3492adc421dd598ea1d3a0c Mon Sep 17 00:00:00 2001 From: Donghun Won Date: Thu, 19 Sep 2024 22:24:41 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Fix=20:=20oauth=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=88=98=EC=A0=95,=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EB=AA=A8=EC=9E=84=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 마이페이지 모임 조회 안되는 문제 수정 마이페이지 모임 인원수 계산 안되는 문제 수정 --- .gitignore | 1 + .../solitour/auth/service/OauthService.java | 3 +- .../solitour/auth/service/TokenService.java | 5 ++- .../dto/response/GatheringMypageResponse.java | 35 +++++++++++++++ .../user/controller/UserController.java | 9 ++-- .../user/repository/UserRepositoryCustom.java | 5 ++- .../user/repository/UserRepositoryImpl.java | 45 ++++++++++++------- .../solitour/user/service/UserService.java | 5 ++- src/main/resources/schema.sql | 3 +- 9 files changed, 84 insertions(+), 27 deletions(-) create mode 100644 src/main/java/solitour_backend/solitour/gathering/dto/response/GatheringMypageResponse.java diff --git a/.gitignore b/.gitignore index 0678df4..9bf4c60 100644 --- a/.gitignore +++ b/.gitignore @@ -181,3 +181,4 @@ Temporary Items # 설정 파일 /src/main/resources/**.yml +/src/main/resources diff --git a/src/main/java/solitour_backend/solitour/auth/service/OauthService.java b/src/main/java/solitour_backend/solitour/auth/service/OauthService.java index ca47091..60b7723 100644 --- a/src/main/java/solitour_backend/solitour/auth/service/OauthService.java +++ b/src/main/java/solitour_backend/solitour/auth/service/OauthService.java @@ -99,7 +99,8 @@ private User checkAndSaveUser(String type, String code, String redirectUrl) { User user = userRepository.findByOauthId(id) .orElseGet(() -> saveKakaoUser(kakaoUserResponse)); - tokenService.saveToken(tokenResponse, user); + Token token = tokenRepository.findByUserId(user.getId()) + .orElseGet(() -> tokenService.saveToken(tokenResponse, user)); return user; } diff --git a/src/main/java/solitour_backend/solitour/auth/service/TokenService.java b/src/main/java/solitour_backend/solitour/auth/service/TokenService.java index f6cc983..99eebc6 100644 --- a/src/main/java/solitour_backend/solitour/auth/service/TokenService.java +++ b/src/main/java/solitour_backend/solitour/auth/service/TokenService.java @@ -30,13 +30,14 @@ public void deleteByMemberId(Long memberId) { } @Transactional - public void saveToken(KakaoTokenResponse tokenResponse, User user) { + public Token saveToken(KakaoTokenResponse tokenResponse, User user) { Token token = Token.builder() .user(user) .oauthToken(tokenResponse.getRefreshToken()) - .refreshToken("test") .build(); tokenRepository.save(token); + + return token; } } diff --git a/src/main/java/solitour_backend/solitour/gathering/dto/response/GatheringMypageResponse.java b/src/main/java/solitour_backend/solitour/gathering/dto/response/GatheringMypageResponse.java new file mode 100644 index 0000000..ae28a0e --- /dev/null +++ b/src/main/java/solitour_backend/solitour/gathering/dto/response/GatheringMypageResponse.java @@ -0,0 +1,35 @@ +package solitour_backend.solitour.gathering.dto.response; + +import java.time.LocalDateTime; +import lombok.AllArgsConstructor; +import lombok.Getter; +import solitour_backend.solitour.gathering.entity.AllowedSex; + +@Getter +@AllArgsConstructor +public class GatheringMypageResponse { + private Long gatheringId; + private String title; + private String zoneCategoryParentName; + private String zoneCategoryChildName; + private Integer viewCount; + private Boolean isBookMark; + private Integer likeCount; + + private String gatheringCategoryName; + private String userName; + + private LocalDateTime scheduleStartDate; + private LocalDateTime scheduleEndDate; + + private LocalDateTime deadline; + + private AllowedSex allowedSex; + + private Integer startAge; + private Integer endAge; + private Integer personCount; + private Integer nowPersonCount; + private Boolean isLike; + private Boolean isFinish; +} diff --git a/src/main/java/solitour_backend/solitour/user/controller/UserController.java b/src/main/java/solitour_backend/solitour/user/controller/UserController.java index 7379613..9f0207f 100644 --- a/src/main/java/solitour_backend/solitour/user/controller/UserController.java +++ b/src/main/java/solitour_backend/solitour/user/controller/UserController.java @@ -24,6 +24,7 @@ import solitour_backend.solitour.auth.support.kakao.KakaoConnector; import solitour_backend.solitour.gathering.dto.response.GatheringApplicantResponse; import solitour_backend.solitour.gathering.dto.response.GatheringBriefResponse; +import solitour_backend.solitour.gathering.dto.response.GatheringMypageResponse; import solitour_backend.solitour.information.dto.response.InformationBriefResponse; import solitour_backend.solitour.user.dto.UpdateAgeAndSex; import solitour_backend.solitour.user.dto.UpdateNicknameRequest; @@ -111,22 +112,22 @@ public ResponseEntity> retrieveInformationBookmar } @GetMapping("/mypage/gathering/host") - public ResponseEntity> retrieveGatheringHost( + public ResponseEntity> retrieveGatheringHost( @RequestParam(defaultValue = "0") int page, @AuthenticationPrincipal Long userId) { Pageable pageable = PageRequest.of(page, PAGE_SIZE); - Page response = userService.retrieveGatheringHost(pageable, userId); + Page response = userService.retrieveGatheringHost(pageable, userId); return ResponseEntity.ok(response); } @GetMapping("/mypage/gathering/bookmark") - public ResponseEntity> retrieveGatheringBookmark( + public ResponseEntity> retrieveGatheringBookmark( @RequestParam(defaultValue = "0") int page, @AuthenticationPrincipal Long userId) { Pageable pageable = PageRequest.of(page, PAGE_SIZE); - Page response = userService.retrieveGatheringBookmark(pageable, + Page response = userService.retrieveGatheringBookmark(pageable, userId); return ResponseEntity.ok(response); diff --git a/src/main/java/solitour_backend/solitour/user/repository/UserRepositoryCustom.java b/src/main/java/solitour_backend/solitour/user/repository/UserRepositoryCustom.java index 4d98c1e..1ae4a26 100644 --- a/src/main/java/solitour_backend/solitour/user/repository/UserRepositoryCustom.java +++ b/src/main/java/solitour_backend/solitour/user/repository/UserRepositoryCustom.java @@ -5,6 +5,7 @@ import org.springframework.data.repository.NoRepositoryBean; import solitour_backend.solitour.gathering.dto.response.GatheringApplicantResponse; import solitour_backend.solitour.gathering.dto.response.GatheringBriefResponse; +import solitour_backend.solitour.gathering.dto.response.GatheringMypageResponse; import solitour_backend.solitour.information.dto.response.InformationBriefResponse; @@ -15,9 +16,9 @@ public interface UserRepositoryCustom { Page retrieveInformationBookmark(Pageable pageable, Long userId); - Page retrieveGatheringHost(Pageable pageable, Long userId); + Page retrieveGatheringHost(Pageable pageable, Long userId); - Page retrieveGatheringBookmark(Pageable pageable, Long userId); + Page retrieveGatheringBookmark(Pageable pageable, Long userId); Page retrieveGatheringApplicant(Pageable pageable, Long userId); diff --git a/src/main/java/solitour_backend/solitour/user/repository/UserRepositoryImpl.java b/src/main/java/solitour_backend/solitour/user/repository/UserRepositoryImpl.java index b2eade6..165203f 100644 --- a/src/main/java/solitour_backend/solitour/user/repository/UserRepositoryImpl.java +++ b/src/main/java/solitour_backend/solitour/user/repository/UserRepositoryImpl.java @@ -19,7 +19,8 @@ import solitour_backend.solitour.book_mark_gathering.entity.QBookMarkGathering; import solitour_backend.solitour.book_mark_information.entity.QBookMarkInformation; import solitour_backend.solitour.gathering.dto.response.GatheringApplicantResponse; -import solitour_backend.solitour.gathering.dto.response.GatheringBriefResponse; +import solitour_backend.solitour.gathering.dto.response.GatheringMypageResponse; +import solitour_backend.solitour.gathering.dto.response.GatheringMypageResponse; import solitour_backend.solitour.gathering.entity.Gathering; import solitour_backend.solitour.gathering.entity.QGathering; import solitour_backend.solitour.gathering_applicants.entity.GatheringStatus; @@ -108,7 +109,7 @@ public Page retrieveInformationBookmark(Pageable pagea .leftJoin(image).on(image.information.id.eq(information.id) .and(image.imageStatus.eq(ImageStatus.THUMBNAIL))) .leftJoin(greatInformation).on(greatInformation.information.id.eq(information.id)) - .where(information.user.id.eq(userId).and(bookMarkInformation.user.id.eq(userId))); + .where(bookMarkInformation.user.id.eq(userId)); List list = query .groupBy(information.id, zoneCategoryParent.id, zoneCategoryChild.id, @@ -136,7 +137,7 @@ public Page retrieveInformationBookmark(Pageable pagea } @Override - public Page retrieveGatheringHost(Pageable pageable, Long userId) { + public Page retrieveGatheringHost(Pageable pageable, Long userId) { NumberExpression likeCount = countGreatGatheringByGatheringById(); BooleanExpression isBookMark = isGatheringBookmark(userId); @@ -150,11 +151,11 @@ public Page retrieveGatheringHost(Pageable pageable, Lon .orderBy(gathering.createdAt.desc()) .where(gathering.user.id.eq(userId)); - List list = query + List list = query .groupBy(gathering.id, zoneCategoryParent.id, zoneCategoryChild.id, gatheringCategory.id) .select(Projections.constructor( - GatheringBriefResponse.class, + GatheringMypageResponse.class, gathering.id, gathering.title, zoneCategoryParent.name, @@ -172,7 +173,8 @@ public Page retrieveGatheringHost(Pageable pageable, Lon gathering.endAge, gathering.personCount, gatheringApplicants.count().coalesce(0L).intValue(), - isUserGreatGathering(userId) + isUserGreatGathering(userId), + gathering.isFinish )) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) @@ -183,7 +185,7 @@ public Page retrieveGatheringHost(Pageable pageable, Lon } @Override - public Page retrieveGatheringBookmark(Pageable pageable, Long userId) { + public Page retrieveGatheringBookmark(Pageable pageable, Long userId) { NumberExpression likeCount = countGreatGatheringByGatheringById(); BooleanExpression isBookMark = isGatheringBookmark(userId); @@ -199,11 +201,11 @@ public Page retrieveGatheringBookmark(Pageable pageable, .orderBy(gathering.createdAt.desc()) .where(bookMarkGathering.user.id.eq(userId)); - List list = query + List list = query .groupBy(gathering.id, zoneCategoryParent.id, zoneCategoryChild.id, gatheringCategory.id) .select(Projections.constructor( - GatheringBriefResponse.class, + GatheringMypageResponse.class, gathering.id, gathering.title, zoneCategoryParent.name, @@ -221,7 +223,8 @@ public Page retrieveGatheringBookmark(Pageable pageable, gathering.endAge, gathering.personCount, gatheringApplicants.count().coalesce(0L).intValue(), - isUserGreatGathering(userId) + isUserGreatGathering(userId), + gathering.isFinish )) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) @@ -236,6 +239,8 @@ public Page retrieveGatheringApplicant(Pageable page NumberExpression likeCount = countGreatGatheringByGatheringById(); BooleanExpression isBookMark = isGatheringBookmark(userId); StringExpression gatheringStatus = getGatheringStatus(); + NumberExpression gatheringApplicantCount = countGatheringApplicant(userId); + JPQLQuery query = from(gathering) .leftJoin(zoneCategoryParent) @@ -243,15 +248,13 @@ public Page retrieveGatheringApplicant(Pageable page .leftJoin(gatheringCategory) .on(gatheringCategory.id.eq(gathering.gatheringCategory.id)) .leftJoin(gatheringApplicants) - .on(gatheringApplicants.gathering.id.eq(gathering.id).and(gatheringApplicants.gatheringStatus.eq(GatheringStatus.CONSENT))) - .leftJoin(gatheringApplicants) .on(gatheringApplicants.gathering.id.eq(gathering.id)) .orderBy(gathering.createdAt.desc()) .where(gatheringApplicants.user.id.eq(userId).and(gathering.user.id.eq(userId).not())); List list = query .groupBy(gathering.id, zoneCategoryParent.id, zoneCategoryChild.id, - gatheringCategory.id, gatheringApplicants.id) + gatheringCategory.id, gatheringApplicants.id) .select(Projections.constructor( GatheringApplicantResponse.class, gathering.id, @@ -270,8 +273,7 @@ public Page retrieveGatheringApplicant(Pageable page gathering.startAge, gathering.endAge, gathering.personCount, - gatheringApplicants.count().coalesce(0L).intValue(), - isUserGreatGathering(userId), + gatheringApplicantCount, isUserGreatGathering(userId), gatheringStatus, gathering.isFinish )) @@ -283,6 +285,19 @@ public Page retrieveGatheringApplicant(Pageable page return new PageImpl<>(list, pageable, total); } + private NumberExpression countGatheringApplicant(Long userId) { + QGatheringApplicants gatheringApplicants = QGatheringApplicants.gatheringApplicants; + + JPQLQuery countApplicant = JPAExpressions + .select(gatheringApplicants.count()) + .from(gatheringApplicants) + .where(gatheringApplicants.user.id.eq(userId).and(gatheringApplicants.gatheringStatus.eq(GatheringStatus.CONSENT))); + + return Expressions.numberTemplate(Long.class, "{0}", countApplicant) + .coalesce(0L) + .intValue(); + } + @Override public String getProfileUrl(String gender) { if ("male".equalsIgnoreCase(gender)) { diff --git a/src/main/java/solitour_backend/solitour/user/service/UserService.java b/src/main/java/solitour_backend/solitour/user/service/UserService.java index a8dc03a..d0b5b0b 100644 --- a/src/main/java/solitour_backend/solitour/user/service/UserService.java +++ b/src/main/java/solitour_backend/solitour/user/service/UserService.java @@ -9,6 +9,7 @@ import org.springframework.web.multipart.MultipartFile; import solitour_backend.solitour.gathering.dto.response.GatheringApplicantResponse; import solitour_backend.solitour.gathering.dto.response.GatheringBriefResponse; +import solitour_backend.solitour.gathering.dto.response.GatheringMypageResponse; import solitour_backend.solitour.image.s3.S3Uploader; import solitour_backend.solitour.information.dto.response.InformationBriefResponse; import solitour_backend.solitour.user.entity.User; @@ -64,11 +65,11 @@ public void updateUserProfile(Long userId, MultipartFile userProfile) { user.updateUserImage(response.getImageUrl()); } - public Page retrieveGatheringHost(Pageable pageable, Long userId) { + public Page retrieveGatheringHost(Pageable pageable, Long userId) { return userRepository.retrieveGatheringHost(pageable, userId); } - public Page retrieveGatheringBookmark(Pageable pageable, Long userId) { + public Page retrieveGatheringBookmark(Pageable pageable, Long userId) { return userRepository.retrieveGatheringBookmark(pageable, userId); } diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 32ea927..d9b1a94 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -57,7 +57,8 @@ CREATE TABLE `token` ( `token_id` BIGINT NOT NULL AUTO_INCREMENT, `user_id` BIGINT NOT NULL, - `refresh_token` VARCHAR(250) NOT NULL, + `refresh_token` VARCHAR(250) NULL, + `oauth_token` VARCHAR(250) NULL, CONSTRAINT PK_TOKEN PRIMARY KEY (`token_id`), CONSTRAINT FK_USER_TO_TOKEN FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ); From 775b4a304efaff8a4e4f4de05b14b960480c6867 Mon Sep 17 00:00:00 2001 From: Donghun Won Date: Sat, 21 Sep 2024 20:39:22 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Fix=20:=20=EC=9C=A0=EC=A0=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20s3=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=82=AD=EC=A0=9C=EB=90=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 11 ++++--- .../solitour/user/service/UserService.java | 32 ++++++++++++++++++- .../controller/UserImageController.java | 2 +- .../user_image/service/UserImageService.java | 2 +- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/main/java/solitour_backend/solitour/user/controller/UserController.java b/src/main/java/solitour_backend/solitour/user/controller/UserController.java index 9f0207f..430a585 100644 --- a/src/main/java/solitour_backend/solitour/user/controller/UserController.java +++ b/src/main/java/solitour_backend/solitour/user/controller/UserController.java @@ -40,10 +40,6 @@ public class UserController { private final UserService userService; - private final OauthService oauthservice; - private final KakaoConnector kakaoConnector; - private final GoogleConnector googleConnector; - public static final int PAGE_SIZE = 6; @GetMapping("/info") @@ -89,6 +85,13 @@ public ResponseEntity updateUserProfile(@AuthenticationPrincipal Long user return ResponseEntity.ok().build(); } + @DeleteMapping("/profile") + public ResponseEntity deleteUserProfile(@AuthenticationPrincipal Long userId) { + userService.deleteUserProfile(userId); + + return ResponseEntity.ok().build(); + } + @GetMapping("/mypage/information/owner") public ResponseEntity> retrieveInformationOwner( @RequestParam(defaultValue = "0") int page, diff --git a/src/main/java/solitour_backend/solitour/user/service/UserService.java b/src/main/java/solitour_backend/solitour/user/service/UserService.java index d0b5b0b..344cfa9 100644 --- a/src/main/java/solitour_backend/solitour/user/service/UserService.java +++ b/src/main/java/solitour_backend/solitour/user/service/UserService.java @@ -28,6 +28,11 @@ public class UserService { private final UserRepository userRepository; private final UserImageService userImageService; + private final S3Uploader s3Uploader; + @Value("${user.profile.url.female}") + private String femaleProfileUrl; + @Value("${user.profile.male}") + private String maleProfileUrl; public UserInfoResponse retrieveUserInfo(Long userId) { User user = userRepository.findByUserId(userId); @@ -60,11 +65,36 @@ public Page retrieveInformationBookmark(Pageable pagea @Transactional public void updateUserProfile(Long userId, MultipartFile userProfile) { - UserImageResponse response = userImageService.registerInformation(userId, userProfile); + UserImageResponse response = userImageService.updateUserProfile(userId, userProfile); User user = userRepository.findByUserId(userId); + checkUserProfile(user.getUserImage().getAddress()); user.updateUserImage(response.getImageUrl()); } + @Transactional + public void deleteUserProfile(Long userId) { + User user = userRepository.findByUserId(userId); + resetUserProfile(user,user.getUserImage().getAddress(),user.getSex()); + } + + private void resetUserProfile(User user, String imageUrl,String sex) { + checkUserProfile(imageUrl); + if(sex.equals("male")){ + user.updateUserImage(maleProfileUrl); + } else if (sex.equals("female")) { + user.updateUserImage(femaleProfileUrl); + }else{ + user.updateUserImage(noneProfileUrl); + } + } + + private void checkUserProfile(String imageUrl) { + if(imageUrl.equals(femaleProfileUrl) || imageUrl.equals(maleProfileUrl )|| imageUrl.equals(noneProfileUrl)){ { + return; + } + s3Uploader.deleteImage(imageUrl); + } + public Page retrieveGatheringHost(Pageable pageable, Long userId) { return userRepository.retrieveGatheringHost(pageable, userId); } diff --git a/src/main/java/solitour_backend/solitour/user_image/controller/UserImageController.java b/src/main/java/solitour_backend/solitour/user_image/controller/UserImageController.java index 0db91a5..bb79834 100644 --- a/src/main/java/solitour_backend/solitour/user_image/controller/UserImageController.java +++ b/src/main/java/solitour_backend/solitour/user_image/controller/UserImageController.java @@ -27,7 +27,7 @@ public ResponseEntity createUserImage(@RequestPart("request") @RequestPart("userImage") MultipartFile userImage, BindingResult bindingResult) { Utils.validationRequest(bindingResult); - UserImageResponse informationResponse = userImageService.registerInformation( + UserImageResponse informationResponse = userImageService.updateUserProfile( imageRequest.getUserId(), userImage); return ResponseEntity diff --git a/src/main/java/solitour_backend/solitour/user_image/service/UserImageService.java b/src/main/java/solitour_backend/solitour/user_image/service/UserImageService.java index 2a9496b..6f50992 100644 --- a/src/main/java/solitour_backend/solitour/user_image/service/UserImageService.java +++ b/src/main/java/solitour_backend/solitour/user_image/service/UserImageService.java @@ -29,7 +29,7 @@ public UserImage saveUserImage(String imageUrl) { } @Transactional - public UserImageResponse registerInformation(Long userId, MultipartFile userImage) { + public UserImageResponse updateUserProfile(Long userId, MultipartFile userImage) { String userImageUrl = s3Uploader.upload(userImage, IMAGE_PATH, userId); From 650c015641a6e2dae0fa211bbadc1877c0d32e2f Mon Sep 17 00:00:00 2001 From: Donghun Won Date: Sat, 21 Sep 2024 23:03:05 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Feat=20:=20=EC=84=B1=EB=B3=84=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=97=86=EC=9D=84=EB=95=8C=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solitour_backend/solitour/user/service/UserService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/solitour_backend/solitour/user/service/UserService.java b/src/main/java/solitour_backend/solitour/user/service/UserService.java index 344cfa9..f6e3fbf 100644 --- a/src/main/java/solitour_backend/solitour/user/service/UserService.java +++ b/src/main/java/solitour_backend/solitour/user/service/UserService.java @@ -33,6 +33,8 @@ public class UserService { private String femaleProfileUrl; @Value("${user.profile.male}") private String maleProfileUrl; + @Value("${user.profile.none}") + private String noneProfileUrl; public UserInfoResponse retrieveUserInfo(Long userId) { User user = userRepository.findByUserId(userId);