-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: 셀프 소개 기능을 구현한다 #46
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4765be2
feat: 셀프 소개글 기능에서 발생할 수 있는 예외클래스 지정
eom-tae-in 758223f
feat: 셀프 소개글 기능에서 사용할 request dto 생성
eom-tae-in 312ff9b
feat: 셀프 소개글 기능에서 사용할 response dto 생성
eom-tae-in c5ccac2
feat: 셀프 소개글을 저장하고 관리하는 엔티티 구현
eom-tae-in 566d9c4
feat: 셀프 소개글을 저장, 조회, 삭제하기 위한 repository 구현
eom-tae-in 05db37a
feat: 셀프 소개글의 읽기 전용 Service 구현
eom-tae-in 4e7ed5b
feat: 셀프 소개글의 쓰기 전용 Service 구현
eom-tae-in 457cc98
feat: 셀프 소개글 Controller 구현
eom-tae-in a073dc7
feat: 셀프 소개글 기능 이용시 인증을 위한 인터셉터에 url에 추가
eom-tae-in 52d2f89
test: 테스트 패키지 구조 변경으로 인한 수정
eom-tae-in 9f003c1
test: SelfIntro를 검증하기 위한 테스트 클래스 작성
eom-tae-in 1a95f1e
test: SelfIntroService를 검증하기 위한 테스트 클래스 작성
eom-tae-in 87d3f19
test: SelfIntroQueryService를 검증하기 위한 테스트 클래스 작성
eom-tae-in 23b7fee
test: SelfIntroQueryRepository를 검증하기 위한 테스트 클래스 작성
eom-tae-in dd63c4f
test: SelfIntroJpaRepository를 검증하기 위한 테스트 클래스 작성
eom-tae-in f2eb231
test: SelfIntro 컨트롤러 단위테스트 작성
eom-tae-in c88c9b4
test: SelfIntro 인수테스트 작성
eom-tae-in b5e3fbd
test: SelfIntro 인수테스트 설정을 하기 위해 helper 작성
eom-tae-in 39c23a0
test: SelfIntro 서비스 계층 테스트시 사용할 FakeRepository 작성
eom-tae-in 99aa725
test: 테스트를 편하게 하기 위해 fixture 작
eom-tae-in 6133fc3
test: 경로 변경으로 인한 테스트 코드 수정
eom-tae-in 3baa3fd
refactor: 개행 추가
eom-tae-in 7eef749
refactor: 메서드 구조 변경
eom-tae-in 8b81c89
test: test 수정
eom-tae-in a16ae8a
refactor: 상수 값 변경
eom-tae-in c7728f4
refactor: 줄바꿈 제거
eom-tae-in 9192c4e
refactor: 사용하는 jpa 내장 메서드 가시화
eom-tae-in fe42b49
docs: selfintro api 명세서 작성
eom-tae-in File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/com/atwoz/member/application/selfintro/SelfIntroQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.atwoz.member.application.selfintro; | ||
|
||
import com.atwoz.member.application.selfintro.dto.SelfIntroFilterRequest; | ||
import com.atwoz.member.application.selfintro.dto.SelfIntrosResponse; | ||
import com.atwoz.member.domain.selfintro.SelfIntroRepository; | ||
import com.atwoz.member.infrastructure.selfintro.dto.SelfIntroResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
@Transactional(readOnly = true) | ||
public class SelfIntroQueryService { | ||
|
||
private final SelfIntroRepository selfIntroRepository; | ||
|
||
public SelfIntrosResponse findAllSelfIntrosWithPaging(final Pageable pageable, | ||
final Long memberId) { | ||
Page<SelfIntroResponse> selfIntroResponses = selfIntroRepository.findAllSelfIntrosWithPaging(pageable, memberId); | ||
|
||
return SelfIntrosResponse.of(selfIntroResponses, pageable); | ||
} | ||
|
||
public SelfIntrosResponse findAllSelfIntrosWithPagingAndFiltering(final Pageable pageable, | ||
final SelfIntroFilterRequest selfIntroFilterRequest, | ||
final Long memberId) { | ||
Page<SelfIntroResponse> selfIntroResponses = selfIntroRepository.findAllSelfIntrosWithPagingAndFiltering( | ||
pageable, | ||
selfIntroFilterRequest.minAge(), | ||
selfIntroFilterRequest.maxAge(), | ||
selfIntroFilterRequest.isOnlyOppositeGender(), | ||
selfIntroFilterRequest.getCities(), | ||
memberId | ||
); | ||
|
||
return SelfIntrosResponse.of(selfIntroResponses, pageable); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/atwoz/member/application/selfintro/SelfIntroService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.atwoz.member.application.selfintro; | ||
|
||
import com.atwoz.member.application.selfintro.dto.SelfIntroCreateRequest; | ||
import com.atwoz.member.application.selfintro.dto.SelfIntroUpdateRequest; | ||
import com.atwoz.member.domain.selfintro.SelfIntro; | ||
import com.atwoz.member.domain.selfintro.SelfIntroRepository; | ||
import com.atwoz.member.exception.exceptions.selfintro.SelfIntroNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
@Transactional | ||
public class SelfIntroService { | ||
|
||
private final SelfIntroRepository selfIntroRepository; | ||
|
||
public void saveSelfIntro(final SelfIntroCreateRequest selfIntroCreateRequest, | ||
final Long memberId) { | ||
SelfIntro selfIntro = SelfIntro.createWith(memberId, selfIntroCreateRequest.content()); | ||
selfIntroRepository.save(selfIntro); | ||
} | ||
|
||
public void updateSelfIntro(final SelfIntroUpdateRequest selfIntroUpdateRequest, | ||
final Long selfIntroId, | ||
final Long memberId) { | ||
SelfIntro foundSelfIntro = findSelfIntroById(selfIntroId); | ||
foundSelfIntro.validateSameWriter(memberId); | ||
foundSelfIntro.update(selfIntroUpdateRequest.content()); | ||
} | ||
|
||
public void deleteSelfIntro(final Long selfIntroId, final Long memberId) { | ||
SelfIntro foundSelfIntro = findSelfIntroById(selfIntroId); | ||
foundSelfIntro.validateSameWriter(memberId); | ||
selfIntroRepository.deleteById(foundSelfIntro.getId()); | ||
} | ||
|
||
private SelfIntro findSelfIntroById(final Long selfIntroId) { | ||
return selfIntroRepository.findById(selfIntroId) | ||
.orElseThrow(SelfIntroNotFoundException::new); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/atwoz/member/application/selfintro/dto/CityRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.atwoz.member.application.selfintro.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record CityRequest( | ||
|
||
@NotBlank(message = "선호하는 지역 정보를 입력해주세요.") | ||
String city | ||
) { | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/atwoz/member/application/selfintro/dto/SelfIntroCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.atwoz.member.application.selfintro.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record SelfIntroCreateRequest( | ||
|
||
@NotBlank(message = "소개글을 입력해주세요") | ||
String content | ||
) { | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/atwoz/member/application/selfintro/dto/SelfIntroFilterRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.atwoz.member.application.selfintro.dto; | ||
|
||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
public record SelfIntroFilterRequest( | ||
|
||
@NotNull(message = "최소 나이를 입력해주세요") | ||
Integer minAge, | ||
|
||
@NotNull(message = "최대 나이를 입력해주세요") | ||
Integer maxAge, | ||
|
||
@NotNull(message = "성별을 선택해주세요") | ||
Boolean isOnlyOppositeGender, | ||
|
||
@Valid | ||
@NotEmpty(message = "선호 지역을 하나 이상 입력해주세요.") | ||
List<CityRequest> cityRequests | ||
) { | ||
|
||
public List<String> getCities() { | ||
return cityRequests.stream() | ||
.map(CityRequest::city) | ||
.toList(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/atwoz/member/application/selfintro/dto/SelfIntroUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.atwoz.member.application.selfintro.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record SelfIntroUpdateRequest( | ||
|
||
@NotBlank(message = "소개글을 입력해주세요") | ||
String content | ||
) { | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/atwoz/member/application/selfintro/dto/SelfIntrosResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.atwoz.member.application.selfintro.dto; | ||
|
||
import com.atwoz.member.infrastructure.selfintro.dto.SelfIntroResponse; | ||
import java.util.List; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public record SelfIntrosResponse( | ||
List<SelfIntroResponse> selfIntros, | ||
int nowPage, | ||
int nextPage, | ||
int totalPages | ||
) { | ||
|
||
private static final int NEXT_PAGE_INDEX = 1; | ||
private static final int NO_MORE_PAGE = -1; | ||
|
||
public static SelfIntrosResponse of(final Page<SelfIntroResponse> selfIntros, | ||
final Pageable pageable) { | ||
return new SelfIntrosResponse( | ||
selfIntros.getContent(), | ||
pageable.getPageNumber(), | ||
getNextPage(pageable.getPageNumber(), selfIntros), | ||
selfIntros.getTotalPages() | ||
); | ||
} | ||
|
||
private static int getNextPage(final int pageNumber, final Page<SelfIntroResponse> selfIntros) { | ||
if (selfIntros.hasNext()) { | ||
return pageNumber + NEXT_PAGE_INDEX; | ||
} | ||
|
||
return NO_MORE_PAGE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/com/atwoz/member/domain/selfintro/SelfIntro.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.atwoz.member.domain.selfintro; | ||
|
||
import com.atwoz.global.domain.BaseEntity; | ||
import com.atwoz.member.exception.exceptions.selfintro.InvalidContentException; | ||
import com.atwoz.member.exception.exceptions.selfintro.WriterNotEqualsException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import java.util.Objects; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@EqualsAndHashCode(of = "id", callSuper = false) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Entity | ||
public class SelfIntro extends BaseEntity { | ||
|
||
private static final int MIN_LENGTH = 1; | ||
private static final int MAX_LENGTH = 30; | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private Long memberId; | ||
|
||
@Column(length = MAX_LENGTH, nullable = false) | ||
private String content; | ||
|
||
public static SelfIntro createWith(final Long memberId, | ||
final String content) { | ||
validateContent(content); | ||
return SelfIntro.builder() | ||
.memberId(memberId) | ||
.content(content) | ||
.build(); | ||
} | ||
|
||
private static void validateContent(final String content) { | ||
int contentLength = content.length(); | ||
if (contentLength < MIN_LENGTH || MAX_LENGTH < contentLength) { | ||
throw new InvalidContentException(); | ||
} | ||
} | ||
|
||
public void validateSameWriter(final Long memberId) { | ||
if (!Objects.equals(this.memberId, memberId)) { | ||
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. 저였다면 습관적으로 직접 두 필드를 비교하는 방식을 썼을 것 같은데 Objects에 있는 걸 이용하면 더 간단히 작성할 수 있어서 좋은 것 같습니다! |
||
throw new WriterNotEqualsException(); | ||
} | ||
} | ||
|
||
public void update(final String content) { | ||
validateContent(content); | ||
this.content = content; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/atwoz/member/domain/selfintro/SelfIntroRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.atwoz.member.domain.selfintro; | ||
|
||
import com.atwoz.member.infrastructure.selfintro.dto.SelfIntroResponse; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public interface SelfIntroRepository { | ||
|
||
SelfIntro save(SelfIntro selfIntro); | ||
|
||
Optional<SelfIntro> findById(Long id); | ||
|
||
void deleteById(Long id); | ||
|
||
Page<SelfIntroResponse> findAllSelfIntrosWithPaging(Pageable pageable, Long memberId); | ||
|
||
Page<SelfIntroResponse> findAllSelfIntrosWithPagingAndFiltering(Pageable pageable, int minAge, int maxAge, | ||
boolean isOnlyOppositeGender, List<String> cities, | ||
Long memberId); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
updateSelfIntro와 deleteSelfIntro에서 모두 findSelfIntroById를 거친 뒤 validateSameWriter를 호출하고 있는데, 이러한 경우라면 findSelfIntroById 안에 validateSameWriter까지 넣어보는 것은 어떨까요?
SelfIntro 조회 시 validateSameWriter를 호출해야 한다
는 조건이 들어가있다면 findSelfIntroById에서 넣어둬도 괜찮지 않을까라는 생각이 드는데 의견이 궁금합니다 :)