Skip to content

Commit

Permalink
style: import 최적화 및 코드 컨벤션 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
J-1ac committed Nov 9, 2024
1 parent 14dd026 commit 41744d7
Show file tree
Hide file tree
Showing 162 changed files with 2,309 additions and 764 deletions.
2 changes: 1 addition & 1 deletion boomerang/src/main/http/Comments.http
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Content-Type: application/json
Cookie: Authorization=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiZW1haWwiOiJrYWthbzM3Mjk0MzgwNTIiLCJpYXQiOjE3Mjc5MzM4MjcsImV4cCI6MjQxNzI3OTMzODI3fQ.LvKK8vbExt91eIqU-rfsdvYE0JqC1MUlsK7gdRE72co

{
"text": "댓글수정!"
"text": "댓글수정!"
}

### delete comments
Expand Down
4 changes: 2 additions & 2 deletions boomerang/src/main/http/Login.http
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ POST http://localhost:8080/api/v1/auth/login/kakao
Content-Type: application/json

{
"access_token":"9WfcdG_SdMnU2oM_GuhKNXCDLrfoN4LIAAAAAQopyWAAAAGTBlsa1OiSikwhugC4"
"access_token": "9WfcdG_SdMnU2oM_GuhKNXCDLrfoN4LIAAAAAQopyWAAAAGTBlsa1OiSikwhugC4"
}


Expand All @@ -15,5 +15,5 @@ Content-Type: application/json
Authorization: {{Authorization}}

{
"new_nickname":"aaa"
"new_nickname": "aaa"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package boomerang.board.controller;

import boomerang.board.domain.Board;
import boomerang.board.dto.*;
import boomerang.board.dto.BoardBestListRequestDto;
import boomerang.board.dto.BoardDetailResponseDto;
import boomerang.board.dto.BoardListRequestDto;
import boomerang.board.dto.BoardRequestDto;
import boomerang.board.dto.BoardResponseDto;
import boomerang.board.dto.BoardSimpleResponseDto;
import boomerang.board.service.BoardService;
import boomerang.comment.dto.CommentListRequestDto;
import boomerang.comment.dto.CommentResponseDto;
Expand All @@ -14,17 +19,26 @@
import boomerang.like.service.LikeService;
import boomerang.member.domain.Member;
import boomerang.member.service.MemberService;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


@Slf4j
@RestController
Expand All @@ -37,8 +51,8 @@ public class BoardController {
private final LikeService likeService;

public BoardController(BoardService boardService, MemberService memberService,
CommentService commentService,
LikeService likeService) {
CommentService commentService,
LikeService likeService) {
this.boardService = boardService;
this.memberService = memberService;
this.commentService = commentService;
Expand All @@ -47,35 +61,35 @@ public BoardController(BoardService boardService, MemberService memberService,

@GetMapping("/best")
public ResponseEntity<PageResponseDto<BoardResponseDto>> getBestBoards(
@ModelAttribute BoardBestListRequestDto boardBestListRequestDto) {
@ModelAttribute BoardBestListRequestDto boardBestListRequestDto) {

Page<Board> boardPage = boardService.getBestBoards(boardBestListRequestDto);
Page<BoardResponseDto> boardResponsePage = boardPage.map(BoardResponseDto::new);

return ResponseEntity.status(HttpStatus.OK)
.body(new PageResponseDto<>(boardResponsePage));
.body(new PageResponseDto<>(boardResponsePage));
}

@GetMapping
public ResponseEntity<PageResponseDto<BoardResponseDto>> getAllBoards(
@ModelAttribute BoardListRequestDto boardListRequestDto) {
@ModelAttribute BoardListRequestDto boardListRequestDto) {

Page<Board> boardPage = boardService.getAllBoards(boardListRequestDto);
Page<BoardResponseDto> boardResponsePage = boardPage.map(BoardResponseDto::new);

return ResponseEntity.status(HttpStatus.OK)
.body(new PageResponseDto<>(boardResponsePage));
.body(new PageResponseDto<>(boardResponsePage));
}

@GetMapping("/{board_id}")
public ResponseEntity<BoardDetailResponseDto> getBoardById(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable(name = "board_id") Long boardId) {
@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable(name = "board_id") Long boardId) {

Board board = boardService.getBoard(boardId);
PageResponseDto<CommentResponseDto> commentListResponseDto = new PageResponseDto<>(
commentService.getAllComment(boardId, new CommentListRequestDto())
.map(CommentResponseDto::new));
commentService.getAllComment(boardId, new CommentListRequestDto())
.map(CommentResponseDto::new));

boolean isLiked = false;

Expand All @@ -85,59 +99,59 @@ public ResponseEntity<BoardDetailResponseDto> getBoardById(
}

return ResponseEntity.status(HttpStatus.OK)
.body(new BoardDetailResponseDto(board, commentListResponseDto, isLiked));
.body(new BoardDetailResponseDto(board, commentListResponseDto, isLiked));
}

@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<BoardSimpleResponseDto> createBoard(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestPart("data") BoardRequestDto boardRequestDto,
@RequestParam("content") String content,
@RequestParam(value = "images", required = false) List<MultipartFile> images
@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestPart("data") BoardRequestDto boardRequestDto,
@RequestParam("content") String content,
@RequestParam(value = "images", required = false) List<MultipartFile> images
) {
Member member = memberService.getMemberByEmail(principalDetails.getMemberEmail());

boardRequestDto.setContent(content);
Board createdBoard = boardService.createBoard(boardRequestDto, member, images);

return ResponseEntity.status(HttpStatus.CREATED)
.body(new BoardSimpleResponseDto(createdBoard, false));
.body(new BoardSimpleResponseDto(createdBoard, false));
}

@PutMapping("/{board_id}")
public ResponseEntity<BoardSimpleResponseDto> updateBoard(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable(name = "board_id") Long boardId,
@RequestPart("data") BoardRequestDto boardRequestDto,
@RequestParam("content") String content,
@RequestParam(value = "images", required = false) List<MultipartFile> images
@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable(name = "board_id") Long boardId,
@RequestPart("data") BoardRequestDto boardRequestDto,
@RequestParam("content") String content,
@RequestParam(value = "images", required = false) List<MultipartFile> images
) {
Member member = memberService.getMemberByEmail(principalDetails.getMemberEmail());

boardRequestDto.setContent(content);
Board updatedBoard = boardService.updateBoard(boardId, boardRequestDto, member, images);

return ResponseEntity.status(HttpStatus.CREATED)
.body(new BoardSimpleResponseDto(updatedBoard, false));
.body(new BoardSimpleResponseDto(updatedBoard, false));
}

@DeleteMapping("/{board_id}")
public ResponseEntity<Void> deleteBoard(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable(name = "board_id") Long boardId) {
@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable(name = "board_id") Long boardId) {

Member member = memberService.getMemberByEmail(principalDetails.getMemberEmail());
boardService.deleteBoard(member, boardId);
return ResponseEntity.status(HttpStatus.OK)
.build();
.build();
}

// GlobalException Handler 에서 처리할 경우,
// RequestBody에서 발생한 에러가 HttpMessageNotReadableException 로 Wrapping 이 되는 문제가 발생한다
// 때문에, 해당 에러로 Wrapping 되기 전 Controller 에서 Domain Error 를 처리해주었다
@ExceptionHandler(DomainValidationException.class)
public ResponseEntity<ErrorResponseDto> handleOptionValidException(
DomainValidationException e) {
DomainValidationException e) {
log.error(e.toString());
return ResponseHelper.createErrorResponse(e.getErrorCode());
}
Expand Down
30 changes: 20 additions & 10 deletions boomerang/src/main/java/boomerang/board/domain/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@

import boomerang.IsDeleted;
import boomerang.board.dto.BoardRequestDto;
import boomerang.comment.domain.Comment;
import boomerang.like.domain.Like;
import boomerang.member.domain.Member;
import jakarta.persistence.*;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import java.util.Objects;
import lombok.Getter;
import org.hibernate.Hibernate;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.jsoup.Jsoup;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Getter
@Entity
@Table(name = "board")
public class Board {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand Down Expand Up @@ -132,9 +139,12 @@ public void decreaseCommentCount() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o))
if (this == o) {
return true;
}
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
return false;
}
Board item = (Board) o;
return Objects.equals(id, item.id);
}
Expand Down
10 changes: 7 additions & 3 deletions boomerang/src/main/java/boomerang/board/domain/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.fasterxml.jackson.annotation.JsonValue;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;

