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

배포 #71

Closed
wants to merge 5 commits into from
Closed
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
@@ -0,0 +1,33 @@
package org.sopt.confeti.api.performance.controller;

import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import org.sopt.confeti.api.performance.dto.response.ConcertDetailResponse;
import org.sopt.confeti.api.performance.facade.PerformanceFacade;
import org.sopt.confeti.api.performance.facade.dto.response.ConcertDetailDTO;
import org.sopt.confeti.global.common.BaseResponse;
import org.sopt.confeti.global.message.SuccessMessage;
import org.sopt.confeti.global.util.ApiResponseUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@Validated
@RequestMapping("/performances")
public class PerformanceController {

private final PerformanceFacade performanceFacade;

@GetMapping("/concerts/{concertId}")
public ResponseEntity<BaseResponse<?>> getConcertInfo(@RequestHeader("Authorization") Long userId,
@PathVariable("concertId") @Min(value = 0, message = "요청 형식이 올바르지 않습니다.") Long concertId) {
ConcertDetailDTO concertDetailDTO = performanceFacade.getConcertDetailInfo(concertId);
return ApiResponseUtil.success(SuccessMessage.SUCCESS, ConcertDetailResponse.from(concertDetailDTO));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.sopt.confeti.api.performance.dto.response;

import org.sopt.confeti.api.performance.facade.dto.response.ConcertArtistDTO;

public record ConcertDetailArtistResponse(
String artistId,
String name,
String profileUrl
) {
public static ConcertDetailArtistResponse from(final ConcertArtistDTO concertArtistDTO) {
return new ConcertDetailArtistResponse(
concertArtistDTO.artistId(),
concertArtistDTO.name(),
concertArtistDTO.profileUrl()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.sopt.confeti.api.performance.dto.response;

import java.time.LocalDate;
import java.time.LocalDateTime;
import org.sopt.confeti.api.performance.facade.dto.response.ConcertDetailDTO;

public record ConcertDetailInfoResponse(
long concertId,
String posterUrl,
String posterBgUrl,
String title,
String subtitle,
LocalDate startAt,
LocalDate endAt,
String area,
LocalDateTime reserveAt,
String reservationUrl,
String time,
String ageRating,
String reservationOffice,
String price,
String infoImgUrl
) {
public static ConcertDetailInfoResponse from(final ConcertDetailDTO concertDetailDTO) {
return new ConcertDetailInfoResponse(
concertDetailDTO.concertId(),
concertDetailDTO.posterUrl(),
concertDetailDTO.posterBgUrl(),
concertDetailDTO.title(),
concertDetailDTO.subtitle(),
concertDetailDTO.startAt(),
concertDetailDTO.endAt(),
concertDetailDTO.area(),
concertDetailDTO.reserveAt(),
concertDetailDTO.reservationUrl(),
concertDetailDTO.time(),
concertDetailDTO.ageRating(),
concertDetailDTO.reservationOffice(),
concertDetailDTO.price(),
concertDetailDTO.infoImgUrl()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.sopt.confeti.api.performance.dto.response;

import java.util.List;
import org.sopt.confeti.api.performance.facade.dto.response.ConcertDetailDTO;

public record ConcertDetailResponse(
ConcertDetailInfoResponse concert,
List<ConcertDetailArtistResponse> concertArtists
) {
public static ConcertDetailResponse from(final ConcertDetailDTO concertDetailDTO) {
return new ConcertDetailResponse(
ConcertDetailInfoResponse.from(concertDetailDTO),
concertDetailDTO.artists().stream()
.map(ConcertDetailArtistResponse::from)
.toList()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.sopt.confeti.api.performance.facade;

import lombok.RequiredArgsConstructor;
import org.sopt.confeti.annotation.Facade;
import org.sopt.confeti.api.performance.facade.dto.response.ConcertDetailDTO;
import org.sopt.confeti.domain.concert.Concert;
import org.sopt.confeti.domain.concert.application.ConcertService;
import org.sopt.confeti.global.util.S3FileHandler;
import org.springframework.transaction.annotation.Transactional;

@Facade
@RequiredArgsConstructor
public class PerformanceFacade {

private final ConcertService concertService;
private final S3FileHandler s3FileHandler;

@Transactional
public ConcertDetailDTO getConcertDetailInfo(final long concertId) {
Concert concert = concertService.getConcertDetailByConcertId(concertId);
return ConcertDetailDTO.of(concert, s3FileHandler);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.sopt.confeti.api.performance.facade.dto.response;

import java.time.LocalDate;
import org.sopt.confeti.domain.concertartist.ConcertArtist;
import org.sopt.confeti.global.util.artistsearcher.ConfetiArtist;

public record ConcertArtistDTO(
String artistId,
String name,
String profileUrl,
LocalDate latestReleaseAt
) {
public static ConcertArtistDTO of(final ConcertArtist concertArtist) {
ConfetiArtist confetiArtist = concertArtist.getArtist();

return new ConcertArtistDTO(
confetiArtist.getArtistId(),
confetiArtist.getName(),
confetiArtist.getProfileUrl(),
confetiArtist.getLatestReleaseAt()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.sopt.confeti.api.performance.facade.dto.response;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import org.sopt.confeti.domain.concert.Concert;
import org.sopt.confeti.global.util.S3FileHandler;

public record ConcertDetailDTO(
long concertId,
String title,
String subtitle,
LocalDate startAt,
LocalDate endAt,
String area,
String posterUrl,
String posterBgUrl,
String infoImgUrl,
String concertReservationBgUrl,
LocalDateTime reserveAt,
String reservationUrl,
String reservationOffice,
String ageRating,
String time,
String price,
List<ConcertArtistDTO> artists
) {
public static ConcertDetailDTO of(final Concert concert, final S3FileHandler s3FileHandler) {
return new ConcertDetailDTO(
concert.getId(),
concert.getConcertTitle(),
concert.getConcertSubtitle(),
concert.getConcertStartAt(),
concert.getConcertEndAt(),
concert.getConcertArea(),
s3FileHandler.getFileUrl(concert.getConcertPosterPath()),
s3FileHandler.getFileUrl(concert.getConcertPosterBgPath()),
s3FileHandler.getFileUrl(concert.getConcertInfoImgPath()),
s3FileHandler.getFileUrl(concert.getConcertReservationBgPath()),
concert.getReserveAt(),
concert.getReservationUrl(),
concert.getReservationOffice(),
concert.getAgeRating(),
concert.getTime(),
concert.getPrice(),
concert.getArtists().stream()
.map(ConcertArtistDTO::of)
.toList()
);
}
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ public ResponseEntity<BaseResponse<?>> deleteFavoriteFestival(@RequestHeader("Au
@Min(value = 0, message = "요청 형식이 올바르지 않습니다.") Long festivalId) {
userFavoriteFacade.delete(userId, festivalId);
return ApiResponseUtil.success(SuccessMessage.SUCCESS);
}}
}
}
1 change: 1 addition & 0 deletions src/main/java/org/sopt/confeti/domain/concert/Concert.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import org.sopt.confeti.global.util.artistsearcher.ConfetiArtist;

@Entity
@Table(name="concerts")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.sopt.confeti.domain.concert.application;

import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.sopt.confeti.domain.concert.Concert;
import org.sopt.confeti.domain.concert.infra.repository.ConcertRepository;
import org.sopt.confeti.global.exception.ConfetiException;
import org.sopt.confeti.global.exception.NotFoundException;
import org.sopt.confeti.global.message.ErrorMessage;
import org.sopt.confeti.global.util.artistsearcher.ArtistResolver;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ConcertService {

private final ConcertRepository concertRepository;
private final ArtistResolver artistResolver;

public Concert getConcertDetailByConcertId(final long concertId) {
Concert concert = concertRepository.findById(concertId)
.orElseThrow(
() -> new NotFoundException(ErrorMessage.NOT_FOUND)
);

artistResolver.load(concert);

return concert;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,47 @@ public class ArtistResolver {

private final ConcurrentHashMap<Class<?>, IntegrateFunction> collectByTypeMapper = new ConcurrentHashMap<Class<?>, IntegrateFunction>() {{
put(List.class, args -> {
if (!(args[0] instanceof List) || !(args[1] instanceof List) || !(args[2] instanceof HashMap)) {
if (!(args[0] instanceof List)) {
// TODO:
// 예외 처리 추가
throw new RuntimeException();
}

collectByListType((List<?>) args[0], (List<String>) args[1], (HashMap<String, ConfetiArtist>) args[2]);
collectByListType((List<?>) args[0]);
return null;
});
}};

private List<String> artistIds;
private HashMap<String, ConfetiArtist> artistMapper;
private HashMap<Object, Boolean> objectTrack;

private final SpotifyAPIHandler spotifyAPIHandler;

private void prologue() {
artistIds = new ArrayList<>();
artistMapper = new HashMap<>();
objectTrack = new HashMap<>();
}

private void epilogue() {
artistIds.clear();
artistMapper.clear();
objectTrack.clear();
}

// Spotify API를 사용해 아티스트를 로드하는 엔트리 포인트
public void load(final Object target) {
List<String> artistIds = new ArrayList<>();
HashMap<String, ConfetiArtist> artistMapper = new HashMap<>();
collect(target, artistIds, artistMapper);
prologue();
collect(target);

List<ConfetiArtist> confetiArtists = searchByArtistIds(artistIds);

injection(artistMapper, confetiArtists);
injection(confetiArtists);
epilogue();
}

private void injection(final HashMap<String, ConfetiArtist> artistMapper, final List<ConfetiArtist> confetiArtists) {
private void injection(final List<ConfetiArtist> confetiArtists) {
confetiArtists.forEach((confetiArtist -> {
ConfetiArtist mappedConfetiArtist = artistMapper.get(confetiArtist.getArtistId());
mappedConfetiArtist.setName(confetiArtist.getName());
Expand All @@ -70,7 +86,15 @@ private List<ConfetiArtist> searchByArtistIds(final List<String> artistIds) {
}

// 리플렉션을 사용해 타겟 오브젝트를 재귀적으로 순회하며 아티스트 아이디를 수집하는 함수
private void collect(final Object target, final List<String> artistIds, final HashMap<String, ConfetiArtist> artistMapper) {
private void collect(final Object target) {
// 이미 탐색한 객체인 경우
if (objectTrack.containsKey(target)) {
return;
}

// 오브젝트 트랙에 현재 탐색 대상 객체를 추가
objectTrack.put(target, true);

// 현재 오브젝트가 ConfetiArtist 타입인 경우
if (isConfetiArtistClass(target)) {
ConfetiArtist artist = (ConfetiArtist) target;
Expand All @@ -93,35 +117,31 @@ private void collect(final Object target, final List<String> artistIds, final Ha
}

try {
collectByType(target, field, artistIds, artistMapper);
collectByType(target, field);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
});
}

private void collectByType(final Object target, final Field field, final List<String> artistIds, final HashMap<String, ConfetiArtist> artistMapper) throws IllegalAccessException {
private void collectByType(final Object target, final Field field) throws IllegalAccessException {
Class<?> fieldType = field.getType();
setAccessibleIfPrivate(field);

try {
collectByTypeMapper.get(fieldType).apply(
field.get(target),
artistIds,
artistMapper
field.get(target)
);
} catch (NullPointerException e) {
collect(
field.get(target),
artistIds,
artistMapper
field.get(target)
);
}
}

private void collectByListType(final List<?> objects, final List<String> artistIds, final HashMap<String, ConfetiArtist> artistMapper) {
objects.forEach((obj) -> collect(obj, artistIds, artistMapper));
private void collectByListType(final List<?> objects) {
objects.forEach(this::collect);
}

private void setAccessibleIfPrivate(final Field field) {
Expand Down
Loading