Skip to content

Commit

Permalink
๐Ÿ‘” ํšŒ์› ํƒˆํ‡ด ๊ธฐ๋Šฅ(Adapter & Service)(#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jun108059 committed Jul 26, 2022
1 parent f30996c commit f2df83f
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package hexagonal.api.member.adapter.in.web;

import hexagonal.api.member.adapter.in.web.response.DeleteMemberResponse;
import hexagonal.api.member.application.port.in.DeleteMemberCommand;
import hexagonal.api.member.application.port.in.DeleteMemberUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class DeleteMemberController {

private final DeleteMemberUseCase deleteMemberUseCase;

@DeleteMapping("/v1/member/{id}")
ResponseEntity<DeleteMemberResponse> deleteMember(@PathVariable("id") Long id) throws Exception {
// ToDo ์ž…๋ ฅ๋ชจ๋ธ Valid Check ์˜ˆ์™ธ ์ฒ˜๋ฆฌ
DeleteMemberCommand command = new DeleteMemberCommand(id);
DeleteMemberResponse deleteMemberResponse = new DeleteMemberResponse(id);
if (deleteMemberUseCase.deleteMember(command)) {
return ResponseEntity.ok(deleteMemberResponse);
} else {
// ToDo Exception ์ •์˜
throw new Exception();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package hexagonal.api.member.adapter.in.web.request;

import lombok.Getter;

@Getter
public class DeleteMemberReq {
Long id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package hexagonal.api.member.adapter.in.web.response;


import lombok.Data;

@Data
public class DeleteMemberResponse {
Long id;

public DeleteMemberResponse(Long id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package hexagonal.api.member.application.service;

import hexagonal.api.member.application.port.in.DeleteMemberCommand;
import hexagonal.api.member.application.port.in.DeleteMemberUseCase;
import hexagonal.api.member.application.port.in.UpdateMemberCommand;
import hexagonal.api.member.application.port.in.UpdateMemberUseCase;
import hexagonal.api.member.application.port.out.DeleteMemberPort;
import hexagonal.api.member.application.port.out.FindMemberPort;
import hexagonal.api.member.application.port.out.UpdateMemberPort;
import hexagonal.core.domain.jpa.MemberJpaEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import javax.persistence.EntityNotFoundException;

@Service
@RequiredArgsConstructor
public class DeleteMemberService implements DeleteMemberUseCase {

private final FindMemberPort findMemberPort;
private final DeleteMemberPort deleteMemberPort;

private boolean checkMemberExistsById(Long id) {
try {
findMemberPort.findMemberById(id);
} catch (EntityNotFoundException e) {
return false;
}

return true;
}

@Override
public Boolean deleteMember(DeleteMemberCommand command) {
// ID ์กด์žฌ ์—ฌ๋ถ€ ๊ฒ€์‚ฌ
if (checkMemberExistsById(command.getId())) {
return deleteMemberPort.deleteMember(command.getId());
} else {
// FixMe Custom Exception ์ฒ˜๋ฆฌํ•˜๊ธฐ
return false;
}
}
}

0 comments on commit f2df83f

Please sign in to comment.