Skip to content

Commit

Permalink
Merge pull request #95 from Dan-sup/feat/danceclass
Browse files Browse the repository at this point in the history
Feat/danceclass
  • Loading branch information
ImTakGyun authored Jan 16, 2024
2 parents b49a783 + 9f299bb commit 7d6eeb2
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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})
Expand All @@ -48,6 +52,18 @@ public Response<Void> signOut(@AuthUser User user, @RequestBody RefreshTokenDto
return Response.success(ResponseCode.SUCCESS_OK);
}

@ApiOperation(value = "Delete User", notes = "탈퇴하기")
@PostMapping(value = "/delete")
public Response<Void> 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<AccessTokenDto> reissueAccessToken(@RequestBody RefreshTokenDto refreshTokenDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<ClassGenre> classGenres = new ArrayList<>();

@Column(nullable = false)
Expand Down Expand Up @@ -98,6 +97,8 @@ public class DanceClass extends BaseEntity {

private String date;

private boolean onSite;

private String reserveLink;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
public interface DanceClassRepository extends JpaRepository<DanceClass, Long>, DanceClassRepositoryCustom {
Optional<DanceClass> findById(Long dance_class_id);
List<DanceClass> findByState(State state);
List<DanceClass> findByUser(User user);

List<DanceClass> findByUserAndStateNot(User user, State state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -100,14 +100,26 @@ public List<GetDanceClassListDto> getAllClassList(){
return createDanceClassListDtos(danceClasses);
}

public void deleteAllClass(User user) throws BaseException {
List<DanceClass> 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{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/dansup/server/api/profile/domain/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<ProfileGenre> 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<Portfolio> portfolios = new ArrayList<>();

@OneToMany(mappedBy = "profile")
@OneToMany(mappedBy = "profile", cascade = CascadeType.REMOVE)
private List<PortfolioVideo> portfolioVideos = new ArrayList<>();

@Column(length = 5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -32,6 +35,7 @@ public class ProfileService {

private final ProfileRepository profileRepository;
private final DanceClassRepository danceClassRepository;
private final DanceClassService danceClassService;


public GetProfileDetailDto getProfileDetail(Long profileId) {
Expand Down Expand Up @@ -100,6 +104,7 @@ public List<GetFileUrlDto> getPortfolioVideoList(Long profileId) {

return profile.getPortfolioVideos().stream().map(
portfolioVideo -> GetFileUrlDto.builder()
.pvId(portfolioVideo.getId())
.url(portfolioVideo.getUrl())
.build()
).collect(Collectors.toList());
Expand Down Expand Up @@ -143,9 +148,39 @@ public List<GetDanceClassListDto> 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<PortfolioVideo> portfolioVideos= profile.getPortfolioVideos();

for(PortfolioVideo portfolioVideo: portfolioVideos){
danceClassService.deleteFile(portfolioVideo.getUrl());
}

profileRepository.delete(profile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ public Response<Void> createPortfolioVideo(@AuthUser User user,
return Response.success(ResponseCode.SUCCESS_CREATED);
}

@ApiOperation(value = "Delete PortfolioVideo", notes = "마이페이지에서 포트폴리오 영상 삭제")
@DeleteMapping("/portfolio/video/{pvId}")
public Response<Void> 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<List<GetPortfolioDto>> getPortfolioList(@AuthUser User user) {
Expand Down Expand Up @@ -101,10 +111,9 @@ public Response<Void> closeDanceClass( @AuthUser User user,

@ApiOperation(value = "Delete DanceClass", notes = "댄스 수업 삭제")
@DeleteMapping("/class/{danceclassId}")
public Response<Void> deletePost(@AuthUser User user,
@PathVariable("danceclassId") Long danceclassId) {
public Response<Void> deleteDanceClass(@AuthUser User user,
@PathVariable("danceclassId") Long danceclassId) {

// DanceClass 의 State 를 Deleted 로 변경
danceClassService.deleteClass(user, danceclassId);

return Response.success(ResponseCode.SUCCESS_OK);
Expand Down
Loading

0 comments on commit 7d6eeb2

Please sign in to comment.