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

Feat : 유저 프로필 삭제 기능 #190

Merged
merged 4 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Expand Up @@ -32,7 +32,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
if (authenticated.isPresent()) {
try {
validateToken(request);
}catch (TokenNotValidException e) {
} catch (TokenNotValidException e) {
throw new TokenNotExistsException("토큰이 존재하지 않습니다.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import solitour_backend.solitour.auth.exception.TokenNotExistsException;
import solitour_backend.solitour.auth.support.CookieExtractor;
import solitour_backend.solitour.auth.support.JwtTokenProvider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public class Token {
@JoinColumn(name = "user_id")
private User user;

@Column(nullable = false,name = "refresh_token")
@Column(nullable = false, name = "refresh_token")
private String refreshToken;

@Column(nullable = false,name = "oauth_token")
@Column(nullable = false, name = "oauth_token")
private String oauthToken;

public Token(User user, String refreshToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import jdk.jshell.spi.ExecutionControl.UserException;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatusCode;
Expand Down Expand Up @@ -81,7 +80,7 @@ public LoginResponse requestAccessToken(String type, String code, String redirec
Cookie accessCookie = createCookie("access_token", token, ACCESS_COOKIE_AGE);
Cookie refreshCookie = createCookie("refresh_token", refreshToken, REFRESH_COOKIE_AGE);

return new LoginResponse(accessCookie, refreshCookie,user.getUserStatus());
return new LoginResponse(accessCookie, refreshCookie, user.getUserStatus());
}

private Cookie createCookie(String name, String value, int maxAge) {
Expand All @@ -100,7 +99,7 @@ private User checkAndSaveUser(String type, String code, String redirectUrl) {
KakaoUserResponse kakaoUserResponse = response.getKakaoUserResponse();

String id = kakaoUserResponse.getId().toString();
User user = userRepository.findByOauthId(id)
User user = userRepository.findByOauthId(id)
.orElseGet(() -> saveKakaoUser(kakaoUserResponse));

checkUserStatus(user);
Expand All @@ -120,18 +119,18 @@ private User checkAndSaveUser(String type, String code, String redirectUrl) {
throw new RuntimeException("지원하지 않는 oauth 타입입니다.");
}
}

private void checkUserStatus(User user) {
UserStatus userStatus = user.getUserStatus();
switch (userStatus){
switch (userStatus) {
case BLOCK -> throw new BlockedUserException("차단된 계정입니다.");
case DELETE -> throw new DeletedUserException("탈퇴한 계정입니다.");
case DORMANT -> throw new DormantUserException("휴면 계정입니다.");
}
}

private void saveToken(KakaoTokenResponse tokenResponse, User user) {
Token token = Token.builder()
Token token = Token.builder()
.user(user)
.oauthToken(tokenResponse.getRefreshToken())
.build();
Expand Down Expand Up @@ -258,21 +257,23 @@ public void deleteUser(Long userId) {

private void changeToDefaultProfile(User user, UserImage userImage) {
String defaultImageUrl = getDefaultProfile(user);
deleteUserProfileFromS3(userImage,defaultImageUrl);
deleteUserProfileFromS3(userImage, defaultImageUrl);
}

private String getDefaultProfile(User user) {
String sex = user.getSex();
if(sex.equals("male")){{
return USER_PROFILE_MALE;
}} else {
if (sex.equals("male")) {
{
return USER_PROFILE_MALE;
}
} else {
return USER_PROFILE_FEMALE;
}
}

private void deleteUserProfileFromS3(UserImage userImage,String defaultImageUrl) {
private void deleteUserProfileFromS3(UserImage userImage, String defaultImageUrl) {
String userImageUrl = userImage.getAddress();
if(userImageUrl.equals(USER_PROFILE_MALE) || userImageUrl.equals(USER_PROFILE_FEMALE)){
if (userImageUrl.equals(USER_PROFILE_MALE) || userImageUrl.equals(USER_PROFILE_FEMALE)) {
return;
}
s3Uploader.deleteImage(userImageUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import java.io.IOException;
import java.util.Collections;
import java.util.Optional;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpEntity;
Expand Down Expand Up @@ -37,10 +36,11 @@ public KakaoTokenAndUserResponse requestKakaoUserInfo(String code, String redire
headers.set("Authorization", String.join(" ", BEARER_TYPE, kakaoToken.getAccessToken()));
HttpEntity<Void> entity = new HttpEntity<>(headers);

ResponseEntity<KakaoUserResponse> responseEntity = REST_TEMPLATE.exchange(provider.getUserInfoUrl(), HttpMethod.GET, entity,
ResponseEntity<KakaoUserResponse> responseEntity = REST_TEMPLATE.exchange(provider.getUserInfoUrl(),
HttpMethod.GET, entity,
KakaoUserResponse.class);

return new KakaoTokenAndUserResponse(kakaoToken,responseEntity.getBody());
return new KakaoTokenAndUserResponse(kakaoToken, responseEntity.getBody());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import solitour_backend.solitour.auth.config.Authenticated;
import solitour_backend.solitour.auth.config.AuthenticationPrincipal;
import solitour_backend.solitour.book_mark_gathering.dto.response.BookMarkGatheringResponse;
import solitour_backend.solitour.book_mark_gathering.entity.BookMarkGathering;
import solitour_backend.solitour.book_mark_gathering.service.BookMarkGatheringService;
import solitour_backend.solitour.book_mark_information.service.BookMarkInformationService;
import solitour_backend.solitour.book_mark_information.service.dto.response.BookMarkInformationResponse;

@Authenticated
@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import solitour_backend.solitour.gathering.entity.Gathering;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import solitour_backend.solitour.book_mark_gathering.entity.BookMarkGathering;
import solitour_backend.solitour.book_mark_information.entity.BookMarkInformation;

public interface BookMarkGatheringRepository extends JpaRepository<BookMarkGathering, Long> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -13,7 +12,6 @@
import solitour_backend.solitour.auth.config.AuthenticationPrincipal;
import solitour_backend.solitour.book_mark_information.entity.BookMarkInformation;
import solitour_backend.solitour.book_mark_information.service.BookMarkInformationService;
import solitour_backend.solitour.book_mark_information.service.dto.response.BookMarkInformationResponse;

@Authenticated
@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package solitour_backend.solitour.book_mark_information.service;

import jakarta.persistence.EntityNotFoundException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import solitour_backend.solitour.book_mark_gathering.entity.BookMarkGathering;
import solitour_backend.solitour.book_mark_information.entity.BookMarkInformation;
import solitour_backend.solitour.book_mark_information.entity.BookMarkInformationRepository;
import solitour_backend.solitour.book_mark_information.exception.InformationBookMarkNotExistsException;
import solitour_backend.solitour.book_mark_information.service.dto.response.BookMarkInformationResponse;
import solitour_backend.solitour.information.entity.Information;
import solitour_backend.solitour.information.repository.InformationRepository;
import solitour_backend.solitour.user.entity.User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import org.springframework.web.bind.annotation.RestController;
import solitour_backend.solitour.auth.config.Authenticated;
import solitour_backend.solitour.auth.config.AuthenticationPrincipal;
import solitour_backend.solitour.diary.dto.request.DiaryCreateRequest;
import solitour_backend.solitour.diary.dto.request.DiaryUpdateRequest;
import solitour_backend.solitour.diary.dto.response.DiaryContent;
import solitour_backend.solitour.diary.dto.request.DiaryCreateRequest;
import solitour_backend.solitour.diary.dto.response.DiaryResponse;
import solitour_backend.solitour.diary.service.DiaryService;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package solitour_backend.solitour.diary.dto.response;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import solitour_backend.solitour.diary.diary_day_content.DiaryDayContent;
import solitour_backend.solitour.diary.dto.request.DiaryCreateRequest;
import solitour_backend.solitour.diary.dto.request.DiaryUpdateRequest;
import solitour_backend.solitour.user.entity.User;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import java.time.LocalDateTime;
import java.util.List;

import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import solitour_backend.solitour.diary.diary_day_content.DiaryDayContent;
import solitour_backend.solitour.diary.dto.request.DiaryCreateRequest;
import solitour_backend.solitour.diary.dto.request.DiaryCreateRequest.DiaryDayRequest;
import solitour_backend.solitour.diary.dto.request.DiaryUpdateRequest;
import solitour_backend.solitour.diary.dto.request.DiaryUpdateRequest.DiaryUpdateDayRequest;
import solitour_backend.solitour.diary.dto.response.DiaryContent;
import solitour_backend.solitour.diary.dto.request.DiaryCreateRequest;
import solitour_backend.solitour.diary.dto.request.DiaryCreateRequest.DiaryDayRequest;
import solitour_backend.solitour.diary.dto.response.DiaryResponse;
import solitour_backend.solitour.diary.entity.Diary;
import solitour_backend.solitour.diary.exception.DiaryNotExistsException;
Expand Down Expand Up @@ -134,7 +133,6 @@ private void deleteDiaryImage(DiaryUpdateRequest request) {
s3Uploader.deleteImage(request.getDeleteTitleImage());
}


for (DiaryUpdateDayRequest dayRequest : request.getDiaryDayRequests()) {
for (String imageUrl : dayRequest.getSplitImageUrl(dayRequest.getDeleteImagesUrl())) {
s3Uploader.deleteImage(imageUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import solitour_backend.solitour.auth.config.AuthenticationPrincipal;
import solitour_backend.solitour.great_gathering.entity.GreatGathering;
import solitour_backend.solitour.great_gathering.service.GreatGatheringService;
import solitour_backend.solitour.great_information.entity.GreatInformation;
import solitour_backend.solitour.great_information.service.GreatInformationService;

@Authenticated
@RestController
Expand All @@ -24,15 +22,15 @@ public class GreatGatheringController {

@PostMapping()
public ResponseEntity<Long> createGatheringGreat(@AuthenticationPrincipal Long userId,
@RequestParam Long gatheringId) {
@RequestParam Long gatheringId) {
GreatGathering greatGathering = service.createGatheringGreat(userId, gatheringId);

return ResponseEntity.ok(greatGathering.getId());
}

@DeleteMapping()
public ResponseEntity<Void> deleteGatheringGreat(@AuthenticationPrincipal Long userId,
@RequestParam Long gatheringId) {
@RequestParam Long gatheringId) {
service.deleteGatheringGreat(userId, gatheringId);

return ResponseEntity.noContent().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import solitour_backend.solitour.great_gathering.entity.GreatGathering;
import solitour_backend.solitour.great_gathering.exception.GatheringGreatNotExistsException;
import solitour_backend.solitour.great_gathering.repository.GreatGatheringRepository;
import solitour_backend.solitour.great_information.exception.InformationGreatNotExistsException;
import solitour_backend.solitour.user.entity.User;
import solitour_backend.solitour.user.repository.UserRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import solitour_backend.solitour.auth.config.Authenticated;
import solitour_backend.solitour.auth.config.AuthenticationPrincipal;
import solitour_backend.solitour.great_information.dto.response.GreatInformationResponse;
import solitour_backend.solitour.great_information.entity.GreatInformation;
import solitour_backend.solitour.great_information.service.GreatInformationService;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package solitour_backend.solitour.user.controller;


import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -19,14 +18,9 @@
import org.springframework.web.multipart.MultipartFile;
import solitour_backend.solitour.auth.config.Authenticated;
import solitour_backend.solitour.auth.config.AuthenticationPrincipal;
import solitour_backend.solitour.auth.service.OauthService;
import solitour_backend.solitour.auth.support.google.GoogleConnector;
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;
import solitour_backend.solitour.user.dto.request.UpdateUserInfoRequest;
import solitour_backend.solitour.user.exception.NicknameAlreadyExistsException;
Expand All @@ -41,7 +35,6 @@
public class UserController {

private final UserService userService;

public static final int PAGE_SIZE = 6;

@GetMapping("/info")
Expand All @@ -52,12 +45,20 @@ public ResponseEntity<UserInfoResponse> retrieveUserInfo(@AuthenticationPrincipa
}

@PutMapping("/info")
public ResponseEntity<Void> updateUserInfo(@AuthenticationPrincipal Long userId, @RequestBody UpdateUserInfoRequest request) {
public ResponseEntity<Void> updateUserInfo(@AuthenticationPrincipal Long userId,
@RequestBody UpdateUserInfoRequest request) {
userService.updateUserInfo(userId, request);

return ResponseEntity.noContent().build();
}

@DeleteMapping("/profile")
public ResponseEntity<Void> deleteUserProfile(@AuthenticationPrincipal Long userId) {
userService.deleteUserProfile(userId);

return ResponseEntity.ok().build();
}

@PutMapping("/nickname")
public ResponseEntity<String> updateNickname(@AuthenticationPrincipal Long userId,
@RequestBody UpdateNicknameRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.springframework.data.domain.Pageable;
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;

Expand Down
Loading
Loading