Skip to content

Commit

Permalink
Merge pull request #80 from dailylifev1/dm
Browse files Browse the repository at this point in the history
#79 DAILYLIFE2-26 by dm
  • Loading branch information
shihhhdm310 authored Aug 3, 2022
2 parents dd972cf + e3dc3d0 commit faa1255
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dailylife.domain.board.controller;

import com.dailylife.domain.board.dto.BoardCreateRequest;
import com.dailylife.domain.board.dto.BoardCreateResponse;
import com.dailylife.domain.board.dto.BoardPagination;
import com.dailylife.domain.board.dto.BoardUpdateRequest;
import com.dailylife.domain.board.entity.Board;
Expand All @@ -16,6 +17,7 @@

import javax.validation.Valid;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
Expand All @@ -28,7 +30,7 @@ public class BoardController {

@ApiOperation(value = "게시물 업로드", notes = "게시물 업로드 완료")
@PostMapping("/create")
public ResponseEntity<Board> createBoard(@Valid @ModelAttribute BoardCreateRequest boardCreateRequest) throws IOException {
public ResponseEntity<BoardCreateResponse> createBoard(@Valid @ModelAttribute BoardCreateRequest boardCreateRequest) throws IOException {
return ResponseEntity.ok(boardService.create(boardCreateRequest));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.dailylife.domain.board.dto;


import com.dailylife.domain.board.entity.Board;
import io.swagger.annotations.ApiModel;
import lombok.*;

import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "게시물 작성시 응답 객체 ")
@Builder
public class BoardCreateResponse {

private String title;
private String content;
private List<String> originalFileName;

public static BoardCreateResponse from(Board board , List<String> originalFileName) {
return BoardCreateResponse.builder()
.title(board.getTitle())
.content(board.getContent())
.originalFileName(originalFileName).build();
}

}
1 change: 0 additions & 1 deletion src/main/java/com/dailylife/domain/board/entity/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class Board {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long boardNum;

private String title;
private String content;
private String userNickName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.dailylife.domain.board.service;

import com.dailylife.domain.board.dto.BoardCreateRequest;
import com.dailylife.domain.board.dto.BoardDeleteRequest;
import com.dailylife.domain.board.dto.BoardPagination;
import com.dailylife.domain.board.dto.BoardUpdateRequest;
import com.dailylife.domain.board.dto.*;
import com.dailylife.domain.board.entity.Board;

import java.io.IOException;
import java.util.List;

public interface BoardService {

Board create(BoardCreateRequest boardCreateRequest) throws IOException;
BoardCreateResponse create(BoardCreateRequest boardCreateRequest) throws IOException;

Board update(BoardCreateRequest boardCreateRequest, Long boardNum) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.dailylife.domain.board.service;

import com.dailylife.domain.board.dto.BoardCreateRequest;
import com.dailylife.domain.board.dto.BoardDeleteRequest;
import com.dailylife.domain.board.dto.BoardPagination;
import com.dailylife.domain.board.dto.BoardUpdateRequest;
import com.dailylife.domain.board.dto.*;
import com.dailylife.domain.board.entity.Board;
import com.dailylife.domain.board.repository.BoardPaginationRepository;
import com.dailylife.domain.board.repository.BoardRepository;
Expand All @@ -19,9 +16,11 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.swing.text.html.parser.Entity;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Slf4j
Expand All @@ -34,20 +33,24 @@ public class BoardServiceImpl implements BoardService{
private final ImageRepository imageRepository;
private final MultiUpload multiUpload;
private final ImageRemove imageRemove;

private final BoardPaginationRepository paginationRepository;

@Override
@Transactional
public Board create(BoardCreateRequest boardCreateRequest) throws IOException {
public BoardCreateResponse create(BoardCreateRequest boardCreateRequest) throws IOException {
List<String> originalFileName = new ArrayList<>();
Board board = boardRepository.save(Board.toEntity(boardCreateRequest, userRepository.findByUserId(jwtService.getLoginId())));
if(boardCreateRequest.getImageName() != null) {
List<String> images = multiUpload.FileUpload(boardCreateRequest.getImageName());
for (MultipartFile file : boardCreateRequest.getImageName()) {
originalFileName.add(file.getOriginalFilename());
}
List<String> images = multiUpload.FileUpload(boardCreateRequest.getImageName());
for (String fileName : images) {

imageRepository.save(Image.toEntity(fileName, board));
}
}
return board;
return BoardCreateResponse.from(board , originalFileName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class JwtInterceptor implements HandlerInterceptor {

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

System.out.println("request.getRequestURI() => "+ request.getRequestURI());

if(request.getMethod().equals("OPTIONS")) {
return true;
}
jwtService.getLoginId();
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/dailylife/global/web/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void addInterceptors(InterceptorRegistry registry) {
"/api/users/loginTest"
,"/error");


}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/jpashop?useUnicode=yes&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Seoul
username: sa
password: km971gb5!!
url: jdbc:mysql://146.56.39.196:3306/dailylife?useUnicode=yes&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Seoul
username: dailylife
password: 1234

mvc:
pathmatch:
Expand Down

0 comments on commit faa1255

Please sign in to comment.