Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ public PagedBoardInfo getBoardListByUserId(@JwtValidation Long loginUserId,
return boardService.getBoardListByUserId(loginUserId, userId, pageable);
}

@GetMapping("/temp/{boardId}")
@GetMapping("/temp")
@Operation(summary = "임시저장된 게시글 단일 조회 API", description = "임시저장된 게시글 단일 조회하는 API 구현.")
public BoardInfo getBoardListByUserId(@JwtValidation Long userId,
@PathVariable Long boardId) {
return boardService.getTempBoard(userId, boardId);
public BoardInfo getBoardListByUserId(@JwtValidation Long userId) {
return boardService.getTempBoard(userId);
}

@PostMapping("/bookmark/{boardId}")
Expand Down Expand Up @@ -116,7 +115,7 @@ public BoardDeleteInfo deleteBoard(@JwtValidation Long userId,
@PatchMapping("/{boardId}/lift-up")
@Operation(summary = "게시글 끌어올리기 API", description = "게시글을 끌어올립니다.")
public BoardInfo updateLiftUpDate(@JwtValidation Long userId,
@PathVariable Long boardId){
@PathVariable Long boardId) {
return boardService.updateLiftUpDate(userId, boardId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Board toEntity(User user, Game game, Club cheerClub, CreateOrUpdateBoardR
.title(boardRequest.getTitle())
.content(boardRequest.getContent())
.maxPerson(boardRequest.getMaxPerson())
.currentPerson(0)
.user(user)
.club(cheerClub)
.game(game)
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/back/catchmate/domain/board/entity/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class Board extends BaseTimeEntity {
@Column(nullable = false)
private String content;

@Column(nullable = false)
private int currentPerson;

@Column(nullable = false)
private int maxPerson;

Expand Down Expand Up @@ -115,4 +118,12 @@ public void deleteBoard() {
// 삭제 시간 기록
super.delete();
}

public boolean canIncrementCurrentPerson() {
return currentPerson < maxPerson;
}

public void incrementCurrentPerson() {
this.currentPerson++;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public interface BoardRepository extends JpaRepository<Board, Long>, BoardReposi

Page<Board> findAllByUserIdAndDeletedAtIsNullAndIsCompletedIsTrue(Long userId, Pageable pageable);

Optional<Board> findByIdAndUserIdAndIsCompletedIsFalse(Long boardId, Long userId);
Optional<Board> findTopByUserIdAndIsCompletedIsFalseOrderByCreatedAtDesc(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface BoardService {

PagedBoardInfo getBoardListByUserId(Long loginUserId, Long userId, Pageable pageable);

BoardInfo getTempBoard(Long userId, Long boardId);
BoardInfo getTempBoard(Long userId);

BoardDeleteInfo deleteBoard(Long userId, Long boardId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ public PagedBoardInfo getBoardListByUserId(Long loginUserId, Long userId, Pageab

@Override
@Transactional
public BoardInfo getTempBoard(Long userId, Long boardId) {
public BoardInfo getTempBoard(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));

Board tempBoard = boardRepository.findByIdAndUserIdAndIsCompletedIsFalse(boardId, user.getId())
Board tempBoard = boardRepository.findTopByUserIdAndIsCompletedIsFalseOrderByCreatedAtDesc(user.getId())
.orElseThrow(() -> new BaseException(ErrorCode.TEMP_BOARD_NOT_FOUND));

if (user.isDifferentUserFrom(tempBoard.getUser())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public UpdateEnrollInfo acceptEnroll(Long enrollId, Long userId) throws IOExcept
User enrollApplicant = userRepository.findById(enroll.getUser().getId())
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));

Board board = enroll.getBoard();
if (board.canIncrementCurrentPerson()) {
board.incrementCurrentPerson();
}

// 게시글 작성자와 로그인한 사용자가 다를 경우 예외 발생
if (loginUser.isDifferentUserFrom(boardWriter)) {
throw new BaseException(ErrorCode.ENROLL_ACCEPT_INVALID);
Expand All @@ -171,7 +176,6 @@ public UpdateEnrollInfo acceptEnroll(Long enrollId, Long userId) throws IOExcept
// 데이터베이스에 저장
notificationService.createNotification(title, body, boardWriter.getProfileImageUrl(), enroll.getBoard().getId(), enrollApplicant.getId());


enroll.respondToEnroll(AcceptStatus.ACCEPTED);
return enrollConverter.toUpdateEnrollInfo(enroll, AcceptStatus.ACCEPTED);
}
Expand Down
Loading