Skip to content

Commit

Permalink
GM-122 회원 정보 조회 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kgh2120 committed Jan 20, 2023
1 parent 0aa22b6 commit 8d899f7
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gaaji.auth.applicationservice;

import com.gaaji.auth.controller.dto.RetrieveResponse;

public interface AuthRetrieveService {

RetrieveResponse retrieveAuth(String authId);
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
5 changes: 0 additions & 5 deletions src/main/java/com/gaaji/auth/applicationservice/Sample.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<RetrieveResponse> retrieveAuth(@PathVariable("authId") String authId){

RetrieveResponse dto = authRetrieveService.retrieveAuth(authId);
return ResponseEntity.ok(dto);
}

}
25 changes: 25 additions & 0 deletions src/main/java/com/gaaji/auth/controller/dto/RetrieveResponse.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
14 changes: 10 additions & 4 deletions src/main/java/com/gaaji/auth/domain/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ 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){
return Auth.builder()
.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){
Expand All @@ -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();
}
}
17 changes: 0 additions & 17 deletions src/main/java/com/gaaji/auth/domain/MannerTemparature.java

This file was deleted.

24 changes: 24 additions & 0 deletions src/main/java/com/gaaji/auth/domain/MannerTemperature.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 8d899f7

Please sign in to comment.