-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
162 additions
and
1 deletion.
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
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
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
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
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,37 @@ | ||
package org.harang.server.domain; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Waiting { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "post_id", nullable = false) | ||
private Post post; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id", nullable = false) | ||
private Member member; | ||
|
||
@Builder | ||
public Waiting(Post post, Member member) { | ||
this.post = post; | ||
this.member = member; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/harang/server/dto/response/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,27 @@ | ||
package org.harang.server.dto.response; | ||
|
||
import lombok.Builder; | ||
import org.harang.server.domain.Category; | ||
import org.harang.server.domain.Post; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Builder | ||
public record PostResponse(Long postId, String title, String author, String createdAt, String contentAbstract, List<String> category) { | ||
public static PostResponse of(Post post) { | ||
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
|
||
String createdAt = post.getCreatedAt().format(dateFormatter); | ||
String contentAbstract = post.getContent().substring(0, Math.min(post.getContent().length(), 70)) + "..."; | ||
|
||
List<String> categories = post.getPostCategoryList().stream() | ||
.map(postCategory -> postCategory.getCategory().getName()) | ||
.collect(Collectors.toList()); | ||
|
||
return new PostResponse(post.getId(), post.getTitle(), post.getMember().getName(), createdAt, contentAbstract, categories); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/harang/server/dto/response/WaitingResponse.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.harang.server.dto.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class WaitingResponse { | ||
private Long memberId; | ||
private String nickname; | ||
|
||
@Builder | ||
public WaitingResponse(Long memberId, String nickname) { | ||
this.memberId = memberId; | ||
this.nickname = nickname; | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/org/harang/server/repository/MemberInfoRepository.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,17 @@ | ||
package org.harang.server.repository; | ||
|
||
import java.util.Optional; | ||
import org.harang.server.domain.MemberInfo; | ||
import org.harang.server.dto.type.ErrorMessage; | ||
import org.harang.server.exception.CustomException; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface MemberInfoRepository extends JpaRepository<MemberInfo, Long> { | ||
default MemberInfo findByMemberIdOrThrow(Long memberId) { | ||
return findByMemberId(memberId).orElseThrow(() -> new CustomException(ErrorMessage.MEMBER_INFO_NOT_FOUND)); | ||
} | ||
|
||
Optional<MemberInfo> findByMemberId(Long memberId); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/harang/server/repository/WaitingRepository.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,12 @@ | ||
package org.harang.server.repository; | ||
|
||
import java.util.List; | ||
import org.harang.server.domain.Member; | ||
import org.harang.server.domain.Waiting; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface WaitingRepository extends JpaRepository<Waiting, Long> { | ||
List<Waiting> findAllByPostId(Long postId); | ||
} |
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
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