import java.util.Objects;

@Embeddable
public class Location {

@Column(name = "location")
private String value;

Expand All @@ -32,8 +32,12 @@ public String toString() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Location that = (Location) o;
return Objects.equals(value, that.value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)은
// JSON 요청 바디에서의 직렬화/역직렬화에만 적용된다. 때문에 직접 필드명을 json 형태로 선언해주었다
public class BoardBestListRequestDto {

@Min(0)
private int size = 10;
private BoardType board_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Getter;

import java.time.LocalDateTime;
import lombok.Getter;

@Getter
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class BoardDetailResponseDto {

private Long id;
private String title;
private String content;
Expand All @@ -30,7 +30,8 @@ public class BoardDetailResponseDto {


// Board 도메인 객체를 받아서 BoardResponseDto를 생성하는 생성자
public BoardDetailResponseDto(Board board, PageResponseDto<CommentResponseDto> commentListResponseDto, boolean isLiked) {
public BoardDetailResponseDto(Board board,
PageResponseDto<CommentResponseDto> commentListResponseDto, boolean isLiked) {
this.id = board.getId();
this.title = board.getTitle();
this.content = board.getContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)은
// JSON 요청 바디에서의 직렬화/역직렬화에만 적용된다. 때문에 직접 필드명을 json 형태로 선언해주었다
public class BoardListRequestDto {

@Min(0)
private int page = 0;
@Min(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
@Getter
@EqualsAndHashCode
public class BoardRequestDto {

private String title;
private String content;
private BoardType board_type;
private Location location;

public BoardRequestDto() {}
public BoardRequestDto() {
}

// 생성자
public BoardRequestDto(String title, String content, BoardType board_type, Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@Getter
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class BoardResponseDto {

private Long id;
private String title;
private String summary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@Getter
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class BoardSimpleResponseDto {

private Long id;
private String title;
private String content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.time.LocalDateTime;

public interface BoardRepository extends JpaRepository<Board, Long> {

@Query("SELECT b FROM Board b WHERE b.boardType = :boardType AND " +
"(:searchWord IS NULL OR :searchWord = '' OR b.title LIKE %:searchWord%)")
"(:searchWord IS NULL OR :searchWord = '' OR b.title LIKE %:searchWord%)")
Page<Board> findByBoardTypeAndTitleContaining(@Param("boardType") BoardType boardType,
@Param("searchWord") String searchWord,
Pageable pageable);
@Param("searchWord") String searchWord,
Pageable pageable);

Page<Board> findByBoardType(BoardType boardType, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import boomerang.board.domain.Board;
import boomerang.board.repository.BoardRepository;
import jakarta.transaction.Transactional;
import java.util.List;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreScheduler {

Expand Down
Loading

0 comments on commit 41744d7

Please sign in to comment.