Skip to content

Commit

Permalink
Merge pull request #56 from NewsFit-jolp/fix/category_enum
Browse files Browse the repository at this point in the history
Fix/category enum
  • Loading branch information
k000927 authored Oct 28, 2024
2 parents 026179f + 0d0b240 commit 6d266a9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public record GetArticle(
@Schema(description = "내용") String content,
@Schema(description = "이미지") List<String> images,
@Schema(description = "언론사") Press press,
@Schema(description = "카테고리") Category category,
@Schema(description = "카테고리") String category,
@Schema(description = "댓글") List<GetComment> comment,
@Schema(description = "좋아요 수") Integer likeCount,
@Schema(description = "내가 좋아요했는지 여부") Boolean likedArticle
Expand All @@ -37,7 +37,7 @@ public static GetArticle of(Article article, Boolean isLikedArticle) {
article.getContent(),
article.getImages(),
article.getPress(),
article.getCategory(),
article.getCategory().toString(),
getComments(article),
article.getLikeCount(),
isLikedArticle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public record GetArticles(
@Schema(description = "기사 제목", example = "기사 제목") String title,
@Schema(description = "헤드라인", example = "헤드라인") String headLine,
@Schema(description = "언론사", example = "Chosun") Press press,
@Schema(description = "카테고리", example = "IT") Category category,
@Schema(description = "카테고리", example = "IT") String category,
@Schema(description = "썸네일", example = "www.example.com/images/1") String thumbnail,
@Schema(description = "원본 기사의 게시일", example = "2024-10-25T10:00") LocalDateTime publishDate
) {
Expand All @@ -25,7 +25,7 @@ public static GetArticles of(Article article) {
article.getTitle(),
article.getHeadLine(),
article.getPress(),
article.getCategory(),
article.getCategory().toString(),
image,
article.getPublishDate()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
package com.example.newsfit.domain.article.entity;

public enum Category {
정치, 경제, 사회, 생활_문화, 세계, 기술_IT, 연예, 스포츠
정치("정치"),
경제("경제"),
사회("사회"),
생활_문화("생활/문화"),
세계("세계"),
기술_IT("기술/IT"),
연예("연예"),
스포츠("스포츠");

private final String displayName;

Category(String displayName) {
this.displayName = displayName;
}

public static Category fromDisplayName(String displayName) {
for (Category category : Category.values()) {
if (category.displayName.equals(displayName)) {
return category;
}
}
throw new IllegalArgumentException("Unknown category: " + displayName);
}

@Override
public String toString() {
return displayName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public GetArticles postArticle(String requestBody) throws ParseException {
String title = (String) jsonObject.get("title");
String content = (String) jsonObject.get("content");
Press press = Press.valueOf(((String) jsonObject.get("press")).toUpperCase());
Category category = Category.valueOf(((String) jsonObject.get("category")).toUpperCase());
Category category = Category.fromDisplayName((String) jsonObject.get("category"));
JSONArray imageArray = (JSONArray) jsonObject.get("image");
List<String> images = new ArrayList<>();
String articleSource = (String) jsonObject.get("articleSource");
Expand Down

0 comments on commit 6d266a9

Please sign in to comment.