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 04ad05e commit 03ca19f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
33 changes: 33 additions & 0 deletions src/main/java/com/ceos/bankids/controller/ChallengeController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
package com.ceos.bankids.controller;

import com.ceos.bankids.config.CommonResponse;
import com.ceos.bankids.domain.User;
import com.ceos.bankids.dto.ChallengeDTO;
import com.ceos.bankids.mapper.ChallengeMapper;
import com.ceos.bankids.mapper.request.ChallengeRequest;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
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.RestController;

@Slf4j
@RestController
@RequestMapping("/challenge")
@RequiredArgsConstructor
public class ChallengeController {

private final ChallengeMapper challengeMapper;

@ApiOperation(value = "돈길 생성")
@PostMapping(produces = "application/json; charset=utf-8")
public CommonResponse<ChallengeDTO> postChallenge(@AuthenticationPrincipal User authUser,
@RequestBody
ChallengeRequest challengeRequest) {

log.info("api = 돈길 생성, req = {}", challengeRequest);

ChallengeDTO challengeDTO = challengeMapper.postChallenge(authUser, challengeRequest);

return CommonResponse.onSuccess(challengeDTO);
}

}
16 changes: 5 additions & 11 deletions src/main/java/com/ceos/bankids/mapper/ChallengeMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,16 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
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
@RestController
@RequestMapping("/challenge")
@Service
@RequiredArgsConstructor
public class ChallengeMapper {

Expand All @@ -67,13 +64,10 @@ public class ChallengeMapper {
private final ParentServiceImpl parentService;
private final KidServiceImpl kidService;

@ApiOperation(value = "돈길 생성")
@PostMapping(produces = "application/json; charset=utf-8")
public CommonResponse<ChallengeDTO> postChallenge(@AuthenticationPrincipal User authUser,
// 돈길 생성 API Mapper
public ChallengeDTO postChallenge(@AuthenticationPrincipal User authUser,
@Valid @RequestBody ChallengeRequest challengeRequest) {

log.info("api = 돈길 생성, req = {}", challengeRequest);

// validation
sundayValidation();
userRoleValidation(authUser, true);
Expand All @@ -93,7 +87,7 @@ public CommonResponse<ChallengeDTO> postChallenge(@AuthenticationPrincipal User
// 저장로직 성공시 알림 로직
notificationService.createPendingChallengeNotification(contractUser, challengeUser);

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

@ApiOperation(value = "돈길 포기하기")
Expand Down

0 comments on commit 03ca19f

Please sign in to comment.