-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] 커뮤니티 게시글 전체 조회 및 상세조회(인터페이스 우선배포) (#254)
* feat: dao 클래스 * delete: 안쓰는 파일들 삭제 * feat: post response * feat: repository 추가 * chore: comment service 객체 * feat: controller 클래스 * feat: comment response * feat: service 객체 추가 * feat: CategoryDto * feat: CategoryHelper * feat: exception 객체 * feat: mapper 객체 * feat: unversion file * chore: query dao
- Loading branch information
1 parent
d522f44
commit 913ba52
Showing
24 changed files
with
795 additions
and
4 deletions.
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
31 changes: 31 additions & 0 deletions
31
src/main/java/org/sopt/makers/internal/dto/community/CategoryDto.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,31 @@ | ||
package org.sopt.makers.internal.dto.community; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.sopt.makers.internal.domain.community.Category; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Data | ||
public class CategoryDto { | ||
|
||
private Long id; | ||
private String name; | ||
private List<CategoryDto> children; | ||
|
||
public static List<CategoryDto> toDtoList(List<Category> categories) { | ||
CategoryHelper helper = CategoryHelper.newInstance( | ||
categories, | ||
c -> new CategoryDto(c.getId(), c.getName(), new ArrayList<>()), | ||
Category::getParent, | ||
Category::getId, | ||
CategoryDto::getChildren); | ||
return helper.convert(); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/org/sopt/makers/internal/dto/community/CategoryHelper.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,78 @@ | ||
package org.sopt.makers.internal.dto.community; | ||
|
||
import org.sopt.makers.internal.exception.CannotConvertHelperException; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
public class CategoryHelper<K, E, D> { | ||
|
||
private List<E> entities; | ||
private Function<E, D> toDto; | ||
private Function<E, E> getParent; | ||
private Function<E, K> getKey; | ||
private Function<D, List<D>> getChildren; | ||
|
||
public static <K, E, D> CategoryHelper newInstance(List<E> entities, Function<E, D> toDto, Function<E, E> getParent, | ||
Function<E, K> getKey, Function<D, List<D>> getChildren) { | ||
return new CategoryHelper<K, E, D>(entities, toDto, getParent, getKey, getChildren); | ||
} | ||
|
||
private CategoryHelper(List<E> entities, Function<E, D> toDto, Function<E, E> getParent, Function<E, K> getKey, | ||
Function<D, List<D>> getChildren) { | ||
this.entities = entities; | ||
this.toDto = toDto; | ||
this.getParent = getParent; | ||
this.getKey = getKey; | ||
this.getChildren = getChildren; | ||
} | ||
|
||
public List<D> convert() { | ||
try { | ||
return convertInternal(); | ||
} catch (NullPointerException e) { | ||
throw new CannotConvertHelperException(e.getMessage()); | ||
} | ||
} | ||
|
||
private List<D> convertInternal() { | ||
Map<K, D> map = new HashMap<>(); | ||
List<D> roots = new ArrayList<>(); | ||
|
||
for (E e : entities) { | ||
D dto = toDto(e); | ||
map.put(getKey(e), dto); | ||
if (hasParent(e)) { | ||
E parent = getParent(e); | ||
K parentKey = getKey(parent); | ||
D parentDto = map.get(parentKey); | ||
getChildren(parentDto).add(dto); | ||
} else { | ||
roots.add(dto); | ||
} | ||
} | ||
return roots; | ||
} | ||
|
||
private boolean hasParent(E e) { | ||
return getParent(e) != null; | ||
} | ||
|
||
private E getParent(E e) { | ||
return getParent.apply(e); | ||
} | ||
|
||
private D toDto(E e) { | ||
return toDto.apply(e); | ||
} | ||
|
||
private K getKey(E e) { | ||
return getKey.apply(e); | ||
} | ||
|
||
private List<D> getChildren(D d) { | ||
return getChildren.apply(d); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/sopt/makers/internal/dto/community/CategoryPostMemberDao.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 org.sopt.makers.internal.dto.community; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import org.sopt.makers.internal.domain.MemberCareer; | ||
import org.sopt.makers.internal.domain.MemberSoptActivity; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record CategoryPostMemberDao( | ||
Long id, | ||
Long categoryId, | ||
Long userId, | ||
String userName, | ||
String profileImage, | ||
List<MemberSoptActivity> activities, | ||
List<MemberCareer> careers, | ||
String title, | ||
String content, | ||
Integer hits, | ||
Boolean isQuestion, | ||
Boolean isBlindWriter, | ||
String[] images, | ||
LocalDateTime createdAt, | ||
LocalDateTime updatedAt | ||
) { | ||
@QueryProjection | ||
public CategoryPostMemberDao {} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/sopt/makers/internal/dto/community/CommentDao.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,24 @@ | ||
package org.sopt.makers.internal.dto.community; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import org.sopt.makers.internal.domain.MemberCareer; | ||
import org.sopt.makers.internal.domain.MemberSoptActivity; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record CommentDao( | ||
Long id, | ||
Long userId, | ||
String userName, | ||
String profileImage, | ||
List<MemberSoptActivity> activities, | ||
List<MemberCareer> careers, | ||
String content, | ||
Boolean isBlindWriter, | ||
LocalDateTime createdAt, | ||
LocalDateTime updatedAt | ||
) { | ||
@QueryProjection | ||
public CommentDao {} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/sopt/makers/internal/dto/community/CommentResponse.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,20 @@ | ||
package org.sopt.makers.internal.dto.community; | ||
|
||
import org.sopt.makers.internal.domain.MemberCareer; | ||
import org.sopt.makers.internal.domain.MemberSoptActivity; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record CommentResponse( | ||
Long id, | ||
Long userId, | ||
String userName, | ||
String profileImage, | ||
List<MemberSoptActivity> activities, | ||
List<MemberCareer> careers, | ||
String content, | ||
Boolean isBlindWriter, | ||
LocalDateTime createdAt, | ||
LocalDateTime updatedAt | ||
){} |
4 changes: 4 additions & 0 deletions
4
src/main/java/org/sopt/makers/internal/dto/community/CommunityCommentDao.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,4 @@ | ||
package org.sopt.makers.internal.dto.community; | ||
|
||
public class CommunityCommentDao { | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/sopt/makers/internal/dto/community/CommunityMemberProfileResponse.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,51 @@ | ||
package org.sopt.makers.internal.dto.community; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public record CommunityMemberProfileResponse( | ||
@Schema(required = true) | ||
Long id, | ||
@Schema(required = true) | ||
String name, | ||
String profileImage, | ||
@Schema(required = true) | ||
List<MemberSoptActivityResponse> activities, | ||
List<MemberLinkResponse> links, | ||
List<MemberCareerResponse> careers, | ||
Boolean allowOfficial | ||
) { | ||
|
||
public record UserFavorResponse( | ||
Boolean isPourSauceLover, | ||
Boolean isHardPeachLover, | ||
Boolean isMintChocoLover, | ||
Boolean isRedBeanFishBreadLover, | ||
Boolean isSojuLover, | ||
Boolean isRiceTteokLover | ||
){} | ||
|
||
public record MemberLinkResponse( | ||
Long id, | ||
String title, | ||
String url | ||
){} | ||
|
||
public record MemberSoptActivityResponse( | ||
Long id, | ||
Integer generation, | ||
String part, | ||
String team | ||
){} | ||
|
||
public record MemberCareerResponse( | ||
Long id, | ||
String companyName, | ||
String title, | ||
String startDate, | ||
String endDate, | ||
Boolean isCurrent | ||
){} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/sopt/makers/internal/dto/community/CommunityMemberResponse.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,16 @@ | ||
package org.sopt.makers.internal.dto.community; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import org.sopt.makers.internal.domain.MemberCareer; | ||
import org.sopt.makers.internal.domain.MemberSoptActivity; | ||
|
||
import java.util.List; | ||
|
||
public record CommunityMemberResponse( | ||
Long id, | ||
String name, | ||
String image, | ||
@Schema(required = true) | ||
List<MemberSoptActivity> activities, | ||
List<MemberCareer> careers | ||
){} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/sopt/makers/internal/dto/community/PostAllResponse.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,9 @@ | ||
package org.sopt.makers.internal.dto.community; | ||
|
||
import java.util.List; | ||
|
||
public record PostAllResponse( | ||
Long categoryId, | ||
Boolean hasNext, | ||
List<PostResponse> posts | ||
) {} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/sopt/makers/internal/dto/community/PostResponse.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 org.sopt.makers.internal.dto.community; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import org.sopt.makers.internal.dto.member.MemberProfileResponse; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record PostResponse( | ||
@Schema(required = true) | ||
Long id, | ||
CommunityMemberResponse member, | ||
Long writerId, | ||
String title, | ||
String content, | ||
Integer hits, | ||
String[] images, | ||
Boolean isQuestion, | ||
Boolean isBlindWriter, | ||
LocalDateTime createdAt, | ||
List<CommentResponse> comments | ||
) {} |
Oops, something went wrong.