Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 미션 내역 상세 조회 구현 #115

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
Comment on lines +37 to +46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

응답값 잘 넘어오는지 controller 테스트 있으면 좋을 것 같네용👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 그러면 금일 이슈 생성해서 작성하도록 하겠습니다!

}
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