Skip to content

Commit 15d7fb1

Browse files
authored
✨ 커뮤니티 게시판 고정으로 변경
✨ 커뮤니티 게시판 고정으로 변경
2 parents 2fd49f2 + 227c432 commit 15d7fb1

File tree

17 files changed

+115
-346
lines changed

17 files changed

+115
-346
lines changed

src/main/java/DC_square/spring/config/jwt/JwtTokenProvider.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ public class JwtTokenProvider {
2222

2323
//토큰 유효기간 설정
2424
// private final long accessTokenValidityInMilliseconds = 1000L * 60 * 1; // 2분
25-
// //private final long accessTokenValidityInMilliseconds = 1000L * 60 * 60* 24; // 24시
26-
// //private final long refreshTokenValidityInMilliseconds = 1000L * 60 * 60 * 24 * 14; // 2주
25+
private final long accessTokenValidityInMilliseconds = 1000L * 60 * 60* 24; // 24시
26+
private final long refreshTokenValidityInMilliseconds = 1000L * 60 * 60 * 24 * 14; // 2주
2727
// private final long refreshTokenValidityInMilliseconds = 1000L * 60 * 5; // 5분
28-
private final long accessTokenValidityInMilliseconds = 1000L * 60 * 10; // 10분
29-
private final long refreshTokenValidityInMilliseconds = 1000L * 60 * 60; // 1시간
3028

3129
private final RefreshTokenRedisRepository refreshTokenRedisRepository;
3230

src/main/java/DC_square/spring/domain/entity/community/Board.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package DC_square.spring.domain.entity.community;
22

3+
import DC_square.spring.domain.enums.BoardType;
34
import jakarta.persistence.*;
45
import lombok.*;
56
import org.springframework.data.annotation.CreatedDate;
@@ -21,8 +22,9 @@ public class Board {
2122
@Column(name = "board_id")
2223
private Long id;
2324

24-
@Column(name = "title",nullable = false)
25-
private String boardName;
25+
@Enumerated(EnumType.STRING)
26+
@Column(name = "board_type",nullable = false)
27+
private BoardType boardType;
2628

2729
@Column(name = "content",nullable = false)
2830
private String content;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package DC_square.spring.domain.entity.community;
2+
3+
import DC_square.spring.domain.enums.BoardType;
4+
import DC_square.spring.repository.community.BoardRepository;
5+
import jakarta.annotation.PostConstruct;
6+
import java.time.LocalDateTime;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.stereotype.Component;
9+
10+
@Component
11+
@RequiredArgsConstructor
12+
public class BoardInitializer {
13+
14+
private final BoardRepository boardRepository;
15+
16+
@PostConstruct
17+
public void initializeBoards() {
18+
for (BoardType type: BoardType.values()) {
19+
//이미 존재하는지 확인
20+
boolean exists = boardRepository.existsByBoardType(type);
21+
22+
// 존재하지 않으면 생성
23+
if (!exists) {
24+
Board board = Board.builder()
25+
.boardType(type)
26+
.content(type.getDisplayName() + "입니다.") // 기본 내용
27+
.createdDate(LocalDateTime.now()).
28+
build();
29+
boardRepository.save(board);
30+
}
31+
}
32+
}
33+
34+
}

src/main/java/DC_square/spring/domain/entity/community/MyBoard.java

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package DC_square.spring.domain.enums;
2+
3+
public enum BoardType {
4+
자유게시판("자유 게시판"),
5+
정보공유게시판("정보 공유 게시판"),
6+
질문상담게시판("질문/상담 게시판"),
7+
입양임보게시판("입양/임보 게시판"),
8+
실종목격게시판("실종/목격 게시판");
9+
10+
private final String displayName;
11+
12+
BoardType(String displayName) {
13+
this.displayName = displayName;
14+
}
15+
16+
public String getDisplayName() {
17+
return displayName;
18+
}
19+
20+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package DC_square.spring.repository.community;
22

33
import DC_square.spring.domain.entity.community.Board;
4+
import DC_square.spring.domain.enums.BoardType;
5+
import java.util.Optional;
46
import org.springframework.data.jpa.repository.JpaRepository;
57
import org.springframework.stereotype.Repository;
68

79
import java.util.List;
810

911
@Repository
1012
public interface BoardRepository extends JpaRepository<Board, Long> {
11-
List<Board> findByBoardNameContainingIgnoreCase(String boardName); // 부분검색 + 대소문자 구분 없이 검색
12-
//📌 ContainingIgnoreCase란?
13-
//findByBoardNameContainingIgnoreCase(String boardName)
14-
//부분 검색(Containing): 검색어가 포함된 모든 데이터를 찾음 ("고양이" 입력 -> "고양이게시판1", "고양이게시판2", "내 고양이"까지 모두 검색 가능)
15-
//대소문자 무시(IgnoreCase): 고양이 / 고양이게시판 / Goyang 등 대소문자 구분 없이 검색
1613

17-
List<Board> findByBoardNameIn(List<String> boardNames);
14+
15+
Board findByBoardType(BoardType boardType);
16+
17+
boolean existsByBoardType(BoardType boardType);
1818
}

src/main/java/DC_square/spring/repository/community/MyBoardRepository.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/DC_square/spring/service/UserService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public class UserService {
6565
private final PostRepository postRepository;
6666
private final PostLikeRepository postLikeRepository;
6767
private final CommentRepository commentRepository;
68-
private final MyBoardRepository myBoardRepository;
6968
private final PlaceWishRepository placeWishRepository;
7069
private final PlaceReviewRepository placeReviewRepository;
7170
private final WalkWishRepository walkWishRepository;
@@ -417,7 +416,7 @@ public void deleteUser(Long userId) {
417416
postRepository.deleteAll(userPosts);
418417

419418
// 커뮤니티 관련
420-
myBoardRepository.deleteAll(myBoardRepository.findByUserOrderByIdAsc(user));
419+
// myBoardRepository.deleteAll(myBoardRepository.findByUserOrderByIdAsc(user));
421420

422421
// 장소 관련
423422
placeWishRepository.deleteAll(placeWishRepository.findAllByUserId(user.getId()));

src/main/java/DC_square/spring/service/community/BoardService.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import DC_square.spring.domain.entity.community.Board;
44
import DC_square.spring.domain.entity.community.Keyword;
5+
import DC_square.spring.domain.enums.BoardType;
56
import DC_square.spring.repository.community.BoardRepository;
67
import DC_square.spring.web.dto.request.community.BoardRequestDto;
78
import DC_square.spring.web.dto.response.community.BoardResponseDto;
89
import jakarta.persistence.EntityNotFoundException;
10+
import java.util.Optional;
911
import lombok.RequiredArgsConstructor;
1012
import org.springframework.stereotype.Service;
1113

@@ -26,7 +28,7 @@ public class BoardService {
2628
public BoardResponseDto createdBoard(BoardRequestDto boardRequestDto) {
2729
//Board 엔티티 생성
2830
Board board = Board.builder()
29-
.boardName(boardRequestDto.getBoardName())
31+
.boardType(boardRequestDto.getBoardType())
3032
.content(boardRequestDto.getContent())
3133
.createdDate(LocalDateTime.now())
3234
.build();
@@ -49,7 +51,7 @@ public BoardResponseDto createdBoard(BoardRequestDto boardRequestDto) {
4951
//BoardResponseDto 생성해서 반환
5052
return BoardResponseDto.builder()
5153
.id(savedBoard.getId())
52-
.boardName(savedBoard.getBoardName())
54+
.boardType(savedBoard.getBoardType().getDisplayName())
5355
.content(savedBoard.getContent())
5456
.keywords(keywordList.stream()
5557
.map(Keyword::getKeyword)
@@ -71,7 +73,7 @@ public BoardResponseDto getBoard(Long id) {
7173

7274
return BoardResponseDto.builder()
7375
.id(board.getId())
74-
.boardName(board.getBoardName())
76+
.boardType(board.getBoardType().getDisplayName())
7577
.content(board.getContent())
7678
.keywords(keywords)
7779
.createdAt(board.getCreatedDate())
@@ -84,7 +86,7 @@ public BoardResponseDto updateBoard(Long boardId, BoardRequestDto boardRequestDt
8486
.orElseThrow(() -> new IllegalArgumentException("해당 게시판 id가 존재하지 않습니다."));
8587

8688
// 2. Board 이름과 내용 업데이트
87-
board.setBoardName(boardRequestDto.getBoardName());
89+
board.setBoardType(boardRequestDto.getBoardType());
8890
board.setContent(boardRequestDto.getContent());
8991
board.setCreatedDate(LocalDateTime.now());
9092

@@ -107,7 +109,7 @@ public BoardResponseDto updateBoard(Long boardId, BoardRequestDto boardRequestDt
107109
// 5. BoardResponseDto 생성 및 반환
108110
return BoardResponseDto.builder()
109111
.id(updatedBoard.getId())
110-
.boardName(updatedBoard.getBoardName())
112+
.boardType(updatedBoard.getBoardType().getDisplayName())
111113
.content(updatedBoard.getContent())
112114
.keywords(updatedBoard.getKeywordList().stream()
113115
.map(Keyword::getKeyword)
@@ -120,22 +122,24 @@ public BoardResponseDto updateBoard(Long boardId, BoardRequestDto boardRequestDt
120122
* 게시판 검색 API(조회)
121123
*/
122124
public List<BoardResponseDto> searchBoardByName(String boardName) {
123-
List<Board> boards = boardRepository.findByBoardNameContainingIgnoreCase(boardName);
124-
if(boards.isEmpty()) {
125-
throw new EntityNotFoundException("해당 이름을 포함하는 게시판을 찾을 수 없습니다: " + boardName);
125+
BoardType boardType;
126+
try {
127+
boardType = BoardType.valueOf(boardName); // 문자열을 enum으로 변환
128+
} catch (IllegalArgumentException e) {
129+
throw new EntityNotFoundException("존재하지 않는 게시판 타입입니다: " + boardName);
126130
}
127131

128-
return boards.stream()
129-
.map(board -> BoardResponseDto.builder()
130-
.id(board.getId())
131-
.boardName(board.getBoardName())
132-
.content(board.getContent())
133-
.keywords(board.getKeywordList().stream()
134-
.map(Keyword::getKeyword)
135-
.collect(Collectors.toList()))
136-
.createdAt(board.getCreatedDate())
137-
.build())
138-
.collect(Collectors.toList());
132+
Board board = boardRepository.findByBoardType(boardType);
133+
134+
return List.of(BoardResponseDto.builder()
135+
.id(board.getId())
136+
.boardType(board.getBoardType().getDisplayName())
137+
.content(board.getContent())
138+
.keywords(board.getKeywordList().stream()
139+
.map(Keyword::getKeyword)
140+
.collect(Collectors.toList()))
141+
.createdAt(board.getCreatedDate())
142+
.build());
139143
}
140144

141145
/**
@@ -146,7 +150,7 @@ public List<BoardResponseDto> getAllBoards() {
146150
return boards.stream()
147151
.map(board -> BoardResponseDto.builder()
148152
.id(board.getId())
149-
.boardName(board.getBoardName())
153+
.boardType(board.getBoardType().getDisplayName())
150154
.content(board.getContent())
151155
.keywords(board.getKeywordList().stream()
152156
.map(Keyword::getKeyword)

0 commit comments

Comments
 (0)