From 30dd090b721b953f231978ad2f73f6f48b7db3b4 Mon Sep 17 00:00:00 2001 From: soyeonii Date: Wed, 11 Oct 2023 21:59:10 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EB=B0=8F?= =?UTF-8?q?=20=EB=B2=88=EC=97=AD=EA=B0=80=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moumi/controller/ClientController.java | 21 +++++++++++++++ .../controller/TranslatorController.java | 21 +++++++++++++++ .../com/makive/moumi/model/dto/ClientDTO.java | 23 ++++++++++++++++ .../model/dto/response/ClientResponse.java | 15 +++++++++++ .../dto/response/TranslatorResponse.java | 15 +++++++++++ .../repository/TranslatorRepository.java | 9 +++++++ .../makive/moumi/service/ClientService.java | 27 +++++++++++++++++++ .../moumi/service/TranslatorService.java | 27 +++++++++++++++++++ 8 files changed, 158 insertions(+) create mode 100644 src/main/java/com/makive/moumi/controller/ClientController.java create mode 100644 src/main/java/com/makive/moumi/controller/TranslatorController.java create mode 100644 src/main/java/com/makive/moumi/model/dto/ClientDTO.java create mode 100644 src/main/java/com/makive/moumi/model/dto/response/ClientResponse.java create mode 100644 src/main/java/com/makive/moumi/model/dto/response/TranslatorResponse.java create mode 100644 src/main/java/com/makive/moumi/repository/TranslatorRepository.java create mode 100644 src/main/java/com/makive/moumi/service/ClientService.java create mode 100644 src/main/java/com/makive/moumi/service/TranslatorService.java diff --git a/src/main/java/com/makive/moumi/controller/ClientController.java b/src/main/java/com/makive/moumi/controller/ClientController.java new file mode 100644 index 0000000..7fdbd0f --- /dev/null +++ b/src/main/java/com/makive/moumi/controller/ClientController.java @@ -0,0 +1,21 @@ +package com.makive.moumi.controller; + +import com.makive.moumi.exception.dto.DataResponse; +import com.makive.moumi.service.ClientService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/clients") +@RequiredArgsConstructor +public class ClientController { + private final ClientService clientService; + + @GetMapping("/{clientId}") + public DataResponse getClient(@PathVariable Long clientId) { + return DataResponse.of(clientService.getClient(clientId)); + } +} diff --git a/src/main/java/com/makive/moumi/controller/TranslatorController.java b/src/main/java/com/makive/moumi/controller/TranslatorController.java new file mode 100644 index 0000000..2716ded --- /dev/null +++ b/src/main/java/com/makive/moumi/controller/TranslatorController.java @@ -0,0 +1,21 @@ +package com.makive.moumi.controller; + +import com.makive.moumi.exception.dto.DataResponse; +import com.makive.moumi.service.TranslatorService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/translators") +@RequiredArgsConstructor +public class TranslatorController { + private final TranslatorService translatorService; + + @GetMapping("/{translatorId}") + public DataResponse getTranslator(@PathVariable Long translatorId) { + return DataResponse.of(translatorService.getTranslator(translatorId)); + } +} diff --git a/src/main/java/com/makive/moumi/model/dto/ClientDTO.java b/src/main/java/com/makive/moumi/model/dto/ClientDTO.java new file mode 100644 index 0000000..29cee6c --- /dev/null +++ b/src/main/java/com/makive/moumi/model/dto/ClientDTO.java @@ -0,0 +1,23 @@ +package com.makive.moumi.model.dto; + +import com.makive.moumi.model.domain.Client; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class ClientDTO { + private String email; + private String name; + + public static ClientDTO fromClient(Client client) { + return ClientDTO.builder() + .email(client.getEmail()) + .name(client.getName()) + .build(); + } +} diff --git a/src/main/java/com/makive/moumi/model/dto/response/ClientResponse.java b/src/main/java/com/makive/moumi/model/dto/response/ClientResponse.java new file mode 100644 index 0000000..0b754cf --- /dev/null +++ b/src/main/java/com/makive/moumi/model/dto/response/ClientResponse.java @@ -0,0 +1,15 @@ +package com.makive.moumi.model.dto.response; + +import com.makive.moumi.model.dto.ClientDTO; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class ClientResponse { + private ClientDTO client; +} diff --git a/src/main/java/com/makive/moumi/model/dto/response/TranslatorResponse.java b/src/main/java/com/makive/moumi/model/dto/response/TranslatorResponse.java new file mode 100644 index 0000000..f2d47f3 --- /dev/null +++ b/src/main/java/com/makive/moumi/model/dto/response/TranslatorResponse.java @@ -0,0 +1,15 @@ +package com.makive.moumi.model.dto.response; + +import com.makive.moumi.model.dto.TranslatorDTO; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class TranslatorResponse { + private TranslatorDTO translator; +} diff --git a/src/main/java/com/makive/moumi/repository/TranslatorRepository.java b/src/main/java/com/makive/moumi/repository/TranslatorRepository.java new file mode 100644 index 0000000..bdd140c --- /dev/null +++ b/src/main/java/com/makive/moumi/repository/TranslatorRepository.java @@ -0,0 +1,9 @@ +package com.makive.moumi.repository; + +import com.makive.moumi.model.domain.Translator; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface TranslatorRepository extends JpaRepository { +} diff --git a/src/main/java/com/makive/moumi/service/ClientService.java b/src/main/java/com/makive/moumi/service/ClientService.java new file mode 100644 index 0000000..fee3257 --- /dev/null +++ b/src/main/java/com/makive/moumi/service/ClientService.java @@ -0,0 +1,27 @@ +package com.makive.moumi.service; + +import com.makive.moumi.exception.Code; +import com.makive.moumi.exception.GeneralException; +import com.makive.moumi.model.domain.Client; +import com.makive.moumi.model.dto.ClientDTO; +import com.makive.moumi.model.dto.response.ClientResponse; +import com.makive.moumi.repository.ClientRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class ClientService { + private final ClientRepository clientRepository; + + public ClientResponse getClient(Long clientId) { + Client client = clientRepository.findById(clientId) + .orElseThrow(() -> new GeneralException(Code.DATA_NOT_FOUND)); + + return ClientResponse.builder() + .client(ClientDTO.fromClient(client)) + .build(); + } +} diff --git a/src/main/java/com/makive/moumi/service/TranslatorService.java b/src/main/java/com/makive/moumi/service/TranslatorService.java new file mode 100644 index 0000000..294b61d --- /dev/null +++ b/src/main/java/com/makive/moumi/service/TranslatorService.java @@ -0,0 +1,27 @@ +package com.makive.moumi.service; + +import com.makive.moumi.exception.Code; +import com.makive.moumi.exception.GeneralException; +import com.makive.moumi.model.domain.Translator; +import com.makive.moumi.model.dto.TranslatorDTO; +import com.makive.moumi.model.dto.response.TranslatorResponse; +import com.makive.moumi.repository.TranslatorRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class TranslatorService { + private final TranslatorRepository translatorRepository; + + public TranslatorResponse getTranslator(Long clientId) { + Translator translator = translatorRepository.findById(clientId) + .orElseThrow(() -> new GeneralException(Code.DATA_NOT_FOUND)); + + return TranslatorResponse.builder() + .translator(TranslatorDTO.fromTranslator(translator)) + .build(); + } +}