Skip to content

Commit

Permalink
refactor: activeInfo 검증 로직 service에서 controller로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
soomanbaek committed Oct 21, 2023
1 parent b679453 commit 4f3aac6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package blacktokkies.toquiz.domain.panel.api;

import blacktokkies.toquiz.domain.activeinfo.ActiveInfoRepository;
import blacktokkies.toquiz.domain.panel.application.PanelService;
import blacktokkies.toquiz.domain.panel.dto.request.CreatePanelRequest;
import blacktokkies.toquiz.domain.panel.dto.request.UpdatePanelRequest;
Expand All @@ -24,6 +25,7 @@
public class PanelApi {
private final PanelService panelService;
private final CookieService cookieService;
private final ActiveInfoRepository activeInfoRepository;

@PostMapping("api/panel")
public ResponseEntity<SuccessResponse<PanelResponse>> createPanel(
Expand Down Expand Up @@ -54,7 +56,7 @@ public ResponseEntity<SuccessMessage> deletePanel(@PathVariable String panelSid)
public ResponseEntity<SuccessResponse<PanelResponse>> updatePanel(
@RequestBody @Valid UpdatePanelRequest request,
@PathVariable String panelSid
){
){
PanelResponse response = panelService.updatePanel(request, panelSid);

return ResponseEntity.ok(new SuccessResponse<>(response));
Expand All @@ -74,7 +76,7 @@ public ResponseEntity<SuccessResponse<GetMyActiveInfoResponse>> getActiveInfo(
@CookieValue(value = "active_info_id", required = false) String activeInfoId
){
// ActiveInfoId가 유효하지 않으면, ActiveInfoId를 쿠키로 새로 발급한다.
if(activeInfoId == null || panelService.isNotExistActiveInfo(activeInfoId)){
if(activeInfoId == null || !activeInfoRepository.existsById(activeInfoId)){
Cookie activeInfoIdCookie = cookieService.issueActiveInfoIdCookie();
httpResponse.addCookie(activeInfoIdCookie);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,4 @@ private ActiveInfo getActiveInfo(String activeInfoId) {
return activeInfoRepository.findById(activeInfoId)
.orElseThrow(() -> new RestApiException(NOT_EXIST_ACTIVE_INFO));
}

public boolean isNotExistActiveInfo(String activeInfoId){
return !activeInfoRepository.existsById(activeInfoId);
}
}

0 comments on commit 4f3aac6

Please sign in to comment.