Skip to content

Commit

Permalink
[Refactor] move feedback package (#109)
Browse files Browse the repository at this point in the history
* refactor(Feedback): Feedback 페키지를 User 하부로 이동

* refactor(Content): Feedback의 본문 내용인 Content 를 값객체로 리팩토링

* test(Feedback): 피드백 도메인 테스트 작성

* test(FeedbackTest): 피드백 동등성 테스트 작성

* test(FeedbackTest): 접근제어자 제거

* test(FeedbackTest):clear_all_feedback 에서 사이즈를 확인하는 단언문을 hasSize를 사용하도록 변경
  • Loading branch information
zbqmgldjfh authored Jan 9, 2024
1 parent ead1bf8 commit fd554a0
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 285 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kustacks.kuring.admin.common.dto;

import com.kustacks.kuring.feedback.domain.Feedback;
import com.kustacks.kuring.user.domain.Feedback;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.kustacks.kuring.feedback.business;
package com.kustacks.kuring.user.business;

import com.kustacks.kuring.admin.common.dto.FeedbackDto;
import com.kustacks.kuring.common.exception.code.ErrorCode;
import com.kustacks.kuring.common.exception.NotFoundException;
import com.kustacks.kuring.feedback.domain.FeedbackRepository;
import com.kustacks.kuring.user.domain.FeedbackRepository;
import com.kustacks.kuring.message.firebase.FirebaseService;
import com.kustacks.kuring.message.firebase.ServerProperties;
import com.kustacks.kuring.user.domain.User;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kustacks.kuring.feedback.common.dto;
package com.kustacks.kuring.user.common.dto;

import com.kustacks.kuring.common.dto.ResponseDto;
import lombok.Getter;
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/kustacks/kuring/user/domain/Content.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.kustacks.kuring.user.domain;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Embeddable;

@Embeddable
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Content {

private static final int MAX_LENGTH = 256;

@Column(name = "content", length = 256, nullable = false)
private String value;

public Content(String content) {
validate(content);
this.value = content;
}

public String getValue() {
return value;
}

private void validate(String content) {
if (content.length() > MAX_LENGTH) throw new IllegalArgumentException("본문 내용은 " + MAX_LENGTH + "자 이하여야 합니다");
if (content.isBlank()) throw new IllegalArgumentException("본문은 공백일 수 없습니다");
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package com.kustacks.kuring.feedback.domain;
package com.kustacks.kuring.user.domain;

import com.kustacks.kuring.common.domain.BaseTimeEntity;
import com.kustacks.kuring.user.domain.User;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.*;
import java.util.Objects;

@Entity
Expand All @@ -26,20 +18,20 @@ public class Feedback extends BaseTimeEntity {
@Column(name = "id", unique = true, nullable = false)
private Long id;

@Column(name = "content", length = 256, nullable = false)
private String content;
@Embedded
private Content content;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

public Feedback(String content, User user) {
this.content = content;
this.content = new Content(content);
this.user = user;
}

public String getContent() {
return content;
return content.getValue();
}

public Long getUserId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kustacks.kuring.feedback.domain;
package com.kustacks.kuring.user.domain;

import org.springframework.data.jpa.repository.JpaRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kustacks.kuring.user.domain;

import com.kustacks.kuring.feedback.domain.Feedback;
import lombok.NoArgsConstructor;

import javax.persistence.CascadeType;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/kustacks/kuring/user/domain/User.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.kustacks.kuring.user.domain;

import com.kustacks.kuring.notice.domain.CategoryName;
import com.kustacks.kuring.feedback.domain.Feedback;
import com.kustacks.kuring.notice.domain.DepartmentName;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kustacks.kuring.user.facade;

import com.kustacks.kuring.feedback.business.FeedbackService;
import com.kustacks.kuring.user.business.FeedbackService;
import com.kustacks.kuring.message.firebase.FirebaseService;
import com.kustacks.kuring.message.firebase.exception.FirebaseSubscribeException;
import com.kustacks.kuring.message.firebase.exception.FirebaseUnSubscribeException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.kustacks.kuring.user.facade;

import com.kustacks.kuring.admin.common.dto.FeedbackDto;
import com.kustacks.kuring.feedback.business.FeedbackService;
import com.kustacks.kuring.user.business.FeedbackService;
import com.kustacks.kuring.notice.domain.CategoryName;
import com.kustacks.kuring.message.firebase.FirebaseService;
import com.kustacks.kuring.notice.common.dto.CategoryNameDto;
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/com/kustacks/kuring/acceptance/FeedbackStep.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.kustacks.kuring.acceptance;

import com.kustacks.kuring.feedback.common.dto.SaveFeedbackV1Request;
import com.kustacks.kuring.user.common.dto.SaveFeedbackRequest;
import io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -13,18 +14,19 @@ public class FeedbackStep {

public static void 피드백_요청_응답_확인(ExtractableResponse<Response> response) {
assertAll(
() -> assertThat(response.jsonPath().getBoolean("isSuccess")).isTrue(),
() -> assertThat(response.jsonPath().getString("resultMsg")).isEqualTo("성공"),
() -> assertThat(response.jsonPath().getInt("resultCode")).isEqualTo(201)
() -> assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()),
() -> assertThat(response.jsonPath().getInt("code")).isEqualTo(200),
() -> assertThat(response.jsonPath().getString("message")).isEqualTo("피드백 저장에 성공하였습니다")
);
}

public static ExtractableResponse<Response> 피드백_요청(String fcmToken, String feedback) {
return RestAssured
.given().log().all()
.header("User-Token", fcmToken)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body(new SaveFeedbackV1Request(fcmToken, feedback))
.when().post("/api/v1/feedback")
.body(new SaveFeedbackRequest(feedback))
.when().post("/api/v2/users/feedbacks")
.then().log().all()
.extract();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

@DisplayName("도메인 : Admin")
class AdminTest {

@DisplayName("Admin 생성 테스트")
Expand Down
Loading

0 comments on commit fd554a0

Please sign in to comment.