-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
55 changed files
with
636 additions
and
161 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
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
60 changes: 60 additions & 0 deletions
60
src/main/java/com/nooblol/board/controller/BoardController.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,60 @@ | ||
package com.nooblol.board.controller; | ||
|
||
import com.nooblol.global.dto.ResponseDto; | ||
import com.nooblol.board.service.CategoryService; | ||
import com.nooblol.global.utils.ResponseUtils; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/board") | ||
@RequiredArgsConstructor | ||
@Validated | ||
public class BoardController { | ||
|
||
private final CategoryService categoryService; | ||
|
||
/** | ||
* 파라미터로 받은 status와 일치하는 모든 category를 반환한다. | ||
* | ||
* @param status Category의 상태값 | ||
* @return | ||
*/ | ||
@GetMapping("/categoryList") | ||
public ResponseDto getCategoryList( | ||
@RequestParam(value = "status", defaultValue = "1") int status) { | ||
return ResponseUtils.makeListToResponseDto( | ||
Optional.of(categoryService.getCategoryList(status)).get() | ||
); | ||
} | ||
|
||
/** | ||
* Parameter로 요청한 CategoryId의 하위 게시판리스트를 OK상태값과 함께 반환한다. | ||
* | ||
* @param categoryId 해당값은 필수로 들어와야한다 | ||
* @param status 희망하는 상태값을 받는다. 없는 경우 DefaultValue로 Active상태값이 주어진다. | ||
* @return | ||
*/ | ||
@GetMapping("/bbsList") | ||
public ResponseDto getBbsList( | ||
@RequestParam(value = "categoryId") int categoryId, | ||
@RequestParam(value = "status", required = false, defaultValue = "1") int status | ||
) { | ||
return ResponseUtils.makeListToResponseDto( | ||
Optional.of(categoryService.getBbsList(categoryId, status)).get() | ||
); | ||
} | ||
|
||
|
||
@GetMapping("/bbsAllList") | ||
public ResponseDto getAllBbsList() { | ||
return ResponseUtils.makeListToResponseDto(categoryService.getAllBbsList()); | ||
} | ||
} |
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,26 @@ | ||
package com.nooblol.board.dto; | ||
|
||
import java.sql.Timestamp; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class BbsDto { | ||
|
||
private int bbsId; | ||
private int categoryId; | ||
private String bbsName; | ||
private int status; | ||
private String createdUserId; | ||
private Timestamp createdAt; | ||
private String updatedUserId; | ||
private Timestamp updatedAt; | ||
|
||
} |
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,22 @@ | ||
package com.nooblol.board.dto; | ||
|
||
import java.sql.Timestamp; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CategoryDto { | ||
|
||
private int categoryId; | ||
private String categoryName; | ||
private int status; | ||
private String createdUserId; | ||
private Timestamp createdAt; | ||
private String updatedUserId; | ||
private Timestamp updatedAt; | ||
} |
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,17 @@ | ||
package com.nooblol.board.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class SearchBbsListDto { | ||
|
||
private int categoryId; | ||
private int status; | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/nooblol/board/mapper/CategoryMapper.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,22 @@ | ||
package com.nooblol.board.mapper; | ||
|
||
import com.nooblol.board.dto.BbsDto; | ||
import com.nooblol.board.dto.CategoryDto; | ||
import com.nooblol.board.dto.SearchBbsListDto; | ||
import java.util.List; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.springframework.cache.annotation.CacheEvict; | ||
|
||
@Mapper | ||
public interface CategoryMapper { | ||
|
||
@CacheEvict(value = "category", allEntries = true, key = "#status") | ||
List<CategoryDto> selectCategory(int status); | ||
|
||
@CacheEvict(value = "bbs", allEntries = true, key = "#searchBbsListDto.categoryId") | ||
List<BbsDto> selectBbsList(SearchBbsListDto searchBbsListDto); | ||
|
||
@CacheEvict(value = "allBbs", allEntries = true) | ||
List<BbsDto> selectAllBbsList(); | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/nooblol/board/service/CategoryService.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,35 @@ | ||
package com.nooblol.board.service; | ||
|
||
import com.nooblol.board.dto.BbsDto; | ||
import com.nooblol.board.dto.CategoryDto; | ||
import java.util.List; | ||
|
||
public interface CategoryService { | ||
|
||
/** | ||
* BBS_CATEGORY 테이블에서 파라미터로 받은 status 상태인 데이터를 조회하여 List로 반환한다 Enum에 존재하지 않는 Status인 경우에는 Null이 | ||
* 반환된다. | ||
* <p> | ||
* 해당 기능은 조회만 하기 때문에 Transactional Readonly설정이 되어있다. | ||
* | ||
* @param status 현재 Category상태값 | ||
* @return | ||
*/ | ||
List<CategoryDto> getCategoryList(int status); | ||
|
||
/** | ||
* parameter로 받은CategoryId의 하위 리스트중 status가 일치하는 데이터를 BBS테이블에서 조회하여 List로 반환한다 | ||
* | ||
* @param categoryId 카테고리ID | ||
* @param status 현재 해당 게시판의 상태값 | ||
* @return | ||
*/ | ||
List<BbsDto> getBbsList(int categoryId, int status); | ||
|
||
/** | ||
* 상태구분없이 모든 게시판 획득 | ||
* @return | ||
*/ | ||
List<BbsDto> getAllBbsList(); | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/com/nooblol/board/service/impl/CategoryServiceImpl.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,55 @@ | ||
package com.nooblol.board.service.impl; | ||
|
||
import com.nooblol.board.dto.BbsDto; | ||
import com.nooblol.board.dto.CategoryDto; | ||
import com.nooblol.board.dto.SearchBbsListDto; | ||
import com.nooblol.board.mapper.CategoryMapper; | ||
import com.nooblol.board.service.CategoryService; | ||
import com.nooblol.board.utils.BoardStatusEnum; | ||
import com.nooblol.global.exception.ExceptionMessage; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class CategoryServiceImpl implements CategoryService { | ||
|
||
private final CategoryMapper categoryMapper; | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
@Cacheable(cacheNames = "category", key = "#status") | ||
public List<CategoryDto> getCategoryList(int status) { | ||
if (BoardStatusEnum.isExistStatus(status)) { | ||
return categoryMapper.selectCategory(status); | ||
} | ||
throw new IllegalArgumentException(ExceptionMessage.BAD_REQUEST); | ||
} | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
@Cacheable(cacheNames = "bbs", key = "#categoryId") | ||
public List<BbsDto> getBbsList(int categoryId, int status) { | ||
if (BoardStatusEnum.isExistStatus(status)) { | ||
return categoryMapper.selectBbsList( | ||
new SearchBbsListDto().builder() | ||
.categoryId(categoryId) | ||
.status(status) | ||
.build() | ||
); | ||
} | ||
throw new IllegalArgumentException(ExceptionMessage.BAD_REQUEST); | ||
} | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
@Cacheable(cacheNames = "allBbs") | ||
public List<BbsDto> getAllBbsList() { | ||
return categoryMapper.selectAllBbsList(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/nooblol/board/utils/BoardStatusEnum.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,22 @@ | ||
package com.nooblol.board.utils; | ||
|
||
import java.util.Arrays; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum BoardStatusEnum { | ||
ACTIVE(1), DEACTIVE(2); | ||
|
||
BoardStatusEnum(int status) { | ||
this.status = status; | ||
} | ||
|
||
int status; | ||
|
||
|
||
public static boolean isExistStatus(int statusType) { | ||
return Arrays.stream(BoardStatusEnum.values()) | ||
.anyMatch(status -> status.getStatus() == statusType); | ||
} | ||
|
||
} |
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.