Skip to content

Commit

Permalink
refactor: 미션 기록 생성 응답 값 response 객체로 Wrapping (#132)
Browse files Browse the repository at this point in the history
* refactor: MissionRecordCreateResponse 생성

* refactor: 미션 기록 생성 응답 값 response 객체로 Wrapping

* test: MissionRecordCreateResponse로 응답되도록 테스트 수정
  • Loading branch information
kdomo authored Jan 11, 2024
1 parent 5d9c931 commit 4b81ad0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 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.MissionRecordCreateResponse;
import com.depromeet.domain.missionRecord.dto.response.MissionRecordFindOneResponse;
import com.depromeet.domain.missionRecord.dto.response.MissionRecordFindResponse;
import com.depromeet.domain.missionRecord.service.MissionRecordService;
Expand Down Expand Up @@ -29,10 +30,10 @@ public class MissionRecordController {

@Operation(summary = "미션 기록 생성", description = "미션 기록을 생성하고 생성 된 id를 반환합니다.")
@PostMapping
public ResponseEntity<Long> missionRecordCreate(
public ResponseEntity<MissionRecordCreateResponse> missionRecordCreate(
@Valid @RequestBody MissionRecordCreateRequest request) {
Long missionRecordId = missionRecordService.createMissionRecord(request);
return ResponseEntity.status(HttpStatus.CREATED).body(missionRecordId);
MissionRecordCreateResponse response = missionRecordService.createMissionRecord(request);
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}

@Operation(summary = "미션 기록 조회", description = "미션 기록을 조회합니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.depromeet.domain.missionRecord.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

public record MissionRecordCreateResponse(
@Schema(description = "미션 기록 ID", defaultValue = "1") Long missionId) {

public static MissionRecordCreateResponse from(Long missionId) {
return new MissionRecordCreateResponse(missionId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.depromeet.domain.missionRecord.domain.MissionRecord;
import com.depromeet.domain.missionRecord.domain.MissionRecordTTL;
import com.depromeet.domain.missionRecord.dto.request.MissionRecordCreateRequest;
import com.depromeet.domain.missionRecord.dto.response.MissionRecordCreateResponse;
import com.depromeet.domain.missionRecord.dto.response.MissionRecordFindOneResponse;
import com.depromeet.domain.missionRecord.dto.response.MissionRecordFindResponse;
import com.depromeet.global.common.constants.RedisExpireEventConstants;
Expand All @@ -32,7 +33,7 @@ public class MissionRecordService {
private final MissionRecordRepository missionRecordRepository;
private final MissionRecordTTLRepository missionRecordTTLRepository;

public Long createMissionRecord(MissionRecordCreateRequest request) {
public MissionRecordCreateResponse createMissionRecord(MissionRecordCreateRequest request) {
final Mission mission = findMissionById(request.missionId());
final Member member = memberUtil.getCurrentMember();

Expand All @@ -56,7 +57,7 @@ public Long createMissionRecord(MissionRecordCreateRequest request) {
RedisExpireEventConstants.EXPIRE_EVENT_IMAGE_UPLOAD_TIME_END.getValue()
+ createdMissionRecord.getId(),
expirationTime));
return createdMissionRecord.getId();
return MissionRecordCreateResponse.from(createdMissionRecord.getId());
}

private Mission findMissionById(Long missionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.depromeet.domain.missionRecord.domain.ImageUploadStatus;
import com.depromeet.domain.missionRecord.domain.MissionRecord;
import com.depromeet.domain.missionRecord.dto.request.MissionRecordCreateRequest;
import com.depromeet.domain.missionRecord.dto.response.MissionRecordCreateResponse;
import com.depromeet.domain.missionRecord.service.MissionRecordService;
import com.depromeet.global.error.exception.CustomException;
import com.depromeet.global.error.exception.ErrorCode;
Expand Down Expand Up @@ -147,10 +148,12 @@ class 미션_기록_이미지_PresignedUrl을_생성할_때 {
missionRecordFinishedAt,
32,
14);
Long missionRecord =

MissionRecordCreateResponse missionRecordCreateResponse =
missionRecordService.createMissionRecord(missionRecordCreateRequest);
MissionRecordImageCreateRequest request =
new MissionRecordImageCreateRequest(missionRecord, ImageFileExtension.JPEG);
new MissionRecordImageCreateRequest(
missionRecordCreateResponse.missionId(), ImageFileExtension.JPEG);

// when, then
assertThatCode(() -> imageService.createMissionRecordPresignedUrl(request))
Expand Down Expand Up @@ -182,11 +185,12 @@ class 미션_기록_이미지_PresignedUrl을_생성할_때 {
missionRecordFinishedAt,
32,
14);
Long missionRecordId =
MissionRecordCreateResponse missionRecordCreateResponse =
missionRecordService.createMissionRecord(missionRecordCreateRequest);
ImageFileExtension imageFileExtension = ImageFileExtension.JPEG;
MissionRecordImageCreateRequest request =
new MissionRecordImageCreateRequest(missionRecordId, imageFileExtension);
new MissionRecordImageCreateRequest(
missionRecordCreateResponse.missionId(), imageFileExtension);

// when
PresignedUrlResponse missionRecordPresignedUrl =
Expand All @@ -195,7 +199,9 @@ class 미션_기록_이미지_PresignedUrl을_생성할_때 {
// then
assertThat(missionRecordPresignedUrl.presignedUrl())
.contains(
String.format("/local/mission_record/%s/image.jpeg", missionRecordId));
String.format(
"/local/mission_record/%s/image.jpeg",
missionRecordCreateResponse.missionId()));
}
}

Expand Down Expand Up @@ -256,28 +262,34 @@ class 미션_기록_이미지_업로드_완료_처리할_때 {
missionRecordFinishedAt,
32,
14);
Long missionRecordId =
MissionRecordCreateResponse missionRecordCreateResponse =
missionRecordService.createMissionRecord(missionRecordCreateRequest);

ImageFileExtension imageFileExtension = ImageFileExtension.JPEG;
MissionRecordImageCreateRequest missionRecordImageCreateRequest =
new MissionRecordImageCreateRequest(missionRecordId, imageFileExtension);
new MissionRecordImageCreateRequest(
missionRecordCreateResponse.missionId(), imageFileExtension);
imageService.createMissionRecordPresignedUrl(missionRecordImageCreateRequest);

MissionRecordImageUploadCompleteRequest request =
new MissionRecordImageUploadCompleteRequest(
missionRecordId, imageFileExtension, "testRemark");
missionRecordCreateResponse.missionId(),
imageFileExtension,
"testRemark");

// when
imageService.uploadCompleteMissionRecord(request);
MissionRecord missionRecord = missionRecordRepository.findById(missionRecordId).get();
MissionRecord missionRecord =
missionRecordRepository.findById(missionRecordCreateResponse.missionId()).get();

// then
assertThat(missionRecord.getUploadStatus()).isEqualTo(ImageUploadStatus.COMPLETE);
assertThat(missionRecord.getRemark()).isEqualTo("testRemark");
assertThat(missionRecord.getImageUrl())
.contains(
String.format("/local/mission_record/%s/image.jpeg", missionRecordId));
String.format(
"/local/mission_record/%s/image.jpeg",
missionRecordCreateResponse.missionId()));
}
}
}

0 comments on commit 4b81ad0

Please sign in to comment.