Skip to content

Commit

Permalink
refactor: 돈길 리스트 API Mapper 구조로 리팩토링 #232
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbonai06 committed Sep 19, 2022
1 parent 90e90fb commit 1781302
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
32 changes: 32 additions & 0 deletions src/main/java/com/ceos/bankids/controller/ChallengeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
import com.ceos.bankids.config.CommonResponse;
import com.ceos.bankids.domain.User;
import com.ceos.bankids.dto.ChallengeDTO;
import com.ceos.bankids.dto.KidChallengeListDTO;
import com.ceos.bankids.mapper.ChallengeMapper;
import com.ceos.bankids.mapper.request.ChallengeRequest;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
Expand Down Expand Up @@ -49,4 +53,32 @@ public CommonResponse<ChallengeDTO> deleteChallenge(@AuthenticationPrincipal Use
return CommonResponse.onSuccess(challengeDTO);
}

@ApiOperation(value = "돈길 리스트 가져오기")
@GetMapping(produces = "application/json; charset=utf-8")
public CommonResponse<List<ChallengeDTO>> getListChallenge(
@AuthenticationPrincipal User authUser, @RequestParam String status) {

log.info("api = 돈길 리스트 가져오기, user = {}, status = {}", authUser.getUsername(), status);

List<ChallengeDTO> challengeDTOList = challengeMapper.getListChallenge(authUser, status);

return CommonResponse.onSuccess(challengeDTOList);
}

@ApiOperation(value = "자녀의 돈길 리스트 가져오기")
@GetMapping(value = "/kid/{kidId}", produces = "application/json; charset=utf-8")
public CommonResponse<KidChallengeListDTO> getListKidChallenge(
@AuthenticationPrincipal User authUser, @PathVariable Long kidId,
@RequestParam String status) {

log.info("api = 자녀의 돈길 리스트 가져오기, user = {}, kidId = {}, status = {}",
authUser.getUsername(), kidId, status);

KidChallengeListDTO kidChallengeListDTO = challengeMapper.getListKidChallenge(authUser,
kidId,
status);

return CommonResponse.onSuccess(kidChallengeListDTO);
}

}
17 changes: 4 additions & 13 deletions src/main/java/com/ceos/bankids/mapper/ChallengeMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ public ChallengeDTO deleteChallenge(User authUser, Long challengeId) {
throw new BadRequestException(ErrorCode.CANT_DELETE_CHALLENGE_STATUS.getErrorCode());
}

@ApiOperation(value = "돈길 리스트 가져오기")
@GetMapping(produces = "application/json; charset=utf-8")
public CommonResponse<List<ChallengeDTO>> getListChallenge(
@AuthenticationPrincipal User authUser, @RequestParam String status) {
public List<ChallengeDTO> getListChallenge(User authUser, String status) {

log.info("api = 돈길 리스트 가져오기, user = {}, status = {}", authUser.getUsername(), status);
if (!Objects.equals(status, "walking") && !Objects.equals(status, "pending")) {
Expand Down Expand Up @@ -167,17 +164,11 @@ public CommonResponse<List<ChallengeDTO>> getListChallenge(
});
}

return CommonResponse.onSuccess(challengeDTOList);
return challengeDTOList;
}

@ApiOperation(value = "자녀의 돈길 리스트 가져오기")
@GetMapping(value = "/kid/{kidId}", produces = "application/json; charset=utf-8")
public CommonResponse<KidChallengeListDTO> getListKidChallenge(
@AuthenticationPrincipal User authUser, @PathVariable Long kidId,
@RequestParam String status) {
public KidChallengeListDTO getListKidChallenge(User authUser, Long kidId, String status) {

log.info("api = 자녀의 돈길 리스트 가져오기, user = {}, kidId = {}, status = {}",
authUser.getUsername(), kidId, status);
Kid kid = kidService.getKid(kidId);
User kidUser = kid.getUser();
List<ChallengeDTO> challengeDTOList = new ArrayList<>();
Expand Down Expand Up @@ -219,7 +210,7 @@ public CommonResponse<KidChallengeListDTO> getListKidChallenge(
}
KidChallengeListDTO kidChallengeListDTO = new KidChallengeListDTO(kidUser,
challengeDTOList);
return CommonResponse.onSuccess(kidChallengeListDTO);
return kidChallengeListDTO;
}

@ApiOperation(value = "자녀의 돈길 수락 / 거절")
Expand Down

0 comments on commit 1781302

Please sign in to comment.