-
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.
- Loading branch information
Showing
8 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/main/java/com/makive/moumi/controller/ClientController.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,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)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/makive/moumi/controller/TranslatorController.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,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)); | ||
} | ||
} |
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,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(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/makive/moumi/model/dto/response/ClientResponse.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,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; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/makive/moumi/model/dto/response/TranslatorResponse.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,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; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/makive/moumi/repository/TranslatorRepository.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,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<Translator, Long> { | ||
} |
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,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(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/makive/moumi/service/TranslatorService.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,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(); | ||
} | ||
} |