Skip to content

Commit

Permalink
GM-10 닉네임 등록하기
Browse files Browse the repository at this point in the history
  • Loading branch information
kgh2120 committed Jan 11, 2023
1 parent b39e71f commit 36aa5cf
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.gaaji.auth.applicationservice;

public interface NicknameRegisterService {

void registerNickname(String authId, String nickname);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.gaaji.auth.applicationservice;

import com.gaaji.auth.domain.Auth;
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 NicknameRegisterServiceImpl implements NicknameRegisterService{

private final AuthRepository authRepository;


public void registerNickname(String authId, String nickname){
Auth auth = authRepository
.findById(authId)
.orElseThrow(); // TODO Exception 추가

auth.registerNickname(nickname);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.gaaji.auth.controller;

import com.gaaji.auth.applicationservice.NicknameRegisterService;
import com.gaaji.auth.controller.dto.NicknameRegisterRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
public class NicknameRegisterController {

private final NicknameRegisterService nicknameRegisterService;

@PatchMapping("/auth/nickname")
public ResponseEntity<Void> registerNickname(@RequestHeader("AUTH-ID") String authId, @RequestBody NicknameRegisterRequest dto){
// body
nicknameRegisterService.registerNickname(authId, dto.getNickname());
return ResponseEntity.ok().build();
}

@PatchMapping("/profile/nickname")
public ResponseEntity<Void> registerProfileNickname(@RequestHeader("AUTH-ID") String authId, @RequestBody NicknameRegisterRequest dto){
// body
nicknameRegisterService.registerNickname(authId, dto.getNickname());
return ResponseEntity.ok().build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gaaji.auth.controller.dto;

import lombok.Data;

@Data
public class NicknameRegisterRequest {
private String nickname;

}
2 changes: 2 additions & 0 deletions src/main/java/com/gaaji/auth/repository/AuthRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
public interface AuthRepository {
Auth save(PlatformType type, String email);

Optional<Auth> findById(String id);

Optional<Auth> findByPlatformInfo(PlatformType type, String email);

default String nextId(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gaaji.auth.repository;

import com.gaaji.auth.domain.Auth;
import com.gaaji.auth.domain.AuthId;
import com.gaaji.auth.domain.PlatformType;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,6 +17,10 @@ public class AuthRepositoryImpl implements AuthRepository{
public Auth save(PlatformType type, String email) {
return jpaAuthRepository.save(Auth.signUp(this.nextId(), type, email));
}
@Override
public Optional<Auth> findById(String id) {
return jpaAuthRepository.findById(AuthId.of(id));
}

@Override
public Optional<Auth> findByPlatformInfo(PlatformType type, String email) {
Expand Down

0 comments on commit 36aa5cf

Please sign in to comment.