Skip to content

Commit

Permalink
Merge pull request #106 from SWM-Flash/integration
Browse files Browse the repository at this point in the history
Integration
  • Loading branch information
wonyangs authored Dec 6, 2024
2 parents 2e356b4 + 470ed88 commit 5e433c3
Show file tree
Hide file tree
Showing 35 changed files with 322 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class ClimbingGymQueryDslRepository {

public List<SectorInfoResponseDto> findSortedSectorNamesByGymId(final Long gymId) {
return jpaQueryFactory.select(
Projections.constructor(SectorInfoResponseDto.class, sector.sectorName.name,
sector.selectedImageUrl))
Projections.constructor(SectorInfoResponseDto.class, sector.id,
sector.sectorName.name, sector.selectedImageUrl))
.from(sector)
.where(sector.gymId.eq(gymId), sector.removalInfo.isExpired.isFalse())
.distinct()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.first.flash.climbing.gym.infrastructure.dto;

public record SectorInfoResponseDto(String name, String selectedImageUrl) {
public record SectorInfoResponseDto(Long id, String name, String selectedImageUrl) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.first.flash.climbing.solution.domain.PerceivedDifficultySetEvent;
import com.first.flash.climbing.solution.domain.SolutionDeletedEvent;
import com.first.flash.climbing.solution.domain.SolutionSavedEvent;
import com.first.flash.climbing.solution.domain.SolutionUpdatedEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -36,9 +37,18 @@ public void expireProblem(final SectorExpiredEvent event) {
@EventListener
@Transactional
public void updateProblemSolutionInfo(final SolutionSavedEvent event) {
problemsService.changeThumbnailInfo(event.getProblemId(), event.getSolutionId(),
event.getThumbnailImageUrl(), event.getUploader());
problemsService.updateProblemSolutionInfo(event.getProblemId());
}

@EventListener
@Transactional
public void updateThumbnailInfo(final SolutionUpdatedEvent event) {
problemsService.changeAllThumbnailInfo(event.getSolutionId(), event.getThumbnailImageUrl(),
event.getUploader());
}

@EventListener
@Transactional
public void updateProblemDeletedSolutionInfo(final SolutionDeletedEvent event) {
Expand Down Expand Up @@ -71,4 +81,6 @@ public void updatePerceivedDifficulty(final PerceivedDifficultySetEvent event) {
problemsService.addPerceivedDifficulty(event.getProblemId(),
event.getPerceivedDifficulty());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import static com.first.flash.climbing.problem.infrastructure.paging.ProblemSortBy.VIEWS;

import com.first.flash.climbing.gym.domian.ClimbingGymIdConfirmRequestedEvent;
import com.first.flash.climbing.problem.application.dto.DuplicateProblemsResponseDto;
import com.first.flash.climbing.problem.application.dto.ProblemDetailResponseDto;
import com.first.flash.climbing.problem.application.dto.ProblemResponseDto;
import com.first.flash.climbing.problem.application.dto.ProblemsResponseDto;
import com.first.flash.climbing.problem.domain.Problem;
import com.first.flash.climbing.problem.domain.ProblemRepository;
Expand Down Expand Up @@ -66,6 +68,13 @@ public QueryProblem findQueryProblemById(final UUID problemId) {
() -> new QueryProblemNotFoundException(problemId));
}

public DuplicateProblemsResponseDto findDuplicateProblems(final Long sectorId, final Long holdId,
final String difficulty) {
List<QueryProblem> duplicateProblems = queryProblemRepository.findBySectorIdAndHoldIdAndDifficulty(sectorId, holdId, difficulty);

return DuplicateProblemsResponseDto.of(duplicateProblems);
}

private void validateExpiration(final Problem problem, final QueryProblem queryProblem) {
if (problem.isExpired() || queryProblem.isExpired()) {
throw new QueryProblemExpiredException(problem.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.first.flash.climbing.gym.application.ClimbingGymService;
import com.first.flash.climbing.gym.domian.ClimbingGym;
import com.first.flash.climbing.hold.application.HoldService;
import com.first.flash.climbing.hold.domain.Hold;
import com.first.flash.climbing.problem.application.dto.ProblemCreateResponseDto;
import com.first.flash.climbing.problem.domain.Problem;
import com.first.flash.climbing.problem.domain.ProblemRepository;
Expand All @@ -24,17 +26,19 @@ public class ProblemsSaveService {
private final QueryProblemRepository queryProblemRepository;
private final ClimbingGymService climbingGymService;
private final SectorService sectorService;
private final HoldService holdService;
private final ProblemsCreateService problemsCreateService;

@Transactional
public ProblemCreateResponseDto saveProblems(final Long gymId, final Long sectorId,
final ProblemCreateRequestDto createRequestDto) {
ClimbingGym climbingGym = climbingGymService.findClimbingGymById(gymId);
Sector sector = sectorService.findById(sectorId);
Hold hold = holdService.findById(createRequestDto.holdId());
Problem problem = problemsCreateService.createProblem(climbingGym, sector,
createRequestDto);
QueryProblem queryProblem = problemsCreateService.createQueryProblem(climbingGym,
sector, problem);
sector, problem, hold);
problemRepository.save(problem);
queryProblemRepository.save(queryProblem);
return ProblemCreateResponseDto.toDto(problem);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.first.flash.climbing.problem.application;

import com.first.flash.climbing.problem.application.dto.ProblemDetailResponseDto;
import com.first.flash.climbing.problem.application.dto.ProblemResponseDto;
import com.first.flash.climbing.problem.application.dto.ProblemsResponseDto;
import com.first.flash.climbing.problem.domain.Problem;
import com.first.flash.climbing.problem.domain.ProblemRepository;
import com.first.flash.climbing.problem.domain.QueryProblem;
import com.first.flash.climbing.problem.domain.QueryProblemRepository;
import com.first.flash.climbing.problem.infrastructure.dto.ThumbnailSolutionDto;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
Expand All @@ -30,6 +34,30 @@ public void expireProblems(final List<Long> expiredSectorsIds) {
queryProblemRepository.expireProblemsBySectorIds(expiredSectorsIds);
problemRepository.expireProblemsBySectorIds(expiredSectorsIds);
}

@Transactional
public void changeThumbnailInfo(final UUID problemId, final Long solutionId,
final String thumbnailImageUrl, final String uploader) {
Problem problem = problemReadService.findProblemById(problemId);
QueryProblem queryProblem = problemReadService.findQueryProblemById(problemId);

if (queryProblem.getHasSolution()) {
return;
}

problem.setThumbnailInfo(solutionId, thumbnailImageUrl, uploader);
queryProblem.setThumbnailInfo(solutionId, thumbnailImageUrl, uploader);
}

@Transactional
public void changeAllThumbnailInfo(final Long solutionId, final String thumbnailImageUrl, final String uploader) {
List<Problem> problems = problemRepository.findProblemsByThumbnailSolutionId(solutionId);
List<QueryProblem> queryProblems = queryProblemRepository.findProblemsByThumbnailSolutionId(
solutionId);

problems.forEach(problem -> problem.setThumbnailInfo(solutionId, thumbnailImageUrl, uploader));
queryProblems.forEach(queryProblem -> queryProblem.setThumbnailInfo(solutionId, thumbnailImageUrl, uploader));
}

@Transactional
public void updateProblemSolutionInfo(final UUID problemId) {
Expand All @@ -40,8 +68,20 @@ public void updateProblemSolutionInfo(final UUID problemId) {
@Transactional
public void updateProblemDeletedSolutionInfo(final UUID problemId,
final Integer perceivedDifficulty) {
Problem problem = problemReadService.findProblemById(problemId);
QueryProblem queryProblem = problemReadService.findQueryProblemById(problemId);

queryProblem.decrementSolutionCount();
if (!queryProblem.getHasSolution()) {
problemRepository.deleteByProblemId(problemId);
queryProblemRepository.deleteByProblemId(problemId);
return;
}

ThumbnailSolutionDto dto = problemRepository.findNextSolution(problemId);
problem.setThumbnailInfo(dto.solutionId(), dto.thumbnailImageUrl(), dto.uploader());
queryProblem.setThumbnailInfo(dto.solutionId(), dto.thumbnailImageUrl(), dto.uploader());

queryProblem.subtractPerceivedDifficulty(perceivedDifficulty);
}

Expand All @@ -68,4 +108,5 @@ public ProblemDetailResponseDto setPerceivedDifficulty(final UUID problemId,
public void updateQueryProblemFixedInfo(final List<Long> sectorIds, final String sectorName) {
queryProblemRepository.updateSectorNameBySectorIds(sectorIds, sectorName);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.first.flash.climbing.problem.application.dto;

import com.first.flash.climbing.problem.domain.QueryProblem;
import com.first.flash.global.paging.Meta;
import java.util.List;

public record DuplicateProblemsResponseDto(List<ProblemResponseDto> problems) {

public static DuplicateProblemsResponseDto of(final List<QueryProblem> queryProblems) {
return new DuplicateProblemsResponseDto(queryProblems.stream()
.map(ProblemResponseDto::toDto)
.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
@Builder
public record ProblemCreateResponseDto(UUID id, String imageUrl, Integer views, Boolean isExpired,
DifficultyInfo difficultyInfo, Long optionalWeight,
Long gymId, Long sectorId, String imageSource
Long gymId, Long sectorId, String imageSource,
Long thumbnailSolutionId, Long holdId
) {

public static ProblemCreateResponseDto toDto(final Problem problem) {
Expand All @@ -22,6 +23,8 @@ public static ProblemCreateResponseDto toDto(final Problem problem) {
.gymId(problem.getGymId())
.sectorId(problem.getSectorId())
.imageSource(problem.getImageSource())
.thumbnailSolutionId(problem.getThumbnailSolutionId())
.holdId(problem.getHoldId())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
public record ProblemDetailResponseDto(UUID id, String sector, String difficulty,
LocalDate settingDate, LocalDate removalDate,
boolean isFakeRemovalDate, boolean hasSolution,
String holdColorCode,
String imageUrl, String gymName, String imageSource, Boolean isHoney) {

public static ProblemDetailResponseDto of(final QueryProblem queryProblem) {
return new ProblemDetailResponseDto(queryProblem.getId(), queryProblem.getSectorName(),
queryProblem.getDifficultyName(), queryProblem.getSettingDate(),
queryProblem.getRemovalDate(), queryProblem.getIsFakeRemovalDate(),
queryProblem.getHasSolution(), queryProblem.getImageUrl(), queryProblem.getGymName(),
queryProblem.getImageSource(), queryProblem.isHoney());
queryProblem.getHasSolution(), queryProblem.getHoldColorCode(), queryProblem.getImageUrl(),
queryProblem.getGymName(), queryProblem.getImageSource(), queryProblem.isHoney());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

public record ProblemResponseDto(UUID id, String sector, String difficulty, LocalDate settingDate,
LocalDate removalDate, boolean hasSolution, String imageUrl,
Boolean isHoney, Integer solutionCount) {
String holdColorCode, Boolean isHoney, Integer solutionCount) {

public static ProblemResponseDto toDto(QueryProblem queryProblem) {
return new ProblemResponseDto(queryProblem.getId(), queryProblem.getSectorName(),
queryProblem.getDifficultyName(), queryProblem.getSettingDate(),
queryProblem.getRemovalDate(), queryProblem.getHasSolution(),
queryProblem.getImageUrl(), queryProblem.isHoney(), queryProblem.getSolutionCount());
queryProblem.getImageUrl(), queryProblem.getHoldColorCode(),
queryProblem.isHoney(), queryProblem.getSolutionCount());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public class Problem {
private Long gymId;
private Long sectorId;
private String imageSource;
private Long thumbnailSolutionId;
private Long holdId;

public static Problem createDefault(final UUID id, final String imageUrl,
final String difficultyName, final Integer difficultyLevel, final Long gymId,
final Long sectorId, final String imageSource) {
final Long sectorId, final String imageSource, final Long thumbnailSolutionId, final Long holdId) {
return Problem.builder()
.id(id)
.imageUrl(imageUrl)
Expand All @@ -49,6 +51,8 @@ public static Problem createDefault(final UUID id, final String imageUrl,
.gymId(gymId)
.sectorId(sectorId)
.imageSource(imageSource)
.thumbnailSolutionId(thumbnailSolutionId)
.holdId(holdId)
.build();
}

Expand All @@ -59,4 +63,11 @@ public void view() {
public boolean isExpired() {
return isExpired;
}

public void setThumbnailInfo(final Long thumbnailSolutionId, final String imageUrl,
final String imageSource) {
this.thumbnailSolutionId = thumbnailSolutionId;
this.imageUrl = imageUrl;
this.imageSource = imageSource;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.first.flash.climbing.problem.domain;

import com.first.flash.climbing.problem.infrastructure.dto.ThumbnailSolutionDto;
import com.first.flash.climbing.solution.domain.Solution;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -11,4 +13,10 @@ public interface ProblemRepository {
Optional<Problem> findById(final UUID id);

void expireProblemsBySectorIds(final List<Long> expiredSectorsIds);

void deleteByProblemId(final UUID problemId);

ThumbnailSolutionDto findNextSolution(final UUID problemId);

List<Problem> findProblemsByThumbnailSolutionId(final Long solutionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.first.flash.climbing.gym.domian.ClimbingGym;
import com.first.flash.climbing.gym.domian.vo.Difficulty;
import com.first.flash.climbing.hold.domain.Hold;
import com.first.flash.climbing.problem.domain.dto.ProblemCreateRequestDto;
import com.first.flash.climbing.problem.util.UUIDGenerator;
import com.first.flash.climbing.sector.domain.Sector;
Expand All @@ -26,11 +27,12 @@ public Problem createProblem(final ClimbingGym climbingGym, final Sector sector,
UUID generatedUUID = uuidGenerator.generate();

return Problem.createDefault(generatedUUID, createRequestDto.imageUrl(),
difficulty.getName(), difficulty.getLevel(), climbingGym.getId(), sector.getId(), createRequestDto.imageSource());
difficulty.getName(), difficulty.getLevel(), climbingGym.getId(), sector.getId(),
createRequestDto.imageSource(), createRequestDto.thumbnailSolutionId(), createRequestDto.holdId());
}

public QueryProblem createQueryProblem(final ClimbingGym climbingGym, final Sector sector,
final Problem problem) {
final Problem problem, final Hold hold) {
return QueryProblem.builder()
.id(problem.getId())
.imageUrl(problem.getImageUrl())
Expand All @@ -51,6 +53,10 @@ public QueryProblem createQueryProblem(final ClimbingGym climbingGym, final Sect
.sectorName(sector.getSectorName().getName())
.settingDate(sector.getSettingDate())
.removalDate(sector.getRemovalDate())
.thumbnailSolutionId(problem.getThumbnailSolutionId())
.holdId(hold.getId())
.holdColorName(hold.getColorName())
.holdColorCode(hold.getColorCode())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class QueryProblem {
private String sectorName;
private LocalDate settingDate;
private LocalDate removalDate;
private Long thumbnailSolutionId;
private Long holdId;
private String holdColorName;
private String holdColorCode;

public boolean isExpired() {
return isExpired;
Expand Down Expand Up @@ -94,6 +98,13 @@ public Boolean isHoney() {
return perceivedDifficulty < 0;
}

public void setThumbnailInfo(final Long thumbnailSolutionId, final String imageUrl,
final String imageSource) {
this.thumbnailSolutionId = thumbnailSolutionId;
this.imageUrl = imageUrl;
this.imageSource = imageSource;
}

private void enableSolution() {
if (!hasSolution) {
hasSolution = true;
Expand All @@ -109,4 +120,5 @@ private void calculateRecommendationValue() {
(STANDARD_VIEW_COUNT + difficultyLevel * DIFFICULTY_LEVEL_WEIGHT) * solutionCount
+ optionalWeight;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ void updateQueryProblemInfo(final Long sectorId, final String sectorName,
final LocalDate settingDate, final boolean isExpired);

void updateSectorNameBySectorIds(final List<Long> sectorIds, final String sectorName);

void deleteByProblemId(final UUID problemId);

List<QueryProblem> findBySectorIdAndHoldIdAndDifficulty(Long sectorId, Long holdId, String difficulty);

List<QueryProblem> findProblemsByThumbnailSolutionId(Long solutionId);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.first.flash.climbing.problem.domain.dto;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;

public record ProblemCreateRequestDto(
@NotEmpty(message = "이미지 URL은 필수입니다.") String imageUrl,
String imageUrl,
String imageSource,
Long thumbnailSolutionId,
@NotEmpty(message = "난이도는 필수입니다.") String difficulty,
@NotEmpty(message = "이미지 출처는 필수입니다.") String imageSource) {
@NotNull(message = "홀드 아이디는 필수입니다.") Long holdId) {

}
Loading

0 comments on commit 5e433c3

Please sign in to comment.