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

Retactor & Feat: 팀 이미지 관련 CRUD 수정 #110

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -14,8 +14,12 @@ public static TeamResponseDTO.CreateTeamResponseDTO toCreateMemberDTO(Team team)
.teamId(team.getTeamId())
.name(team.getName())
.intro(team.getIntro())
.bannerImageUrl(team.getBannerImage().getImageUrl())
.profileImageUrl(team.getProfileImage().getImageUrl())
.bannerImageUrl((team.getBannerImage() != null)
? team.getBannerImage().getImageUrl()
: "")
.profileImageUrl((team.getProfileImage() != null)
? team.getProfileImage().getImageUrl()
: "")
.build();
}

Expand All @@ -29,8 +33,12 @@ public static TeamResponseDTO.TeamCheckResponseDTO toTeamCheckResponseDTO(Team t
.teamId(team.getTeamId())
.name(team.getName())
.intro(team.getIntro())
.bannerImageUrl(team.getBannerImage().getImageUrl())
.profileImageUrl(team.getProfileImage().getImageUrl())
.bannerImageUrl((team.getBannerImage() != null)
? team.getBannerImage().getImageUrl()
: "")
.profileImageUrl((team.getProfileImage() != null)
? team.getProfileImage().getImageUrl()
: "")
.github(team.getGithub())
.email(team.getEmail())
.linkedIn(team.getLinkedin())
Expand All @@ -43,8 +51,12 @@ public static TeamResponseDTO.UpdateTeamDTO toUpdateTeamDTO(Team team) {
return TeamResponseDTO.UpdateTeamDTO.builder()
.name(team.getName())
.intro(team.getIntro())
.bannerImageUrl(team.getBannerImage().getImageUrl())
.profileImageUrl(team.getProfileImage().getImageUrl())
.bannerImageUrl((team.getBannerImage() != null)
? team.getBannerImage().getImageUrl()
: "")
.profileImageUrl((team.getProfileImage() != null)
? team.getProfileImage().getImageUrl()
: "")
.github(team.getGithub())
.linkedIn(team.getLinkedin())
.discord(team.getDiscord())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public interface TeamCommandService {
ApiResponse<TeamResponseDTO.TeamImageDTO> updateTeamBannerImage(Long teamId, TeamRequestDTO.TeamImageRequestDTO request);

ApiResponse<TeamResponseDTO.TeamImageDTO> updateTeamProfileImage(Long teamId, TeamRequestDTO.TeamImageRequestDTO request);

ApiResponse<String> deleteTeamBannerImage(Long teamId);

ApiResponse<String> deleteTeamProfileImage(Long teamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,12 @@ public Team createTeam(TeamRequestDTO.CreateTeamRequestDTO request) {
.email(request.getEmail())
.linkedin(request.getLinkedIn())
.instagram(request.getInstagram())
.bannerImage(null)
.profileImage(null)
.build();

Team savedTeam = teamRepository.save(team);

// 배너 이미지 저장
String bannerUuid = UUID.randomUUID().toString();
Uuid savedBannerUuid = uuidRepository.save(Uuid.builder().uuid(bannerUuid).build());
String bannerImageUrl = s3Manager.uploadFile(s3Manager.generatePostName(savedBannerUuid), request.getBannerPhoto());
TeamBannerImage bannerImage = TeamBannerImage.builder()
.imageUrl(bannerImageUrl)
.team(savedTeam)
.build();
savedTeam.setBannerImage(bannerImageRepository.save(bannerImage));

// 프로필 이미지 저장
String profileUuid = UUID.randomUUID().toString();
Uuid savedProfileUuid = uuidRepository.save(Uuid.builder().uuid(profileUuid).build());
String profileImageUrl = s3Manager.uploadFile(s3Manager.generatePostName(savedProfileUuid), request.getProfilePhoto());
TeamProfileImage profileImage = TeamProfileImage.builder()
.imageUrl(profileImageUrl)
.team(savedTeam)
.build();
savedTeam.setProfileImage(profileImageRepository.save(profileImage));

return teamRepository.save(savedTeam);
return savedTeam;
}

@Override
Expand All @@ -84,8 +65,10 @@ public Team updateTeam(Long teamId, TeamRequestDTO.UpdateTeamDTO request) {
public ApiResponse<TeamResponseDTO.TeamImageDTO> updateTeamBannerImage(Long teamId, TeamRequestDTO.TeamImageRequestDTO request) {
Team team = teamRepository.findById(teamId).orElseThrow(); // 예외 처리 필요

s3Manager.deleteFile(team.getBannerImage().getImageUrl());
teamBannerImageRepository.delete(team.getBannerImage());
if (team.getBannerImage() != null) {
s3Manager.deleteFile(team.getBannerImage().getImageUrl());
teamBannerImageRepository.delete(team.getBannerImage());
}

String uuid = UUID.randomUUID().toString();
Uuid savedUuid = uuidRepository.save(Uuid.builder().uuid(uuid).build());
Expand All @@ -105,8 +88,10 @@ public ApiResponse<TeamResponseDTO.TeamImageDTO> updateTeamBannerImage(Long team
public ApiResponse<TeamResponseDTO.TeamImageDTO> updateTeamProfileImage(Long teamId, TeamRequestDTO.TeamImageRequestDTO request) {
Team team = teamRepository.findById(teamId).orElseThrow(); // 예외 처리 필요

s3Manager.deleteFile(team.getProfileImage().getImageUrl());
teamProfileImageRepository.delete(team.getProfileImage());
if (team.getProfileImage() != null) {
s3Manager.deleteFile(team.getProfileImage().getImageUrl());
teamProfileImageRepository.delete(team.getProfileImage());
}

String uuid = UUID.randomUUID().toString();
Uuid savedUuid = uuidRepository.save(Uuid.builder().uuid(uuid).build());
Expand All @@ -122,5 +107,32 @@ public ApiResponse<TeamResponseDTO.TeamImageDTO> updateTeamProfileImage(Long tea
return ApiResponse.onSuccess(SuccessStatus.TEAM_OK, response);
}

@Override
public ApiResponse<String> deleteTeamBannerImage(Long teamId) {
Team team = teamRepository.findById(teamId).orElseThrow(); // 예외 처리 필요

if (team.getBannerImage() != null) {
s3Manager.deleteFile(team.getBannerImage().getImageUrl());
teamBannerImageRepository.delete(team.getBannerImage());
team.setBannerImage(null);
teamRepository.save(team);
}

return ApiResponse.onSuccess(SuccessStatus.TEAM_OK, "성공적으로 삭제되었습니다!");
}

@Override
public ApiResponse<String> deleteTeamProfileImage(Long teamId) {
Team team = teamRepository.findById(teamId).orElseThrow(); // 예외 처리 필요

if (team.getProfileImage() != null) {
s3Manager.deleteFile(team.getProfileImage().getImageUrl());
teamProfileImageRepository.delete(team.getProfileImage());
team.setProfileImage(null);
teamRepository.save(team);
}

return ApiResponse.onSuccess(SuccessStatus.TEAM_OK, "성공적으로 삭제되었습니다!");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public class TeamQueryServiceImpl implements TeamQueryService {
public ApiResponse<TeamResponseDTO.TeamImageDTO> getBannerImage(Long teamId) {
Team team = teamRepository.findById(teamId).orElseThrow(); // 예외 처리 필요

TeamResponseDTO.TeamImageDTO response = new TeamResponseDTO.TeamImageDTO(team.getBannerImage().getImageUrl());
TeamResponseDTO.TeamImageDTO response = new TeamResponseDTO.TeamImageDTO(
(team.getBannerImage() != null)
? team.getBannerImage().getImageUrl()
: "");

return ApiResponse.onSuccess(SuccessStatus.TEAM_OK, response);
}
Expand All @@ -31,7 +34,10 @@ public ApiResponse<TeamResponseDTO.TeamImageDTO> getBannerImage(Long teamId) {
public ApiResponse<TeamResponseDTO.TeamImageDTO> getProfileImage(Long teamId) {
Team team = teamRepository.findById(teamId).orElseThrow(); // 예외 처리 필요

TeamResponseDTO.TeamImageDTO response = new TeamResponseDTO.TeamImageDTO(team.getProfileImage().getImageUrl());
TeamResponseDTO.TeamImageDTO response = new TeamResponseDTO.TeamImageDTO(
(team.getProfileImage() != null)
? team.getProfileImage().getImageUrl()
: "");

return ApiResponse.onSuccess(SuccessStatus.TEAM_OK, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class TeamController {
private final TeamQueryService teamQueryService;

//팀 생성
@PostMapping(consumes = "multipart/form-data")
@PostMapping()
@Operation(summary = "팀 생성")
public ApiResponse<TeamResponseDTO.CreateTeamResponseDTO> createTeam(
@ModelAttribute TeamRequestDTO.CreateTeamRequestDTO request
@RequestBody TeamRequestDTO.CreateTeamRequestDTO request
){
Team newTeam = teamCommandService.createTeam(request);
return ApiResponse.onSuccess(
Expand Down Expand Up @@ -95,5 +95,21 @@ public ApiResponse<TeamResponseDTO.TeamImageDTO> getProfileImage(
return teamQueryService.getProfileImage(teamId);
}

// 이미지 삭제 요청
@DeleteMapping("/{teamId}/bannerImage")
@Operation(summary = "팀 배너 사진 삭제 요청")
public ApiResponse<String> deleteBannerImage(
@PathVariable Long teamId
) {
return teamCommandService.deleteTeamBannerImage(teamId);
}

@DeleteMapping("/{teamId}/profileImage")
@Operation(summary = "팀 프로필 사진 삭제 요청")
public ApiResponse<String> deleteProfileImage(
@PathVariable Long teamId
) {
return teamCommandService.deleteTeamProfileImage(teamId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public class TeamRequestDTO {
@NoArgsConstructor
public static class CreateTeamRequestDTO { //팀 생성
private String name;
private MultipartFile profilePhoto;
private MultipartFile bannerPhoto;
private String intro;
private String github;
private String email;
Expand Down
Loading