-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐ ํ์ ํํด ๊ธฐ๋ฅ(Adapter & Service)(#15)
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
api/src/main/java/hexagonal/api/member/adapter/in/web/DeleteMemberController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
api/src/main/java/hexagonal/api/member/adapter/in/web/request/DeleteMemberReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
13 changes: 13 additions & 0 deletions
13
api/src/main/java/hexagonal/api/member/adapter/in/web/response/DeleteMemberResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
api/src/main/java/hexagonal/api/member/application/service/DeleteMemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |