Skip to content

Commit

Permalink
feat: 사용자 및 번역가 정보 조회 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
soyeonii committed Oct 11, 2023
1 parent e122124 commit 30dd090
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/com/makive/moumi/controller/ClientController.java
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));
}
}
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));
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/makive/moumi/model/dto/ClientDTO.java
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();
}
}
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;
}
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;
}
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> {
}
27 changes: 27 additions & 0 deletions src/main/java/com/makive/moumi/service/ClientService.java
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 src/main/java/com/makive/moumi/service/TranslatorService.java
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();
}
}

0 comments on commit 30dd090

Please sign in to comment.