Skip to content

Commit

Permalink
Merge pull request #43 from dear-santa/feature/create
Browse files Browse the repository at this point in the history
fix: 게시물 작성 카테고리 별 작성
  • Loading branch information
skybluelion authored Dec 14, 2023
2 parents d3037b2 + 5b94c65 commit 1b76641
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 30 deletions.
21 changes: 9 additions & 12 deletions src/main/java/com/dearsanta/app/controller/BoardController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.dearsanta.app.controller;

import com.dearsanta.app.domain.enumtype.Sorted;
import com.dearsanta.app.dto.BoardDto;
import com.dearsanta.app.dto.BoardLikeDto;
import com.dearsanta.app.dto.BoardRequestDto;
import com.dearsanta.app.dto.BoardListDto;
import com.dearsanta.app.dto.*;
import com.dearsanta.app.service.BoardService;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,24 +25,24 @@ public class BoardController {

@PostMapping(value="auth/board/new", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Void> createBoard(
@RequestPart("boardRequestDto") BoardRequestDto boardRequestDto,
@RequestPart("boardCreateRequestDto") BoardCreateRequestDto boardCreateRequestDto,
@RequestPart("boardImage") MultipartFile boardImage) {
log.info(boardRequestDto.getTitle() + boardRequestDto.getContent() + boardImage);
log.info(boardCreateRequestDto.getTitle() + boardCreateRequestDto.getContent() + boardImage);
String memberId = (String) RequestContextHolder
.currentRequestAttributes().getAttribute("memberId", RequestAttributes.SCOPE_REQUEST);
if (memberId == null) {
throw new RuntimeException("권한이 없습니다.");
}
if (boardRequestDto.getTitle().length() > 100) {
if (boardCreateRequestDto.getTitle().length() > 100) {
throw new IllegalArgumentException("제목은 100자 이하로 입력해주세요.");
}
if (boardRequestDto.getContent().length() > 1000) {
if (boardCreateRequestDto.getContent().length() > 1000) {
throw new IllegalArgumentException("내용은 1000자 이하로 입력해주세요.");
}

boardRequestDto.setMemberId(memberId);

boardService.createBoard(boardRequestDto, boardImage);
String boardCategoryId = boardService.findBoardCategoryId(boardCreateRequestDto.getMainCategory(), boardCreateRequestDto.getSubCategory());
boardCreateRequestDto.setMemberId(memberId);
boardCreateRequestDto.setBoardCategoryId(boardCategoryId);
boardService.createBoard(boardCreateRequestDto, boardImage);

return ResponseEntity.ok().build();
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/dearsanta/app/domain/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class Board {
private Date updatedDate;
private String memberId;
private String imgUrl;
private String mainCategory;
private String subCategory;
private int likeCount;
private int replyCount;
private int viewCount;
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/dearsanta/app/dto/BoardCreateRequestDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.dearsanta.app.dto;

import com.dearsanta.app.domain.Board;
import lombok.*;

@Getter
@Setter
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class BoardCreateRequestDto {
private String id;
private String boardCategoryId;
private String title;
private String content;
private String memberId;
private String imgUrl;
private String mainCategory;
private String subCategory;
public Board toEntity() {
return Board.builder()
.id(id)
.boardCategoryId(boardCategoryId)
.title(title)
.content(content)
.memberId(memberId)
.imgUrl(imgUrl)
.mainCategory(mainCategory)
.subCategory(subCategory)
.build();
}
}
7 changes: 2 additions & 5 deletions src/main/java/com/dearsanta/app/service/BoardService.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.dearsanta.app.service;

import com.dearsanta.app.domain.enumtype.Sorted;
import com.dearsanta.app.dto.BoardDto;
import com.dearsanta.app.dto.BoardLikeDto;
import com.dearsanta.app.dto.BoardListDto;
import com.dearsanta.app.dto.BoardRequestDto;
import com.dearsanta.app.dto.*;
import org.springframework.web.multipart.MultipartFile;

public interface BoardService {
void createBoard(BoardRequestDto boardRequestDto, MultipartFile boardImage);
void createBoard(BoardCreateRequestDto boardCreateRequestDto, MultipartFile boardImage);
BoardDto getBoard(String boardId);
void updateBoard(String boardId, BoardRequestDto boardRequestDto, MultipartFile boardImage);
void deleteBoard(String boardId);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/dearsanta/app/service/BoardServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public String findBoardCategoryId(String mainCategory, String subCategory) {
}

@Override
public void createBoard(BoardRequestDto boardRequestDto, MultipartFile boardImage) {
boardRequestDto.setId(UUID.randomUUID().toString());
public void createBoard(BoardCreateRequestDto boardCreateRequestDto, MultipartFile boardImage) {
boardCreateRequestDto.setId(UUID.randomUUID().toString());

if (boardImage != null) {
String imgUrl = aWSS3.uploadImage(boardRequestDto.getId(), boardImage);
boardRequestDto.setImgUrl(imgUrl);
String imgUrl = aWSS3.uploadImage(boardCreateRequestDto.getId(), boardImage);
boardCreateRequestDto.setImgUrl(imgUrl);
}
Board board = boardRequestDto.toEntity();
Board board = boardCreateRequestDto.toEntity();

boardMapper.createBoard(board);
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
title,
content,
member_id,
img_url
img_url,
main_category,
sub_category
) VALUES (
#{id, jdbcType=VARCHAR},
#{boardCategoryId, jdbcType=VARCHAR},
#{title, jdbcType=VARCHAR},
#{content, jdbcType=VARCHAR},
#{memberId, jdbcType=VARCHAR},
#{imgUrl, jdbcType=VARCHAR}
#{imgUrl, jdbcType=VARCHAR},
#{mainCategory, jdbcType=VARCHAR},
#{subCategory, jdbcType=VARCHAR}
)
</insert>
<select id="getBoard" resultType="com.dearsanta.app.dto.BoardDto">
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/com/dearsanta/app/service/BoardServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.dearsanta.app.service;

import com.dearsanta.app.domain.enumtype.Sorted;
import com.dearsanta.app.dto.BoardDto;
import com.dearsanta.app.dto.BoardLikeDto;
import com.dearsanta.app.dto.BoardListDto;
import com.dearsanta.app.dto.BoardRequestDto;
import com.dearsanta.app.dto.*;
import lombok.extern.log4j.Log4j;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -91,13 +88,13 @@ public void createBoard() {
String title = "제목";
String content = "내용";
String memberId = "test member";
BoardRequestDto boardRequestDto = BoardRequestDto.builder()
BoardCreateRequestDto boardCreateRequestDto = BoardCreateRequestDto.builder()
.boardCategoryId(boardCategoryId)
.title(title)
.content(content)
.memberId(memberId)
.build();
boardService.createBoard(boardRequestDto, null);
boardService.createBoard(boardCreateRequestDto, null);
}

@DisplayName("게시물을 상세조회합니다. 게시글이 존재할 경우")
Expand Down

0 comments on commit 1b76641

Please sign in to comment.