-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : #4 User 조회 생성 API 작성 및 H2 설정 추가
* findAll, create, validation 작성 * H2 config 작성 * UserDTO 작성
- Loading branch information
Showing
9 changed files
with
128 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#Thu Oct 15 19:57:46 KST 2020 | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |
4 changes: 2 additions & 2 deletions
4
src/main/java/com/resumers/server/oauth/controller/SocialController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/resumers/server/oauth/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.resumers.server.oauth.controller; | ||
|
||
import com.resumers.server.oauth.model.dto.UserDto; | ||
import com.resumers.server.oauth.model.entity.User; | ||
import com.resumers.server.oauth.service.UserService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/19 | ||
* Descrpition : | ||
*/ | ||
|
||
@Slf4j | ||
@Controller | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/users") | ||
public class UserController { | ||
private final UserService userService; | ||
|
||
// TODO : Response 객체 작성 | ||
@GetMapping | ||
public List<UserDto> findAll(UserDto.SearchQuery userDto){ | ||
return userService.findAll(); | ||
} | ||
|
||
@PostMapping | ||
public void save(UserDto.InsertUser user) { | ||
userService.create(user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/resumers/server/oauth/model/dto/UserDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
package com.resumers.server.oauth.model.dto; | ||
|
||
import com.resumers.server.oauth.model.entity.User; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/03 | ||
*/ | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class UserDto { | ||
private Long userId; | ||
private String email; | ||
private String nickname; | ||
private String description; | ||
|
||
public UserDto(User user) { | ||
this.userId = user.getUserId(); | ||
this.email = user.getEmail(); | ||
this.nickname = user.getNickname(); | ||
this.description = user.getDescription(); | ||
} | ||
|
||
@Getter | ||
public class SearchQuery extends UserDto{ | ||
public SearchQuery(){ | ||
super(); | ||
} | ||
} | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class InsertUser extends UserDto { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/09 | ||
* Descrpition : | ||
*/ | ||
|
||
@Entity | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/resumers/server/oauth/service/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,51 @@ | ||
package com.resumers.server.oauth.service; | ||
|
||
import com.common.Utils; | ||
import com.resumers.server.oauth.model.dto.UserDto; | ||
import com.resumers.server.oauth.model.entity.User; | ||
import com.resumers.server.oauth.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import javax.persistence.EntityExistsException; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/03 | ||
*/ | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
private final UserRepository userRepository; | ||
|
||
public List<UserDto> findAll() { | ||
List<User> users = userRepository.findAll(); | ||
return users.stream() | ||
.map(UserDto::new) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Transactional | ||
public void create(UserDto userDto) { | ||
if (Utils.isNotEmpty(userDto)) { | ||
validation(userDto.getEmail(), userDto.getNickname()); | ||
User user = new User(userDto); | ||
userRepository.save(user); | ||
} | ||
} | ||
|
||
// TODO : CustomException 만들어서 log error 라인 수정 | ||
private void validation(String email, String nickname) { | ||
if (Utils.isEmpty(email) || Utils.isEmpty(nickname)) { | ||
log.error("BAD REQUEST EXCEPTION"); | ||
} | ||
userRepository.findAllByEmailOrNickname(email, nickname) | ||
.ifPresent(user -> log.error("DUPLICATION ERROR")); | ||
} | ||
} |