diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..36d4cc4
Binary files /dev/null and b/.DS_Store differ
diff --git a/.gradle/8.1.1/executionHistory/executionHistory.lock b/.gradle/8.1.1/executionHistory/executionHistory.lock
index 1edfd7e..582608f 100644
Binary files a/.gradle/8.1.1/executionHistory/executionHistory.lock and b/.gradle/8.1.1/executionHistory/executionHistory.lock differ
diff --git a/.gradle/8.1.1/fileHashes/fileHashes.lock b/.gradle/8.1.1/fileHashes/fileHashes.lock
index d9a1ec5..f96e3fd 100644
Binary files a/.gradle/8.1.1/fileHashes/fileHashes.lock and b/.gradle/8.1.1/fileHashes/fileHashes.lock differ
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
index b02c4fb..b2275d1 100644
Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 859c9b3..327925f 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -14,7 +14,6 @@
-
diff --git a/out/production/resources/application.yml b/out/production/resources/application.yml
index 04772a2..a68b00e 100644
--- a/out/production/resources/application.yml
+++ b/out/production/resources/application.yml
@@ -3,12 +3,6 @@ logging:
com.example.carrotmarket: debug
org.hibernate.SQL: debug
-spring:
- jpa:
- properties:
- hibernate:
- format_sql: true
- show_sql: true
---
# Settings for local
spring:
@@ -18,4 +12,11 @@ spring:
password: qwe335577!
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
- hibernate.ddl-auto: update
\ No newline at end of file
+ hibernate.ddl-auto: update
+ properties:
+ hibernate:
+ format_sql: true
+ show_sql: true
+ jwt:
+ secret-key: 6B64DCA4EA2F53EDIKU9AAB215FE7
+
diff --git a/src/.DS_Store b/src/.DS_Store
new file mode 100644
index 0000000..bf31819
Binary files /dev/null and b/src/.DS_Store differ
diff --git a/src/main/.DS_Store b/src/main/.DS_Store
new file mode 100644
index 0000000..e9581f0
Binary files /dev/null and b/src/main/.DS_Store differ
diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/accountBookSharingController.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/accountBookSharingController.java
index 67d39ea..799d1b8 100644
--- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/accountBookSharingController.java
+++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/accountBookSharingController.java
@@ -8,6 +8,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@@ -22,18 +23,16 @@ public class accountBookSharingController {
/*
* [가계부 공유] 게시글 검색
* @param keyword
- * @param pageable
*
* @param pageable
* size : 페이지 사이즈
* page : 페이지
* sortBy : 정렬순
- * - like
+ * - likes
* - createdAt
*/
@GetMapping("/search")
-
public ResponseEntity> searchAll(@RequestParam("keyword") String keyword, @RequestParam("category") int category, Pageable pageable) {
log.info("searching : " + keyword + category);
List res = accountBookSharingService.searchByKeyword(keyword, category, pageable);
@@ -43,14 +42,14 @@ public ResponseEntity> searchAll(@RequestParam("keyword") String keyword, @Req
/*
* [가계부 공유] 게시글 등록
-
*
* @param RequestDto
*/
-
@PostMapping("")
- public ResponseEntity> createPost(@RequestBody SharingDto.Request req) {
- accountBookSharingService.createPost(req);
+ public ResponseEntity> createPost(@RequestPart SharingDto.Request req,
+ @RequestPart(value = "file", required = false) List files) {
+ log.info("req open");
+ accountBookSharingService.createPost(req, files);
return new ResponseEntity<>(HttpStatus.OK);
}
diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/SharingDto.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/SharingDto.java
index dcacacd..0f0b9c4 100644
--- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/SharingDto.java
+++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/SharingDto.java
@@ -26,7 +26,6 @@ public static class Request {
private String content;
- private List images;
public SharingBoard toEntity(User user) {
return SharingBoard.builder()
diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingBoardRepository.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingBoardRepository.java
index 44692ff..f8828e0 100644
--- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingBoardRepository.java
+++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingBoardRepository.java
@@ -33,7 +33,7 @@ public interface SharingBoardRepository extends JpaRepository
// }
- @Query(value = "SELECT sharing_board.*, COUNT(sharing_sympathy.sharing_board_id) AS cnt FROM sharing_board\n" +
+ @Query(value = "SELECT sharing_board.*, COUNT(sharing_sympathy.sharing_board_id) AS likes FROM sharing_board\n" +
"LEFT JOIN sharing_sympathy ON sharing_board.sharing_board_id = sharing_sympathy.sharing_board_id\n" +
"WHERE (sharing_board.title LIKE %:keyword% OR sharing_board.content LIKE %:keyword%)\n" +
"AND sharing_board.category = :category GROUP BY sharing_board.sharing_board_id ", nativeQuery = true)
diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingService.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingService.java
index e85afc6..2d9bc9b 100644
--- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingService.java
+++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingService.java
@@ -2,6 +2,7 @@
import com.umc.DongnaeFriend.domain.account.sharing.dto.SharingDto;
import org.springframework.data.domain.Pageable;
+import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@@ -9,7 +10,7 @@ public interface AccountBookSharingService {
List searchByKeyword(String keyword, int category, Pageable pageable);
- void createPost(SharingDto.Request req);
+ void createPost(SharingDto.Request req, List files);
/*
* [가계부 공유] 게시글 상세 조회
diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingServiceImpl.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingServiceImpl.java
index 01e836a..58f7d9c 100644
--- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingServiceImpl.java
+++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingServiceImpl.java
@@ -8,6 +8,7 @@
import com.umc.DongnaeFriend.domain.account.sharing.repository.SharingImgRepository;
import com.umc.DongnaeFriend.domain.account.sharing.repository.SharingSympathyRepository;
import com.umc.DongnaeFriend.domain.dongnae.entity.Dongnae;
+import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeImg;
import com.umc.DongnaeFriend.domain.type.Age;
import com.umc.DongnaeFriend.domain.type.Gender;
import com.umc.DongnaeFriend.domain.type.SharingCategory;
@@ -15,11 +16,15 @@
import com.umc.DongnaeFriend.domain.user.entity.User;
import com.umc.DongnaeFriend.global.exception.CustomException;
import com.umc.DongnaeFriend.global.exception.ErrorCode;
+import com.umc.DongnaeFriend.global.util.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+import java.io.File;
+import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -59,17 +64,37 @@ public List searchByKeyword(String keyword, int categor
if (sharingBoards.isEmpty()) {
throw new CustomException(ErrorCode.NO_CONTENT_FOUND);
}
- log.info("board found" + sharingBoards.get(0).getId());
return getListResponses(sharingBoards);
}
+
/*
* [가계부 공유] 게시글 등록
*/
@Override
- public void createPost(SharingDto.Request req) {
- sharingBoardRepository.save(req.toEntity(user));
- //TODO : Img 파일 업로드
+ public void createPost(SharingDto.Request req, List files) {
+ SharingBoard board = sharingBoardRepository.save(req.toEntity(user));
+ log.info("파일 검사");
+
+ if (files == null) {
+ return;
+ }
+ log.info("파일 인식");
+
+ for (int i = 0; i < files.size(); i++) {
+ String fileName = "SharingBoard_" + board.getId().toString() + "_" + i + ".png";
+ try {
+ FileUtil.fileUpload(files.get(i),fileName );
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ sharingImgRepository.save(
+ SharingImg.builder()
+ .sharingBoard(board)
+ .imageUrl(fileName)
+ .build()
+ );
+ }
}
diff --git a/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardService.java b/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardService.java
index 8f1c978..aa72049 100644
--- a/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardService.java
+++ b/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardService.java
@@ -2,6 +2,7 @@
import com.umc.DongnaeFriend.domain.dongnae.dto.DongnaeBoardDto;
import com.umc.DongnaeFriend.domain.dongnae.dto.UserLocationDto;
+import org.springframework.web.multipart.MultipartFile;
import javax.naming.AuthenticationException;
import java.util.List;
@@ -12,12 +13,16 @@ public interface DongnaeBoardService {
List searchAll(int sort);
- void createBoard(DongnaeBoardDto.Request req);
-
List home(int category);
UserLocationDto getUserLocation();
+
+ /*
+ * [동네정보] 게시글 등록
+ */
+ void createBoard(DongnaeBoardDto.Request req);
+
DongnaeBoardDto.Response getBoard(long board_id);
void updateBoard(long board_id, DongnaeBoardDto.Request request) throws AuthenticationException;
diff --git a/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardServiceImpl.java b/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardServiceImpl.java
index 8ae14e8..5e984b8 100644
--- a/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardServiceImpl.java
+++ b/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardServiceImpl.java
@@ -118,8 +118,7 @@ public List searchAll(int sort) {
*/
@Override
public void createBoard(DongnaeBoardDto.Request req) {
- //TODO : User Mapping UserRepository 필요.
- dongnaeBoardRepository.save(req.toEntity(user, dongnae));
+ DongnaeBoard board= dongnaeBoardRepository.save(req.toEntity(user, dongnae));
}
diff --git a/src/main/java/com/umc/DongnaeFriend/global/exception/GlobalExceptionHandler.java b/src/main/java/com/umc/DongnaeFriend/global/exception/GlobalExceptionHandler.java
index 986c73d..eeb9b7c 100644
--- a/src/main/java/com/umc/DongnaeFriend/global/exception/GlobalExceptionHandler.java
+++ b/src/main/java/com/umc/DongnaeFriend/global/exception/GlobalExceptionHandler.java
@@ -14,8 +14,8 @@ public class GlobalExceptionHandler {
@ExceptionHandler({CustomException.class})
protected ResponseEntity> handlecustomException(CustomException e) {
return ResponseEntity
- .status(e.getErrorCode().getHttpStatus())
- .body(new ErrorResponse(e));
+ .status(e.getErrorCode().getHttpStatus())
+ .body(new ErrorResponse(e));
}
//@valid Exception
@@ -25,16 +25,17 @@ protected ResponseEntity> handleMethodArgumentNotValidException(MethodArgument
CustomException validException = new CustomException(INVALID_VALUE, message);
return ResponseEntity
- .status(HttpStatus.BAD_REQUEST)
- .body(new ErrorResponse(validException));
+ .status(HttpStatus.BAD_REQUEST)
+ .body(new ErrorResponse(validException));
}
+}
//일반 예외처리
- @ExceptionHandler({Exception.class})
- protected ResponseEntity> handleServerException(Exception ex) {
- CustomException exception = new CustomException(SERVER_ERROR);
- return ResponseEntity
- .status(SERVER_ERROR.getHttpStatus())
- .body(new ErrorResponse(exception));
- }
-}
\ No newline at end of file
+// @ExceptionHandler({Exception.class})
+// protected ResponseEntity> handleServerException(Exception ex) {
+// CustomException exception = new CustomException(SERVER_ERROR);
+// return ResponseEntity
+// .status(SERVER_ERROR.getHttpStatus())
+// .body(new ErrorResponse(exception));
+// }
+//}
\ No newline at end of file
diff --git a/src/main/java/com/umc/DongnaeFriend/global/util/FileUtil.java b/src/main/java/com/umc/DongnaeFriend/global/util/FileUtil.java
index 5f72d7a..ae7a68e 100644
--- a/src/main/java/com/umc/DongnaeFriend/global/util/FileUtil.java
+++ b/src/main/java/com/umc/DongnaeFriend/global/util/FileUtil.java
@@ -1,5 +1,6 @@
package com.umc.DongnaeFriend.global.util;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
@@ -7,19 +8,15 @@
import java.util.ArrayList;
import java.util.List;
+@Slf4j
public class FileUtil {
- public static String fileUpload(List files) throws IOException {
- String filepath = "/resources/static/img";
+ public static void fileUpload(MultipartFile file, String fileName) throws IOException {
+ String filepath = "/Users/kimdonghyun/Desktop/Dong_Hyun/projects/동네친구/Server/src/main/resources/static/img/"; //절대경로 지정
- List list = new ArrayList<>();
- for (MultipartFile file : files) {
- String originalfileName = file.getOriginalFilename();
- File dest = new File(filepath + originalfileName);
- file.transferTo(dest);
- list.add(dest.getPath());
- }
- return String.join(",", list);
+ File dest = new File(filepath + fileName);
+ file.transferTo(dest);
}
+
}
diff --git a/src/main/resources/.DS_Store b/src/main/resources/.DS_Store
new file mode 100644
index 0000000..c87f7b6
Binary files /dev/null and b/src/main/resources/.DS_Store differ
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 04772a2..a68b00e 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -3,12 +3,6 @@ logging:
com.example.carrotmarket: debug
org.hibernate.SQL: debug
-spring:
- jpa:
- properties:
- hibernate:
- format_sql: true
- show_sql: true
---
# Settings for local
spring:
@@ -18,4 +12,11 @@ spring:
password: qwe335577!
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
- hibernate.ddl-auto: update
\ No newline at end of file
+ hibernate.ddl-auto: update
+ properties:
+ hibernate:
+ format_sql: true
+ show_sql: true
+ jwt:
+ secret-key: 6B64DCA4EA2F53EDIKU9AAB215FE7
+
diff --git a/src/main/resources/static/.DS_Store b/src/main/resources/static/.DS_Store
new file mode 100644
index 0000000..62e105b
Binary files /dev/null and b/src/main/resources/static/.DS_Store differ
diff --git a/src/main/resources/static/img/SharingBoard_21_0.png b/src/main/resources/static/img/SharingBoard_21_0.png
new file mode 100644
index 0000000..782faf3
Binary files /dev/null and b/src/main/resources/static/img/SharingBoard_21_0.png differ
diff --git a/src/main/resources/static/img/SharingBoard_22_0.png b/src/main/resources/static/img/SharingBoard_22_0.png
new file mode 100644
index 0000000..782faf3
Binary files /dev/null and b/src/main/resources/static/img/SharingBoard_22_0.png differ
diff --git a/src/main/resources/static/img/SharingBoard_22_1.png b/src/main/resources/static/img/SharingBoard_22_1.png
new file mode 100644
index 0000000..95c4719
Binary files /dev/null and b/src/main/resources/static/img/SharingBoard_22_1.png differ
diff --git a/src/main/resources/static/img/abc.jpeg b/src/main/resources/static/img/abc.jpeg
new file mode 100644
index 0000000..782faf3
Binary files /dev/null and b/src/main/resources/static/img/abc.jpeg differ