Skip to content

Commit

Permalink
Merge pull request #20 from team-REDDI/feat/#19/marketing-api
Browse files Browse the repository at this point in the history
Feat/#19/marketing api
  • Loading branch information
itsme-shawn authored Jan 21, 2024
2 parents b7c8bb1 + 8e737c9 commit 25a8dab
Show file tree
Hide file tree
Showing 25 changed files with 573 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ApiExceptionHandler {
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse<?>> handleExceptions(RuntimeException exception) {

log.error(exception.getMessage());
log.error("Exception occurred:", exception); // 스택 트레이스 정보를 포함한 로깅

return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.errorResponse(exception.getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@RequestMapping("/api/brand")
public class BrandController {

private final BrandService brandService;;
private final BrandService brandService;

@Operation(summary = "브랜드 리스트 조회")
@GetMapping("/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -14,23 +17,30 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/notion")
@Slf4j
public class NotionController {

private final NotionService notionService;

@Hidden
@Operation(summary = "[테스트용] 노션 api 호출해서 자체 DB 갱신")
@GetMapping("/update")
public ApiResponse<List<String>> getNotionData() {
public ApiResponse<?> getNotionData() {

// DB init
notionService.deleteAll();

List<String> brandPageIds = notionService.getBrandPageIds();
notionService.getBrandPageContents(brandPageIds);

// 임시로 하나만 조회
// notionService.getBrandPageContents(Collections.singletonList(brandPageIds.get(0)));

List<String> marketingPageIds = notionService.getMarketingPageIds();
notionService.getMarketingPageContents(marketingPageIds);


return ApiResponse.successResponse(notionService.getBrandPageIds());
return ApiResponse.successWithNoContent();
}

}
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);
}
}
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.reddiserver.dto.brand.response;

import com.example.reddiserver.dto.post.response.PostResponseDto;
import com.example.reddiserver.entity.Brand;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -14,20 +15,21 @@ public class BrandResponseDto {
private Long id;
private String name;
private List<BrandTagDto> brandTags;
private String imageUrl;
private String cover_url;
private String notion_page_url;
private String notion_page_created_time;
private String notion_page_last_edited_time;


public BrandResponseDto(Brand brand) {
this.id = brand.getId();
this.brandTags = BrandTagDto.convertToDtoList(brand.getBrandTags());
this.name = brand.getName();
this.imageUrl = brand.getImage_url();
this.notion_page_url = brand.getNotion_page_url();
this.notion_page_created_time = brand.getNotion_page_created_time();
this.notion_page_last_edited_time = brand.getNotion_page_last_edited_time();

// 정적 메서드
public static BrandResponseDto from(Brand brand) {
BrandResponseDto brandResponseDto = new BrandResponseDto();
brandResponseDto.setId(brand.getId());
brandResponseDto.setName(brand.getName());
brandResponseDto.setBrandTags(BrandTagDto.convertToDtoList(brand.getBrandTags()));
brandResponseDto.setCover_url(brand.getCover_url());
brandResponseDto.setNotion_page_url(brand.getNotion_page_url());
brandResponseDto.setNotion_page_created_time(brand.getNotion_page_created_time());
brandResponseDto.setNotion_page_last_edited_time(brand.getNotion_page_last_edited_time());
return brandResponseDto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public BrandTagDto(BrandTag brandTag) {
this.tag = brandTag.getTag();
}

// Getters and setters (if needed)

public static List<BrandTagDto> convertToDtoList(List<BrandTag> brandTags) {
return brandTags.stream()
.map(BrandTagDto::new)
Expand Down
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;
}
}
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;
}
}
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();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/example/reddiserver/entity/Bookmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Bookmark extends BaseTimeEntity {
@OneToMany(mappedBy = "bookmark")
private List<BookmarkPost> bookmarkPosts = new ArrayList<>();

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY) // 연관관계 주인
@JoinColumn(name = "member_id")
private Member member;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public class BookmarkPost extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY) // 연관관계 주인
@JoinColumn(name = "bookmark_id")
private Bookmark bookmark;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY) // 연관관계 주인
@JoinColumn(name = "post_id")
private Post post;

Expand Down
15 changes: 2 additions & 13 deletions src/main/java/com/example/reddiserver/entity/Brand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class Brand extends BaseTimeEntity {
@Column
private String name;

@Column
private String image_url;
@Column(columnDefinition = "LONGTEXT")
private String cover_url;

@Column(columnDefinition = "LONGTEXT")
private String content;
Expand All @@ -44,15 +44,4 @@ public class Brand extends BaseTimeEntity {
@Column
private String notion_page_last_edited_time;


@Builder
public Brand(String name, String image_url, String content, String notion_page_id, String notion_page_url, String notion_page_created_time, String notion_page_last_edited_time) {
this.name = name;
this.image_url = image_url;
this.content = content;
this.notion_page_id = notion_page_id;
this.notion_page_url = notion_page_url;
this.notion_page_created_time = notion_page_created_time;
this.notion_page_last_edited_time = notion_page_last_edited_time;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/example/reddiserver/entity/BrandTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class BrandTag extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY) // 연관관계 주인
@JoinColumn(name = "brand_id")
private Brand brand;

Expand Down
Loading

0 comments on commit 25a8dab

Please sign in to comment.