Skip to content

Commit

Permalink
feat: 미션 내역 상세 조회 구현 (#115)
Browse files Browse the repository at this point in the history
* feat: 미션 내역 상세 조회

* fix: duration toMinutes로 변경

* fix: description 수정

* fix: MISSION_RECORD_USER_MISMATCH statusCode 400 -> 403
  • Loading branch information
char-yb authored Jan 10, 2024
1 parent 81f8147 commit bc58d55
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.depromeet.domain.missionRecord.api;

import com.depromeet.domain.missionRecord.dto.request.MissionRecordCreateRequest;
import com.depromeet.domain.missionRecord.dto.response.MissionRecordFindOneResponse;
import com.depromeet.domain.missionRecord.dto.response.MissionRecordFindResponse;
import com.depromeet.domain.missionRecord.service.MissionRecordService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -12,6 +13,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
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;
Expand All @@ -33,6 +35,12 @@ public ResponseEntity<Long> missionRecordCreate(
return ResponseEntity.status(HttpStatus.CREATED).body(missionRecordId);
}

@Operation(summary = "미션 기록 조회", description = "미션 기록을 조회합니다.")
@GetMapping("/{recordId}")
public MissionRecordFindOneResponse missionRecordFindOne(@PathVariable Long recordId) {
return missionRecordService.findOneMissionRecord(recordId);
}

@Operation(summary = "미션 기록 조회 (캘린더 뷰)", description = "미션 기록을 조회합니다.")
@GetMapping
public List<MissionRecordFindResponse> missionRecordFind(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public record MissionRecordCreateRequest(
timezone = "Asia/Seoul")
@Schema(
description = "미션 기록 시작 시간",
defaultValue = "2024-01-03 00:00:00",
defaultValue = "2023-01-03 00:00:00",
type = "string")
LocalDateTime startedAt,
@NotNull(message = "미션 기록 종료 시간은 비워둘 수 없습니다.")
Expand All @@ -28,7 +28,7 @@ public record MissionRecordCreateRequest(
timezone = "Asia/Seoul")
@Schema(
description = "미션 기록 종료 시간",
defaultValue = "2023-01-03 00:34:00",
defaultValue = "2024-01-03 00:34:00",
type = "string")
LocalDateTime finishedAt,
@NotNull(message = "미션 참여 시간(분)은 비워둘 수 없습니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.depromeet.domain.missionRecord.dto.response;

import com.depromeet.domain.missionRecord.domain.MissionRecord;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.Duration;
import java.time.LocalDateTime;

public record MissionRecordFindOneResponse(
@Schema(description = "미션 기록 ID", defaultValue = "1") Long recordId,
@Schema(description = "미션 기록 일지", defaultValue = "default MissionRecord Remark")
String remark,
@Schema(
description = "미션 기록 인증 사진 Url",
defaultValue = "https://ik.imagekit.io/demo/medium_cafe_B1iTdD0C.jpg")
String imageUrl,
@Schema(description = "미션 수행한 시간", defaultValue = "21") long duration,
@Schema(description = "미션 시작한 지 N일차", defaultValue = "3") long sinceDay,
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "Asia/Seoul")
@Schema(
description = "미션 기록 시작 시간",
defaultValue = "2023-01-03 00:00:00",
type = "string")
LocalDateTime startedAt,
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "Asia/Seoul")
@Schema(
description = "미션 기록 종료 시간",
defaultValue = "2024-01-03 00:34:00",
type = "string")
LocalDateTime finishedAt) {
public static MissionRecordFindOneResponse from(MissionRecord missionRecord) {
return new MissionRecordFindOneResponse(
missionRecord.getId(),
missionRecord.getRemark(),
missionRecord.getImageUrl(),
missionRecord.getDuration().toMinutes(),
Duration.between(missionRecord.getStartedAt(), LocalDateTime.now()).toDays(),
missionRecord.getStartedAt(),
missionRecord.getFinishedAt());
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
package com.depromeet.domain.missionRecord.dto.response;

import com.depromeet.domain.missionRecord.domain.MissionRecord;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;

public record MissionRecordFindResponse(
Long recordId,
String remark,
String imageUrl,
int missionDay,
LocalDateTime startedAt,
LocalDateTime finishedAt) {
@Schema(description = "미션 기록 ID", defaultValue = "1") Long recordId,
@Schema(description = "미션 기록 일지", defaultValue = "default MissionRecord Remark")
String remark,
@Schema(
description = "미션 기록 인증 사진 Url",
defaultValue = "https://ik.imagekit.io/demo/medium_cafe_B1iTdD0C.jpg")
String imageUrl,
@Schema(description = "미션 시작 일자", defaultValue = "3") int missionDay,
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "Asia/Seoul")
@Schema(
description = "미션 기록 시작 시간",
defaultValue = "2023-01-03 00:00:00",
type = "string")
LocalDateTime startedAt,
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "Asia/Seoul")
@Schema(
description = "미션 기록 종료 시간",
defaultValue = "2024-01-03 00:34:00",
type = "string")
LocalDateTime finishedAt) {
public static MissionRecordFindResponse from(MissionRecord missionRecord) {
return new MissionRecordFindResponse(
missionRecord.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.depromeet.domain.missionRecord.dao.MissionRecordRepository;
import com.depromeet.domain.missionRecord.domain.MissionRecord;
import com.depromeet.domain.missionRecord.dto.request.MissionRecordCreateRequest;
import com.depromeet.domain.missionRecord.dto.response.MissionRecordFindOneResponse;
import com.depromeet.domain.missionRecord.dto.response.MissionRecordFindResponse;
import com.depromeet.global.error.exception.CustomException;
import com.depromeet.global.error.exception.ErrorCode;
Expand Down Expand Up @@ -41,6 +42,16 @@ public Long createMissionRecord(MissionRecordCreateRequest request) {
return missionRecordRepository.save(missionRecord).getId();
}

@Transactional(readOnly = true)
public MissionRecordFindOneResponse findOneMissionRecord(Long recordId) {
MissionRecord missionRecord =
missionRecordRepository
.findById(recordId)
.orElseThrow(() -> new CustomException(ErrorCode.MISSION_RECORD_NOT_FOUND));
return MissionRecordFindOneResponse.from(missionRecord);
}

@Transactional(readOnly = true)
public List<MissionRecordFindResponse> findAllMissionRecord(
Long missionId, YearMonth yearMonth) {
List<MissionRecord> missionRecords =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public enum ErrorCode {
MISSION_VISIBILITY_NULL(HttpStatus.BAD_REQUEST, "미션 공개 여부가 null입니다."),

// MissionRecord
MISSION_RECORD_USER_MISMATCH(HttpStatus.BAD_REQUEST, "미션을 생성한 유저와 로그인된 계정이 일치하지 않습니다"),
MISSION_RECORD_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 미션 기록을 찾을 수 없습니다."),
MISSION_RECORD_USER_MISMATCH(HttpStatus.FORBIDDEN, "미션을 생성한 유저와 로그인된 계정이 일치하지 않습니다"),
MISSION_RECORD_DURATION_OVERBALANCE(HttpStatus.BAD_REQUEST, "미션 참여 시간이 지정 된 시간보다 초과하였습니다"),
;

Expand Down

0 comments on commit bc58d55

Please sign in to comment.