-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
670 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/stempo/api/domain/application/service/BoardService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.stempo.api.domain.application.service; | ||
|
||
import com.stempo.api.domain.domain.model.BoardCategory; | ||
import com.stempo.api.domain.presentation.dto.request.BoardRequestDto; | ||
import com.stempo.api.domain.presentation.dto.request.BoardUpdateRequestDto; | ||
import com.stempo.api.domain.presentation.dto.response.BoardResponseDto; | ||
|
||
import java.util.List; | ||
|
||
public interface BoardService { | ||
|
||
Long registerBoard(BoardRequestDto requestDto); | ||
|
||
List<BoardResponseDto> getBoardsByCategory(BoardCategory category); | ||
|
||
Long updateBoard(Long boardId, BoardUpdateRequestDto requestDto); | ||
|
||
Long deleteBoard(Long boardId); | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/stempo/api/domain/application/service/BoardServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.stempo.api.domain.application.service; | ||
|
||
import com.stempo.api.domain.domain.model.Board; | ||
import com.stempo.api.domain.domain.model.BoardCategory; | ||
import com.stempo.api.domain.domain.model.User; | ||
import com.stempo.api.domain.domain.repository.BoardRepository; | ||
import com.stempo.api.domain.presentation.dto.request.BoardRequestDto; | ||
import com.stempo.api.domain.presentation.dto.request.BoardUpdateRequestDto; | ||
import com.stempo.api.domain.presentation.dto.response.BoardResponseDto; | ||
import com.stempo.api.global.exception.PermissionDeniedException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BoardServiceImpl implements BoardService { | ||
|
||
private final UserService userService; | ||
private final BoardRepository repository; | ||
|
||
@Override | ||
public Long registerBoard(BoardRequestDto requestDto) { | ||
User user = userService.getCurrentUser(); | ||
Board board = BoardRequestDto.toDomain(requestDto, user.getDeviceTag()); | ||
board.validateAccessPermissionForNotice(user); | ||
return repository.save(board).getId(); | ||
} | ||
|
||
@Override | ||
public List<BoardResponseDto> getBoardsByCategory(BoardCategory category) { | ||
validateAccessPermissionForSuggestion(category); | ||
List<Board> boards = repository.findByCategory(category); | ||
return boards.stream() | ||
.map(BoardResponseDto::toDto) | ||
.toList(); | ||
} | ||
|
||
@Override | ||
public Long updateBoard(Long boardId, BoardUpdateRequestDto requestDto) { | ||
User user = userService.getCurrentUser(); | ||
Board board = repository.findByIdOrThrow(boardId); | ||
board.validateAccessPermission(user); | ||
board.update(requestDto); | ||
return repository.save(board).getId(); | ||
} | ||
|
||
@Override | ||
public Long deleteBoard(Long boardId) { | ||
User user = userService.getCurrentUser(); | ||
Board board = repository.findByIdOrThrow(boardId); | ||
board.validateAccessPermission(user); | ||
board.delete(); | ||
return repository.save(board).getId(); | ||
} | ||
|
||
private void validateAccessPermissionForSuggestion(BoardCategory category) { | ||
User user = userService.getCurrentUser(); | ||
if (category.equals(BoardCategory.SUGGESTION) && !user.isAdmin()) { | ||
throw new PermissionDeniedException("건의하기는 관리자만 조회할 수 있습니다."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/com/stempo/api/domain/domain/model/Board.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.stempo.api.domain.domain.model; | ||
|
||
import com.stempo.api.domain.presentation.dto.request.BoardUpdateRequestDto; | ||
import com.stempo.api.global.exception.PermissionDeniedException; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class Board { | ||
|
||
private Long id; | ||
private String deviceTag; | ||
private BoardCategory category; | ||
private String title; | ||
private String content; | ||
private List<String> fileUrls; | ||
private LocalDateTime createdAt; | ||
private boolean deleted; | ||
|
||
public void update(BoardUpdateRequestDto requestDto) { | ||
Optional.ofNullable(requestDto.getCategory()).ifPresent(category -> this.category = category); | ||
Optional.ofNullable(requestDto.getTitle()).ifPresent(title -> this.title = title); | ||
Optional.ofNullable(requestDto.getContent()).ifPresent(content -> this.content = content); | ||
} | ||
|
||
public void delete() { | ||
setDeleted(true); | ||
} | ||
|
||
public boolean isOwner(User user) { | ||
return this.deviceTag.equals(user.getDeviceTag()); | ||
} | ||
|
||
public void validateAccessPermission(User user) { | ||
if (!(isOwner(user) || user.isAdmin())) { | ||
throw new PermissionDeniedException("게시글을 수정/삭제할 권한이 없습니다."); | ||
} | ||
} | ||
|
||
public void validateAccessPermissionForNotice(User user) { | ||
if (isNotice() && !user.isAdmin()) { | ||
throw new PermissionDeniedException("공지사항 관리 권한이 없습니다."); | ||
} | ||
} | ||
|
||
public boolean isNotice() { | ||
return category.equals(BoardCategory.NOTICE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/stempo/api/domain/domain/repository/BoardRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.stempo.api.domain.domain.repository; | ||
|
||
import com.stempo.api.domain.domain.model.Board; | ||
import com.stempo.api.domain.domain.model.BoardCategory; | ||
|
||
import java.util.List; | ||
|
||
public interface BoardRepository { | ||
|
||
Board save(Board board); | ||
|
||
List<Board> findByCategory(BoardCategory category); | ||
|
||
Board findByIdOrThrow(Long boardId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.