Skip to content

Commit

Permalink
Merge pull request #87 from SWM-Flash/integration
Browse files Browse the repository at this point in the history
Integration
  • Loading branch information
wonyangs authored Oct 15, 2024
2 parents 4379eb5 + 01edda5 commit a6b492f
Show file tree
Hide file tree
Showing 28 changed files with 274 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.first.flash.climbing.sector.domain.SectorExpiredEvent;
import com.first.flash.climbing.sector.domain.SectorInfoUpdatedEvent;
import com.first.flash.climbing.sector.domain.SectorRemovalDateUpdatedEvent;
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 lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -39,7 +40,7 @@ public void updateProblemSolutionInfo(final SolutionSavedEvent event) {
@EventListener
@Transactional
public void updateProblemDeletedSolutionInfo(final SolutionDeletedEvent event) {
problemsService.updateProblemDeletedSolutionInfo(event.getProblemId());
problemsService.updateProblemDeletedSolutionInfo(event.getProblemId(), event.getPerceivedDifficulty());
}

@EventListener
Expand All @@ -54,4 +55,10 @@ public void updateQueryProblemInfo(final SectorInfoUpdatedEvent event) {
public void confirmProblemId(final ProblemIdConfirmRequestedEvent event) {
problemReadService.findProblemById(event.getProblemId());
}

@EventListener
@Transactional
public void updatePerceivedDifficulty(final PerceivedDifficultySetEvent event) {
problemsService.addPerceivedDifficulty(event.getProblemId(), event.getPerceivedDifficulty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ public class ProblemReadService {
private final ProblemRepository problemRepository;

public ProblemsResponseDto findAll(final Long gymId, final String cursor,
final String sortByRequest, final Integer size,
final List<String> difficulty, final List<String> sector, final Boolean hasSolution) {
final String sortByRequest, final Integer size, final List<String> difficulty,
final List<String> sector, final Boolean hasSolution, final Boolean isHoney) {
ProblemCursor prevProblemCursor = ProblemCursor.decode(cursor);
ProblemSortBy problemSortBy = ProblemSortBy.from(sortByRequest);

Events.raise(ClimbingGymIdConfirmRequestedEvent.of(gymId));

List<QueryProblem> queryProblems = queryProblemRepository.findAll(prevProblemCursor,
problemSortBy, size,
gymId, difficulty, sector, hasSolution);
gymId, difficulty, sector, hasSolution, isHoney);
String nextCursor = getNextCursor(problemSortBy, size, queryProblems);
return ProblemsResponseDto.of(queryProblems, nextCursor);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.first.flash.climbing.problem.application;

import com.first.flash.climbing.problem.application.dto.ProblemDetailResponseDto;
import com.first.flash.climbing.problem.domain.ProblemRepository;
import com.first.flash.climbing.problem.domain.QueryProblem;
import com.first.flash.climbing.problem.domain.QueryProblemRepository;
Expand Down Expand Up @@ -37,14 +38,28 @@ public void updateProblemSolutionInfo(final UUID problemId) {
}

@Transactional
public void updateProblemDeletedSolutionInfo(final UUID problemId) {
public void updateProblemDeletedSolutionInfo(final UUID problemId, final Integer perceivedDifficulty) {
QueryProblem queryProblem = problemReadService.findQueryProblemById(problemId);
queryProblem.decrementSolutionCount();
queryProblem.subtractPerceivedDifficulty(perceivedDifficulty);
}

@Transactional
public void updateQueryProblemInfo(final Long sectorId, final String sectorName,
final LocalDate settingDate) {
queryProblemRepository.updateQueryProblemInfo(sectorId, sectorName, settingDate);
}

@Transactional
public void addPerceivedDifficulty(final UUID problemId, final Integer perceivedDifficulty) {
QueryProblem queryProblem = problemReadService.findQueryProblemById(problemId);
queryProblem.addPerceivedDifficulty(perceivedDifficulty);
}

@Transactional
public ProblemDetailResponseDto setPerceivedDifficulty(final UUID problemId, final Integer perceivedDifficulty) {
QueryProblem queryProblem = problemReadService.findQueryProblemById(problemId);
queryProblem.setPerceivedDifficulty(perceivedDifficulty);
return ProblemDetailResponseDto.of(queryProblem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
public record ProblemDetailResponseDto(UUID id, String sector, String difficulty,
LocalDate settingDate, LocalDate removalDate,
boolean isFakeRemovalDate, boolean hasSolution,
String imageUrl, String gymName, String imageSource) {
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.getImageSource(), queryProblem.isHoney());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.first.flash.climbing.problem.application.dto;

import jakarta.validation.constraints.NotNull;

public record ProblemPerceivedDifficultyRequestDto(
@NotNull(message = "변경할 체감 난이도 수치는 필수입니다.") Integer perceivedDifficulty) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.util.UUID;

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

public static ProblemResponseDto toDto(QueryProblem queryProblem) {
return new ProblemResponseDto(queryProblem.getId(), queryProblem.getSectorName(),
queryProblem.getDifficultyName(), queryProblem.getSettingDate(),
queryProblem.getRemovalDate(), queryProblem.getHasSolution(),
queryProblem.getImageUrl());
queryProblem.getImageUrl(), queryProblem.isHoney());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ProblemsCreateService {
private static final Boolean DEFAULT_HAS_SOLUTION = false;
private static final Integer INITIAL_SOLUTION_COUNT = 0;
private static final Long INITIAL_RECOMMENDATION_VALUE = 0L;
private static final Integer INITIAL_PERCEIVED_DIFFICULTY_VALUE = 0;

private final UUIDGenerator uuidGenerator;

Expand All @@ -36,6 +37,7 @@ public QueryProblem createQueryProblem(final ClimbingGym climbingGym, final Sect
.views(problem.getViews())
.isExpired(problem.getIsExpired())
.hasSolution(DEFAULT_HAS_SOLUTION)
.perceivedDifficulty(INITIAL_PERCEIVED_DIFFICULTY_VALUE)
.recommendationValue(INITIAL_RECOMMENDATION_VALUE)
.solutionCount(INITIAL_SOLUTION_COUNT)
.isFakeRemovalDate(sector.getRemovalInfo().getIsFakeRemovalDate())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Entity
Expand Down Expand Up @@ -42,6 +43,8 @@ public class QueryProblem {
private Integer views;
private Boolean isExpired;
private Integer solutionCount;
@Setter
private Integer perceivedDifficulty;
private Long recommendationValue;
private Boolean hasSolution;
private Boolean isFakeRemovalDate;
Expand Down Expand Up @@ -79,6 +82,18 @@ public void decrementSolutionCount() {
calculateRecommendationValue();
}

public void addPerceivedDifficulty(final Integer value) {
perceivedDifficulty += value;
}

public void subtractPerceivedDifficulty(final Integer value) {
perceivedDifficulty -= value;
}

public Boolean isHoney() {
return perceivedDifficulty < 0;
}

private void enableSolution() {
if (!hasSolution) {
hasSolution = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface QueryProblemRepository {

List<QueryProblem> findAll(final ProblemCursor preProblemCursor, final ProblemSortBy problemSortBy, final int size,
final Long gymId, final List<String> difficulty, final List<String> sector,
final Boolean hasSolution);
final Boolean hasSolution, final Boolean isHoney);

void updateRemovalDateBySectorId(final Long sectorId, final LocalDate removalDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public class QueryProblemQueryDslRepository {

public List<QueryProblem> findAll(final ProblemCursor prevProblemCursor, final ProblemSortBy problemSortBy, final int size,
final Long gymId, final List<String> difficulty, final List<String> sector,
final Boolean hasSolution) {
final Boolean hasSolution, final Boolean isHoney) {
return queryFactory
.selectFrom(queryProblem)
.where(notExpired(), cursorCondition(prevProblemCursor), inGym(gymId), inSectors(sector),
inDifficulties(difficulty), hasSolution(hasSolution))
inDifficulties(difficulty), hasSolution(hasSolution), isHoneyCondition(isHoney))
.orderBy(sortItem(problemSortBy), queryProblem.id.desc())
.limit(size)
.fetch();
Expand Down Expand Up @@ -63,6 +63,13 @@ private BooleanExpression inGym(final Long gymId) {
return queryProblem.gymId.eq(gymId);
}

private BooleanExpression isHoneyCondition(final Boolean isHoney) {
if (Boolean.TRUE.equals(isHoney)) {
return queryProblem.perceivedDifficulty.lt(0);
}
return null;
}

private BooleanExpression cursorCondition(final ProblemCursor prevProblemCursor) {
if (Objects.isNull(prevProblemCursor) || Objects.isNull(prevProblemCursor.cursorValue())) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public Optional<QueryProblem> findById(final UUID id) {
@Override
public List<QueryProblem> findAll(final ProblemCursor prevProblemCursor, final ProblemSortBy problemSortBy, final int size,
final Long gymId, final List<String> difficulty, final List<String> sector,
final Boolean hasSolution) {
final Boolean hasSolution, final Boolean isHoney) {
return queryProblemQueryDslRepository.findAll(prevProblemCursor, problemSortBy, size,
gymId, difficulty, sector, hasSolution);
gymId, difficulty, sector, hasSolution, isHoney);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.first.flash.climbing.problem.application.ProblemReadService;
import com.first.flash.climbing.problem.application.ProblemsSaveService;
import com.first.flash.climbing.problem.application.ProblemsService;
import com.first.flash.climbing.problem.application.dto.ProblemCreateResponseDto;
import com.first.flash.climbing.problem.application.dto.ProblemDetailResponseDto;
import com.first.flash.climbing.problem.application.dto.ProblemPerceivedDifficultyRequestDto;
import com.first.flash.climbing.problem.application.dto.ProblemsResponseDto;
import com.first.flash.climbing.problem.domain.dto.ProblemCreateRequestDto;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -20,6 +22,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -36,6 +39,7 @@ public class ProblemController {

private final ProblemsSaveService problemsSaveService;
private final ProblemReadService problemReadService;
private final ProblemsService problemsService;

@Operation(summary = "문제 생성", description = "특정 섹터에 문제 생성")
@ApiResponses(value = {
Expand Down Expand Up @@ -78,10 +82,11 @@ public ResponseEntity<ProblemsResponseDto> findAllProblems(
@RequestParam(defaultValue = DEFAULT_SIZE, required = false) final int size,
@RequestParam(required = false) final List<String> difficulty,
@RequestParam(required = false) final List<String> sector,
@RequestParam(name = "has-solution", required = false) final Boolean hasSolution) {
@RequestParam(name = "has-solution", required = false) final Boolean hasSolution,
@RequestParam(name = "is-honey", required = false) final Boolean isHoney) {
return ResponseEntity.ok(
problemReadService.findAll(gymId, cursor, sortBy, size, difficulty, sector,
hasSolution));
hasSolution, isHoney));
}

@Operation(summary = "문제 단건 조회", description = "특정 문제의 정보 조회")
Expand All @@ -98,4 +103,24 @@ public ResponseEntity<ProblemDetailResponseDto> findProblemById(
@PathVariable final UUID problemId) {
return ResponseEntity.ok(problemReadService.viewProblems(problemId));
}

@Operation(summary = "문제 체감 난이도 수정", description = "특정 문제의 체감 난이도 수정")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "성공적으로 문제 정보 수정함",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ProblemDetailResponseDto.class))),
@ApiResponse(responseCode = "400", description = "유효하지 않은 요청 형식",
content = @Content(mediaType = "application/json", examples = {
@ExampleObject(name = "요청값 누락", value = "{\"perceivedDifficulty\": \"변경할 체감 난이도 수치는 필수입니다.\"}")
})),
@ApiResponse(responseCode = "404", description = "리소스를 찾을 수 없음",
content = @Content(mediaType = "application/json", examples = {
@ExampleObject(name = "문제 없음", value = "{\"error\": \"아이디가 0190c558-9063-7050-b4fc-eb421e3236b3인 문제를 찾을 수 없습니다.\"}")
}))
})
@PatchMapping("/admin/problems/{problemId}/perceivedDifficulty")
public ResponseEntity<ProblemDetailResponseDto> changePerceivedDifficulty(
@PathVariable final UUID problemId,
@Valid @RequestBody final ProblemPerceivedDifficultyRequestDto requestDto) {
return ResponseEntity.ok(problemsService.setPerceivedDifficulty(problemId, requestDto.perceivedDifficulty()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.first.flash.account.member.domain.Member;
import com.first.flash.climbing.solution.application.dto.SolutionWriteResponseDto;
import com.first.flash.climbing.solution.application.dto.UnregisteredMemberSolutionCreateRequest;
import com.first.flash.climbing.solution.domain.PerceivedDifficulty;
import com.first.flash.climbing.solution.domain.PerceivedDifficultySetEvent;
import com.first.flash.climbing.solution.domain.Solution;
import com.first.flash.climbing.solution.domain.SolutionRepository;
import com.first.flash.climbing.solution.domain.SolutionSavedEvent;
Expand All @@ -29,9 +31,12 @@ public SolutionWriteResponseDto saveSolution(final UUID problemId,
UUID id = AuthUtil.getId();
Member member = memberService.findById(id);

PerceivedDifficulty perceivedDifficulty = createRequestDto.perceivedDifficulty();
Solution solution = Solution.of(member.getNickName(), createRequestDto.review(),
member.getInstagramId(), createRequestDto.videoUrl(), problemId, member.getId(),
member.getProfileImageUrl());
member.getProfileImageUrl(), perceivedDifficulty);
Events.raise(PerceivedDifficultySetEvent.of(solution.getProblemId(), perceivedDifficulty.getValue()));

Solution savedSolution = solutionRepository.save(solution);
Events.raise(SolutionSavedEvent.of(savedSolution.getProblemId()));
return SolutionWriteResponseDto.toDto(savedSolution);
Expand All @@ -49,10 +54,13 @@ public SolutionWriteResponseDto saveUnregisteredMemberSolution(final UUID proble
UUID id = AuthUtil.getId();
Member member = memberService.findById(id);

PerceivedDifficulty perceivedDifficulty = requestDto.perceivedDifficulty();
Solution solution = Solution.of(requestDto.nickName(), requestDto.review(),
requestDto.instagramId(), requestDto.videoUrl(), problemId, member.getId(),
requestDto.profileImageUrl());
requestDto.profileImageUrl(), perceivedDifficulty);

Solution savedSolution = solutionRepository.save(solution);
Events.raise(PerceivedDifficultySetEvent.of(solution.getProblemId(), perceivedDifficulty.getValue()));
Events.raise(SolutionSavedEvent.of(savedSolution.getProblemId()));
return SolutionWriteResponseDto.toDto(savedSolution);
}
Expand Down
Loading

0 comments on commit a6b492f

Please sign in to comment.