Skip to content

Commit

Permalink
Merge pull request #94 from SWM-Flash/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
wonyangs authored Oct 19, 2024
2 parents 30bbd60 + 9fa0e07 commit 467f952
Show file tree
Hide file tree
Showing 63 changed files with 1,014 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public MemberReportResponse reportMember(final Long reportedContentId,
UUID reporterId = AuthUtil.getId();
Member reporter = memberService.findById(reporterId);
MemberReport memberReport = MemberReport.reportContent(request.reason(), reporter,
reportedContentId);
reportRepository.save(memberReport);
return MemberReportResponse.toDto(reportedContentId, request.reason());
reportedContentId, request.contentType());
MemberReport savedReport = reportRepository.save(memberReport);
return MemberReportResponse.toDto(savedReport.getReportedContentId(),
savedReport.getContentType(), savedReport.getReason());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.first.flash.account.member.application.dto;

import com.first.flash.account.member.domain.ContentType;
import com.first.flash.global.annotation.ValidEnum;
import jakarta.validation.constraints.NotEmpty;

public record MemberReportRequest(@NotEmpty(message = "신고 사유는 필수입니다.") String reason) {
public record MemberReportRequest(@NotEmpty(message = "신고 사유는 필수입니다.") String reason,
@ValidEnum(enumClass = ContentType.class) ContentType contentType) {

public MemberReportRequest(final String reason, final ContentType contentType) {
this.reason = reason;
this.contentType = contentType != null ? contentType : ContentType.SOLUTION;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.first.flash.account.member.application.dto;

public record MemberReportResponse(Long reportedContentId, String reason) {
import com.first.flash.account.member.domain.ContentType;

public static MemberReportResponse toDto(final Long reportedContentId, final String reason) {
return new MemberReportResponse(reportedContentId, reason);
public record MemberReportResponse(Long reportedContentId, String contentType, String reason) {

public static MemberReportResponse toDto(final Long reportedContentId,
final ContentType contentType, final String reason) {
return new MemberReportResponse(reportedContentId, contentType.name(), reason);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.first.flash.account.member.domain;

import lombok.ToString;

@ToString
public enum ContentType {
SOLUTION, COMMENT;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.first.flash.global.domain.BaseEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -27,15 +29,19 @@ public class MemberReport extends BaseEntity {
@JoinColumn(name = "reporterId")
private Member reporter;
private Long reportedContentId;
@Enumerated(EnumType.STRING)
private ContentType contentType;

private MemberReport(final String reason, final Member reporter, final Long reportedContentId) {
private MemberReport(final String reason, final Member reporter, final Long reportedContentId,
final ContentType contentType) {
this.reason = reason;
this.reporter = reporter;
this.reportedContentId = reportedContentId;
this.contentType = contentType;
}

public static MemberReport reportContent(final String reason, final Member reporter,
final Long reportedContentId) {
return new MemberReport(reason, reporter, reportedContentId);
final Long reportedContentId, final ContentType contentType) {
return new MemberReport(reason, reporter, reportedContentId, contentType);
}
}
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()));
}
}
Loading

0 comments on commit 467f952

Please sign in to comment.