diff --git a/src/main/java/com/gaaji/auth/applicationservice/AuthRetrieveService.java b/src/main/java/com/gaaji/auth/applicationservice/AuthRetrieveService.java new file mode 100644 index 0000000..332b080 --- /dev/null +++ b/src/main/java/com/gaaji/auth/applicationservice/AuthRetrieveService.java @@ -0,0 +1,8 @@ +package com.gaaji.auth.applicationservice; + +import com.gaaji.auth.controller.dto.RetrieveResponse; + +public interface AuthRetrieveService { + + RetrieveResponse retrieveAuth(String authId); +} diff --git a/src/main/java/com/gaaji/auth/applicationservice/AuthRetrieveServiceImpl.java b/src/main/java/com/gaaji/auth/applicationservice/AuthRetrieveServiceImpl.java new file mode 100644 index 0000000..b118dbe --- /dev/null +++ b/src/main/java/com/gaaji/auth/applicationservice/AuthRetrieveServiceImpl.java @@ -0,0 +1,25 @@ +package com.gaaji.auth.applicationservice; + +import com.gaaji.auth.controller.dto.RetrieveResponse; +import com.gaaji.auth.domain.Auth; +import com.gaaji.auth.domain.AuthId; +import com.gaaji.auth.repository.AuthRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Transactional +@Service +public class AuthRetrieveServiceImpl implements + AuthRetrieveService { + + private final AuthRepository authRepository; + + @Override + public RetrieveResponse retrieveAuth(String authId) { + Auth auth = authRepository.findById(authId) + .orElseThrow(); + return RetrieveResponse.of(authId, auth.getNickname(), auth.getMannerTemperature()); + } +} diff --git a/src/main/java/com/gaaji/auth/applicationservice/Sample.java b/src/main/java/com/gaaji/auth/applicationservice/Sample.java deleted file mode 100644 index adb60ff..0000000 --- a/src/main/java/com/gaaji/auth/applicationservice/Sample.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.gaaji.auth.applicationservice; - -public class Sample { - -} diff --git a/src/main/java/com/gaaji/auth/controller/AuthRetrieveController.java b/src/main/java/com/gaaji/auth/controller/AuthRetrieveController.java new file mode 100644 index 0000000..f16ea50 --- /dev/null +++ b/src/main/java/com/gaaji/auth/controller/AuthRetrieveController.java @@ -0,0 +1,25 @@ +package com.gaaji.auth.controller; + + +import com.gaaji.auth.applicationservice.AuthRetrieveService; +import com.gaaji.auth.controller.dto.RetrieveResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +@RequiredArgsConstructor +@RestController +public class AuthRetrieveController { + + private final AuthRetrieveService authRetrieveService; + + @GetMapping("/auth/{authId}") + public ResponseEntity retrieveAuth(@PathVariable("authId") String authId){ + + RetrieveResponse dto = authRetrieveService.retrieveAuth(authId); + return ResponseEntity.ok(dto); + } + +} diff --git a/src/main/java/com/gaaji/auth/controller/dto/RetrieveResponse.java b/src/main/java/com/gaaji/auth/controller/dto/RetrieveResponse.java new file mode 100644 index 0000000..a79c5fe --- /dev/null +++ b/src/main/java/com/gaaji/auth/controller/dto/RetrieveResponse.java @@ -0,0 +1,25 @@ +package com.gaaji.auth.controller.dto; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@NoArgsConstructor +public class RetrieveResponse { + + private String authId; + private String nickname; + private double mannerTemperature; + + + public static RetrieveResponse of(String authId, String nickname, double mannerTemperature) { + return new RetrieveResponse(authId, validateNickname(nickname), mannerTemperature); + } + + private static String validateNickname(String nickname){ + return nickname == null ? "익명" : nickname; + } +} diff --git a/src/main/java/com/gaaji/auth/domain/Auth.java b/src/main/java/com/gaaji/auth/domain/Auth.java index 2f759a7..c6de260 100644 --- a/src/main/java/com/gaaji/auth/domain/Auth.java +++ b/src/main/java/com/gaaji/auth/domain/Auth.java @@ -20,16 +20,16 @@ public class Auth { private PlatformInfo platformInfo; @Embedded - private MannerTemparature mannerTemparature; + private MannerTemperature mannerTemperature; @Builder private Auth(AuthId id, String nickname, PlatformInfo platformInfo, - MannerTemparature mannerTemparature) { + MannerTemperature mannerTemperature) { this.id = id; this.nickname = nickname; this.platformInfo = platformInfo; - this.mannerTemparature = mannerTemparature; + this.mannerTemperature = mannerTemperature; } public static Auth signUp(String id, PlatformType type, String email){ @@ -37,7 +37,7 @@ public static Auth signUp(String id, PlatformType type, String email){ .id(AuthId.of(id)) .nickname("익명") .platformInfo(PlatformInfo.of(type,email)) - .mannerTemparature(MannerTemparature.of(36.5)) + .mannerTemperature(MannerTemperature.of(36.5)) .build(); } public void registerNickname(String nickname){ @@ -46,4 +46,10 @@ public void registerNickname(String nickname){ public String getAuthIdForToken(){ return id.getId(); } + public String getNickname(){ + return nickname; + } + public double getMannerTemperature(){ + return mannerTemperature.getTemperature(); + } } diff --git a/src/main/java/com/gaaji/auth/domain/MannerTemparature.java b/src/main/java/com/gaaji/auth/domain/MannerTemparature.java deleted file mode 100644 index 24787f6..0000000 --- a/src/main/java/com/gaaji/auth/domain/MannerTemparature.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.gaaji.auth.domain; - -import javax.persistence.Embeddable; -import lombok.NoArgsConstructor; - -@Embeddable @NoArgsConstructor -public class MannerTemparature { - - private double temparature; - - private MannerTemparature(double temparature) { - this.temparature = temparature; - } - public static MannerTemparature of(double temparature){ - return new MannerTemparature(temparature); - } -} diff --git a/src/main/java/com/gaaji/auth/domain/MannerTemperature.java b/src/main/java/com/gaaji/auth/domain/MannerTemperature.java new file mode 100644 index 0000000..61ce5f4 --- /dev/null +++ b/src/main/java/com/gaaji/auth/domain/MannerTemperature.java @@ -0,0 +1,24 @@ +package com.gaaji.auth.domain; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Embeddable; +import lombok.NoArgsConstructor; + +@Access(AccessType.FIELD) +@Embeddable @NoArgsConstructor +public class MannerTemperature { + + private double temperature; + + private MannerTemperature(double temperature) { + this.temperature = temperature; + } + public static MannerTemperature of(double temperature){ + return new MannerTemperature(temperature); + } + + public double getTemperature() { + return temperature; + } +}