Skip to content

Commit

Permalink
[BE] dev 코드를 main에 반영한다. (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsulocalize authored Sep 24, 2024
2 parents daabd50 + 95ffdb5 commit f786743
Show file tree
Hide file tree
Showing 143 changed files with 2,954 additions and 1,659 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.bang_ggood.article.dto.request.ArticleCreateRequest;
import com.bang_ggood.article.dto.response.ArticleResponse;
import com.bang_ggood.article.dto.response.ArticlesDetailPreviewResponse;
import com.bang_ggood.article.dto.response.ArticlesPreviewResponse;
import com.bang_ggood.article.dto.response.ArticlesListViewResponse;
import com.bang_ggood.article.dto.response.ArticlesCardViewResponse;
import com.bang_ggood.article.service.ArticleService;
import com.bang_ggood.auth.config.AuthPrincipal;
import com.bang_ggood.user.domain.User;
Expand Down Expand Up @@ -38,14 +38,14 @@ public ResponseEntity<ArticleResponse> readArticle(@PathVariable("id") Long id)
return ResponseEntity.ok(articleService.readArticle(id));
}

@GetMapping("/articles")
public ResponseEntity<ArticlesDetailPreviewResponse> readArticles() {
return ResponseEntity.ok(articleService.readArticles());
@GetMapping("/articles/card")
public ResponseEntity<ArticlesCardViewResponse> readArticlesCardView() {
return ResponseEntity.ok(articleService.readArticlesCardView());
}

@GetMapping("/articles/latest")
public ResponseEntity<ArticlesPreviewResponse> readLatestArticles() {
return ResponseEntity.ok(articleService.readLatestArticles());
@GetMapping("/articles/list")
public ResponseEntity<ArticlesListViewResponse> readArticlesListView() {
return ResponseEntity.ok(articleService.readArticlesListView());
}

@DeleteMapping("/articles/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ public class Article extends BaseEntity {

private String summary;

public Article(String title, String content, String keyword, String summary) {
private String thumbnail;

public Article(String title, String content, String keyword, String summary, String thumbnail) {
this.title = title;
this.content = content;
this.keyword = keyword;
this.summary = summary;
this.thumbnail = thumbnail;
}

protected Article() {
Expand All @@ -52,6 +55,10 @@ public String getSummary() {
return summary;
}

public String getThumbnail() {
return thumbnail;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -77,6 +84,7 @@ public String toString() {
", content='" + content + '\'' +
", keyword='" + keyword + '\'' +
", summary='" + summary + '\'' +
", thumbnail='" + thumbnail + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import jakarta.validation.constraints.NotBlank;

public record ArticleCreateRequest(@NotBlank(message = "제목을 입력해야 합니다.") String title, String content, String keyword,
String summary) {
String summary, String thumbnail) {

public Article toEntity() {
return new Article(title, content, keyword, summary);
return new Article(title, content, keyword, summary, thumbnail);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.bang_ggood.article.dto.response;

import com.bang_ggood.article.domain.Article;

public record ArticleCardViewResponse(Long articleId, String title, String keyword, String thumbnail) {

public static ArticleCardViewResponse from(Article article) {
return new ArticleCardViewResponse(
article.getId(),
article.getTitle(),
article.getKeyword(),
article.getThumbnail()
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bang_ggood.article.dto.response;

import com.bang_ggood.article.domain.Article;
import java.time.LocalDateTime;

public record ArticleListViewResponse(Long articleId, String title, String keyword, String summary, String thumbnail,
LocalDateTime createdAt) {

public static ArticleListViewResponse from(Article article) {
return new ArticleListViewResponse(
article.getId(),
article.getTitle(),
article.getKeyword(),
article.getSummary(),
article.getThumbnail(),
article.getCreatedAt()
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.bang_ggood.article.dto.response;

import java.util.List;

public record ArticlesCardViewResponse(List<ArticleCardViewResponse> articles) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.bang_ggood.article.dto.response;

import java.util.List;

public record ArticlesListViewResponse(List<ArticleListViewResponse> articles) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.bang_ggood.article.repository;

import com.bang_ggood.article.domain.Article;
import com.bang_ggood.exception.BangggoodException;
import com.bang_ggood.exception.ExceptionCode;
import com.bang_ggood.global.exception.BangggoodException;
import com.bang_ggood.global.exception.ExceptionCode;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -22,14 +22,15 @@ default Article getById(Long id) {
Optional<Article> findById(@Param("id") Long id);

@Query("SELECT a FROM Article a " +
"WHERE a.deleted = false")
List<Article> findAll();
"WHERE a.deleted = false " +
"ORDER BY a.createdAt DESC ")
List<Article> findLatestArticles();

@Query("SELECT a FROM Article a " +
"WHERE a.deleted = false " +
"ORDER BY a.createdAt DESC " +
"LIMIT :count")
List<Article> findLatest(@Param("count") int count);
List<Article> findLatestArticles(@Param("count") int count);

@Modifying(flushAutomatically = true, clearAutomatically = true)
@Query("UPDATE Article a " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.bang_ggood.article.domain.Article;
import com.bang_ggood.article.dto.request.ArticleCreateRequest;
import com.bang_ggood.article.dto.response.ArticleDetailPreviewResponse;
import com.bang_ggood.article.dto.response.ArticlePreviewResponse;
import com.bang_ggood.article.dto.response.ArticleListViewResponse;
import com.bang_ggood.article.dto.response.ArticleCardViewResponse;
import com.bang_ggood.article.dto.response.ArticleResponse;
import com.bang_ggood.article.dto.response.ArticlesDetailPreviewResponse;
import com.bang_ggood.article.dto.response.ArticlesPreviewResponse;
import com.bang_ggood.article.dto.response.ArticlesListViewResponse;
import com.bang_ggood.article.dto.response.ArticlesCardViewResponse;
import com.bang_ggood.article.repository.ArticleRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -36,19 +36,19 @@ public ArticleResponse readArticle(Long id) {
}

@Transactional(readOnly = true)
public ArticlesDetailPreviewResponse readArticles() {
List<ArticleDetailPreviewResponse> articles = articleRepository.findAll().stream()
.map(ArticleDetailPreviewResponse::from)
public ArticlesListViewResponse readArticlesListView() {
List<ArticleListViewResponse> articles = articleRepository.findLatestArticles().stream()
.map(ArticleListViewResponse::from)
.toList();
return new ArticlesDetailPreviewResponse(articles);
return new ArticlesListViewResponse(articles);
}

@Transactional(readOnly = true)
public ArticlesPreviewResponse readLatestArticles() {
List<ArticlePreviewResponse> articles = articleRepository.findLatest(MAX_ARTICLE_CARDS).stream()
.map(ArticlePreviewResponse::from)
public ArticlesCardViewResponse readArticlesCardView() {
List<ArticleCardViewResponse> articles = articleRepository.findLatestArticles(MAX_ARTICLE_CARDS).stream()
.map(ArticleCardViewResponse::from)
.toList();
return new ArticlesPreviewResponse(articles);
return new ArticlesCardViewResponse(articles);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.bang_ggood.auth.controller.CookieProvider;
import com.bang_ggood.auth.service.AuthService;
import com.bang_ggood.exception.BangggoodException;
import com.bang_ggood.exception.ExceptionCode;
import com.bang_ggood.global.exception.BangggoodException;
import com.bang_ggood.global.exception.ExceptionCode;
import com.bang_ggood.user.domain.User;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import com.bang_ggood.auth.dto.request.OauthLoginRequest;
import com.bang_ggood.auth.dto.response.OauthInfoApiResponse;
import com.bang_ggood.checklist.domain.Answer;
import com.bang_ggood.checklist.domain.CustomChecklistQuestion;
import com.bang_ggood.checklist.domain.Option;
import com.bang_ggood.checklist.domain.Question;
import com.bang_ggood.checklist.dto.request.ChecklistRequest;
import com.bang_ggood.checklist.dto.request.QuestionRequest;
import com.bang_ggood.checklist.repository.CustomChecklistQuestionRepository;
import com.bang_ggood.checklist.service.ChecklistService;
import com.bang_ggood.exception.BangggoodException;
import com.bang_ggood.exception.ExceptionCode;
import com.bang_ggood.checklist.service.ChecklistManageService;
import com.bang_ggood.global.exception.BangggoodException;
import com.bang_ggood.global.exception.ExceptionCode;
import com.bang_ggood.option.domain.Option;
import com.bang_ggood.question.domain.Answer;
import com.bang_ggood.question.domain.CustomChecklistQuestion;
import com.bang_ggood.question.domain.Question;
import com.bang_ggood.question.dto.request.QuestionRequest;
import com.bang_ggood.question.repository.CustomChecklistQuestionRepository;
import com.bang_ggood.room.dto.request.RoomRequest;
import com.bang_ggood.user.domain.User;
import com.bang_ggood.user.repository.UserRepository;
Expand All @@ -28,16 +28,17 @@ public class AuthService {

private final OauthClient oauthClient;
private final JwtTokenProvider jwtTokenProvider;
private final ChecklistService checklistService;
private final ChecklistManageService checklistManageService;
private final UserRepository userRepository;
private final CustomChecklistQuestionRepository customChecklistQuestionRepository;

public AuthService(OauthClient oauthClient, JwtTokenProvider jwtTokenProvider, ChecklistService checklistService,
public AuthService(OauthClient oauthClient, JwtTokenProvider jwtTokenProvider,
ChecklistManageService checklistManageService,
UserRepository userRepository,
CustomChecklistQuestionRepository customChecklistQuestionRepository) {
this.oauthClient = oauthClient;
this.jwtTokenProvider = jwtTokenProvider;
this.checklistService = checklistService;
this.checklistManageService = checklistManageService;
this.userRepository = userRepository;
this.customChecklistQuestionRepository = customChecklistQuestionRepository;
}
Expand Down Expand Up @@ -97,7 +98,8 @@ private void createDefaultChecklist(User user) {
new QuestionRequest(Question.BATHROOM_2.getId(), Answer.GOOD.name()));

ChecklistRequest checklistRequest = new ChecklistRequest(roomRequest, options, questionRequests);
checklistService.createChecklist(user, checklistRequest);
checklistManageService.createChecklist(user, checklistRequest);
//TODO: 로직 리팩토링 필요
}

public void logout(String accessToken, User user) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bang_ggood.auth.service;

import com.bang_ggood.exception.BangggoodException;
import com.bang_ggood.exception.ExceptionCode;
import com.bang_ggood.global.exception.BangggoodException;
import com.bang_ggood.global.exception.ExceptionCode;
import com.bang_ggood.user.domain.User;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
Expand Down
Loading

0 comments on commit f786743

Please sign in to comment.