diff --git a/src/main/java/com/dansup/server/api/auth/controller/AuthController.java b/src/main/java/com/dansup/server/api/auth/controller/AuthController.java index d0be50e..90c1622 100644 --- a/src/main/java/com/dansup/server/api/auth/controller/AuthController.java +++ b/src/main/java/com/dansup/server/api/auth/controller/AuthController.java @@ -4,6 +4,8 @@ import com.dansup.server.api.auth.dto.request.SignUpDto; import com.dansup.server.api.auth.dto.response.AccessTokenDto; import com.dansup.server.api.auth.service.AuthService; +import com.dansup.server.api.danceclass.service.DanceClassService; +import com.dansup.server.api.profile.service.ProfileService; import com.dansup.server.api.user.domain.User; import com.dansup.server.common.AuthUser; import com.dansup.server.common.response.Response; @@ -26,6 +28,8 @@ public class AuthController { private final AuthService authService; + private final ProfileService profileService; + private final DanceClassService danceClassService; @ApiOperation(value = "Sign Up", notes = "회원 가입") @PostMapping(value = "/sign-up", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) @@ -48,6 +52,18 @@ public Response signOut(@AuthUser User user, @RequestBody RefreshTokenDto return Response.success(ResponseCode.SUCCESS_OK); } + @ApiOperation(value = "Delete User", notes = "탈퇴하기") + @PostMapping(value = "/delete") + public Response deleteUser(@AuthUser User user, @RequestBody RefreshTokenDto refreshTokenDto) { + authService.signOut(user, refreshTokenDto); + + danceClassService.deleteAllClass(user); + profileService.deleteProfile(user); + + authService.deleteUser(user); + return Response.success(ResponseCode.SUCCESS_OK); + } + @ApiOperation(value = "Reissue Access Token by Refresh Token", notes = "리프레쉬 토큰을 통해 액세스 토큰 재발급") @PostMapping(value = "/reissuance") public Response reissueAccessToken(@RequestBody RefreshTokenDto refreshTokenDto) { diff --git a/src/main/java/com/dansup/server/api/auth/service/AuthService.java b/src/main/java/com/dansup/server/api/auth/service/AuthService.java index 3c9da8d..6281ebf 100644 --- a/src/main/java/com/dansup/server/api/auth/service/AuthService.java +++ b/src/main/java/com/dansup/server/api/auth/service/AuthService.java @@ -97,6 +97,15 @@ public void signOut(User user, RefreshTokenDto refreshTokenDto) { SecurityContextHolder.clearContext(); } + public void deleteUser(User user){ + + User findUser = userRepository.findByEmail(user.getEmail()).orElseThrow( + () -> new BaseException(ResponseCode.USER_NOT_FOUND) + ); + + userRepository.delete(findUser); + } + public AccessTokenDto reissueAccessToken(RefreshTokenDto refreshTokenDto) { if(!jwtTokenProvider.validateToken(refreshTokenDto.getRefreshToken())) { diff --git a/src/main/java/com/dansup/server/api/danceclass/controller/DanceClassController.java b/src/main/java/com/dansup/server/api/danceclass/controller/DanceClassController.java index 9c5340b..ee8ae20 100644 --- a/src/main/java/com/dansup/server/api/danceclass/controller/DanceClassController.java +++ b/src/main/java/com/dansup/server/api/danceclass/controller/DanceClassController.java @@ -6,7 +6,6 @@ import com.dansup.server.api.danceclass.dto.response.GetDanceClassDto; import com.dansup.server.api.danceclass.dto.response.GetDanceClassListDto; import com.dansup.server.api.danceclass.service.DanceClassService; -import com.dansup.server.api.profile.dto.response.GetFileUrlDto; import com.dansup.server.api.user.domain.User; import com.dansup.server.common.AuthUser; import com.dansup.server.common.response.Response; diff --git a/src/main/java/com/dansup/server/api/danceclass/domain/DanceClass.java b/src/main/java/com/dansup/server/api/danceclass/domain/DanceClass.java index 1bafdfb..955f81a 100644 --- a/src/main/java/com/dansup/server/api/danceclass/domain/DanceClass.java +++ b/src/main/java/com/dansup/server/api/danceclass/domain/DanceClass.java @@ -7,6 +7,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -30,16 +31,14 @@ public class DanceClass extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") - @OnDelete(action = OnDeleteAction.CASCADE) private User user; - @OneToOne(fetch = FetchType.LAZY) + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) @JoinColumn(name = "cv_id") - @OnDelete(action = OnDeleteAction.CASCADE) private ClassVideo classVideo; @Builder.Default - @OneToMany(mappedBy = "danceClass") + @OneToMany(mappedBy = "danceClass", cascade = CascadeType.REMOVE) private List classGenres = new ArrayList<>(); @Column(nullable = false) @@ -98,6 +97,8 @@ public class DanceClass extends BaseEntity { private String date; + private boolean onSite; + private String reserveLink; @NotNull diff --git a/src/main/java/com/dansup/server/api/danceclass/dto/request/CreateDanceClassDto.java b/src/main/java/com/dansup/server/api/danceclass/dto/request/CreateDanceClassDto.java index b699614..9dab7b7 100644 --- a/src/main/java/com/dansup/server/api/danceclass/dto/request/CreateDanceClassDto.java +++ b/src/main/java/com/dansup/server/api/danceclass/dto/request/CreateDanceClassDto.java @@ -90,6 +90,9 @@ public class CreateDanceClassDto { @ApiModelProperty(value = "원데이 클래스에서의 날짜" , example = "2023/5/29") private String date; + @ApiModelProperty(value = "현장 결제 등록" , example = "1") + private boolean onSite; + @ApiModelProperty(value = "수업 예약 링크" , example = "com.googleform.") private String reserveLink; diff --git a/src/main/java/com/dansup/server/api/danceclass/dto/response/GetDanceClassDto.java b/src/main/java/com/dansup/server/api/danceclass/dto/response/GetDanceClassDto.java index 898204d..f86304c 100644 --- a/src/main/java/com/dansup/server/api/danceclass/dto/response/GetDanceClassDto.java +++ b/src/main/java/com/dansup/server/api/danceclass/dto/response/GetDanceClassDto.java @@ -87,6 +87,8 @@ public class GetDanceClassDto { private String endTime; @ApiModelProperty(value = "원데이 클래스에서의 날짜" , example = "2023/5/29") private String date; + @ApiModelProperty(value = "현장 결제 등록" , example = "1") + private boolean onSite; @ApiModelProperty(value = "수업 예약 링크" , example = "com.googleform.") private String reserveLink; diff --git a/src/main/java/com/dansup/server/api/danceclass/repository/DanceClassRepository.java b/src/main/java/com/dansup/server/api/danceclass/repository/DanceClassRepository.java index 2afecac..dddeff8 100644 --- a/src/main/java/com/dansup/server/api/danceclass/repository/DanceClassRepository.java +++ b/src/main/java/com/dansup/server/api/danceclass/repository/DanceClassRepository.java @@ -15,6 +15,7 @@ public interface DanceClassRepository extends JpaRepository, DanceClassRepositoryCustom { Optional findById(Long dance_class_id); List findByState(State state); + List findByUser(User user); List findByUserAndStateNot(User user, State state); diff --git a/src/main/java/com/dansup/server/api/danceclass/service/DanceClassService.java b/src/main/java/com/dansup/server/api/danceclass/service/DanceClassService.java index f470a67..c3f58a6 100644 --- a/src/main/java/com/dansup/server/api/danceclass/service/DanceClassService.java +++ b/src/main/java/com/dansup/server/api/danceclass/service/DanceClassService.java @@ -27,8 +27,7 @@ import java.util.List; import java.util.stream.Collectors; -import static com.dansup.server.common.response.ResponseCode.CLASS_NOT_FOUND; -import static com.dansup.server.common.response.ResponseCode.FAIL_BAD_REQUEST; +import static com.dansup.server.common.response.ResponseCode.*; @Service @RequiredArgsConstructor @@ -82,6 +81,7 @@ public void createClass(User user, CreateDanceClassDto createDanceClassDto, Mult .endHour(createDanceClassDto.getEndHour()) .endTime(createDanceClassDto.getEndTime()) .date(createDanceClassDto.getDate()) + .onSite(createDanceClassDto.isOnSite()) .reserveLink(createDanceClassDto.getReserveLink()) .state(State.Active) .build(); @@ -100,14 +100,26 @@ public List getAllClassList(){ return createDanceClassListDtos(danceClasses); } + public void deleteAllClass(User user) throws BaseException { + List danceClasses = danceClassRepository.findByUser(user); + + for (DanceClass danceClass: danceClasses) { + deleteClass(user, danceClass.getId()); + } +// danceClasses.stream().map(danceClass -> { +// deleteClass(user, danceClass.getId()); +// return null; +// }); + } + public void deleteClass(User user, Long classId) throws BaseException { DanceClass danceClass = loadDanceClass(classId); compareUser(danceClass, user); - danceClass.updateState(State.Delete); - danceClassRepository.save(danceClass); + deleteFile(danceClass.getClassVideo().getVideoUrl()); + danceClassRepository.delete(danceClass); } public void closeClass(User user, Long classId) throws BaseException{ @@ -163,6 +175,7 @@ public GetDanceClassDto detailClass(Long classId) throws BaseException { .startTime(danceClass.getStartTime()) .endTime(danceClass.getEndTime()) .date(danceClass.getDate()) + .onSite(danceClass.isOnSite()) .reserveLink(danceClass.getReserveLink()) .state(danceClass.getState().toString()) .build(); @@ -232,13 +245,21 @@ private DanceClass loadDanceClass(Long classId) { private void compareUser(DanceClass danceClass, User user) { if(!danceClass.getUser().getId().equals(user.getId())){ - throw new BaseException(FAIL_BAD_REQUEST); + throw new BaseException(FAIL_NOT_POSTER); } } - private Profile loadProfile(User user){ + public Profile loadProfile(User user){ return profileRepository.findByUser(user).orElseThrow( () -> new BaseException(ResponseCode.PROFILE_NOT_FOUND) ); } + + public void deleteFile(String ImageURL) { + if(ImageURL == null){ + return; + } + String ImageName = ImageURL.split("com/")[1].trim(); + s3UploaderService.deleteFile(ImageName); + } } \ No newline at end of file diff --git a/src/main/java/com/dansup/server/api/genre/domain/ClassGenre.java b/src/main/java/com/dansup/server/api/genre/domain/ClassGenre.java index 80fa054..360010b 100644 --- a/src/main/java/com/dansup/server/api/genre/domain/ClassGenre.java +++ b/src/main/java/com/dansup/server/api/genre/domain/ClassGenre.java @@ -30,7 +30,7 @@ public class ClassGenre extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "dance_class_id") - @OnDelete(action = OnDeleteAction.CASCADE) +// @OnDelete(action = OnDeleteAction.CASCADE) private DanceClass danceClass; } diff --git a/src/main/java/com/dansup/server/api/profile/domain/Portfolio.java b/src/main/java/com/dansup/server/api/profile/domain/Portfolio.java index 2cb265a..c13e1c8 100644 --- a/src/main/java/com/dansup/server/api/profile/domain/Portfolio.java +++ b/src/main/java/com/dansup/server/api/profile/domain/Portfolio.java @@ -24,7 +24,6 @@ public class Portfolio extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "profile_id") - @OnDelete(action = OnDeleteAction.CASCADE) private Profile profile; @Column diff --git a/src/main/java/com/dansup/server/api/profile/domain/PortfolioVideo.java b/src/main/java/com/dansup/server/api/profile/domain/PortfolioVideo.java index 045c254..8fa2ceb 100644 --- a/src/main/java/com/dansup/server/api/profile/domain/PortfolioVideo.java +++ b/src/main/java/com/dansup/server/api/profile/domain/PortfolioVideo.java @@ -24,7 +24,6 @@ public class PortfolioVideo extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "profile_id") - @OnDelete(action = OnDeleteAction.CASCADE) private Profile profile; @Column(nullable = false) diff --git a/src/main/java/com/dansup/server/api/profile/domain/Profile.java b/src/main/java/com/dansup/server/api/profile/domain/Profile.java index 2fc1cc4..2adc41b 100644 --- a/src/main/java/com/dansup/server/api/profile/domain/Profile.java +++ b/src/main/java/com/dansup/server/api/profile/domain/Profile.java @@ -28,7 +28,6 @@ public class Profile extends BaseEntity { @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") - @OnDelete(action = OnDeleteAction.CASCADE) private User user; @Column(nullable = false, unique = true) @@ -40,21 +39,21 @@ public class Profile extends BaseEntity { @Column(length = 50) private String intro; - @OneToMany(mappedBy = "profile") + @OneToMany(mappedBy = "profile", cascade = CascadeType.REMOVE) private List profileGenres = new ArrayList<>(); - @OneToOne(fetch = FetchType.LAZY) + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) @JoinColumn(name = "pv_id") private ProfileVideo profileVideo; - @OneToOne(fetch = FetchType.LAZY) + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) @JoinColumn(name = "pi_id") private ProfileImage profileImage; - @OneToMany(mappedBy = "profile") + @OneToMany(mappedBy = "profile", cascade = CascadeType.REMOVE) private List portfolios = new ArrayList<>(); - @OneToMany(mappedBy = "profile") + @OneToMany(mappedBy = "profile", cascade = CascadeType.REMOVE) private List portfolioVideos = new ArrayList<>(); @Column(length = 5) diff --git a/src/main/java/com/dansup/server/api/profile/dto/response/GetFileUrlDto.java b/src/main/java/com/dansup/server/api/profile/dto/response/GetFileUrlDto.java index 9574dbb..32103fd 100644 --- a/src/main/java/com/dansup/server/api/profile/dto/response/GetFileUrlDto.java +++ b/src/main/java/com/dansup/server/api/profile/dto/response/GetFileUrlDto.java @@ -14,6 +14,9 @@ @NoArgsConstructor public class GetFileUrlDto { + @ApiModelProperty(value = "portfolio ID", example = "23") + private Long pvId; + @ApiModelProperty(value = "file url", example = "url") private String url; diff --git a/src/main/java/com/dansup/server/api/profile/service/PortfolioService.java b/src/main/java/com/dansup/server/api/profile/service/PortfolioService.java index 553d560..ba13766 100644 --- a/src/main/java/com/dansup/server/api/profile/service/PortfolioService.java +++ b/src/main/java/com/dansup/server/api/profile/service/PortfolioService.java @@ -8,7 +8,6 @@ import com.dansup.server.api.danceclass.repository.DanceClassRepository; import com.dansup.server.api.profile.domain.Portfolio; import com.dansup.server.api.profile.domain.Profile; -import com.dansup.server.api.profile.dto.response.GetFileUrlDto; import com.dansup.server.api.profile.dto.response.GetPortfolioDto; import com.dansup.server.api.profile.dto.response.GetProfileDetailDto; import com.dansup.server.api.profile.repository.PortfolioRepository; diff --git a/src/main/java/com/dansup/server/api/profile/service/ProfileService.java b/src/main/java/com/dansup/server/api/profile/service/ProfileService.java index 74f4266..210613c 100644 --- a/src/main/java/com/dansup/server/api/profile/service/ProfileService.java +++ b/src/main/java/com/dansup/server/api/profile/service/ProfileService.java @@ -5,6 +5,8 @@ import com.dansup.server.api.danceclass.domain.State; import com.dansup.server.api.danceclass.dto.response.GetDanceClassListDto; import com.dansup.server.api.danceclass.repository.DanceClassRepository; +import com.dansup.server.api.danceclass.service.DanceClassService; +import com.dansup.server.api.profile.domain.PortfolioVideo; import com.dansup.server.api.profile.domain.Profile; import com.dansup.server.api.profile.dto.response.GetFileUrlDto; import com.dansup.server.api.profile.dto.response.GetPortfolioDto; @@ -15,6 +17,7 @@ import com.dansup.server.api.user.repository.UserRepository; import com.dansup.server.common.exception.BaseException; import com.dansup.server.common.response.ResponseCode; +import com.dansup.server.config.s3.S3UploaderService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -23,7 +26,7 @@ import java.util.List; import java.util.stream.Collectors; -import static com.dansup.server.common.response.ResponseCode.FAIL_BAD_REQUEST; +import static com.dansup.server.common.response.ResponseCode.*; @Service @RequiredArgsConstructor @@ -32,6 +35,7 @@ public class ProfileService { private final ProfileRepository profileRepository; private final DanceClassRepository danceClassRepository; + private final DanceClassService danceClassService; public GetProfileDetailDto getProfileDetail(Long profileId) { @@ -100,6 +104,7 @@ public List getPortfolioVideoList(Long profileId) { return profile.getPortfolioVideos().stream().map( portfolioVideo -> GetFileUrlDto.builder() + .pvId(portfolioVideo.getId()) .url(portfolioVideo.getUrl()) .build() ).collect(Collectors.toList()); @@ -143,9 +148,39 @@ public List getProfileClassList(Long profileId) { } private Profile loadProfile(Long profileId) { - return profileRepository.findById(profileId).orElseThrow( () -> new BaseException(ResponseCode.PROFILE_NOT_FOUND) ); } + + private Profile loadProfile(User user) { + return profileRepository.findByUser(user).orElseThrow( + () -> new BaseException(ResponseCode.PROFILE_NOT_FOUND) + ); + } + + public void compareUser(Profile profile, User user) { + + if(!profile.getUser().getId().equals(user.getId())){ + throw new BaseException(FAIL_NOT_POSTER); + } + } + + public void deleteProfile(User user) throws BaseException { + + Profile profile = loadProfile(user); + + compareUser(profile, user); + + danceClassService.deleteFile(profile.getProfileImage().getUrl()); + danceClassService.deleteFile(profile.getProfileVideo().getUrl()); + + List portfolioVideos= profile.getPortfolioVideos(); + + for(PortfolioVideo portfolioVideo: portfolioVideos){ + danceClassService.deleteFile(portfolioVideo.getUrl()); + } + + profileRepository.delete(profile); + } } diff --git a/src/main/java/com/dansup/server/api/user/controller/MyPageController.java b/src/main/java/com/dansup/server/api/user/controller/MyPageController.java index 23c5855..3044bad 100644 --- a/src/main/java/com/dansup/server/api/user/controller/MyPageController.java +++ b/src/main/java/com/dansup/server/api/user/controller/MyPageController.java @@ -56,6 +56,16 @@ public Response createPortfolioVideo(@AuthUser User user, return Response.success(ResponseCode.SUCCESS_CREATED); } + @ApiOperation(value = "Delete PortfolioVideo", notes = "마이페이지에서 포트폴리오 영상 삭제") + @DeleteMapping("/portfolio/video/{pvId}") + public Response deletePostPortfolioVideo(@AuthUser User user, + @PathVariable("pvId") Long pvId) { + + myPageService.deletePortfolioVideo(user, pvId); + + return Response.success(ResponseCode.SUCCESS_OK); + } + @ApiOperation(value = "Get Mypage Portfolio", notes = "마이페이지에서 포트폴리오(공연 및 활동 경력) 조회") @GetMapping(value = "/portfolio") public Response> getPortfolioList(@AuthUser User user) { @@ -101,10 +111,9 @@ public Response closeDanceClass( @AuthUser User user, @ApiOperation(value = "Delete DanceClass", notes = "댄스 수업 삭제") @DeleteMapping("/class/{danceclassId}") - public Response deletePost(@AuthUser User user, - @PathVariable("danceclassId") Long danceclassId) { + public Response deleteDanceClass(@AuthUser User user, + @PathVariable("danceclassId") Long danceclassId) { - // DanceClass 의 State 를 Deleted 로 변경 danceClassService.deleteClass(user, danceclassId); return Response.success(ResponseCode.SUCCESS_OK); diff --git a/src/main/java/com/dansup/server/api/user/service/MyPageService.java b/src/main/java/com/dansup/server/api/user/service/MyPageService.java index 05c6517..04aecb2 100644 --- a/src/main/java/com/dansup/server/api/user/service/MyPageService.java +++ b/src/main/java/com/dansup/server/api/user/service/MyPageService.java @@ -5,6 +5,7 @@ import com.dansup.server.api.danceclass.domain.State; import com.dansup.server.api.danceclass.dto.response.GetDanceClassListDto; import com.dansup.server.api.danceclass.repository.DanceClassRepository; +import com.dansup.server.api.danceclass.service.DanceClassService; import com.dansup.server.api.profile.domain.PortfolioVideo; import com.dansup.server.api.profile.domain.Profile; import com.dansup.server.api.profile.domain.ProfileVideo; @@ -30,18 +31,18 @@ import java.util.List; import java.util.stream.Collectors; +import static com.dansup.server.common.response.ResponseCode.FAIL_NOT_POSTER; + @Service @RequiredArgsConstructor @Slf4j @Transactional public class MyPageService { + private final S3UploaderService s3UploaderService; + private final DanceClassService danceClassService; private final ProfileRepository profileRepository; - private final DanceClassRepository danceClassRepository; - - private final S3UploaderService s3UploaderService; - private final PortfolioVideoRepository portfolioVideoRepository; public GetProfileDetailDto getMyPage(User user) { @@ -85,6 +86,7 @@ public List getPortfolioVideoList(User user) { return myPage.getPortfolioVideos().stream().map( portfolioVideo -> GetFileUrlDto.builder() + .pvId(portfolioVideo.getId()) .url(portfolioVideo.getUrl()) .build() ).collect(Collectors.toList()); @@ -139,6 +141,18 @@ public void uploadPortfolioVideo(User user, MultipartFile multipartFile) throws portfolioVideoRepository.save(portfolioVideo); } + public void deletePortfolioVideo(User user, Long pvId) throws BaseException { + + PortfolioVideo portfolioVideo = portfolioVideoRepository.findById(pvId).orElseThrow( + () -> new BaseException(ResponseCode.VIDEO_NOT_FOUND) + );; + + compareUser(portfolioVideo, user); + + danceClassService.deleteFile(portfolioVideo.getUrl()); + portfolioVideoRepository.delete(portfolioVideo); + } + private Profile loadMyPage(User user) { return profileRepository.findByUser(user).orElseThrow( @@ -146,4 +160,12 @@ private Profile loadMyPage(User user) { ); } + private void compareUser(PortfolioVideo portfolioVideo, User user) { + + Profile profile = loadMyPage(user); + + if(!portfolioVideo.getProfile().equals(profile)){ + throw new BaseException(FAIL_NOT_POSTER); + } + } } diff --git a/src/main/java/com/dansup/server/common/response/ResponseCode.java b/src/main/java/com/dansup/server/common/response/ResponseCode.java index 98b00d2..3bbe873 100644 --- a/src/main/java/com/dansup/server/common/response/ResponseCode.java +++ b/src/main/java/com/dansup/server/common/response/ResponseCode.java @@ -18,6 +18,7 @@ public enum ResponseCode { //fail FAIL_BAD_REQUEST(BAD_REQUEST, "잘못된 요청입니다."), + FAIL_NOT_POSTER(BAD_REQUEST, "작성자가 아닙니다."), FAIL_SERVER_ERROR(INTERNAL_SERVER_ERROR, "서버 에러가 발생했습니다."), // Auth @@ -36,7 +37,10 @@ public enum ResponseCode { PROFILE_NOT_FOUND(NOT_FOUND, "존재하지 않는 프로필입니다."), //class - CLASS_NOT_FOUND(NOT_FOUND, "존재하지 않는 클래스입니다."); + CLASS_NOT_FOUND(NOT_FOUND, "존재하지 않는 클래스입니다."), + + //video + VIDEO_NOT_FOUND(NOT_FOUND, "존재하지 않는 영상입니다."); private final HttpStatus httpStatus; private final String message;