-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/#933' into glen/test1
- Loading branch information
Showing
14 changed files
with
663 additions
and
39 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
backend/src/main/java/com/festago/admin/application/AdminQueryInfoRenewalService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.festago.admin.application; | ||
|
||
import com.festago.admin.repository.AdminFestivalIdResolverQueryDslRepository; | ||
import com.festago.admin.repository.AdminStageIdResolverQueryDslRepository; | ||
import com.festago.festival.application.FestivalQueryInfoArtistRenewService; | ||
import com.festago.stage.application.StageQueryInfoService; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class AdminQueryInfoRenewalService { | ||
|
||
private final FestivalQueryInfoArtistRenewService festivalQueryInfoArtistRenewService; | ||
private final StageQueryInfoService stageQueryInfoService; | ||
private final AdminStageIdResolverQueryDslRepository adminStageIdResolverQueryDslRepository; | ||
private final AdminFestivalIdResolverQueryDslRepository adminFestivalIdResolverQueryDslRepository; | ||
|
||
public void renewalByFestivalId(Long festivalId) { | ||
festivalQueryInfoArtistRenewService.renewArtistInfo(festivalId); | ||
adminStageIdResolverQueryDslRepository.findStageIdsByFestivalId(festivalId) | ||
.forEach(stageQueryInfoService::renewalStageQueryInfo); | ||
} | ||
|
||
public void renewalByFestivalStartDatePeriod(LocalDate to, LocalDate end) { | ||
List<Long> festivalIds = adminFestivalIdResolverQueryDslRepository.findFestivalIdsByStartDatePeriod(to, end); | ||
log.info("{}๊ฐ์ ์ถ์ ์ ๋ํด QueryInfo๋ฅผ ์๋ก ๊ฐฑ์ ํฉ๋๋ค.", festivalIds.size()); | ||
festivalIds.forEach(festivalQueryInfoArtistRenewService::renewArtistInfo); | ||
adminStageIdResolverQueryDslRepository.findStageIdsByFestivalIdIn(festivalIds) | ||
.forEach(stageQueryInfoService::renewalStageQueryInfo); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...rc/main/java/com/festago/admin/dto/queryinfo/QueryInfoRenewalFestivalPeriodV1Request.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.festago.admin.dto.queryinfo; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import java.time.LocalDate; | ||
|
||
public record QueryInfoRenewalFestivalPeriodV1Request( | ||
@NotNull LocalDate to, | ||
@NotNull LocalDate end | ||
) { | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...nd/src/main/java/com/festago/admin/presentation/v1/AdminQueryInfoRenewalV1Controller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.festago.admin.presentation.v1; | ||
|
||
import com.festago.admin.application.AdminQueryInfoRenewalService; | ||
import com.festago.admin.dto.queryinfo.QueryInfoRenewalFestivalPeriodV1Request; | ||
import io.swagger.v3.oas.annotations.Hidden; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/admin/api/v1/query-info/renewal") | ||
@RequiredArgsConstructor | ||
@Hidden | ||
public class AdminQueryInfoRenewalV1Controller { | ||
|
||
private final AdminQueryInfoRenewalService queryInfoRenewalService; | ||
|
||
@PostMapping("/festival-id/{festivalId}") | ||
public ResponseEntity<Void> renewalByFestivalId( | ||
@PathVariable Long festivalId | ||
) { | ||
queryInfoRenewalService.renewalByFestivalId(festivalId); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@PostMapping("/festival-period") | ||
public ResponseEntity<Void> renewalByFestivalStartDatePeriod( | ||
@RequestBody @Valid QueryInfoRenewalFestivalPeriodV1Request request | ||
) { | ||
queryInfoRenewalService.renewalByFestivalStartDatePeriod(request.to(), request.end()); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...src/main/java/com/festago/admin/repository/AdminFestivalIdResolverQueryDslRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.festago.admin.repository; | ||
|
||
import static com.festago.festival.domain.QFestival.festival; | ||
|
||
import com.festago.common.querydsl.QueryDslRepositorySupport; | ||
import com.festago.festival.domain.Festival; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class AdminFestivalIdResolverQueryDslRepository extends QueryDslRepositorySupport { | ||
|
||
public AdminFestivalIdResolverQueryDslRepository() { | ||
super(Festival.class); | ||
} | ||
|
||
public List<Long> findFestivalIdsByStartDatePeriod(LocalDate to, LocalDate end) { | ||
return select(festival.id) | ||
.from(festival) | ||
.where(festival.festivalDuration.startDate.goe(to) | ||
.and(festival.festivalDuration.startDate.loe(end))) | ||
.fetch(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...nd/src/main/java/com/festago/admin/repository/AdminStageIdResolverQueryDslRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.festago.admin.repository; | ||
|
||
import static com.festago.festival.domain.QFestival.festival; | ||
import static com.festago.stage.domain.QStage.stage; | ||
|
||
import com.festago.common.querydsl.QueryDslRepositorySupport; | ||
import com.festago.stage.domain.Stage; | ||
import java.util.List; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class AdminStageIdResolverQueryDslRepository extends QueryDslRepositorySupport { | ||
|
||
public AdminStageIdResolverQueryDslRepository() { | ||
super(Stage.class); | ||
} | ||
|
||
public List<Long> findStageIdsByFestivalId(Long festivalId) { | ||
return select(stage.id) | ||
.from(stage) | ||
.innerJoin(festival).on(festival.id.eq(stage.festival.id)) | ||
.where(festival.id.eq(festivalId)) | ||
.fetch(); | ||
} | ||
|
||
public List<Long> findStageIdsByFestivalIdIn(List<Long> festivalIds) { | ||
return select(stage.id) | ||
.from(stage) | ||
.innerJoin(festival).on(festival.id.eq(stage.festival.id)) | ||
.where(festival.id.in(festivalIds)) | ||
.fetch(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
backend/src/main/java/com/festago/stage/application/StageQueryInfoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.festago.stage.application; | ||
|
||
import com.festago.artist.domain.Artist; | ||
import com.festago.artist.domain.ArtistsSerializer; | ||
import com.festago.artist.repository.ArtistRepository; | ||
import com.festago.common.exception.ErrorCode; | ||
import com.festago.common.exception.InternalServerException; | ||
import com.festago.common.exception.NotFoundException; | ||
import com.festago.stage.domain.StageQueryInfo; | ||
import com.festago.stage.repository.StageArtistRepository; | ||
import com.festago.stage.repository.StageQueryInfoRepository; | ||
import java.util.List; | ||
import java.util.Set; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class StageQueryInfoService { | ||
|
||
private final StageQueryInfoRepository stageQueryInfoRepository; | ||
private final StageArtistRepository stageArtistRepository; | ||
private final ArtistRepository artistRepository; | ||
private final ArtistsSerializer serializer; | ||
|
||
public void initialStageQueryInfo(Long stageId) { | ||
List<Artist> artists = getStageArtists(stageId); | ||
StageQueryInfo stageQueryInfo = StageQueryInfo.of(stageId, artists, serializer); | ||
stageQueryInfoRepository.save(stageQueryInfo); | ||
} | ||
|
||
private List<Artist> getStageArtists(Long stageId) { | ||
Set<Long> artistIds = stageArtistRepository.findAllArtistIdByStageId(stageId); | ||
List<Artist> artists = artistRepository.findByIdIn(artistIds); | ||
if (artists.size() != artistIds.size()) { | ||
log.error("StageArtist์ ์กด์ฌํ์ง ์์ Artist๊ฐ ์์ต๋๋ค. artistsIds=" + artistIds); | ||
throw new InternalServerException(ErrorCode.ARTIST_NOT_FOUND); | ||
} | ||
return artists; | ||
} | ||
|
||
public void renewalStageQueryInfo(Long stageId) { | ||
StageQueryInfo stageQueryInfo = stageQueryInfoRepository.findByStageId(stageId) | ||
.orElseThrow(() -> new NotFoundException(ErrorCode.STAGE_NOT_FOUND)); | ||
List<Artist> artists = getStageArtists(stageId); | ||
stageQueryInfo.updateArtist(artists, serializer); | ||
} | ||
|
||
public void deleteStageQueryInfo(Long stageId) { | ||
stageQueryInfoRepository.deleteByStageId(stageId); | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
...rc/test/java/com/festago/admin/presentation/v1/AdminQueryInfoRenewalV1ControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.festago.admin.presentation.v1; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.festago.admin.application.AdminQueryInfoRenewalService; | ||
import com.festago.admin.dto.queryinfo.QueryInfoRenewalFestivalPeriodV1Request; | ||
import com.festago.auth.domain.Role; | ||
import com.festago.support.CustomWebMvcTest; | ||
import com.festago.support.WithMockAuth; | ||
import jakarta.servlet.http.Cookie; | ||
import java.time.LocalDate; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
@CustomWebMvcTest | ||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
@SuppressWarnings("NonAsciiCharacters") | ||
class AdminQueryInfoRenewalV1ControllerTest { | ||
|
||
private static final Cookie TOKEN_COOKIE = new Cookie("token", "token"); | ||
|
||
@Autowired | ||
MockMvc mockMvc; | ||
|
||
@Autowired | ||
ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
AdminQueryInfoRenewalService adminQueryInfoRenewalService; | ||
|
||
@Nested | ||
class QueryInfo_์ฌ๊ฐฑ์ _by_festivalId { | ||
|
||
final String uri = "/admin/api/v1/query-info/renewal/festival-id/{festivalId}"; | ||
|
||
@Nested | ||
@DisplayName("POST " + uri) | ||
class ์ฌ๋ฐ๋ฅธ_์ฃผ์๋ก { | ||
|
||
private long festivalId = 1L; | ||
|
||
@Test | ||
@WithMockAuth(role = Role.ADMIN) | ||
void ์์ฒญ์_๋ณด๋ด๋ฉด_200_์๋ต์ด_๋ฐํ๋๋ค() throws Exception { | ||
// when & then | ||
mockMvc.perform(post(uri, festivalId) | ||
.cookie(TOKEN_COOKIE) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
@Test | ||
void ํ ํฐ_์์ด_๋ณด๋ด๋ฉด_401_์๋ต์ด_๋ฐํ๋๋ค() throws Exception { | ||
// when & then | ||
mockMvc.perform(post(uri, festivalId)) | ||
.andExpect(status().isUnauthorized()); | ||
} | ||
|
||
@Test | ||
@WithMockAuth(role = Role.MEMBER) | ||
void ํ ํฐ์_๊ถํ์ด_Admin์ด_์๋๋ฉด_404_์๋ต์ด_๋ฐํ๋๋ค() throws Exception { | ||
// when & then | ||
mockMvc.perform(post(uri, festivalId) | ||
.cookie(TOKEN_COOKIE)) | ||
.andExpect(status().isNotFound()); | ||
} | ||
} | ||
} | ||
|
||
@Nested | ||
class QueryInfo_์ฌ๊ฐฑ์ _by_festival_startDate_period { | ||
|
||
final String uri = "/admin/api/v1/query-info/renewal/festival-period"; | ||
|
||
@Nested | ||
@DisplayName("POST " + uri) | ||
class ์ฌ๋ฐ๋ฅธ_์ฃผ์๋ก { | ||
|
||
@Test | ||
@WithMockAuth(role = Role.ADMIN) | ||
void ์์ฒญ์_๋ณด๋ด๋ฉด_200_์๋ต์ด_๋ฐํ๋๋ค() throws Exception { | ||
// given | ||
var request = new QueryInfoRenewalFestivalPeriodV1Request(LocalDate.now(), LocalDate.now()); | ||
// when & then | ||
mockMvc.perform(post(uri) | ||
.content(objectMapper.writeValueAsString(request)) | ||
.cookie(TOKEN_COOKIE) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
@Test | ||
void ํ ํฐ_์์ด_๋ณด๋ด๋ฉด_401_์๋ต์ด_๋ฐํ๋๋ค() throws Exception { | ||
// when & then | ||
mockMvc.perform(post(uri)) | ||
.andExpect(status().isUnauthorized()); | ||
} | ||
|
||
@Test | ||
@WithMockAuth(role = Role.MEMBER) | ||
void ํ ํฐ์_๊ถํ์ด_Admin์ด_์๋๋ฉด_404_์๋ต์ด_๋ฐํ๋๋ค() throws Exception { | ||
// when & then | ||
mockMvc.perform(post(uri) | ||
.cookie(TOKEN_COOKIE)) | ||
.andExpect(status().isNotFound()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.