From 3cdde2678d740f2bea5cefccf8f58c86e21142eb Mon Sep 17 00:00:00 2001 From: SEONG JUN SHIN Date: Tue, 16 Jan 2024 02:46:24 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20add=20User=20controller,=20service,=20d?= =?UTF-8?q?ao=20=ED=8B=80=20=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pointer/controller/UserController.java | 14 ++++++------ src/main/java/gdsc/pointer/dao/UserDao.java | 6 +++++ src/main/java/gdsc/pointer/domain/User.java | 1 + .../gdsc/pointer/dto/request/UserDto.java | 10 +++++++++ .../pointer/dto/{ => response}/ResultDto.java | 2 +- .../gdsc/pointer/service/UserService.java | 3 ++- .../gdsc/pointer/service/UserServiceImpl.java | 22 +++++-------------- 7 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 src/main/java/gdsc/pointer/dto/request/UserDto.java rename src/main/java/gdsc/pointer/dto/{ => response}/ResultDto.java (96%) diff --git a/src/main/java/gdsc/pointer/controller/UserController.java b/src/main/java/gdsc/pointer/controller/UserController.java index 2dc3410..1e538fa 100644 --- a/src/main/java/gdsc/pointer/controller/UserController.java +++ b/src/main/java/gdsc/pointer/controller/UserController.java @@ -1,11 +1,10 @@ package gdsc.pointer.controller; import gdsc.pointer.domain.User; -import gdsc.pointer.dto.ResultDto; +import gdsc.pointer.dto.request.UserDto; +import gdsc.pointer.dto.response.ResultDto; import gdsc.pointer.service.UserService; import lombok.RequiredArgsConstructor; -import org.apache.coyote.Response; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -26,10 +25,11 @@ public ResponseEntity getUsers() throws Exception { } -// @PostMapping("/insertUser") -// public ResponseEntity insertUser(@RequestBody User user) throws Exception{ -// return userService.insertUser(user); -// } + @PostMapping() + public ResponseEntity addUser(@RequestBody UserDto userDto) throws Exception{ + userService.addUser(userDto); + return ResponseEntity.ok(ResultDto.res(HttpStatus.CREATED, "회원 가입 완료")); + } // // @GetMapping("/getUserDetail") // public ResponseEntity getUserDetail(@RequestParam("id") String id) throws Exception{ diff --git a/src/main/java/gdsc/pointer/dao/UserDao.java b/src/main/java/gdsc/pointer/dao/UserDao.java index e53875b..15ce657 100644 --- a/src/main/java/gdsc/pointer/dao/UserDao.java +++ b/src/main/java/gdsc/pointer/dao/UserDao.java @@ -6,6 +6,7 @@ import com.google.cloud.firestore.QuerySnapshot; import com.google.firebase.cloud.FirestoreClient; import gdsc.pointer.domain.User; +import gdsc.pointer.dto.request.UserDto; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Repository; @@ -29,4 +30,9 @@ public List getUsers() throws Exception { return list; } + public void addUser(UserDto userDto) throws Exception { + + } + + } diff --git a/src/main/java/gdsc/pointer/domain/User.java b/src/main/java/gdsc/pointer/domain/User.java index ff3985d..a40d820 100644 --- a/src/main/java/gdsc/pointer/domain/User.java +++ b/src/main/java/gdsc/pointer/domain/User.java @@ -13,5 +13,6 @@ public class User { private String id; private String name; + private String email; } diff --git a/src/main/java/gdsc/pointer/dto/request/UserDto.java b/src/main/java/gdsc/pointer/dto/request/UserDto.java new file mode 100644 index 0000000..e2a7e0f --- /dev/null +++ b/src/main/java/gdsc/pointer/dto/request/UserDto.java @@ -0,0 +1,10 @@ +package gdsc.pointer.dto.request; + +import lombok.Getter; + +@Getter +public class UserDto { + private String id; + private String name; + private String email; +} diff --git a/src/main/java/gdsc/pointer/dto/ResultDto.java b/src/main/java/gdsc/pointer/dto/response/ResultDto.java similarity index 96% rename from src/main/java/gdsc/pointer/dto/ResultDto.java rename to src/main/java/gdsc/pointer/dto/response/ResultDto.java index 9021d38..4e00e7c 100644 --- a/src/main/java/gdsc/pointer/dto/ResultDto.java +++ b/src/main/java/gdsc/pointer/dto/response/ResultDto.java @@ -1,4 +1,4 @@ -package gdsc.pointer.dto; +package gdsc.pointer.dto.response; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/gdsc/pointer/service/UserService.java b/src/main/java/gdsc/pointer/service/UserService.java index 70f1ad4..4f667d4 100644 --- a/src/main/java/gdsc/pointer/service/UserService.java +++ b/src/main/java/gdsc/pointer/service/UserService.java @@ -1,11 +1,12 @@ package gdsc.pointer.service; import gdsc.pointer.domain.User; +import gdsc.pointer.dto.request.UserDto; import org.springframework.http.ResponseEntity; import java.util.List; public interface UserService { List getUsers() throws Exception; - + void addUser(UserDto userDto) throws Exception; } diff --git a/src/main/java/gdsc/pointer/service/UserServiceImpl.java b/src/main/java/gdsc/pointer/service/UserServiceImpl.java index ffa869d..b7c8c0a 100644 --- a/src/main/java/gdsc/pointer/service/UserServiceImpl.java +++ b/src/main/java/gdsc/pointer/service/UserServiceImpl.java @@ -1,23 +1,16 @@ package gdsc.pointer.service; -import com.google.api.core.ApiFuture; -import com.google.cloud.firestore.DocumentReference; -import com.google.cloud.firestore.DocumentSnapshot; -import com.google.cloud.firestore.Firestore; -import com.google.cloud.firestore.WriteResult; -import com.google.firebase.cloud.FirestoreClient; import gdsc.pointer.dao.UserDao; import gdsc.pointer.domain.User; +import gdsc.pointer.dto.request.UserDto; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import java.util.List; @Service @RequiredArgsConstructor -public class UserServiceImpl implements UserService{ +public class UserServiceImpl implements UserService { private final UserDao userDao; @@ -27,13 +20,10 @@ public List getUsers() throws Exception { } -// @Override -// public ResponseEntity insertUser(User user) throws Exception { -// Firestore firestore = FirestoreClient.getFirestore(); -// ApiFuture apiFuture = -// firestore.collection(COLLECTION_NAME).document(user.getId()).set(user); -// return new ResponseEntity<>("회원 추가 완료", HttpStatus.OK); -// } + @Override + public void addUser(UserDto userDto) throws Exception { + userDao.addUser(userDto); + } // // @Override // public ResponseEntity getUserDetail(String id) throws Exception {