From 5aac5ec74f81460fd90cb39e0ab95395e21deea8 Mon Sep 17 00:00:00 2001 From: arkchive Date: Wed, 24 Jul 2024 14:38:59 +0900 Subject: [PATCH 01/25] =?UTF-8?q?feat=20:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?Entity=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/space/space_spring/dao/PostDao.java | 4 ++ .../java/space/space_spring/entity/Post.java | 28 ++++++++++ .../space_spring/service/PostService.java | 4 ++ src/main/resources/application-local.yml | 55 +++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 src/main/java/space/space_spring/dao/PostDao.java create mode 100644 src/main/java/space/space_spring/entity/Post.java create mode 100644 src/main/java/space/space_spring/service/PostService.java create mode 100644 src/main/resources/application-local.yml diff --git a/src/main/java/space/space_spring/dao/PostDao.java b/src/main/java/space/space_spring/dao/PostDao.java new file mode 100644 index 00000000..2956f08d --- /dev/null +++ b/src/main/java/space/space_spring/dao/PostDao.java @@ -0,0 +1,4 @@ +package space.space_spring.dao; + +public class PostDao { +} diff --git a/src/main/java/space/space_spring/entity/Post.java b/src/main/java/space/space_spring/entity/Post.java new file mode 100644 index 00000000..7019f202 --- /dev/null +++ b/src/main/java/space/space_spring/entity/Post.java @@ -0,0 +1,28 @@ +package space.space_spring.entity; + +import jakarta.persistence.*; +import lombok.Getter; + +@Entity +@Table(name = "Posts") +@Getter +public class Post extends BaseEntity { + @Id @GeneratedValue + @Column(name = "post_id") + private Long postId; + + @Column(name = "title") + private String title; + + @Column(name = "content") + private String content; + + @Column(name = "type") + private String type; + + @Column(name = "like") + private int like; + + + +} diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java new file mode 100644 index 00000000..4d6e6e50 --- /dev/null +++ b/src/main/java/space/space_spring/service/PostService.java @@ -0,0 +1,4 @@ +package space.space_spring.service; + +public class PostService { +} diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml new file mode 100644 index 00000000..adf35033 --- /dev/null +++ b/src/main/resources/application-local.yml @@ -0,0 +1,55 @@ +spring: + config: + activate: + on-profile: "localPort" + +server: + port: 8080 +--- +spring: + config: + activate: + on-profile: "localRDB" + + datasource: + url: ${DATASOURCE_URL_LOCAL} + username: ${DATASOURCE_USERNAME} + password: ${DATASOURCE_PASSWORD} + driver-class-name: ${DATASOURCE_DRIVER:com.mysql.cj.jdbc.Driver} +logging: + level: + org.hibernate.sql: debug +--- +spring: + config: + activate: + on-profile: "localMongoDB" + data: + mongodb: + uri: mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}/${MONGO_DB} + +--- +spring: + config: + activate: + on-profile: "localJPA" + + jpa: + hibernate: + ddl-auto: update # table을 전부 drop했다가 다시 생성 -> 테스트용 + properties: + hibernate: + format_sql: true + show_sql: true +--- + +spring: + config: + activate: + on-profile: "localSecret" + +secret: + jwt-secret-key: ${JWT_SECRET_KEY:b237a73895f5e617b7364708413fff71c228721a5f8c84a7bb2a3b84f1bb1c23} + jwt-login-secret-key: ${JWT_SECRET_KEY_LOGIN} + jwt-user-space-secret-key: ${JWT_SECRET_KEY_USER_SPACE} + jwt-expired-in: ${JWT_EXPIRED_IN:3600000} From 77dbd765e9458f9a2b94e3b22862a71ab0739f46 Mon Sep 17 00:00:00 2001 From: arkchive Date: Wed, 24 Jul 2024 15:39:18 +0900 Subject: [PATCH 02/25] =?UTF-8?q?feat=20:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?Entity=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/space/space_spring/entity/Post.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/space/space_spring/entity/Post.java b/src/main/java/space/space_spring/entity/Post.java index 7019f202..c0d09bea 100644 --- a/src/main/java/space/space_spring/entity/Post.java +++ b/src/main/java/space/space_spring/entity/Post.java @@ -8,19 +8,27 @@ @Getter public class Post extends BaseEntity { @Id @GeneratedValue - @Column(name = "post_id") + @Column(name = "space_post_id") private Long postId; - @Column(name = "title") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "space_id") + private Space space; + + @Column(name = "post_title") private String title; @Column(name = "content") private String content; - @Column(name = "type") + @Column(name = "post_type") private String type; - @Column(name = "like") + @Column(name = "post_like") private int like; From 9119cf4aa2426d81e5164864db968a87a3b2f1e6 Mon Sep 17 00:00:00 2001 From: arkchive Date: Wed, 24 Jul 2024 17:26:56 +0900 Subject: [PATCH 03/25] =?UTF-8?q?refactor=20:=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=ED=8C=90=20Entity=20=EB=B3=80=EC=88=98=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/space/space_spring/entity/Post.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/space/space_spring/entity/Post.java b/src/main/java/space/space_spring/entity/Post.java index c0d09bea..4025284f 100644 --- a/src/main/java/space/space_spring/entity/Post.java +++ b/src/main/java/space/space_spring/entity/Post.java @@ -8,7 +8,7 @@ @Getter public class Post extends BaseEntity { @Id @GeneratedValue - @Column(name = "space_post_id") + @Column(name = "post_id") private Long postId; @ManyToOne(fetch = FetchType.LAZY) @@ -19,13 +19,13 @@ public class Post extends BaseEntity { @JoinColumn(name = "space_id") private Space space; - @Column(name = "post_title") + @Column(name = "title") private String title; - @Column(name = "content") + @Column(name = "post_content") private String content; - @Column(name = "post_type") + @Column(name = "type") private String type; @Column(name = "post_like") From b110fd9eb00abe87780bc9713c74e2e31d752de4 Mon Sep 17 00:00:00 2001 From: arkchive Date: Mon, 29 Jul 2024 16:24:20 +0900 Subject: [PATCH 04/25] pull develop --- .../controller/BoardController.java | 16 +++++++ .../java/space/space_spring/dao/BoardDao.java | 12 +++++ .../java/space/space_spring/dao/PostDao.java | 4 -- .../entity/{Post.java => Board.java} | 4 +- .../space_spring/service/BoardService.java | 13 ++++++ .../space_spring/service/PostService.java | 4 -- src/main/resources/application-local.yml | 44 +++++++++++++++++++ 7 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 src/main/java/space/space_spring/controller/BoardController.java create mode 100644 src/main/java/space/space_spring/dao/BoardDao.java delete mode 100644 src/main/java/space/space_spring/dao/PostDao.java rename src/main/java/space/space_spring/entity/{Post.java => Board.java} (90%) create mode 100644 src/main/java/space/space_spring/service/BoardService.java delete mode 100644 src/main/java/space/space_spring/service/PostService.java diff --git a/src/main/java/space/space_spring/controller/BoardController.java b/src/main/java/space/space_spring/controller/BoardController.java new file mode 100644 index 00000000..4730821a --- /dev/null +++ b/src/main/java/space/space_spring/controller/BoardController.java @@ -0,0 +1,16 @@ +package space.space_spring.controller; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import space.space_spring.service.BoardService; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/space/{spaceId}/board") +@Slf4j +public class BoardController { + private final BoardService postService; + +} diff --git a/src/main/java/space/space_spring/dao/BoardDao.java b/src/main/java/space/space_spring/dao/BoardDao.java new file mode 100644 index 00000000..187a2b15 --- /dev/null +++ b/src/main/java/space/space_spring/dao/BoardDao.java @@ -0,0 +1,12 @@ +package space.space_spring.dao; + +import org.springframework.stereotype.Repository; + +@Repository +public class BoardDao { + + + + + +} diff --git a/src/main/java/space/space_spring/dao/PostDao.java b/src/main/java/space/space_spring/dao/PostDao.java deleted file mode 100644 index 2956f08d..00000000 --- a/src/main/java/space/space_spring/dao/PostDao.java +++ /dev/null @@ -1,4 +0,0 @@ -package space.space_spring.dao; - -public class PostDao { -} diff --git a/src/main/java/space/space_spring/entity/Post.java b/src/main/java/space/space_spring/entity/Board.java similarity index 90% rename from src/main/java/space/space_spring/entity/Post.java rename to src/main/java/space/space_spring/entity/Board.java index 4025284f..44223a07 100644 --- a/src/main/java/space/space_spring/entity/Post.java +++ b/src/main/java/space/space_spring/entity/Board.java @@ -4,9 +4,9 @@ import lombok.Getter; @Entity -@Table(name = "Posts") +@Table(name = "Boards") @Getter -public class Post extends BaseEntity { +public class Board extends BaseEntity { @Id @GeneratedValue @Column(name = "post_id") private Long postId; diff --git a/src/main/java/space/space_spring/service/BoardService.java b/src/main/java/space/space_spring/service/BoardService.java new file mode 100644 index 00000000..d3a9b397 --- /dev/null +++ b/src/main/java/space/space_spring/service/BoardService.java @@ -0,0 +1,13 @@ +package space.space_spring.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import space.space_spring.dao.BoardDao; + +@Service +@RequiredArgsConstructor +public class BoardService { + private final BoardDao boardDao; + + +} diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java deleted file mode 100644 index 4d6e6e50..00000000 --- a/src/main/java/space/space_spring/service/PostService.java +++ /dev/null @@ -1,4 +0,0 @@ -package space.space_spring.service; - -public class PostService { -} diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index adf35033..0e090112 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -19,6 +19,34 @@ spring: logging: level: org.hibernate.sql: debug + +--- +spring: + # H2 Database 설정 + datasource: + driver-class-name: org.h2.Driver + url: 'jdbc:h2:mem:test' # H2 DB 연결 주소 (In-Memory Mode) + #url: 'jdbc:h2:~/test' # H2 DB 연결 주소 (Embedded Mode) + username: arkchive # H2 DB 접속 ID (사용자 지정) + password: a;sldkfj7 # H2 DB 접속 PW (사용자 지정) + + # H2 Console 설정 + h2: + console: # H2 DB를 웹에서 관리할 수 있는 기능 + enabled: true # H2 Console 사용 여부 + path: /h2-console # H2 Console 접속 주소 + + # JPA 설정 + jpa: + database-platform: org.hibernate.dialect.H2Dialect + hibernate: + ddl-auto: create # DB 초기화 전략 (none, create, create-drop, update, validate) + properties: + hibernate: + dialect: org.hibernate.dialect.H2Dialect + format_sql: true # 쿼리 로그 포맷 (정렬) + show_sql: true # 쿼리 로그 출력 + --- spring: config: @@ -42,7 +70,23 @@ spring: format_sql: true show_sql: true --- +spring: + config: + activate: + on-profile: "localS3" +cloud: + aws: + credentials: + access-key: ${S3-ACCESS-KEY} + secret-key: ${S3-SECRET-KEY} + s3: + bucket: project-space-image-storage + region: + static: ap-northeast-2 # 리전 정보(서울) + stack: + auto: false +--- spring: config: activate: From 0139fec07bc90ec8f99b3fbd4b75bf9ebdf7faac Mon Sep 17 00:00:00 2001 From: arkchive Date: Wed, 31 Jul 2024 04:38:58 +0900 Subject: [PATCH 05/25] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20Rea?= =?UTF-8?q?dBoardResponse=20dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/post/ReadBoardResponse.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/space/space_spring/dto/post/ReadBoardResponse.java diff --git a/src/main/java/space/space_spring/dto/post/ReadBoardResponse.java b/src/main/java/space/space_spring/dto/post/ReadBoardResponse.java new file mode 100644 index 00000000..ed83fb25 --- /dev/null +++ b/src/main/java/space/space_spring/dto/post/ReadBoardResponse.java @@ -0,0 +1,28 @@ +package space.space_spring.dto.post; + +import lombok.*; +import space.space_spring.entity.Space; +import space.space_spring.entity.User; + +@Builder +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class ReadBoardResponse { + + private Long postId; + + private User user; + + private Space space; + + private String title; + + private String content; + + private String type; + + private int like; + +} From 19a18463c3529b958e1a78896202cf1840386c7d Mon Sep 17 00:00:00 2001 From: arkchive Date: Wed, 31 Jul 2024 04:39:36 +0900 Subject: [PATCH 06/25] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20Boa?= =?UTF-8?q?rdDao=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/space/space_spring/dao/BoardDao.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/space/space_spring/dao/BoardDao.java b/src/main/java/space/space_spring/dao/BoardDao.java index 187a2b15..252c6c52 100644 --- a/src/main/java/space/space_spring/dao/BoardDao.java +++ b/src/main/java/space/space_spring/dao/BoardDao.java @@ -1,12 +1,16 @@ package space.space_spring.dao; +import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import space.space_spring.entity.Board; +import space.space_spring.entity.Space; +import space.space_spring.entity.User; -@Repository -public class BoardDao { - - +import java.util.List; +@Repository +public interface BoardDao extends JpaRepository { + List findByUserAndSpace(User user, Space space); } From 5533375adc37c9b31aa46568da8c42b253abfc6e Mon Sep 17 00:00:00 2001 From: arkchive Date: Wed, 31 Jul 2024 04:40:11 +0900 Subject: [PATCH 07/25] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20Boa?= =?UTF-8?q?rdService=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_spring/service/BoardService.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/main/java/space/space_spring/service/BoardService.java b/src/main/java/space/space_spring/service/BoardService.java index d3a9b397..618071d8 100644 --- a/src/main/java/space/space_spring/service/BoardService.java +++ b/src/main/java/space/space_spring/service/BoardService.java @@ -3,11 +3,51 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import space.space_spring.dao.BoardDao; +import space.space_spring.dao.UserDao; +import space.space_spring.dto.post.ReadBoardResponse; +import space.space_spring.entity.Board; +import space.space_spring.entity.Space; +import space.space_spring.entity.User; +import space.space_spring.util.space.SpaceUtils; +import space.space_spring.util.user.UserUtils; + +import java.util.List; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class BoardService { + + private final UserUtils userUtils; + private final SpaceUtils spaceUtils; private final BoardDao boardDao; + public List getAllPosts(Long userId, Long spaceId) { + // TODO 1: userId에 해당하는 user find + User userByUserId = userUtils.findUserByUserId(userId); + + // TODO 2: spaceId에 해당하는 space find + Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); + + // TODO 3: 해당 user의 해당 space 내의 게시판 게시글 리스트 return + List posts = boardDao.findByUserAndSpace(userByUserId, spaceBySpaceId); + return posts.stream() + .map(this::convertToReadResponse) + .collect(Collectors.toList()); + } + + public ReadBoardResponse convertToReadResponse(Board board) { + return ReadBoardResponse.builder() + .postId(board.getPostId()) + .user(board.getUser()) + .space(board.getSpace()) + .title(board.getTitle()) + .content(board.getContent()) + .type(board.getType()) + .like(board.getLike()) + .build(); + + } + } From a38a9171020b4e7edbf95ff7bc100573ec46e8a1 Mon Sep 17 00:00:00 2001 From: arkchive Date: Wed, 31 Jul 2024 04:40:28 +0900 Subject: [PATCH 08/25] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20Boa?= =?UTF-8?q?rdController=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BoardController.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/space/space_spring/controller/BoardController.java b/src/main/java/space/space_spring/controller/BoardController.java index 4730821a..8ec74ddb 100644 --- a/src/main/java/space/space_spring/controller/BoardController.java +++ b/src/main/java/space/space_spring/controller/BoardController.java @@ -2,15 +2,28 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import space.space_spring.argument_resolver.jwtLogin.JwtLoginAuth; +import space.space_spring.dto.post.ReadBoardResponse; +import space.space_spring.response.BaseResponse; import space.space_spring.service.BoardService; +import java.util.List; + @RestController @RequiredArgsConstructor -@RequestMapping("/space/{spaceId}/board") +@RequestMapping("/space/{spaceId}") @Slf4j public class BoardController { - private final BoardService postService; + private final BoardService boardService; + + @GetMapping("/board") + public BaseResponse> getBoard(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { + List board = boardService.getAllPosts(userId, spaceId); + return new BaseResponse<>(board); + } } From eda28fe33a11836f66cf3e5a4efd172f74b985c0 Mon Sep 17 00:00:00 2001 From: arkchive Date: Wed, 31 Jul 2024 14:56:05 +0900 Subject: [PATCH 09/25] =?UTF-8?q?chore:=20.gitignore=EC=97=90=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=EB=AA=A8=EB=93=A0=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94?= =?UTF-8?q?=EC=A0=81=20=EC=B7=A8=EC=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradlew | 0 gradlew.bat | 184 +++++++++++------------ src/main/resources/application-local.yml | 99 ------------ 3 files changed, 92 insertions(+), 191 deletions(-) mode change 100755 => 100644 gradlew delete mode 100644 src/main/resources/application-local.yml diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 diff --git a/gradlew.bat b/gradlew.bat index 7101f8e4..25da30db 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,92 +1,92 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml deleted file mode 100644 index 0e090112..00000000 --- a/src/main/resources/application-local.yml +++ /dev/null @@ -1,99 +0,0 @@ -spring: - config: - activate: - on-profile: "localPort" - -server: - port: 8080 ---- -spring: - config: - activate: - on-profile: "localRDB" - - datasource: - url: ${DATASOURCE_URL_LOCAL} - username: ${DATASOURCE_USERNAME} - password: ${DATASOURCE_PASSWORD} - driver-class-name: ${DATASOURCE_DRIVER:com.mysql.cj.jdbc.Driver} -logging: - level: - org.hibernate.sql: debug - ---- -spring: - # H2 Database 설정 - datasource: - driver-class-name: org.h2.Driver - url: 'jdbc:h2:mem:test' # H2 DB 연결 주소 (In-Memory Mode) - #url: 'jdbc:h2:~/test' # H2 DB 연결 주소 (Embedded Mode) - username: arkchive # H2 DB 접속 ID (사용자 지정) - password: a;sldkfj7 # H2 DB 접속 PW (사용자 지정) - - # H2 Console 설정 - h2: - console: # H2 DB를 웹에서 관리할 수 있는 기능 - enabled: true # H2 Console 사용 여부 - path: /h2-console # H2 Console 접속 주소 - - # JPA 설정 - jpa: - database-platform: org.hibernate.dialect.H2Dialect - hibernate: - ddl-auto: create # DB 초기화 전략 (none, create, create-drop, update, validate) - properties: - hibernate: - dialect: org.hibernate.dialect.H2Dialect - format_sql: true # 쿼리 로그 포맷 (정렬) - show_sql: true # 쿼리 로그 출력 - ---- -spring: - config: - activate: - on-profile: "localMongoDB" - data: - mongodb: - uri: mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}/${MONGO_DB} - ---- -spring: - config: - activate: - on-profile: "localJPA" - - jpa: - hibernate: - ddl-auto: update # table을 전부 drop했다가 다시 생성 -> 테스트용 - properties: - hibernate: - format_sql: true - show_sql: true ---- -spring: - config: - activate: - on-profile: "localS3" -cloud: - aws: - credentials: - access-key: ${S3-ACCESS-KEY} - secret-key: ${S3-SECRET-KEY} - s3: - bucket: project-space-image-storage - region: - static: ap-northeast-2 # 리전 정보(서울) - stack: - auto: false - ---- -spring: - config: - activate: - on-profile: "localSecret" - -secret: - jwt-secret-key: ${JWT_SECRET_KEY:b237a73895f5e617b7364708413fff71c228721a5f8c84a7bb2a3b84f1bb1c23} - jwt-login-secret-key: ${JWT_SECRET_KEY_LOGIN} - jwt-user-space-secret-key: ${JWT_SECRET_KEY_USER_SPACE} - jwt-expired-in: ${JWT_EXPIRED_IN:3600000} From 0db48f38de9b2e16c8a712379c4f06019c88abf4 Mon Sep 17 00:00:00 2001 From: arkchive Date: Wed, 31 Jul 2024 15:16:47 +0900 Subject: [PATCH 10/25] =?UTF-8?q?feat:=20ReadBoardResponse=20userId,=20spa?= =?UTF-8?q?ceId=20=ED=95=84=EB=93=9C=EB=A7=8C=20=EB=B6=88=EB=9F=AC?= =?UTF-8?q?=EC=98=A4=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/space/space_spring/dto/post/ReadBoardResponse.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/space/space_spring/dto/post/ReadBoardResponse.java b/src/main/java/space/space_spring/dto/post/ReadBoardResponse.java index ed83fb25..e9d27d01 100644 --- a/src/main/java/space/space_spring/dto/post/ReadBoardResponse.java +++ b/src/main/java/space/space_spring/dto/post/ReadBoardResponse.java @@ -13,9 +13,9 @@ public class ReadBoardResponse { private Long postId; - private User user; + private Long userId; - private Space space; + private Long spaceId; private String title; From 18a6846cfe062090c6a0bb6f9102a2e75de65957 Mon Sep 17 00:00:00 2001 From: arkchive Date: Wed, 31 Jul 2024 15:22:47 +0900 Subject: [PATCH 11/25] =?UTF-8?q?feat:=20BoardService=20userId,=20spaceId?= =?UTF-8?q?=20=ED=95=84=EB=93=9C=EB=A7=8C=20=EB=B6=88=EB=9F=AC=EC=98=A4?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/space/space_spring/service/BoardService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/space/space_spring/service/BoardService.java b/src/main/java/space/space_spring/service/BoardService.java index 618071d8..d06ea32e 100644 --- a/src/main/java/space/space_spring/service/BoardService.java +++ b/src/main/java/space/space_spring/service/BoardService.java @@ -39,8 +39,8 @@ public List getAllPosts(Long userId, Long spaceId) { public ReadBoardResponse convertToReadResponse(Board board) { return ReadBoardResponse.builder() .postId(board.getPostId()) - .user(board.getUser()) - .space(board.getSpace()) + .userId(board.getUser().getUserId()) + .spaceId(board.getSpace().getSpaceId()) .title(board.getTitle()) .content(board.getContent()) .type(board.getType()) From afde87a627597cfacd1987b94a3047246cc24496 Mon Sep 17 00:00:00 2001 From: arkchive Date: Wed, 31 Jul 2024 15:30:10 +0900 Subject: [PATCH 12/25] =?UTF-8?q?feat:=20spaceId=EB=A1=9C=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_spring/controller/BoardController.java | 4 ++-- src/main/java/space/space_spring/dao/BoardDao.java | 2 +- .../space/space_spring/service/BoardService.java | 12 ++++-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/space/space_spring/controller/BoardController.java b/src/main/java/space/space_spring/controller/BoardController.java index 8ec74ddb..b49b8a23 100644 --- a/src/main/java/space/space_spring/controller/BoardController.java +++ b/src/main/java/space/space_spring/controller/BoardController.java @@ -21,8 +21,8 @@ public class BoardController { private final BoardService boardService; @GetMapping("/board") - public BaseResponse> getBoard(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { - List board = boardService.getAllPosts(userId, spaceId); + public BaseResponse> getBoard(@PathVariable Long spaceId) { + List board = boardService.getAllPosts(spaceId); return new BaseResponse<>(board); } diff --git a/src/main/java/space/space_spring/dao/BoardDao.java b/src/main/java/space/space_spring/dao/BoardDao.java index 252c6c52..6168b75a 100644 --- a/src/main/java/space/space_spring/dao/BoardDao.java +++ b/src/main/java/space/space_spring/dao/BoardDao.java @@ -11,6 +11,6 @@ @Repository public interface BoardDao extends JpaRepository { - List findByUserAndSpace(User user, Space space); + List findBySpace(Space space); } diff --git a/src/main/java/space/space_spring/service/BoardService.java b/src/main/java/space/space_spring/service/BoardService.java index d06ea32e..f57dc779 100644 --- a/src/main/java/space/space_spring/service/BoardService.java +++ b/src/main/java/space/space_spring/service/BoardService.java @@ -18,19 +18,16 @@ @RequiredArgsConstructor public class BoardService { - private final UserUtils userUtils; private final SpaceUtils spaceUtils; private final BoardDao boardDao; - public List getAllPosts(Long userId, Long spaceId) { - // TODO 1: userId에 해당하는 user find - User userByUserId = userUtils.findUserByUserId(userId); + public List getAllPosts(Long spaceId) { - // TODO 2: spaceId에 해당하는 space find + // TODO 1: spaceId에 해당하는 space find Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); - // TODO 3: 해당 user의 해당 space 내의 게시판 게시글 리스트 return - List posts = boardDao.findByUserAndSpace(userByUserId, spaceBySpaceId); + // TODO 2: 해당 user의 해당 space 내의 게시판 게시글 리스트 return + List posts = boardDao.findBySpace(spaceBySpaceId); return posts.stream() .map(this::convertToReadResponse) .collect(Collectors.toList()); @@ -39,7 +36,6 @@ public List getAllPosts(Long userId, Long spaceId) { public ReadBoardResponse convertToReadResponse(Board board) { return ReadBoardResponse.builder() .postId(board.getPostId()) - .userId(board.getUser().getUserId()) .spaceId(board.getSpace().getSpaceId()) .title(board.getTitle()) .content(board.getContent()) From 1940a9a53ad0496325eb75508c75b76d191c858e Mon Sep 17 00:00:00 2001 From: arkchive Date: Fri, 2 Aug 2024 11:06:46 +0900 Subject: [PATCH 13/25] =?UTF-8?q?feat:=20board->post=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ardController.java => PostController.java} | 13 +++-- .../dao/{BoardDao.java => PostDao.java} | 7 ++- .../entity/{Board.java => Post.java} | 4 +- .../space_spring/service/BoardService.java | 49 ------------------- .../space_spring/service/PostService.java | 46 +++++++++++++++++ 5 files changed, 57 insertions(+), 62 deletions(-) rename src/main/java/space/space_spring/controller/{BoardController.java => PostController.java} (61%) rename src/main/java/space/space_spring/dao/{BoardDao.java => PostDao.java} (55%) rename src/main/java/space/space_spring/entity/{Board.java => Post.java} (90%) delete mode 100644 src/main/java/space/space_spring/service/BoardService.java create mode 100644 src/main/java/space/space_spring/service/PostService.java diff --git a/src/main/java/space/space_spring/controller/BoardController.java b/src/main/java/space/space_spring/controller/PostController.java similarity index 61% rename from src/main/java/space/space_spring/controller/BoardController.java rename to src/main/java/space/space_spring/controller/PostController.java index b49b8a23..186833d4 100644 --- a/src/main/java/space/space_spring/controller/BoardController.java +++ b/src/main/java/space/space_spring/controller/PostController.java @@ -6,10 +6,9 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import space.space_spring.argument_resolver.jwtLogin.JwtLoginAuth; -import space.space_spring.dto.post.ReadBoardResponse; +import space.space_spring.dto.post.ReadPostsResponse; import space.space_spring.response.BaseResponse; -import space.space_spring.service.BoardService; +import space.space_spring.service.PostService; import java.util.List; @@ -17,12 +16,12 @@ @RequiredArgsConstructor @RequestMapping("/space/{spaceId}") @Slf4j -public class BoardController { - private final BoardService boardService; +public class PostController { + private final PostService postService; @GetMapping("/board") - public BaseResponse> getBoard(@PathVariable Long spaceId) { - List board = boardService.getAllPosts(spaceId); + public BaseResponse> getBoard(@PathVariable Long spaceId) { + List board = postService.getAllPosts(spaceId); return new BaseResponse<>(board); } diff --git a/src/main/java/space/space_spring/dao/BoardDao.java b/src/main/java/space/space_spring/dao/PostDao.java similarity index 55% rename from src/main/java/space/space_spring/dao/BoardDao.java rename to src/main/java/space/space_spring/dao/PostDao.java index 6168b75a..8271e1d1 100644 --- a/src/main/java/space/space_spring/dao/BoardDao.java +++ b/src/main/java/space/space_spring/dao/PostDao.java @@ -2,15 +2,14 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import space.space_spring.entity.Board; +import space.space_spring.entity.Post; import space.space_spring.entity.Space; -import space.space_spring.entity.User; import java.util.List; @Repository -public interface BoardDao extends JpaRepository { +public interface PostDao extends JpaRepository { - List findBySpace(Space space); + List findBySpace(Space space); } diff --git a/src/main/java/space/space_spring/entity/Board.java b/src/main/java/space/space_spring/entity/Post.java similarity index 90% rename from src/main/java/space/space_spring/entity/Board.java rename to src/main/java/space/space_spring/entity/Post.java index 44223a07..4025284f 100644 --- a/src/main/java/space/space_spring/entity/Board.java +++ b/src/main/java/space/space_spring/entity/Post.java @@ -4,9 +4,9 @@ import lombok.Getter; @Entity -@Table(name = "Boards") +@Table(name = "Posts") @Getter -public class Board extends BaseEntity { +public class Post extends BaseEntity { @Id @GeneratedValue @Column(name = "post_id") private Long postId; diff --git a/src/main/java/space/space_spring/service/BoardService.java b/src/main/java/space/space_spring/service/BoardService.java deleted file mode 100644 index f57dc779..00000000 --- a/src/main/java/space/space_spring/service/BoardService.java +++ /dev/null @@ -1,49 +0,0 @@ -package space.space_spring.service; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import space.space_spring.dao.BoardDao; -import space.space_spring.dao.UserDao; -import space.space_spring.dto.post.ReadBoardResponse; -import space.space_spring.entity.Board; -import space.space_spring.entity.Space; -import space.space_spring.entity.User; -import space.space_spring.util.space.SpaceUtils; -import space.space_spring.util.user.UserUtils; - -import java.util.List; -import java.util.stream.Collectors; - -@Service -@RequiredArgsConstructor -public class BoardService { - - private final SpaceUtils spaceUtils; - private final BoardDao boardDao; - - public List getAllPosts(Long spaceId) { - - // TODO 1: spaceId에 해당하는 space find - Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); - - // TODO 2: 해당 user의 해당 space 내의 게시판 게시글 리스트 return - List posts = boardDao.findBySpace(spaceBySpaceId); - return posts.stream() - .map(this::convertToReadResponse) - .collect(Collectors.toList()); - } - - public ReadBoardResponse convertToReadResponse(Board board) { - return ReadBoardResponse.builder() - .postId(board.getPostId()) - .spaceId(board.getSpace().getSpaceId()) - .title(board.getTitle()) - .content(board.getContent()) - .type(board.getType()) - .like(board.getLike()) - .build(); - - } - - -} diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java new file mode 100644 index 00000000..7e72eccc --- /dev/null +++ b/src/main/java/space/space_spring/service/PostService.java @@ -0,0 +1,46 @@ +package space.space_spring.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import space.space_spring.dao.PostDao; +import space.space_spring.dto.post.ReadPostsResponse; +import space.space_spring.entity.Post; +import space.space_spring.entity.Space; +import space.space_spring.util.space.SpaceUtils; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class PostService { + + private final SpaceUtils spaceUtils; + private final PostDao postDao; + + public List getAllPosts(Long spaceId) { + + // TODO 1: spaceId에 해당하는 space find + Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); + + // TODO 2: 해당 user의 해당 space 내의 게시판 게시글 리스트 return + List posts = postDao.findBySpace(spaceBySpaceId); + return posts.stream() + .map(this::convertToReadResponse) + .collect(Collectors.toList()); + } + + public ReadPostsResponse convertToReadResponse(Post post) { + return ReadPostsResponse.builder() + .postId(post.getPostId()) + .spaceId(post.getSpace().getSpaceId()) + .title(post.getTitle()) + .content(post.getContent()) + .type(post.getType()) + .like_count(post.getLike()) + .build(); + + } + + +} From dc52ef8ca2e3dc8826e9778df81a375726b1b5ca Mon Sep 17 00:00:00 2001 From: arkchive Date: Fri, 2 Aug 2024 18:07:46 +0900 Subject: [PATCH 14/25] =?UTF-8?q?feat:=20postImage,=20postComment=20?= =?UTF-8?q?=EC=96=91=EB=B0=A9=ED=96=A5=20=EB=A7=A4=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/space/space_spring/entity/Post.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/space/space_spring/entity/Post.java b/src/main/java/space/space_spring/entity/Post.java index 4025284f..78d0aa90 100644 --- a/src/main/java/space/space_spring/entity/Post.java +++ b/src/main/java/space/space_spring/entity/Post.java @@ -3,6 +3,8 @@ import jakarta.persistence.*; import lombok.Getter; +import java.util.List; + @Entity @Table(name = "Posts") @Getter @@ -31,6 +33,10 @@ public class Post extends BaseEntity { @Column(name = "post_like") private int like; + @OneToMany(mappedBy = "post") + private List postImages; + @OneToMany(mappedBy = "post") + private List postComments; } From b27afa02d77b57d66fdc8fc028f1b4a0499df64f Mon Sep 17 00:00:00 2001 From: arkchive Date: Fri, 2 Aug 2024 18:08:06 +0900 Subject: [PATCH 15/25] =?UTF-8?q?feat:=20postImage,=20postComment=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_spring/entity/PostComment.java | 34 +++++++++++++++++++ .../space/space_spring/entity/PostImage.java | 22 ++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/main/java/space/space_spring/entity/PostComment.java create mode 100644 src/main/java/space/space_spring/entity/PostImage.java diff --git a/src/main/java/space/space_spring/entity/PostComment.java b/src/main/java/space/space_spring/entity/PostComment.java new file mode 100644 index 00000000..20d9f00f --- /dev/null +++ b/src/main/java/space/space_spring/entity/PostComment.java @@ -0,0 +1,34 @@ +package space.space_spring.entity; + +import jakarta.persistence.*; +import lombok.Getter; + +@Entity +@Table(name = "Post_Comment") +@Getter +public class PostComment extends BaseEntity{ + @Id + @GeneratedValue + @Column(name = "comment_id") + private Long commentId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "space_post_id") + private Post post; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @Column(name = "comment_content") + private String content; + + @Column(name = "comment_like") + private int like; + + @Column(name = "isReply") + private boolean isReply; + + @Column(name = "comment_target_id") + private String targetId; +} diff --git a/src/main/java/space/space_spring/entity/PostImage.java b/src/main/java/space/space_spring/entity/PostImage.java new file mode 100644 index 00000000..9a56aef2 --- /dev/null +++ b/src/main/java/space/space_spring/entity/PostImage.java @@ -0,0 +1,22 @@ +package space.space_spring.entity; + +import jakarta.persistence.*; +import lombok.Getter; + +@Entity +@Table(name = "Post_Image") +@Getter +public class PostImage extends BaseEntity{ + @Id + @GeneratedValue + @Column(name = "post_image_id") + private Long postImgId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "space_post_id") + private Post post; + + @Column(name = "post_image") + private String postImgUrl; + +} From 48ea57c09db550b309b00aa8fb2387e5b9114fe5 Mon Sep 17 00:00:00 2001 From: arkchive Date: Fri, 2 Aug 2024 18:09:09 +0900 Subject: [PATCH 16/25] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=A1=B0=ED=9A=8C=20response=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=EC=A0=81=EC=9D=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/post/ReadBoardResponse.java | 28 --------------- .../dto/post/ReadPostsResponse.java | 35 +++++++++++++++++++ .../space_spring/service/PostService.java | 9 ++++- 3 files changed, 43 insertions(+), 29 deletions(-) delete mode 100644 src/main/java/space/space_spring/dto/post/ReadBoardResponse.java create mode 100644 src/main/java/space/space_spring/dto/post/ReadPostsResponse.java diff --git a/src/main/java/space/space_spring/dto/post/ReadBoardResponse.java b/src/main/java/space/space_spring/dto/post/ReadBoardResponse.java deleted file mode 100644 index e9d27d01..00000000 --- a/src/main/java/space/space_spring/dto/post/ReadBoardResponse.java +++ /dev/null @@ -1,28 +0,0 @@ -package space.space_spring.dto.post; - -import lombok.*; -import space.space_spring.entity.Space; -import space.space_spring.entity.User; - -@Builder -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -public class ReadBoardResponse { - - private Long postId; - - private Long userId; - - private Long spaceId; - - private String title; - - private String content; - - private String type; - - private int like; - -} diff --git a/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java b/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java new file mode 100644 index 00000000..9c072ed9 --- /dev/null +++ b/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java @@ -0,0 +1,35 @@ +package space.space_spring.dto.post; + +import lombok.*; + +import java.util.List; + +@Builder +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class ReadPostsResponse { + + // 스페이스 관련 + private Long spaceId; + + // 유저 관련 + private Long userId; + private String userProfileImg; + private String userName; + + // 게시글 관련 + private Long postId; + private String title; + private String content; + private List postImage; + private String time; + private String type; + private int post_count; + + // 댓글 및 좋아요 + private int comment_count; + private int like_count; + +} diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java index 7e72eccc..6da37e87 100644 --- a/src/main/java/space/space_spring/service/PostService.java +++ b/src/main/java/space/space_spring/service/PostService.java @@ -3,8 +3,10 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import space.space_spring.dao.PostDao; +import space.space_spring.dao.PostImageDao; import space.space_spring.dto.post.ReadPostsResponse; import space.space_spring.entity.Post; +import space.space_spring.entity.PostImage; import space.space_spring.entity.Space; import space.space_spring.util.space.SpaceUtils; @@ -31,6 +33,11 @@ public List getAllPosts(Long spaceId) { } public ReadPostsResponse convertToReadResponse(Post post) { + List postImages = post.getPostImages(); + List postImageUrls = postImages.stream() + .map(PostImage::getPostImgUrl) + .toList(); + return ReadPostsResponse.builder() .postId(post.getPostId()) .spaceId(post.getSpace().getSpaceId()) @@ -38,9 +45,9 @@ public ReadPostsResponse convertToReadResponse(Post post) { .content(post.getContent()) .type(post.getType()) .like_count(post.getLike()) + .postImage(postImageUrls) .build(); } - } From 333f650f8ca11ca844c3b8b1aef55bd48942f521 Mon Sep 17 00:00:00 2001 From: arkchive Date: Fri, 2 Aug 2024 18:09:37 +0900 Subject: [PATCH 17/25] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20=EC=8B=9C=EA=B0=84=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20util=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/post/ConvertCreatedDate.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/space/space_spring/util/post/ConvertCreatedDate.java diff --git a/src/main/java/space/space_spring/util/post/ConvertCreatedDate.java b/src/main/java/space/space_spring/util/post/ConvertCreatedDate.java new file mode 100644 index 00000000..070d865a --- /dev/null +++ b/src/main/java/space/space_spring/util/post/ConvertCreatedDate.java @@ -0,0 +1,22 @@ +package space.space_spring.util.post; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; + +public class ConvertCreatedDate { + public static String setCreatedDate(LocalDateTime createdAt) { + LocalDateTime now = LocalDateTime.now(); + if(ChronoUnit.YEARS.between(createdAt, now) != 0) + return ChronoUnit.YEARS.between(createdAt, now) + "년 전"; + else if(ChronoUnit.MONTHS.between(createdAt, now) != 0) + return ChronoUnit.MONTHS.between(createdAt, now) + "달 전"; + else if(ChronoUnit.WEEKS.between(createdAt, now) != 0) + return ChronoUnit.WEEKS.between(createdAt, now) + "주 전"; + else if(ChronoUnit.DAYS.between(createdAt, now) != 0) + return ChronoUnit.DAYS.between(createdAt, now) + "일 전"; + else if(ChronoUnit.HOURS.between(createdAt, now) != 0) + return ChronoUnit.HOURS.between(createdAt, now) + "시간 전"; + else + return "방금"; + } +} From bf24e442a795849b1fea6ecee6cbb19dd946ffcb Mon Sep 17 00:00:00 2001 From: arkchive Date: Fri, 2 Aug 2024 18:16:53 +0900 Subject: [PATCH 18/25] =?UTF-8?q?feat:=20=ED=95=84=EC=9A=94=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20import=EB=AC=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/space/space_spring/service/PostService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java index 6da37e87..7be7d963 100644 --- a/src/main/java/space/space_spring/service/PostService.java +++ b/src/main/java/space/space_spring/service/PostService.java @@ -3,7 +3,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import space.space_spring.dao.PostDao; -import space.space_spring.dao.PostImageDao; import space.space_spring.dto.post.ReadPostsResponse; import space.space_spring.entity.Post; import space.space_spring.entity.PostImage; From 4cc238aab79d7df4d0f9a289338e93707d8cd02d Mon Sep 17 00:00:00 2001 From: arkchive Date: Fri, 2 Aug 2024 18:50:56 +0900 Subject: [PATCH 19/25] =?UTF-8?q?refactor:=20ReadPostsResponse=20=EC=A0=95?= =?UTF-8?q?=EC=A0=81=20=ED=8C=A9=ED=86=A0=EB=A6=AC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/post/ReadPostsResponse.java | 17 +++++++++++++++ .../space_spring/service/PostService.java | 21 +------------------ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java b/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java index 9c072ed9..46d5a12d 100644 --- a/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java +++ b/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java @@ -1,6 +1,8 @@ package space.space_spring.dto.post; import lombok.*; +import space.space_spring.entity.Post; +import space.space_spring.entity.PostImage; import java.util.List; @@ -32,4 +34,19 @@ public class ReadPostsResponse { private int comment_count; private int like_count; + public static ReadPostsResponse from(Post post) { + List postImageUrls = post.getPostImages().stream() + .map(PostImage::getPostImgUrl) + .toList(); + + return ReadPostsResponse.builder() + .postId(post.getPostId()) + .spaceId(post.getSpace().getSpaceId()) + .title(post.getTitle()) + .content(post.getContent()) + .type(post.getType()) + .like_count(post.getLike()) + .postImage(postImageUrls) + .build(); + } } diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java index 7be7d963..65f5fc8d 100644 --- a/src/main/java/space/space_spring/service/PostService.java +++ b/src/main/java/space/space_spring/service/PostService.java @@ -27,26 +27,7 @@ public List getAllPosts(Long spaceId) { // TODO 2: 해당 user의 해당 space 내의 게시판 게시글 리스트 return List posts = postDao.findBySpace(spaceBySpaceId); return posts.stream() - .map(this::convertToReadResponse) + .map(ReadPostsResponse::from) .collect(Collectors.toList()); } - - public ReadPostsResponse convertToReadResponse(Post post) { - List postImages = post.getPostImages(); - List postImageUrls = postImages.stream() - .map(PostImage::getPostImgUrl) - .toList(); - - return ReadPostsResponse.builder() - .postId(post.getPostId()) - .spaceId(post.getSpace().getSpaceId()) - .title(post.getTitle()) - .content(post.getContent()) - .type(post.getType()) - .like_count(post.getLike()) - .postImage(postImageUrls) - .build(); - - } - } From 76820db7327fb116f02229ff8d07c76d7af42ac3 Mon Sep 17 00:00:00 2001 From: arkchive Date: Sat, 3 Aug 2024 10:50:20 +0900 Subject: [PATCH 20/25] =?UTF-8?q?feat:=20ReadPostsResponse=20=EB=86=93?= =?UTF-8?q?=EC=B9=9C=20=ED=95=84=EB=93=9C=EB=93=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_spring/dto/post/ReadPostsResponse.java | 10 +++++++++- .../java/space/space_spring/entity/BaseEntity.java | 2 ++ .../java/space/space_spring/service/PostService.java | 12 ++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java b/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java index 46d5a12d..98ec0280 100644 --- a/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java +++ b/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java @@ -3,6 +3,8 @@ import lombok.*; import space.space_spring.entity.Post; import space.space_spring.entity.PostImage; +import space.space_spring.entity.UserSpace; +import space.space_spring.util.post.ConvertCreatedDate; import java.util.List; @@ -34,7 +36,7 @@ public class ReadPostsResponse { private int comment_count; private int like_count; - public static ReadPostsResponse from(Post post) { + public static ReadPostsResponse of(Post post, int postCount, UserSpace userSpace) { List postImageUrls = post.getPostImages().stream() .map(PostImage::getPostImgUrl) .toList(); @@ -42,9 +44,15 @@ public static ReadPostsResponse from(Post post) { return ReadPostsResponse.builder() .postId(post.getPostId()) .spaceId(post.getSpace().getSpaceId()) + .userId(post.getUser().getUserId()) + .userProfileImg(userSpace.getUserProfileImg()) + .userName(userSpace.getUserName()) .title(post.getTitle()) .content(post.getContent()) + .time(ConvertCreatedDate.setCreatedDate(post.getCreatedAt())) .type(post.getType()) + .post_count(postCount) + .comment_count(post.getPostComments().size()) .like_count(post.getLike()) .postImage(postImageUrls) .build(); diff --git a/src/main/java/space/space_spring/entity/BaseEntity.java b/src/main/java/space/space_spring/entity/BaseEntity.java index 4b035dd0..c1130aec 100644 --- a/src/main/java/space/space_spring/entity/BaseEntity.java +++ b/src/main/java/space/space_spring/entity/BaseEntity.java @@ -1,9 +1,11 @@ package space.space_spring.entity; import jakarta.persistence.*; +import lombok.Getter; import java.time.LocalDateTime; +@Getter @MappedSuperclass public abstract class BaseEntity { diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java index 65f5fc8d..702790e9 100644 --- a/src/main/java/space/space_spring/service/PostService.java +++ b/src/main/java/space/space_spring/service/PostService.java @@ -3,10 +3,11 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import space.space_spring.dao.PostDao; +import space.space_spring.dao.UserSpaceDao; import space.space_spring.dto.post.ReadPostsResponse; import space.space_spring.entity.Post; -import space.space_spring.entity.PostImage; import space.space_spring.entity.Space; +import space.space_spring.entity.UserSpace; import space.space_spring.util.space.SpaceUtils; import java.util.List; @@ -18,6 +19,7 @@ public class PostService { private final SpaceUtils spaceUtils; private final PostDao postDao; + private final UserSpaceDao userSpaceDao; public List getAllPosts(Long spaceId) { @@ -26,8 +28,14 @@ public List getAllPosts(Long spaceId) { // TODO 2: 해당 user의 해당 space 내의 게시판 게시글 리스트 return List posts = postDao.findBySpace(spaceBySpaceId); + int postCount = posts.size(); + return posts.stream() - .map(ReadPostsResponse::from) + .map(post ->{ + UserSpace userSpace = userSpaceDao.findUserSpaceByUserAndSpace(post.getUser(), post.getSpace()) + .orElseThrow(() -> new IllegalStateException("스페이스 안에 사용자가 없음")); + return ReadPostsResponse.of(post, postCount, userSpace); + }) .collect(Collectors.toList()); } } From 30de57affb25194922e2688b2e2ae566a8c5cd24 Mon Sep 17 00:00:00 2001 From: arkchive Date: Sun, 4 Aug 2024 00:57:37 +0900 Subject: [PATCH 21/25] =?UTF-8?q?feat:=20UserSpaceUtils=EB=A5=BC=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EA=B6=8C=ED=95=9C=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space/space_spring/dto/post/ReadPostsResponse.java | 4 ++-- src/main/java/space/space_spring/service/PostService.java | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java b/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java index 98ec0280..1d5e77ea 100644 --- a/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java +++ b/src/main/java/space/space_spring/dto/post/ReadPostsResponse.java @@ -45,8 +45,8 @@ public static ReadPostsResponse of(Post post, int postCount, UserSpace userSpace .postId(post.getPostId()) .spaceId(post.getSpace().getSpaceId()) .userId(post.getUser().getUserId()) - .userProfileImg(userSpace.getUserProfileImg()) - .userName(userSpace.getUserName()) + .userProfileImg(userSpace != null ? userSpace.getUserProfileImg() : null) + .userName(userSpace != null ? userSpace.getUserName() : null) .title(post.getTitle()) .content(post.getContent()) .time(ConvertCreatedDate.setCreatedDate(post.getCreatedAt())) diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java index 702790e9..fe7d3605 100644 --- a/src/main/java/space/space_spring/service/PostService.java +++ b/src/main/java/space/space_spring/service/PostService.java @@ -9,8 +9,10 @@ import space.space_spring.entity.Space; import space.space_spring.entity.UserSpace; import space.space_spring.util.space.SpaceUtils; +import space.space_spring.util.userSpace.UserSpaceUtils; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Service @@ -18,6 +20,7 @@ public class PostService { private final SpaceUtils spaceUtils; + private final UserSpaceUtils userSpaceUtils; private final PostDao postDao; private final UserSpaceDao userSpaceDao; @@ -32,9 +35,8 @@ public List getAllPosts(Long spaceId) { return posts.stream() .map(post ->{ - UserSpace userSpace = userSpaceDao.findUserSpaceByUserAndSpace(post.getUser(), post.getSpace()) - .orElseThrow(() -> new IllegalStateException("스페이스 안에 사용자가 없음")); - return ReadPostsResponse.of(post, postCount, userSpace); + Optional userSpace = userSpaceUtils.isUserInSpace(post.getUser().getUserId(), spaceId); + return ReadPostsResponse.of(post, postCount, userSpace.orElse(null)); }) .collect(Collectors.toList()); } From ce5aed28f71cdaa799713d5927de95524aab2da4 Mon Sep 17 00:00:00 2001 From: arkchive Date: Sun, 4 Aug 2024 01:46:05 +0900 Subject: [PATCH 22/25] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=ED=95=84=ED=84=B0=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_spring/controller/PostController.java | 11 +++++------ src/main/java/space/space_spring/dao/PostDao.java | 2 ++ .../java/space/space_spring/service/PostService.java | 12 +++++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/space/space_spring/controller/PostController.java b/src/main/java/space/space_spring/controller/PostController.java index 186833d4..8d02cac0 100644 --- a/src/main/java/space/space_spring/controller/PostController.java +++ b/src/main/java/space/space_spring/controller/PostController.java @@ -2,10 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import space.space_spring.dto.post.ReadPostsResponse; import space.space_spring.response.BaseResponse; import space.space_spring.service.PostService; @@ -20,8 +17,10 @@ public class PostController { private final PostService postService; @GetMapping("/board") - public BaseResponse> getBoard(@PathVariable Long spaceId) { - List board = postService.getAllPosts(spaceId); + public BaseResponse> getBoard( + @PathVariable Long spaceId, + @RequestParam(required = false) String filter) { + List board = postService.getAllPosts(spaceId, filter); return new BaseResponse<>(board); } diff --git a/src/main/java/space/space_spring/dao/PostDao.java b/src/main/java/space/space_spring/dao/PostDao.java index 8271e1d1..8c1e6bc8 100644 --- a/src/main/java/space/space_spring/dao/PostDao.java +++ b/src/main/java/space/space_spring/dao/PostDao.java @@ -12,4 +12,6 @@ public interface PostDao extends JpaRepository { List findBySpace(Space space); + List findBySpaceAndType(Space space, String type); + } diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java index fe7d3605..ff778d7e 100644 --- a/src/main/java/space/space_spring/service/PostService.java +++ b/src/main/java/space/space_spring/service/PostService.java @@ -24,13 +24,19 @@ public class PostService { private final PostDao postDao; private final UserSpaceDao userSpaceDao; - public List getAllPosts(Long spaceId) { + public List getAllPosts(Long spaceId, String filter) { // TODO 1: spaceId에 해당하는 space find Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); - // TODO 2: 해당 user의 해당 space 내의 게시판 게시글 리스트 return - List posts = postDao.findBySpace(spaceBySpaceId); + // TODO 2: 필터에 따라 해당 user의 해당 space 내의 게시판 게시글 리스트 return + List posts; + if(filter != null && !filter.isEmpty()) { + posts = postDao.findBySpaceAndType(spaceBySpaceId, filter); + } else { + posts = postDao.findBySpace(spaceBySpaceId); + } + int postCount = posts.size(); return posts.stream() From e399e3b8a89189926dd0c46ade75761f4fc966c3 Mon Sep 17 00:00:00 2001 From: arkchive Date: Mon, 5 Aug 2024 20:43:58 +0900 Subject: [PATCH 23/25] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=ED=95=84=ED=84=B0=20all,=20notice,=20gene?= =?UTF-8?q?ral=20=EC=84=B8=EA=B0=80=EC=A7=80=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/space/space_spring/controller/PostController.java | 2 +- src/main/java/space/space_spring/service/PostService.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/space/space_spring/controller/PostController.java b/src/main/java/space/space_spring/controller/PostController.java index 8d02cac0..e44e4f96 100644 --- a/src/main/java/space/space_spring/controller/PostController.java +++ b/src/main/java/space/space_spring/controller/PostController.java @@ -19,7 +19,7 @@ public class PostController { @GetMapping("/board") public BaseResponse> getBoard( @PathVariable Long spaceId, - @RequestParam(required = false) String filter) { + @RequestParam(defaultValue = "all") String filter) { List board = postService.getAllPosts(spaceId, filter); return new BaseResponse<>(board); } diff --git a/src/main/java/space/space_spring/service/PostService.java b/src/main/java/space/space_spring/service/PostService.java index ff778d7e..94f41597 100644 --- a/src/main/java/space/space_spring/service/PostService.java +++ b/src/main/java/space/space_spring/service/PostService.java @@ -31,9 +31,12 @@ public List getAllPosts(Long spaceId, String filter) { // TODO 2: 필터에 따라 해당 user의 해당 space 내의 게시판 게시글 리스트 return List posts; - if(filter != null && !filter.isEmpty()) { - posts = postDao.findBySpaceAndType(spaceBySpaceId, filter); + if("notice".equalsIgnoreCase(filter)) { + posts = postDao.findBySpaceAndType(spaceBySpaceId, "notice"); + } else if ("general".equalsIgnoreCase(filter)){ + posts = postDao.findBySpaceAndType(spaceBySpaceId, "general"); } else { + // filter = "all" 일 경우 전체 게시글 조회 posts = postDao.findBySpace(spaceBySpaceId); } From 65b4ef2efac7f56cbe10051b98f12b82301b206d Mon Sep 17 00:00:00 2001 From: arkchive Date: Tue, 6 Aug 2024 04:49:42 +0900 Subject: [PATCH 24/25] =?UTF-8?q?feat:=20isUserInSpace=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space/space_spring/controller/PostController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/space/space_spring/controller/PostController.java b/src/main/java/space/space_spring/controller/PostController.java index e44e4f96..4d6e85e7 100644 --- a/src/main/java/space/space_spring/controller/PostController.java +++ b/src/main/java/space/space_spring/controller/PostController.java @@ -3,11 +3,15 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; +import space.space_spring.argument_resolver.jwtLogin.JwtLoginAuth; import space.space_spring.dto.post.ReadPostsResponse; +import space.space_spring.entity.UserSpace; import space.space_spring.response.BaseResponse; import space.space_spring.service.PostService; +import space.space_spring.util.userSpace.UserSpaceUtils; import java.util.List; +import java.util.Optional; @RestController @RequiredArgsConstructor @@ -15,11 +19,15 @@ @Slf4j public class PostController { private final PostService postService; + private final UserSpaceUtils userSpaceUtils; @GetMapping("/board") public BaseResponse> getBoard( + @JwtLoginAuth Long userId, @PathVariable Long spaceId, @RequestParam(defaultValue = "all") String filter) { + Optional userInSpace = userSpaceUtils.isUserInSpace(userId, spaceId); + log.info("UserName = {}, UserSpaceAuth = {}", userInSpace.get().getUserName(), userInSpace.get().getUserSpaceAuth()); List board = postService.getAllPosts(spaceId, filter); return new BaseResponse<>(board); } From 9c78d96cd42497a2f4a8ffd591ed367205263973 Mon Sep 17 00:00:00 2001 From: arkchive Date: Tue, 6 Aug 2024 13:17:41 +0900 Subject: [PATCH 25/25] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=B6=84=EB=8B=A8=EC=9C=84=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/space/space_spring/util/post/ConvertCreatedDate.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/space/space_spring/util/post/ConvertCreatedDate.java b/src/main/java/space/space_spring/util/post/ConvertCreatedDate.java index 070d865a..838246d9 100644 --- a/src/main/java/space/space_spring/util/post/ConvertCreatedDate.java +++ b/src/main/java/space/space_spring/util/post/ConvertCreatedDate.java @@ -16,6 +16,8 @@ else if(ChronoUnit.DAYS.between(createdAt, now) != 0) return ChronoUnit.DAYS.between(createdAt, now) + "일 전"; else if(ChronoUnit.HOURS.between(createdAt, now) != 0) return ChronoUnit.HOURS.between(createdAt, now) + "시간 전"; + else if (ChronoUnit.MINUTES.between(createdAt, now) != 0) + return ChronoUnit.MINUTES.between(createdAt, now) + "분 전"; else return "방금"; }