Skip to content

Commit

Permalink
refactor: modify response
Browse files Browse the repository at this point in the history
- add voteIncompletionCount field
  • Loading branch information
aiaiaiai1 committed Nov 29, 2024
1 parent a92e033 commit 17c6917
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ public ResponseEntity<List<FavoriteMissionResponse>> seeFavoriteMissions(
}

@GetMapping("/workspaces/{workspaceId}/workout-confirmations")
public ResponseEntity<List<WorkoutConfirmationOrObjectionResponse>> seeWorkoutConfirmations(
public ResponseEntity<WorkoutConfirmationResponse> seeWorkoutConfirmations(
@Logined User user,
@PathVariable Long workspaceId,
@RequestParam int pageNumber
) {
List<WorkoutConfirmationOrObjectionResponse> responses = workspaceQueryService.getWorkoutConfirmations(user, workspaceId, pageNumber);
return ResponseEntity.ok().body(responses);
WorkoutConfirmationResponse response = workspaceQueryService.getWorkoutConfirmations(user, workspaceId, pageNumber);
return ResponseEntity.ok().body(response);
}

@GetMapping("/workspaces/{workspaceId}/workout-confirmations/{workoutConfirmationId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package gymmi.workspace.response;

import gymmi.workspace.domain.entity.WorkoutHistory;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.List;

@Getter
public class WorkoutConfirmationResponse {

private final List<WorkoutConfirmationOrObjectionResponse> data;
private final Integer voteIncompletionCount;

public WorkoutConfirmationResponse(List<WorkoutConfirmationOrObjectionResponse> data, Integer voteIncompletionCount) {
this.data = data;
this.voteIncompletionCount = voteIncompletionCount;
}
}
11 changes: 8 additions & 3 deletions src/main/java/gymmi/workspace/service/WorkspaceQueryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ public List<FavoriteMissionResponse> getFavoriteMissions(User loginedUser, Long
.toList();
}

public List<WorkoutConfirmationOrObjectionResponse> getWorkoutConfirmations(User loginedUser, Long workspaceId, int page) {
public WorkoutConfirmationResponse getWorkoutConfirmations(User loginedUser, Long workspaceId, int page) {
Workspace workspace = workspaceRepository.getWorkspaceById(workspaceId);
validateIfWorkerIsInWorkspace(loginedUser.getId(), workspace.getId());
Worker worker = validateIfWorkerIsInWorkspace(loginedUser.getId(), workspace.getId());
List<WorkoutConfirmationOrObjectionProjection> dtos = workoutHistoryRepository.getWorkoutConfirmationAndObjectionDto(workspace.getId(), page);

int voteIncompletionCount = 0;
List<WorkoutConfirmationOrObjectionResponse> responses = new ArrayList<>();
for (WorkoutConfirmationOrObjectionProjection dto : dtos) {
if (dto.getType().equals("workoutHistory")) {
Expand All @@ -184,9 +185,13 @@ public List<WorkoutConfirmationOrObjectionResponse> getWorkoutConfirmations(User
Objection objection = objectionRepository.getByObjectionId(dto.getId());
WorkoutHistory workoutHistory = workoutHistoryRepository.getByWorkoutConfirmationId(objection.getWorkoutConfirmation().getId());
responses.add(WorkoutConfirmationOrObjectionResponse.objection(loginedUser, objection, workoutHistory.getWorker().getUser()));
if (objection.isInProgress() && !objection.hasVoteBy(worker)) {
voteIncompletionCount++;
}
}
}
return responses;

return new WorkoutConfirmationResponse(responses, voteIncompletionCount);
}

public WorkoutConfirmationDetailResponse getWorkoutConfirmation(User loginedUser, Long workspaceId, Long workoutConfirmationId) {
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/gymmi/helper/Persister.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,10 @@ public PhotoFeed persistPhotoFeed(User user, int thumpsUpCount) {
return photoFeed;
}

public PhotoFeed persistPhotoFeed(User user, LocalDateTime createdAt, LocalDateTime lastModifiedAt) {
public PhotoFeed persistPhotoFeed(User user, boolean isModified) {
PhotoFeed photoFeed = Instancio.of(PhotoFeed.class)
.set(field(PhotoFeed::getUser), user)
.set(field(PhotoFeed::getLastModifiedAt), lastModifiedAt)
.set(field(PhotoFeed::getCreatedAt), createdAt)
.set(field(PhotoFeed::getIsModified), isModified)
.ignore(field(PhotoFeed::getId))
.create();
entityManager.persist(photoFeed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -60,14 +59,14 @@ class PhotoFeedServiceTest extends IntegrationTest {
void 사진_피드를_확인_한다() {
// given
User user = persister.persistUser();
PhotoFeed photoFeed = persister.persistPhotoFeed(user, LocalDateTime.now(), LocalDateTime.now().plusDays(1));
PhotoFeed photoFeed = persister.persistPhotoFeed(user, true);
PhotoFeedImage photoFeedImage = persister.persistPhotoFeedImage(photoFeed);

// when
PhotoFeedDetailResponse result = photoFeedService.getPhotoFeed(user, photoFeed.getId());

// then
assertThat(result.getIsModified()).isFalse();
assertThat(result.getIsModified()).isTrue();
assertThat(result.getThumpsUpCount()).isEqualTo(photoFeed.getThumpsUpCount());
assertThat(result.getCreatedAt()).isEqualTo(photoFeed.getCreatedAt());
assertThat(result.getProfileImageUrl()).isEqualTo(user.getProfileImageName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ class WorkspaceQueryServiceTest extends IntegrationTest {
WorkoutHistory workoutHistory = persister.persistWorkoutHistoryAndApply(creatorWorker, Map.of(mission, 2, mission1, 2), workoutConfirmation);
Objection objection = persister.persistObjection(userWorker, true, workoutConfirmation);
WorkoutHistory workoutHistory1 = persister.persistWorkoutHistoryAndApply(userWorker, Map.of(mission, 2, mission1, 2), workoutConfirmation1);

persister.persistVote(userWorker, objection, false);

// when
List<WorkoutConfirmationOrObjectionResponse> responses = workspaceQueryService.getWorkoutConfirmations(user, workspace.getId(), 0);
WorkoutConfirmationResponse workoutConfirmationResponse = workspaceQueryService.getWorkoutConfirmations(user, workspace.getId(), 0);

// then
List<WorkoutConfirmationOrObjectionResponse> responses = workoutConfirmationResponse.getData();
assertThat(responses).hasSize(3);
assertThat(workoutConfirmationResponse.getVoteIncompletionCount()).isEqualTo(0);

WorkoutConfirmationOrObjectionResponse response = responses.get(0);
assertThat(response.getIsMine()).isEqualTo(true);
Expand Down Expand Up @@ -233,7 +235,7 @@ class 이의_신청_목록 {
List<ObjectionAlarmResponse> responses = workspaceQueryService.getObjections(creator, workspace.getId(), 0, ObjectionStatus.INCOMPLETION);

// then
assertThat(responses).hasSize (7);
assertThat(responses).hasSize(7);
assertThat(responses.get(6).getObjectionId()).isEqualTo(objections.get(2).getId());
assertThat(responses.get(6).getVoteCompletion()).isEqualTo(false);
assertThat(responses.get(6).getTargetWorkerNickname()).isEqualTo(creator.getNickname());
Expand Down

0 comments on commit 17c6917

Please sign in to comment.