-
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.
Browse files
Browse the repository at this point in the history
Feat/#19/marketing api
- Loading branch information
Showing
25 changed files
with
573 additions
and
159 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
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/example/reddiserver/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,34 @@ | ||
package com.example.reddiserver.controller; | ||
|
||
import com.example.reddiserver.common.ApiResponse; | ||
import com.example.reddiserver.dto.post.response.PostContentsResponseDto; | ||
import com.example.reddiserver.dto.post.response.PostResponseDto; | ||
import com.example.reddiserver.service.PostService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
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 | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/post") | ||
public class PostController { | ||
private final PostService postService; | ||
|
||
@Operation(summary = "포스트(마케팅) 리스트 조회") | ||
@GetMapping("/") | ||
public ApiResponse<List<PostResponseDto>> getPostList() { | ||
List<PostResponseDto> postList = postService.getPostList(); | ||
return ApiResponse.successResponse(postList); | ||
} | ||
|
||
@Operation(summary = "포스트(마케팅) 단건(상세) 조회") | ||
@GetMapping("/{id}") | ||
public ApiResponse<PostContentsResponseDto> getPostById(Long id) { | ||
PostContentsResponseDto post = postService.getPostById(id); | ||
return ApiResponse.successResponse(post); | ||
} | ||
} |
19 changes: 15 additions & 4 deletions
19
src/main/java/com/example/reddiserver/dto/brand/response/BrandContentsResponseDto.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 |
---|---|---|
@@ -1,24 +1,35 @@ | ||
package com.example.reddiserver.dto.brand.response; | ||
|
||
import com.example.reddiserver.entity.Brand; | ||
import com.example.reddiserver.entity.Post; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import com.fasterxml.jackson.annotation.JsonRawValue; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class BrandContentsResponseDto { | ||
private Long id; | ||
private BrandResponseDto brand; | ||
|
||
private List<Long> postIds; | ||
|
||
@JsonRawValue | ||
private String content; | ||
|
||
public BrandContentsResponseDto(Brand brand) { | ||
this.id = brand.getId(); | ||
this.content = brand.getContent(); | ||
public static BrandContentsResponseDto from(Brand brand) { | ||
BrandContentsResponseDto brandContentsResponseDto = new BrandContentsResponseDto(); | ||
brandContentsResponseDto.setBrand(BrandResponseDto.from(brand)); | ||
brandContentsResponseDto.setContent(brand.getContent()); | ||
|
||
// Post의 id 목록 추가 | ||
brandContentsResponseDto.setPostIds(brand.getPosts().stream() | ||
.map(Post::getId) | ||
.collect(Collectors.toList())); | ||
return brandContentsResponseDto; | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/example/reddiserver/dto/post/response/PostContentsResponseDto.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 com.example.reddiserver.dto.post.response; | ||
|
||
import com.example.reddiserver.entity.Post; | ||
import com.fasterxml.jackson.annotation.JsonRawValue; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class PostContentsResponseDto { | ||
private PostResponseDto post; | ||
|
||
@JsonRawValue | ||
private String content; | ||
|
||
public static PostContentsResponseDto from(Post post) { | ||
PostContentsResponseDto postContentsResponseDto = new PostContentsResponseDto(); | ||
postContentsResponseDto.setPost(PostResponseDto.from(post)); | ||
postContentsResponseDto.setContent(post.getContent()); | ||
return postContentsResponseDto; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/example/reddiserver/dto/post/response/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,46 @@ | ||
package com.example.reddiserver.dto.post.response; | ||
|
||
import com.example.reddiserver.dto.brand.response.BrandResponseDto; | ||
import com.example.reddiserver.entity.Post; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class PostResponseDto { | ||
private Long id; | ||
private Long brand_id; | ||
private String title; | ||
private String subtitle; | ||
private String description; | ||
private List<PostTagDto> postTags; | ||
private String cover_url; | ||
private String notion_page_url; | ||
private String notion_page_created_time; | ||
private String notion_page_last_edited_time; | ||
|
||
// 정적 메서드 | ||
public static PostResponseDto from(Post post) { | ||
PostResponseDto postResponseDto = new PostResponseDto(); | ||
postResponseDto.setId(post.getId()); | ||
postResponseDto.setTitle(post.getTitle()); | ||
postResponseDto.setSubtitle(post.getSubtitle()); | ||
postResponseDto.setDescription(post.getDescription()); | ||
postResponseDto.setPostTags(PostTagDto.convertToDtoList(post.getPostTags())); | ||
postResponseDto.setCover_url(post.getCover_url()); | ||
postResponseDto.setNotion_page_url(post.getNotion_page_url()); | ||
postResponseDto.setNotion_page_created_time(post.getNotion_page_created_time()); | ||
postResponseDto.setNotion_page_last_edited_time(post.getNotion_page_last_edited_time()); | ||
|
||
// Brand 정보 추가 | ||
if (post.getBrand() != null){ | ||
postResponseDto.setBrand_id(post.getBrand().getId()); | ||
} | ||
|
||
return postResponseDto; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/reddiserver/dto/post/response/PostTagDto.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.example.reddiserver.dto.post.response; | ||
|
||
import com.example.reddiserver.entity.PostTag; | ||
import com.example.reddiserver.entity.enums.PostTagType; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class PostTagDto { | ||
private PostTagType postTagType; | ||
private String tag; | ||
|
||
public PostTagDto(PostTag postTag) { | ||
this.postTagType = postTag.getPostTagType(); | ||
this.tag = postTag.getTag(); | ||
} | ||
|
||
public static List<PostTagDto> convertToDtoList(List<PostTag> postTags) { | ||
return postTags.stream() | ||
.map(PostTagDto::new) | ||
.toList(); | ||
} | ||
} |
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
Oops, something went wrong.