Skip to content

Commit

Permalink
sprint/2-4 (#17)
Browse files Browse the repository at this point in the history
* refactor: modify response field

* fix: change to nullable

* fix: add param

* fix: nullable column (ddl.sql)

* refactor: add field to response

* fix: add length limit

* fix: add isModified column

* fix: set field to photo feed persister
  • Loading branch information
aiaiaiai1 authored Dec 2, 2024
1 parent af7a920 commit 52433c0
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 33 deletions.
8 changes: 6 additions & 2 deletions src/main/java/gymmi/photoboard/domain/entity/PhotoFeed.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ public class PhotoFeed extends TimeEntity {
@JoinColumn(name = "user_id", nullable = false)
private User user;

@Column(nullable = false)
@Column
private String comment;

@Column(nullable = false)
private Boolean isModified;

@Column(nullable = false)
private Integer thumpsUpCount;

public PhotoFeed(User user, String comment) {
this.user = user;
this.comment = comment;
this.isModified = false;
this.thumpsUpCount = 0;
}

public boolean isModified() {
return !getCreatedAt().isEqual(getLastModifiedAt());
return isModified;
}

public void increase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class CreatePhotoFeedRequest {
@NotBlank
private String filename;

@NotBlank
private String comment;

public CreatePhotoFeedRequest(String filename, String comment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class WorkoutConfirmation {
@Column(nullable = false)
private String filename;

@Column(nullable = false)
@Column
private String comment;

public WorkoutConfirmation(String filename, String comment) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gymmi/workspace/request/ObjectionRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

@Getter
@NoArgsConstructor
public class ObjectionRequest {

@NotBlank
@Length(min = 10, max = 150)
private String reason;

public ObjectionRequest(String reason) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/gymmi/workspace/request/WorkoutRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class WorkoutRequest {
@NotNull
private String imageUrl;

@NotNull
private String comment;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
public class ObjectionAlarmResponse {

private Long objectionId;
private Long workoutConfirmationId;
private String targetWorkerNickname;
private Boolean voteCompletion;
private LocalDateTime createdAt;

public ObjectionAlarmResponse(Objection objection, String targetWorkerNickname, Boolean voteCompletion) {
this.objectionId = objection.getId();
this.workoutConfirmationId = objection.getWorkoutConfirmation().getId();
this.targetWorkerNickname = targetWorkerNickname;
this.voteCompletion = voteCompletion;
this.createdAt = objection.getCreatedAt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public WorkoutConfirmationOrObjectionResponse(
this.isObjection = isObjection;
}

public static WorkoutConfirmationOrObjectionResponse workoutConfirmation(User loginedUser, WorkoutHistory workoutHistory, String workoutConfirmationImageUrl) {
public static WorkoutConfirmationOrObjectionResponse workoutConfirmation(User loginedUser, Objection objection, WorkoutHistory workoutHistory, String workoutConfirmationImageUrl) {
User user = workoutHistory.getWorker().getUser();
LocalDateTime createdAt = workoutHistory.getCreatedAt();
return WorkoutConfirmationOrObjectionResponse.builder()
.workoutConfirmationId(workoutHistory.getWorkoutConfirmation().getId())
.objectionId(null)
.objectionId(getObjectId(objection))
.nickname(user.getNickname())
.profileImageUrl(user.getProfileImageName())
.workoutConfirmationImageUrl(workoutConfirmationImageUrl)
Expand All @@ -53,6 +53,13 @@ public static WorkoutConfirmationOrObjectionResponse workoutConfirmation(User lo
.build();
}

private static Long getObjectId(Objection objection) {
if (objection == null) {
return null;
}
return objection.getId();
}

public static WorkoutConfirmationOrObjectionResponse objection(User loginedUser, Objection objection, User objectionTargetUser) {
LocalDateTime createdAt = objection.getCreatedAt();
return WorkoutConfirmationOrObjectionResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ public List<WorkoutConfirmationOrObjectionResponse> getWorkoutConfirmations(User
WorkoutHistory workoutHistory = workoutHistoryRepository.getByWorkoutHistoryId(dto.getId());
WorkoutConfirmation workoutConfirmation = workoutHistory.getWorkoutConfirmation();
String imagePresignedUrl = s3Service.getPresignedUrl(ImageUse.WORKOUT_CONFIRMATION, workoutConfirmation.getFilename());
responses.add(WorkoutConfirmationOrObjectionResponse.workoutConfirmation(loginedUser, workoutHistory, imagePresignedUrl));
Objection objection = objectionRepository.findByWorkoutConfirmationId(workoutConfirmation.getId()).orElseGet(() -> null);
responses.add(WorkoutConfirmationOrObjectionResponse.workoutConfirmation(loginedUser, objection, workoutHistory, imagePresignedUrl));
}
if (dto.getType().equals("objection")) {
Objection objection = objectionRepository.getByObjectionId(dto.getId());
Expand All @@ -188,8 +189,7 @@ public List<WorkoutConfirmationOrObjectionResponse> getWorkoutConfirmations(User
return responses;
}

public WorkoutConfirmationDetailResponse getWorkoutConfirmation(User loginedUser, Long workspaceId, Long
workoutConfirmationId) {
public WorkoutConfirmationDetailResponse getWorkoutConfirmation(User loginedUser, Long workspaceId, Long workoutConfirmationId) {
Workspace workspace = workspaceRepository.getWorkspaceById(workspaceId);
validateIfWorkerIsInWorkspace(loginedUser.getId(), workspace.getId());
WorkoutHistory workoutHistory = workoutHistoryRepository.getByWorkoutConfirmationId(workoutConfirmationId);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/migration/V241128.2__add_column.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table photo_feed add column is_modified boolean not null;
2 changes: 2 additions & 0 deletions src/main/resources/db/migration/V241128__nullable.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table workout_confirmation change column comment comment varchar(255);
alter table photo_feed change column comment comment varchar(1000);
6 changes: 2 additions & 4 deletions src/test/java/gymmi/helper/Persister.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -213,11 +212,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::isModified), isModified)
.ignore(field(PhotoFeed::getId))
.create();
entityManager.persist(photoFeed);
Expand Down
17 changes: 0 additions & 17 deletions src/test/java/gymmi/photoboard/domain/entity/PhotoFeedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@

class PhotoFeedTest {

@ParameterizedTest
@CsvSource(value = {"1,true", "0,false"})
void 수정여부를_확인_한다(int plusDay, boolean isModified) {
// given
LocalDateTime now = LocalDateTime.now();
PhotoFeed photoFeed = Instancio.of(PhotoFeed.class)
.set(Select.field(PhotoFeed::getCreatedAt), now)
.set(Select.field(PhotoFeed::getLastModifiedAt), now.plusDays(plusDay))
.create();

// when
boolean result = photoFeed.isModified();

// then
assertThat(result).isEqualTo(isModified);
}

@Test
void 작성자가_아닌_경우_예외가_발생한다() {
// given
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,7 +59,7 @@ 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, false);
PhotoFeedImage photoFeedImage = persister.persistPhotoFeedImage(photoFeed);

// when
Expand Down

0 comments on commit 52433c0

Please sign in to comment.