Skip to content

Commit

Permalink
fix: 공연 업데이트 오류 문제 (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Aug 24, 2024
1 parent 23cd82f commit 0659f8a
Show file tree
Hide file tree
Showing 14 changed files with 283 additions and 291 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.example.error;

import jakarta.validation.ConstraintViolationException;
import java.util.NoSuchElementException;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.example.exception.BusinessException;
Expand Down Expand Up @@ -46,6 +47,21 @@ protected ResponseEntity<ErrorResponse> handleBusinessException(final BusinessEx
.body(response);
}

@ExceptionHandler(NoSuchElementException.class)
protected ResponseEntity<ErrorResponse> handleNoSuchElementException(final NoSuchElementException e) {
String errorId = UUID.randomUUID().toString();
ErrorResponse response = ErrorResponse.messageCustomErrorResponseBuilder()
.errorId(errorId)
.message(GlobalError.ELEMENT_NOT_FOUND.getClientMessage())
.error(GlobalError.ELEMENT_NOT_FOUND)
.build();

log.error(errorId, e);

return ResponseEntity.status(response.httpStatus())
.body(response);
}

@ExceptionHandler(MethodArgumentNotValidException.class)
protected ResponseEntity<ErrorResponse> handleRequestArgumentNotValidException(
MethodArgumentNotValidException e
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package com.example.artist.service;

import com.example.artist.error.ArtistError;
import com.example.artist.service.dto.request.ArtistCreateServiceRequest;
import com.example.artist.service.dto.request.ArtistUpdateServiceRequest;
import com.example.artist.service.dto.response.ArtistDetailServiceResponse;
import com.example.artist.service.dto.response.ArtistKoreanNameServiceResponse;
import com.example.artist.service.dto.response.ArtistKoreanNameWithShowIdServiceResponse;
import com.example.component.FileUploadComponent;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.example.dto.artist.response.ArtistDetailDomainResponse;
import org.example.entity.artist.Artist;
import org.example.exception.BusinessException;
import org.example.usecase.artist.ArtistUseCase;
import org.springframework.stereotype.Service;

Expand All @@ -27,6 +23,7 @@ public class ArtistAdminService {
public void save(ArtistCreateServiceRequest artistCreateServiceRequest) {
String imageUrl = fileUploadComponent.uploadFile("artists", artistCreateServiceRequest.image());
Artist artist = artistCreateServiceRequest.toArtistWithImageUrl(imageUrl);

artistUseCase.save(artist, artistCreateServiceRequest.genreIds());
}

Expand All @@ -42,39 +39,22 @@ public List<ArtistKoreanNameServiceResponse> findAllArtistKoreanName() {
.toList();
}

public List<ArtistKoreanNameWithShowIdServiceResponse> findArtistKoreanNamesWithShowId() {
return artistUseCase.findArtistKoreanNamesWithShowId().stream()
.map(ArtistKoreanNameWithShowIdServiceResponse::from)
.toList();
}

public ArtistDetailServiceResponse findArtistById(UUID id) {
ArtistDetailDomainResponse response;
try {
response = artistUseCase.findArtistDetailById(id);
} catch (NoSuchElementException e) {
throw new BusinessException(ArtistError.ENTITY_NOT_FOUND);
}
response = artistUseCase.findArtistDetailById(id);

return new ArtistDetailServiceResponse(response);
}

public void updateArtist(UUID id, ArtistUpdateServiceRequest artistUpdateServiceRequest) {
String imageUrl = fileUploadComponent.uploadFile("artist", artistUpdateServiceRequest.image());
String imageUrl = fileUploadComponent.uploadFile("artist",
artistUpdateServiceRequest.image());
Artist artist = artistUpdateServiceRequest.toArtist(imageUrl);

try {
artistUseCase.updateArtist(id, artist, artistUpdateServiceRequest.genreIds());
} catch (NoSuchElementException e) {
throw new BusinessException(ArtistError.ENTITY_NOT_FOUND);
}
artistUseCase.updateArtist(id, artist, artistUpdateServiceRequest.genreIds());
}

public void deleteArtist(UUID id) {
try {
artistUseCase.deleteArtist(id);
} catch (NoSuchElementException e) {
throw new BusinessException(ArtistError.ENTITY_NOT_FOUND);
}
artistUseCase.deleteArtist(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public ArtistFilterTotalCountServiceResponse filterArtistTotalCount(
try {
return new ArtistFilterTotalCountServiceResponse(
artistUseCase.findFilterArtistTotalCount(
request.toDomainRequest(subscriptionArtistIds))
request.toDomainRequest(subscriptionArtistIds)
)
);
} catch (NoSuchElementException e) {
return ArtistFilterTotalCountServiceResponse.noneTotalCount();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.example.genre.service;

import com.example.genre.error.GenreError;
import com.example.genre.service.dto.request.GenreCreateServiceRequest;
import com.example.genre.service.dto.request.GenreUpdateServiceRequest;
import com.example.genre.service.dto.response.GenreNameServiceResponse;
import com.example.genre.service.dto.response.GenreNameWithShowIdServiceResponse;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.example.entity.genre.Genre;
import org.example.exception.BusinessException;
import org.example.usecase.genre.GenreUseCase;
import org.springframework.stereotype.Service;

Expand All @@ -24,12 +20,6 @@ public void save(GenreCreateServiceRequest genreCreateServiceRequest) {
genreUseCase.save(genreCreateServiceRequest.toGenre());
}

public List<GenreNameWithShowIdServiceResponse> findGenreNamesWithShowId() {
return genreUseCase.findGenreNamesWithShowId().stream()
.map(GenreNameWithShowIdServiceResponse::new)
.toList();
}

public List<GenreNameServiceResponse> findAllGenres() {
List<Genre> genres = genreUseCase.findAllGenres();
return genres.stream()
Expand All @@ -38,28 +28,15 @@ public List<GenreNameServiceResponse> findAllGenres() {
}

public void updateGenre(UUID id, GenreUpdateServiceRequest genreUpdateServiceRequest) {
try {
genreUseCase.updateGenre(id, genreUpdateServiceRequest.name());
} catch (NoSuchElementException e) {
throw new BusinessException(GenreError.ENTITY_NOT_FOUND);
}
genreUseCase.updateGenre(id, genreUpdateServiceRequest.name());
}

public void deleteGenre(UUID id) {
try {
genreUseCase.deleteGenre(id);
} catch (NoSuchElementException e) {
throw new BusinessException(GenreError.ENTITY_NOT_FOUND);
}
genreUseCase.deleteGenre(id);
}

public GenreNameServiceResponse findGenreById(UUID id) {
Genre genre;
try {
genre = genreUseCase.findGenreById(id);
} catch (NoSuchElementException e) {
throw new BusinessException(GenreError.ENTITY_NOT_FOUND);
}
Genre genre = genreUseCase.findGenreById(id);

return new GenreNameServiceResponse(genre.getId(), genre.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@
import com.example.component.FileUploadComponent;
import com.example.publish.MessagePublisher;
import com.example.publish.message.ShowRelationArtistAndGenreServiceMessage;
import com.example.show.error.ShowError;
import com.example.show.service.dto.request.ShowCreateServiceRequest;
import com.example.show.service.dto.request.ShowUpdateServiceRequest;
import com.example.show.service.dto.response.ShowInfoServiceResponse;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.example.dto.show.response.ShowInfoDomainResponse;
import org.example.exception.BusinessException;
import org.example.usecase.artist.ArtistUseCase;
import org.example.usecase.genre.GenreUseCase;
import org.example.usecase.show.ShowUseCase;
import org.example.usecase.show.ShowAdminUseCase;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ShowAdminService {

private final ShowUseCase showUseCase;
private final ShowAdminUseCase showAdminUseCase;
private final GenreUseCase genreUseCase;
private final ArtistUseCase artistUseCase;
private final FileUploadComponent fileUploadComponent;
Expand All @@ -32,7 +29,7 @@ public class ShowAdminService {
public void save(ShowCreateServiceRequest showCreateServiceRequest) {
String imageURL = fileUploadComponent.uploadFile("show", showCreateServiceRequest.post());

showUseCase.save(
showAdminUseCase.save(
showCreateServiceRequest.toDomainRequest(imageURL)
);

Expand All @@ -46,7 +43,7 @@ public void save(ShowCreateServiceRequest showCreateServiceRequest) {
}

public List<ShowInfoServiceResponse> findShowDetailWithTicketingTimes() {
var showWithTicketingTimesDomainResponses = showUseCase.findShowDetailWithTicketingTimes();
var showWithTicketingTimesDomainResponses = showAdminUseCase.findShowDetailWithTicketingTimes();
var artistKoreanNameWithShowIdDomainResponses = artistUseCase.findArtistKoreanNamesWithShowId();
var genreNameWithShowIdDomainResponses = genreUseCase.findGenreNamesWithShowId();

Expand All @@ -59,37 +56,28 @@ public List<ShowInfoServiceResponse> findShowDetailWithTicketingTimes() {
}

public ShowInfoServiceResponse findShowInfo(UUID id) {
ShowInfoDomainResponse showInfoDomainResponse;
try {
showInfoDomainResponse = showUseCase.findShowInfo(id);
} catch (NoSuchElementException e) {
throw new BusinessException(ShowError.ENTITY_NOT_FOUND);
}
ShowInfoDomainResponse showInfoDomainResponse = showAdminUseCase.findShowInfo(id);

return new ShowInfoServiceResponse(showInfoDomainResponse);
}

public void updateShow(UUID id, ShowUpdateServiceRequest showUpdateServiceRequest) {
String imageUrl = fileUploadComponent.uploadFile("show", showUpdateServiceRequest.post());

var artistIdsToPublish = showUseCase.getArtistIdsToAdd(
var artistIdsToPublish = showAdminUseCase.getArtistIdsToAdd(
showUpdateServiceRequest.artistIds(),
showUseCase.findShowArtistsByShowId(id)
showAdminUseCase.findShowArtistsByShowId(id)
);

var genreIdsToPublish = showUseCase.getGenreIdsToAdd(
var genreIdsToPublish = showAdminUseCase.getGenreIdsToAdd(
showUpdateServiceRequest.genreIds(),
showUseCase.findShowGenresByShowId(id)
showAdminUseCase.findShowGenresByShowId(id)
);

try {
showUseCase.updateShow(
id,
showUpdateServiceRequest.toDomainRequest(imageUrl)
);
} catch (NoSuchElementException e) {
throw new BusinessException(ShowError.ENTITY_NOT_FOUND);
}
showAdminUseCase.updateShow(
id,
showUpdateServiceRequest.toDomainRequest(imageUrl)
);

if (!artistIdsToPublish.isEmpty() || !genreIdsToPublish.isEmpty()) {
messagePublisher.publishShow(
Expand All @@ -103,10 +91,6 @@ public void updateShow(UUID id, ShowUpdateServiceRequest showUpdateServiceReques
}

public void deleteShow(UUID id) {
try {
showUseCase.deleteShow(id);
} catch (NoSuchElementException e) {
throw new BusinessException(ShowError.ENTITY_NOT_FOUND);
}
showAdminUseCase.deleteShow(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.example.publish.MessagePublisher;
import com.example.publish.message.TicketingAlertsToReserveServiceMessage;
import com.example.show.controller.vo.TicketingApiType;
import com.example.show.error.ShowError;
import com.example.show.service.dto.param.ShowAlertPaginationServiceParam;
import com.example.show.service.dto.param.ShowSearchPaginationServiceParam;
import com.example.show.service.dto.request.InterestShowPaginationServiceRequest;
Expand All @@ -23,7 +22,6 @@
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand All @@ -34,7 +32,6 @@
import org.example.entity.TicketingAlert;
import org.example.entity.show.Show;
import org.example.entity.show.ShowTicketingTime;
import org.example.exception.BusinessException;
import org.example.usecase.TicketingAlertUseCase;
import org.example.usecase.UserShowUseCase;
import org.example.usecase.show.ShowUseCase;
Expand All @@ -51,12 +48,7 @@ public class ShowService {


public ShowDetailServiceResponse getShow(UUID id) {
ShowDetailDomainResponse showDetail;
try {
showDetail = showUseCase.findShowDetail(id);
} catch (NoSuchElementException e) {
throw new BusinessException(ShowError.ENTITY_NOT_FOUND);
}
ShowDetailDomainResponse showDetail = showUseCase.findShowDetail(id);

return ShowDetailServiceResponse.from(showDetail);
}
Expand Down
Loading

0 comments on commit 0659f8a

Please sign in to comment.