-
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.
Merge pull request #12 from Likelion-Inner-Join/feat/11
[Feat]: 홍보글 리스트
- Loading branch information
Showing
8 changed files
with
138 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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/likelion/innerjoin/post/controller/PostController.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,25 @@ | ||
package com.likelion.innerjoin.post.controller; | ||
|
||
import com.likelion.innerjoin.common.response.CommonResponse; | ||
import com.likelion.innerjoin.post.model.dto.PostResponseDTO; | ||
import com.likelion.innerjoin.post.service.PostService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/posts") | ||
public class PostController { | ||
|
||
@Autowired | ||
private PostService postService; | ||
|
||
@GetMapping | ||
public CommonResponse<List<PostResponseDTO>> getPosts() { | ||
List<PostResponseDTO> response = postService.getAllPosts(); | ||
return new CommonResponse<>(response); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/likelion/innerjoin/post/model/dto/PostResponseDTO.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.likelion.innerjoin.post.model.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public class PostResponseDTO { | ||
|
||
private Long postId; | ||
private Long clubId; | ||
private String title; | ||
private String body; | ||
|
||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") | ||
private LocalDateTime createdAt; | ||
|
||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") | ||
private LocalDateTime startTime; | ||
|
||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") | ||
private LocalDateTime endTime; | ||
|
||
private String status; | ||
private String recruitmentType; | ||
private Integer recruitmentCount; | ||
|
||
private List<PostImageDTO> image; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public static class PostImageDTO { | ||
private Long imageId; | ||
private String imageUrl; | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/likelion/innerjoin/post/repository/PostRepository.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,7 @@ | ||
package com.likelion.innerjoin.post.repository; | ||
|
||
import com.likelion.innerjoin.post.model.entity.Post; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PostRepository extends JpaRepository<Post, Long> { | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/likelion/innerjoin/post/service/PostService.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,46 @@ | ||
package com.likelion.innerjoin.post.service; | ||
|
||
import com.likelion.innerjoin.post.model.dto.PostResponseDTO; | ||
import com.likelion.innerjoin.post.model.entity.Post; | ||
import com.likelion.innerjoin.post.repository.PostRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
public class PostService { | ||
|
||
@Autowired | ||
private PostRepository postRepository; | ||
|
||
public List<PostResponseDTO> getAllPosts() { | ||
List<Post> posts = postRepository.findAll(); // 게시글 목록을 데이터베이스에서 가져옴 | ||
|
||
|
||
// Post 엔티티 리스트를 PostResponseDTO로 변환 | ||
return posts.stream() | ||
.map(post -> toPostResponseDTO(post)) // Post -> PostResponseDTO 변환 | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
// Post 엔티티를 PostResponseDTO로 변환하는 메서드 | ||
private PostResponseDTO toPostResponseDTO(Post post) { | ||
return PostResponseDTO.builder() | ||
.postId(post.getId()) | ||
.clubId(post.getClub().getId()) | ||
.title(post.getTitle()) | ||
.body(post.getBody()) | ||
.createdAt(post.getCreatedAt()) | ||
.startTime(post.getStartTime()) | ||
.endTime(post.getEndTime()) | ||
.status(post.getStatus().toString()) | ||
.recruitmentType(post.getRecruitmentType()) | ||
.recruitmentCount(Integer.parseInt(post.getRecruitmentCount())) // String -> Integer 변환 | ||
.image(post.getImageList().stream() | ||
.map(image -> new PostResponseDTO.PostImageDTO(image.getId(), image.getUrl())) | ||
.collect(Collectors.toList())) | ||
.build(); | ||
} | ||
} |
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