Skip to content

Commit

Permalink
Merge pull request #39 from f-lab-edu/feature/#38
Browse files Browse the repository at this point in the history
[#34, #38 ] 카테고리와 게시판의 리스트 조회 기능 구현
  • Loading branch information
donsonioc2010 authored Sep 26, 2022
2 parents bfd0e01 + 7e5cf40 commit 3d3f4fe
Show file tree
Hide file tree
Showing 55 changed files with 636 additions and 161 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-mail'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-aop'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-cache'
implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '3.0.6'
implementation group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '2.2.2'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import com.nooblol.account.service.MatchGameAddInfoService;
import com.nooblol.account.service.MatchGameInfoService;
import com.nooblol.global.dto.ResponseDto;
import com.nooblol.global.utils.ResponseEnum;
import java.util.List;
import com.nooblol.global.utils.ResponseUtils;
import javax.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -66,7 +64,9 @@ public ResponseDto selectMatchList(
public ResponseDto getMatchAllParticipants(
@RequestParam(value = "matchId", required = false) @NotBlank String matchId
) {
return makeReturnValue(matchGameAddInfoService.getMatchAllParticipantsList(matchId));
return ResponseUtils.makeListToResponseDto(
matchGameAddInfoService.getMatchAllParticipantsList(matchId)
);
}

/**
Expand All @@ -79,7 +79,7 @@ public ResponseDto getMatchAllParticipants(
public ResponseDto getMatchBan(
@RequestParam(value = "matchId", required = false) @NotBlank String matchId
) {
return makeReturnValue(matchGameAddInfoService.getMatchBanList(matchId));
return ResponseUtils.makeListToResponseDto(matchGameAddInfoService.getMatchBanList(matchId));
}

/**
Expand All @@ -94,24 +94,9 @@ public ResponseDto getMatchUseRun(
@RequestParam(value = "matchId", required = false) @NotBlank String matchId,
@RequestParam(value = "puuid", required = false) @NotBlank String puuid
) {
return makeReturnValue(matchGameAddInfoService.getMatchUseRunList(matchId, puuid));
return ResponseUtils.makeListToResponseDto(
matchGameAddInfoService.getMatchUseRunList(matchId, puuid)
);
}

/**
* MatchGameInfo에서의 경우에는 사용하지 않은 방식이며, 해당 테이블의 경우 대량의 정보를 서로 주고받기 때문에 한개의 메소드에서 모든 처리를 하는 과정을 막고
* 싶었다.
* <p>
* 해당 클래스에서 사용한 이유는 MatchGameInfo에 비해 상대적으로 적은 요청이 들어오는 경우가 많을 것이라 예상되어 한개의 메소드에서 모든 Return작업을
* 처리하였다.
*
* @param list
* @param <T>
* @return
*/
private <T> ResponseDto makeReturnValue(List<T> list) {
if (list == null || list.size() == 0) {
return ResponseEnum.NOT_FOUND.getResponse();
}
return new ResponseDto(HttpStatus.OK.value(), list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.nooblol.account.service.SummonerHistoryService;
import com.nooblol.global.config.RiotConfiguration;
import com.nooblol.global.dto.ResponseDto;
import com.nooblol.global.utils.CommonUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -21,6 +20,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;

@Service
Expand Down Expand Up @@ -73,7 +73,7 @@ public ResponseDto selSummonerHistoryByRiot(String summonerId) {
} catch (Exception e) {
log.error(e.getMessage());
} finally {
if (CommonUtils.objectIsNull(rtnDto)) {
if (ObjectUtils.isEmpty(rtnDto)) {
rtnDto = new ResponseDto(HttpStatus.NOT_FOUND.value(), HttpStatus.NOT_FOUND);
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ private void summonerHistoryDBHandle(SummonerHistoryDto summonerHistoryDto) {
SummonerHistoryDto existDataByDB =
summonerHistoryMapper.selectSummonerHistoryByLeagueAndId(leagueId, summonerId);

if (CommonUtils.objectIsNotNull(existDataByDB)) {
if (!ObjectUtils.isEmpty(existDataByDB)) {
summonerHistoryMapper.updateSummonerHistory(summonerHistoryDto);
} else {
summonerHistoryMapper.insertSummonerHistory(summonerHistoryDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;

import static com.nooblol.global.utils.CommonUtils.*;
import static com.nooblol.global.utils.StringUtils.summonerNameWhiteSpaceReplace;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -56,7 +57,7 @@ public void summonerAccountDBProcess(ResponseDto responseDto) {
SummonerDto riotSearchData = (SummonerDto) responseDto.getResult();
SummonerDto serviceDBData = selectSummonerAccountByDB(riotSearchData);

if (objectIsNotNull(serviceDBData)) {
if (ObjectUtils.isEmpty(serviceDBData)) {
boolean isSame = riotSearchData.equals(serviceDBData);
if (!isSame) {
summonerMapper.updateSummonerAccount(riotSearchData);
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/com/nooblol/board/controller/BoardController.java
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());
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/nooblol/board/dto/BbsDto.java
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;

}
22 changes: 22 additions & 0 deletions src/main/java/com/nooblol/board/dto/CategoryDto.java
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;
}
17 changes: 17 additions & 0 deletions src/main/java/com/nooblol/board/dto/SearchBbsListDto.java
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 src/main/java/com/nooblol/board/mapper/CategoryMapper.java
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 src/main/java/com/nooblol/board/service/CategoryService.java
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();

}
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 src/main/java/com/nooblol/board/utils/BoardStatusEnum.java
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);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.nooblol.global.config;

import com.nooblol.community.utils.UserRoleStatus;
import com.nooblol.user.utils.UserRoleStatus;
import com.nooblol.global.exception.ExceptionMessage;
import com.nooblol.global.utils.SessionUtils;
import java.util.Optional;
Expand Down
Loading

0 comments on commit 3d3f4fe

Please sign in to comment.