Skip to content

Commit

Permalink
Merge pull request #124 from Kumoh-talk/feat/refactor-board-save
Browse files Browse the repository at this point in the history
패키지 구조 리팩터링 및 세미나 게시물 저장 로직 리팩터링
  • Loading branch information
kang20 authored Feb 24, 2025
2 parents a760508 + d3dc0f3 commit a50c42c
Show file tree
Hide file tree
Showing 107 changed files with 838 additions and 552 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.demo.domain.board.api;
package com.example.demo.application.board.api;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.demo.domain.board.api;
package com.example.demo.application.board.api;



Expand All @@ -10,14 +10,13 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import com.example.demo.domain.board.domain.dto.request.BoardCreateRequest;
import com.example.demo.domain.board.domain.dto.request.BoardUpdateRequest;
import com.example.demo.domain.board.domain.dto.response.BoardInfoResponse;
import com.example.demo.domain.board.domain.dto.response.BoardTitleInfoResponse;
import com.example.demo.domain.board.domain.dto.response.DraftBoardTitleResponse;
import com.example.demo.domain.board.domain.dto.vo.BoardType;

import com.example.demo.application.board.dto.request.BoardCreateRequest;
import com.example.demo.application.board.dto.request.BoardUpdateRequest;
import com.example.demo.application.board.dto.response.BoardInfoResponse;
import com.example.demo.application.board.dto.response.BoardTitleInfoResponse;
import com.example.demo.application.board.dto.response.DraftBoardTitleResponse;
import com.example.demo.application.board.dto.vo.BoardType;
import com.example.demo.global.base.dto.ResponseBody;
import com.example.demo.global.base.dto.page.GlobalPageResponse;
import com.example.demo.global.base.exception.ErrorCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.example.demo.domain.board.api;
package com.example.demo.application.board.api;


import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import com.example.demo.domain.board.domain.dto.request.FileRequest;
import com.example.demo.domain.board.domain.dto.request.PresignedUrlRequest;
import com.example.demo.application.board.dto.request.FileRequest;
import com.example.demo.application.board.dto.request.PresignedUrlRequest;
import com.example.demo.global.base.dto.ResponseBody;
import com.example.demo.global.base.exception.ErrorCode;
import com.example.demo.global.config.swagger.ApiErrorResponseExplanation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package com.example.demo.domain.board.api;

import static com.example.demo.global.base.dto.ResponseUtil.*;
package com.example.demo.application.board.api;

import java.util.List;

Expand All @@ -9,14 +7,11 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.example.demo.domain.board.domain.dto.response.BoardTitleInfoResponse;
import com.example.demo.application.board.dto.response.BoardTitleInfoResponse;
import com.example.demo.global.base.dto.ResponseBody;
import com.example.demo.global.base.dto.page.GlobalPageResponse;
import com.example.demo.global.base.exception.ErrorCode;
import com.example.demo.global.config.swagger.ApiErrorResponseExplanation;
import com.example.demo.global.config.swagger.ApiResponseExplanations;
import com.example.demo.global.config.swagger.ApiSuccessResponseExplanation;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package com.example.demo.domain.board.api;
package com.example.demo.application.board.api;


import static com.example.demo.global.base.dto.ResponseUtil.*;

import org.springdoc.core.annotations.ParameterObject;
import org.springdoc.core.converters.models.PageableAsQueryParam;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import com.example.demo.domain.board.domain.dto.response.BoardTitleInfoResponse;
import com.example.demo.global.aop.AssignUserId;
import com.example.demo.application.board.dto.response.BoardTitleInfoResponse;
import com.example.demo.global.base.dto.ResponseBody;
import com.example.demo.global.base.dto.page.GlobalPageResponse;
import com.example.demo.global.base.exception.ErrorCode;
Expand All @@ -25,7 +18,6 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;

