Skip to content

Commit

Permalink
Merge branch 'dev' into feat/#971
Browse files Browse the repository at this point in the history
# Conflicts:
#	backend/src/test/java/com/festago/festival/application/integration/query/PopularFestivalV1QueryServiceIntegrationTest.java
  • Loading branch information
BGuga committed May 15, 2024
2 parents 6ca103e + 75f69eb commit 7351ae4
Show file tree
Hide file tree
Showing 83 changed files with 1,846 additions and 681 deletions.
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public record ArtistV1CreateRequest(
) {

public ArtistCreateCommand toCommand() {
return new ArtistCreateCommand(
name,
profileImageUrl,
backgroundImageUrl
);
return ArtistCreateCommand.builder()
.name(name)
.profileImageUrl(profileImageUrl)
.backgroundImageUrl(backgroundImageUrl)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public record ArtistV1UpdateRequest(
) {

public ArtistUpdateCommand toCommand() {
return new ArtistUpdateCommand(
name,
profileImageUrl,
backgroundImageUrl
);
return ArtistUpdateCommand.builder()
.name(name)
.profileImageUrl(profileImageUrl)
.backgroundImageUrl(backgroundImageUrl)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public record FestivalV1CreateRequest(
) {

public FestivalCreateCommand toCommand() {
return new FestivalCreateCommand(
name,
startDate,
endDate,
posterImageUrl,
schoolId
);
return FestivalCreateCommand.builder()
.name(name)
.startDate(startDate)
.endDate(endDate)
.posterImageUrl(posterImageUrl)
.schoolId(schoolId)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public record FestivalV1UpdateRequest(
) {

public FestivalUpdateCommand toCommand() {
return new FestivalUpdateCommand(
name,
startDate,
endDate,
posterImageUrl
);
return FestivalUpdateCommand.builder()
.name(name)
.startDate(startDate)
.endDate(endDate)
.posterImageUrl(posterImageUrl)
.build();
}
}
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
) {

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.festago.admin.dto.school;

import com.festago.school.domain.SchoolRegion;
import com.festago.school.dto.SchoolCreateCommand;
import com.festago.school.dto.command.SchoolCreateCommand;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.festago.admin.dto.school;

import com.festago.school.domain.SchoolRegion;
import com.festago.school.dto.SchoolUpdateCommand;
import com.festago.school.dto.command.SchoolUpdateCommand;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public record StageV1CreateRequest(
) {

public StageCreateCommand toCommand() {
return new StageCreateCommand(
festivalId,
startTime,
ticketOpenTime,
artistIds
);
return StageCreateCommand.builder()
.festivalId(festivalId)
.startTime(startTime)
.ticketOpenTime(ticketOpenTime)
.artistIds(artistIds)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public record StageV1UpdateRequest(
) {

public StageUpdateCommand toCommand() {
return new StageUpdateCommand(
startTime,
ticketOpenTime,
artistIds
);
return StageUpdateCommand.builder()
.startTime(startTime)
.ticketOpenTime(ticketOpenTime)
.artistIds(artistIds)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.festago.admin.dto.upload;

import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;

public record AdminDeleteAbandonedPeriodUploadFileV1Request(
@NotNull LocalDateTime startTime,
@NotNull LocalDateTime endTime
) {

}
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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.festago.admin.presentation.v1;

import com.festago.admin.dto.upload.AdminDeleteAbandonedPeriodUploadFileV1Request;
import com.festago.upload.application.UploadFileDeleteService;
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.DeleteMapping;
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/upload/delete")
@RequiredArgsConstructor
@Hidden
public class AdminUploadFileDeleteV1Controller {

private final UploadFileDeleteService uploadFileDeleteService;

@DeleteMapping("/abandoned-period")
public ResponseEntity<Void> deleteAbandonedWithPeriod(
@RequestBody @Valid AdminDeleteAbandonedPeriodUploadFileV1Request request
) {
uploadFileDeleteService.deleteAbandonedStatusWithPeriod(request.startTime(), request.endTime());
return ResponseEntity.ok()
.build();
}

@DeleteMapping("/old-uploaded")
public ResponseEntity<Void> deleteOldUploaded() {
uploadFileDeleteService.deleteOldUploadedStatus();
return ResponseEntity.ok()
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@RequestMapping("/admin/api/v1/upload/images")
@RequiredArgsConstructor
@Hidden
public class AdminUploadV1Controller {
public class AdminUploadImageV1Controller {

private final ImageFileUploadService imageFileUploadService;

Expand Down
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();
}
}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.festago.artist.dto.event.ArtistDeletedEvent;
import com.festago.artist.dto.event.ArtistUpdatedEvent;
import com.festago.artist.repository.ArtistRepository;
import com.festago.common.exception.BadRequestException;
import com.festago.common.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
Expand All @@ -21,13 +23,20 @@ public class ArtistCommandService {
private final ApplicationEventPublisher eventPublisher;

public Long save(ArtistCreateCommand command) {
validateSave(command);
Artist artist = artistRepository.save(
new Artist(command.name(), command.profileImageUrl(), command.backgroundImageUrl())
);
eventPublisher.publishEvent(new ArtistCreatedEvent(artist));
return artist.getId();
}

private void validateSave(ArtistCreateCommand command) {
if (artistRepository.existsByName(command.name())) {
throw new BadRequestException(ErrorCode.DUPLICATE_ARTIST_NAME);
}
}

public void update(ArtistUpdateCommand command, Long artistId) {
Artist artist = artistRepository.getOrThrow(artistId);
artist.update(command.name(), command.profileImageUrl(), command.backgroundImageUrl());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.festago.artist.dto.command;

import lombok.Builder;

@Builder
public record ArtistCreateCommand(
String name,
String profileImageUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.festago.artist.dto.command;

import lombok.Builder;

@Builder
public record ArtistUpdateCommand(
String name,
String profileImageUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ default Artist getOrThrow(Long artistId) {
List<Artist> findByIdIn(Collection<Long> artistIds);

boolean existsById(Long id);

boolean existsByName(String name);
}

This file was deleted.

Loading

0 comments on commit 7351ae4

Please sign in to comment.