-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] 도메인 별 기본 클래스 구현 완료 #10
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
Changes from all commits
0fa5042
e726586
7be9e31
e4e8de0
321598c
f849e88
47f3ff5
5f9d400
556defb
59b6cf1
95f60cf
49f9701
03945be
c5df0ba
63215be
3a8af36
5f05e6b
0ce6768
28847ec
c61723c
6d7d78e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.wayble.server.common.entity; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Embeddable; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @Embeddable | ||
| public class Address { | ||
| /** 시·도 */ | ||
| @Column(name = "state", length = 100, nullable = false) | ||
| private String state; | ||
|
|
||
| /** 시·군·구 */ | ||
| @Column(name = "city", length = 100, nullable = false) | ||
| private String city; | ||
|
|
||
| /** 동·읍·면 */ | ||
| @Column(name = "district", length = 100) | ||
| private String district; | ||
|
|
||
| /** 도로명 주소 */ | ||
| @Column(name = "street_address", length = 200) | ||
| private String streetAddress; | ||
|
|
||
| /** 상세 주소 */ | ||
| @Column(name = "detail_address", length = 200) | ||
| private String detailAddress; | ||
|
|
||
| /** 위도 */ | ||
| @Column(name = "latitude", columnDefinition = "DECIMAL(10,7)", nullable = false) | ||
| private Double latitude; | ||
|
|
||
| /** 경도 */ | ||
| @Column(name = "longitude", columnDefinition = "DECIMAL(10,7)", nullable = false) | ||
| private Double longitude; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.wayble.server.common.entity; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.EntityListeners; | ||
| import jakarta.persistence.MappedSuperclass; | ||
| import lombok.Getter; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import org.springframework.data.annotation.CreatedDate; | ||
| import org.springframework.data.annotation.LastModifiedDate; | ||
| import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
|
||
| @MappedSuperclass | ||
| @Getter | ||
| @EntityListeners(AuditingEntityListener.class) | ||
| public class BaseEntity { | ||
|
|
||
| @CreatedDate | ||
| private LocalDateTime createdAt; | ||
|
|
||
| @LastModifiedDate | ||
| private LocalDateTime updatedAt; | ||
|
|
||
| @Column(name = "deleted_at") | ||
| private LocalDateTime deletedAt; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.wayble.server.direction.controller; | ||
|
|
||
| import com.wayble.server.common.response.CommonResponse; | ||
| import com.wayble.server.direction.service.DirectionService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/directions") | ||
| public class DirectionController { | ||
|
|
||
| private final DirectionService directionService; | ||
|
|
||
| // 참고용 컨트롤러(지우셔도 돼요) | ||
| @GetMapping("/hello") | ||
| public CommonResponse<String> hello() { | ||
| return CommonResponse.success("hello"); | ||
| } | ||
|
|
||
| // 예외 사용 참고용 컨트롤러(지우셔도 돼요) | ||
| @GetMapping("/ex") | ||
| public CommonResponse<String> exception() { | ||
| directionService.makeException(); | ||
| return CommonResponse.success("예외 발생!"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.wayble.server.direction.exception; | ||
|
|
||
| import com.wayble.server.common.exception.ErrorCase; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum DirectionErrorCase implements ErrorCase { | ||
|
|
||
| PATH_NOT_FOUND(400, 4001, "해당하는 경로를 찾을 수 없습니다."); | ||
|
|
||
| private final Integer httpStatusCode; | ||
| private final Integer errorCode; | ||
| private final String message; | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.wayble.server.direction.service; | ||
|
|
||
| import com.wayble.server.common.exception.ApplicationException; | ||
| import com.wayble.server.direction.exception.DirectionErrorCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class DirectionService { | ||
|
|
||
| public void makeException() { | ||
| throw new ApplicationException(DirectionErrorCase.PATH_NOT_FOUND); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||
| package com.wayble.server.review.controller; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import com.wayble.server.common.response.CommonResponse; | ||||||||||||||||||||||||||||||
| import com.wayble.server.review.service.ReviewService; | ||||||||||||||||||||||||||||||
| import lombok.RequiredArgsConstructor; | ||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.RestController; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @RestController | ||||||||||||||||||||||||||||||
| @RequiredArgsConstructor | ||||||||||||||||||||||||||||||
| @RequestMapping("/reviews") | ||||||||||||||||||||||||||||||
| public class ReviewController { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| private final ReviewService reviewService; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // 참고용 컨트롤러(지우셔도 돼요) | ||||||||||||||||||||||||||||||
| @GetMapping("/hello") | ||||||||||||||||||||||||||||||
| public CommonResponse<String> hello() { | ||||||||||||||||||||||||||||||
| return CommonResponse.success("hello"); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // 예외 사용 참고용 컨트롤러(지우셔도 돼요) | ||||||||||||||||||||||||||||||
| @GetMapping("/ex") | ||||||||||||||||||||||||||||||
| public CommonResponse<String> exception() { | ||||||||||||||||||||||||||||||
| reviewService.makeException(); | ||||||||||||||||||||||||||||||
| return CommonResponse.success("예외 발생!"); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 예외 처리 로직이 잘못되었습니다.
현재 구현에서는 예외가 실제로 발생하지 않거나, 발생해도 적절히 처리되지 않는 상황을 암시합니다. 다음과 같이 수정하는 것을 고려해보세요: // 예외 사용 참고용 컨트롤러(지우셔도 돼요)
@GetMapping("/ex")
public CommonResponse<String> exception() {
- reviewService.makeException();
- return CommonResponse.success("예외 발생!");
+ // 이 메서드는 예외를 발생시키므로 성공 응답은 반환되지 않습니다
+ reviewService.makeException();
+ // 이 줄은 실행되지 않습니다
+ return CommonResponse.success("이 메시지는 보이지 않습니다");
}또는 예외 처리를 명시적으로 보여주려면: @GetMapping("/ex")
public CommonResponse<String> exception() {
+ try {
+ reviewService.makeException();
+ return CommonResponse.success("예외가 발생하지 않았습니다");
+ } catch (Exception e) {
+ // 실제로는 GlobalExceptionHandler에서 처리됩니다
+ throw e;
+ }
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package com.wayble.server.review.dto; | ||
|
|
||
| public record ReviewRegisterDto() { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package com.wayble.server.review.dto; | ||
|
|
||
| public record ReviewResponseDto() { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.wayble.server.review.entity; | ||
|
|
||
| import com.wayble.server.common.entity.BaseEntity; | ||
| import com.wayble.server.user.entity.User; | ||
| import com.wayble.server.wayblezone.entity.WaybleZone; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
| import org.hibernate.annotations.SQLDelete; | ||
| import org.hibernate.annotations.SQLRestriction; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder(access = AccessLevel.PRIVATE) | ||
| @AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @SQLDelete(sql = "UPDATE review SET deleted_at = now() WHERE id = ?") | ||
| @SQLRestriction("deleted_at IS NULL") | ||
| @Table(name = "review") | ||
| public class Review extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Lob | ||
| @Column(columnDefinition = "TEXT") | ||
| private String content; | ||
|
|
||
| @Column(nullable = false) | ||
| private double rating = 0.0; | ||
|
|
||
| @Column(nullable = false) | ||
| private Integer likeCount = 0; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "user_id", nullable = false) | ||
| private User user; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "wayble_zone_id", nullable = false) | ||
| private WaybleZone waybleZone; | ||
|
|
||
| @OneToMany(mappedBy = "review", cascade = CascadeType.ALL, orphanRemoval = true) | ||
| private List<ReviewImage> reviewImageList = new ArrayList<>(); | ||
|
|
||
| /** | ||
| * TODO: 접근성 정보 관련 구현 필요 | ||
| */ | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.wayble.server.review.entity; | ||
|
|
||
| import com.wayble.server.common.entity.BaseEntity; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
| import org.hibernate.annotations.SQLDelete; | ||
| import org.hibernate.annotations.SQLRestriction; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder(access = AccessLevel.PRIVATE) | ||
| @AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table(name = "review_image") | ||
| @SQLDelete(sql = "UPDATE review_image SET deleted_at = now() WHERE id = ?") | ||
| @SQLRestriction("deleted_at IS NULL") | ||
| public class ReviewImage extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "review_id", nullable = false) | ||
| private Review review; | ||
|
|
||
| @Column(name = "image_url", nullable = false) | ||
| private String imageUrl; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.wayble.server.review.exception; | ||
|
|
||
| import com.wayble.server.common.exception.ErrorCase; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum ReviewErrorCase implements ErrorCase { | ||
|
|
||
| REVIEW_NOT_FOUND(400, 3001, "리뷰를 찾을 수 없습니다."); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain도메인 간 에러 케이스 사용 검증 필요 DirectionService에서 이 ReviewErrorCase를 잘못 사용하고 있는 것이 확인되었습니다. 각 도메인은 자신만의 에러 케이스를 사용해야 합니다. 다음 스크립트를 실행하여 ReviewErrorCase가 다른 도메인에서 잘못 사용되고 있는지 확인해주세요: 🏁 Script executed: #!/bin/bash
# ReviewErrorCase가 review 도메인 외부에서 사용되는지 확인
rg -A 3 "ReviewErrorCase" --type java | grep -v "review/"Length of output: 799 DirectionService에서 ReviewErrorCase 사용 금지 및 도메인 전용 에러 케이스 도입 DirectionService에서 리뷰 도메인 전용 에러 케이스(
🤖 Prompt for AI Agents |
||
|
|
||
| private final Integer httpStatusCode; | ||
| private final Integer errorCode; | ||
| private final String message; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.wayble.server.review.repository; | ||
|
|
||
| import com.wayble.server.review.entity.ReviewImage; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface ReviewImageRepository extends JpaRepository<ReviewImage, Long> { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.wayble.server.review.repository; | ||
|
|
||
| import com.wayble.server.review.entity.Review; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface ReviewRepository extends JpaRepository<Review, Long> { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.wayble.server.review.service; | ||
|
|
||
| import com.wayble.server.common.exception.ApplicationException; | ||
| import com.wayble.server.review.exception.ReviewErrorCase; | ||
| import com.wayble.server.review.repository.ReviewRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class ReviewService { | ||
| private final ReviewRepository reviewRepository; | ||
|
|
||
| public void makeException() { | ||
| throw new ApplicationException(ReviewErrorCase.REVIEW_NOT_FOUND); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||
| package com.wayble.server.search.controller; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import com.wayble.server.common.response.CommonResponse; | ||||||||||||||||||||||||||||||
| import com.wayble.server.search.service.SearchService; | ||||||||||||||||||||||||||||||
| import lombok.RequiredArgsConstructor; | ||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.RestController; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @RestController | ||||||||||||||||||||||||||||||
| @RequiredArgsConstructor | ||||||||||||||||||||||||||||||
| @RequestMapping("/search") | ||||||||||||||||||||||||||||||
| public class SearchController { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| private final SearchService searchService; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // 참고용 컨트롤러(지우셔도 돼요) | ||||||||||||||||||||||||||||||
| @GetMapping("/hello") | ||||||||||||||||||||||||||||||
| public CommonResponse<String> hello() { | ||||||||||||||||||||||||||||||
| return CommonResponse.success("hello"); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // 예외 사용 참고용 컨트롤러(지우셔도 돼요) | ||||||||||||||||||||||||||||||
| @GetMapping("/ex") | ||||||||||||||||||||||||||||||
| public CommonResponse<String> exception() { | ||||||||||||||||||||||||||||||
| searchService.makeException(); | ||||||||||||||||||||||||||||||
| return CommonResponse.success("예외 발생!"); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 예외 처리 로직 오류
예외 처리 데모가 목적이라면 try-catch 블록을 사용하거나, 아니면 success 응답 반환 부분을 제거해야 합니다: @GetMapping("/ex")
public CommonResponse<String> exception() {
- searchService.makeException();
- return CommonResponse.success("예외 발생!");
+ try {
+ searchService.makeException();
+ return CommonResponse.success("예외 발생하지 않음");
+ } catch (ApplicationException e) {
+ throw e; // 글로벌 예외 핸들러에서 처리
+ }
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.wayble.server.search.exception; | ||
|
|
||
| import com.wayble.server.common.exception.ErrorCase; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum SearchErrorCase implements ErrorCase { | ||
|
|
||
| SEARCH_EXCEPTION(400, 5001, "검색 과정에서 오류가 발생했습니다."); | ||
|
|
||
| private final Integer httpStatusCode; | ||
| private final Integer errorCode; | ||
| private final String message; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.wayble.server.search.service; | ||
|
|
||
| import com.wayble.server.common.exception.ApplicationException; | ||
| import com.wayble.server.search.exception.SearchErrorCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class SearchService { | ||
|
|
||
| public void makeException() { | ||
| throw new ApplicationException(SearchErrorCase.SEARCH_EXCEPTION); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
생성자와 유효성 검증 추가 고려
Address 클래스에 생성자와 유효성 검증을 추가하는 것을 고려해보세요.
🤖 Prompt for AI Agents