public interface LikeApi {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.demo.domain.board.controller;
package com.example.demo.application.board.controller;

import static com.example.demo.global.base.dto.ResponseUtil.*;

Expand All @@ -9,7 +9,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.domain.board.api.AdminBoardApi;
import com.example.demo.application.board.api.AdminBoardApi;
import com.example.demo.domain.board.service.usecase.BoardAdminUseCase;
import com.example.demo.global.base.dto.ResponseBody;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.example.demo.domain.board.controller;
package com.example.demo.application.board.controller;


import static com.example.demo.global.base.dto.ResponseUtil.*;

import com.example.demo.domain.board.api.BoardApi;
import com.example.demo.domain.board.domain.dto.request.BoardCreateRequest;
import com.example.demo.domain.board.domain.dto.request.BoardUpdateRequest;
import com.example.demo.domain.board.domain.dto.response.BoardInfoResponse;
import com.example.demo.domain.board.domain.dto.response.BoardTitleInfoResponse;
import com.example.demo.domain.board.domain.dto.response.DraftBoardTitleResponse;
import com.example.demo.domain.board.domain.dto.vo.BoardType;
import com.example.demo.domain.board.service.usecase.BoardUseCase;
import com.example.demo.application.board.api.BoardApi;
import com.example.demo.application.board.dto.request.BoardCreateRequest;
import com.example.demo.application.board.dto.request.BoardUpdateRequest;
import com.example.demo.application.board.dto.response.BoardInfoResponse;
import com.example.demo.application.board.dto.response.BoardTitleInfoResponse;
import com.example.demo.application.board.dto.response.DraftBoardTitleResponse;
import com.example.demo.application.board.dto.vo.BoardType;
import com.example.demo.domain.board.service.entity.BoardInfo;
import com.example.demo.domain.board.service.usecase.BoardService;
import com.example.demo.global.aop.AssignUserId;
import com.example.demo.global.base.dto.ResponseBody;
import com.example.demo.global.base.dto.page.GlobalPageResponse;
Expand All @@ -29,14 +30,20 @@
@RequestMapping("/api")
@RequiredArgsConstructor
public class BoardController implements BoardApi {
private final BoardUseCase boardUsecase;
private final BoardService boardUsecase;

@AssignUserId
@PreAuthorize("hasRole('ROLE_SEMINAR_WRITER') and isAuthenticated()")
@PostMapping("/v1/boards")
public ResponseEntity<ResponseBody<BoardInfoResponse>> saveDraftSeminar(Long userId,
@RequestBody @Valid BoardCreateRequest boardCreateRequest) {
return ResponseEntity.ok(createSuccessResponse(boardUsecase.saveDraftBoard(userId, boardCreateRequest)));
@RequestBody @Valid BoardCreateRequest boardCreateRequest) {

return ResponseEntity.ok(createSuccessResponse(
BoardInfoResponse.of(
boardUsecase.saveDraftBoard(
userId,
boardCreateRequest.toBoardCore(),
boardCreateRequest.toBoardCategoryNames()))));
}

@GetMapping("/v1/boards/{boardId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.demo.domain.board.controller;
package com.example.demo.application.board.controller;

import static com.example.demo.global.base.dto.ResponseUtil.*;

Expand All @@ -13,9 +13,9 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.domain.board.api.BoardFileApi;
import com.example.demo.domain.board.domain.dto.request.FileRequest;
import com.example.demo.domain.board.domain.dto.request.PresignedUrlRequest;
import com.example.demo.application.board.api.BoardFileApi;
import com.example.demo.application.board.dto.request.FileRequest;
import com.example.demo.application.board.dto.request.PresignedUrlRequest;
import com.example.demo.domain.board.service.usecase.BoardFileUseCase;
import com.example.demo.global.aop.AssignUserId;
import com.example.demo.global.base.dto.ResponseBody;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.demo.domain.board.controller;
package com.example.demo.application.board.controller;

import static com.example.demo.global.base.dto.ResponseUtil.*;

Expand All @@ -13,8 +13,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.domain.board.api.CategoryApi;
import com.example.demo.domain.board.domain.dto.response.BoardTitleInfoResponse;
import com.example.demo.application.board.api.CategoryApi;
import com.example.demo.application.board.dto.response.BoardTitleInfoResponse;
import com.example.demo.domain.board.service.usecase.CategoryUseCase;
import com.example.demo.global.base.dto.ResponseBody;
import com.example.demo.global.base.dto.page.GlobalPageResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.demo.domain.board.controller;
package com.example.demo.application.board.controller;

import static com.example.demo.global.base.dto.ResponseUtil.*;

Expand All @@ -14,8 +14,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.domain.board.api.LikeApi;
import com.example.demo.domain.board.domain.dto.response.BoardTitleInfoResponse;
import com.example.demo.application.board.api.LikeApi;
import com.example.demo.application.board.dto.response.BoardTitleInfoResponse;
import com.example.demo.domain.board.service.usecase.LikeUseCase;
import com.example.demo.global.aop.AssignUserId;
import com.example.demo.global.base.dto.ResponseBody;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
package com.example.demo.domain.board.domain.dto.request;
package com.example.demo.application.board.dto.request;


import static com.example.demo.global.regex.S3UrlRegex.*;

import com.example.demo.domain.board.domain.dto.vo.BoardType;
import com.example.demo.application.board.dto.vo.BoardType;
import com.example.demo.domain.board.service.entity.BoardCategoryNames;
import com.example.demo.domain.board.service.entity.BoardCore;
import com.example.demo.global.aop.valid.ValidEnum;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.*;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@NoArgsConstructor
@Schema(description = "게시물 생성 요청")
public class BoardCreateRequest {
public record BoardCreateRequest (

@Schema(description = "게시물 제목", example = "게시물 제목")
@NotBlank(message = "제목은 필수 항목입니다.")
@Size(max = 50,message = "최대 제한 45글자 입니다.")
private String title;
String title,

@Schema(description = "게시물 내용", example = "게시물 내용")
@NotBlank(message = "게시물 내용은 필수 항목입니다.")
private String contents;
String contents,

@Schema(
description = "게시물 카테고리 이름 리스트",
example = "[\"카테고리1\", \"카테고리2\"]"
)
@Nullable
@Size(max = 5,message = "카테고리는 최대 5개까지 가능합니다.")
private List<String> categoryName;
List<String> categoryName,

@Schema(description = "게시물 태그", example = "SEMINAR")
@ValidEnum(enumClass = BoardType.class,message = "태그는 'SEMINAR', 'NOTICE' 중 하나여야 합니다.")
@NotNull(message = "태그는 필수 항목입니다.")
private BoardType boardType;
BoardType boardType,

@Schema(description = "게시물 대표 이미지 URL", example = "https://kumoh-talk-bucket.s3.ap-northeast-2.amazonaws.com/board/15/image/54599f59-1d5b-4167-b9f7-96f84d3c452d/example.jpg")
@NotBlank(message = "게시물 대표 이미지는 필수 항목입니다.")
@Pattern(regexp = S3_BOARD_FILE_URL)
private String boardHeadImageUrl;
String boardHeadImageUrl
){
public BoardCore toBoardCore(){
return new BoardCore(
this.title,
this.contents,
this.boardType,
this.boardHeadImageUrl
);
}

public BoardCategoryNames toBoardCategoryNames() {
return new BoardCategoryNames(
this.categoryName
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.demo.domain.board.domain.dto.request;
package com.example.demo.application.board.dto.request;

import static com.example.demo.global.regex.S3UrlRegex.*;

Expand Down Expand Up @@ -46,4 +46,5 @@ public class BoardUpdateRequest {
@NotBlank(message = "게시물 대표 이미지는 필수 항목입니다.")
@Pattern(regexp = S3_BOARD_FILE_URL)
private String boardHeadImageUrl;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.demo.domain.board.domain.dto.request;
package com.example.demo.application.board.dto.request;

import static com.example.demo.global.regex.S3UrlRegex.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.demo.domain.board.domain.dto.request;
package com.example.demo.application.board.dto.request;

import com.example.demo.domain.board.domain.dto.vo.FileType;
import com.example.demo.application.board.dto.vo.FileType;
import com.example.demo.global.aop.valid.ValidEnum;

import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.demo.domain.board.domain.dto.response;
package com.example.demo.application.board.dto.response;

import com.example.demo.domain.board.domain.entity.Board;
import com.example.demo.domain.board.service.entity.BoardInfo;
import com.example.demo.infra.board.entity.Board;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
Expand Down Expand Up @@ -42,12 +43,12 @@ public class BoardInfoResponse {
private final LocalDateTime createdAt;

@Builder
public BoardInfoResponse(Long boardId, String username, String title, String contents, String tag, String status, Long view, Long like, List<String> categoryNames,String boardHeadImageUrl, LocalDateTime updatedAt, LocalDateTime createdAt) {
public BoardInfoResponse(Long boardId, String username, String title, String contents, String boardType, String status, Long view, Long like, List<String> categoryNames,String boardHeadImageUrl, LocalDateTime updatedAt, LocalDateTime createdAt) {
this.boardId = boardId;
this.username = username;
this.title = title;
this.contents = contents;
this.boardType = tag;
this.boardType = boardType;
this.status = status;
this.view = view;
this.like = like;
Expand All @@ -63,7 +64,7 @@ public static BoardInfoResponse from(Board board, String username, Long like, L
.username(username)
.title(board.getTitle())
.contents(board.getContent())
.tag(board.getBoardType().name())
.boardType(board.getBoardType().name())
.status(board.getStatus().name())
.view(board.getViewCount())
.like(like)
Expand All @@ -74,4 +75,20 @@ public static BoardInfoResponse from(Board board, String username, Long like, L
.build();
}

public static BoardInfoResponse of(BoardInfo boardInfo) {
return BoardInfoResponse.builder()
.boardId(boardInfo.getBoardId())
.username(boardInfo.getUserTarget().getNickName())
.title(boardInfo.getBoardCore().getTitle())
.contents(boardInfo.getBoardCore().getContents())
.boardType(boardInfo.getBoardCore().getBoardType().toString())
.status(boardInfo.getBoardCore().getBoardStatus().toString())
.view(boardInfo.getViewCount())
.like(boardInfo.getLikeCount())
.categoryNames(boardInfo.getBoardCategoryNames().getCategories())
.boardHeadImageUrl(boardInfo.getBoardCore().getBoardHeadImageUrl())
.createdAt(boardInfo.getCreatedAt())
.updatedAt(boardInfo.getUpdatedAt())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.demo.domain.board.domain.dto.response;
package com.example.demo.application.board.dto.response;

import java.time.LocalDateTime;

import com.example.demo.domain.board.domain.dto.vo.BoardType;
import com.example.demo.application.board.dto.vo.BoardType;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.demo.domain.board.domain.dto.response;
package com.example.demo.application.board.dto.response;

import java.time.LocalDateTime;

Expand Down
Loading

0 comments on commit a50c42c

Please sign in to comment.