-
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.
Merge pull request #8 from resume-reading-service/oauth
feat : #4 user role, penalty 도메인 작성 및 user 조회 전략 일괄 수정
- Loading branch information
Showing
31 changed files
with
591 additions
and
32 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 |
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,28 @@ | ||
package com.component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.i18n.LocaleContextHolder; | ||
import org.springframework.context.support.ResourceBundleMessageSource; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/31 | ||
*/ | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class MessageComponent { | ||
private final ResourceBundleMessageSource messageSource; | ||
|
||
public String getMessage(String code) { | ||
String message; | ||
try { | ||
message = messageSource.getMessage(code, null, LocaleContextHolder.getLocale()); | ||
} catch (Exception e){ | ||
message = "UNDEFINED ERROR"; | ||
} | ||
return StringUtils.isEmpty(message) ? "UNDEFINED ERROR" : message; | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
src/main/java/com/resumers/server/oauth/ResumersOauthApplication.java
This file was deleted.
Oops, something went wrong.
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
34 changes: 34 additions & 0 deletions
34
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,34 @@ | ||
package com.resumers.server.oauth.controller; | ||
|
||
import com.resumers.server.oauth.model.dto.ApiResponse; | ||
import com.resumers.server.oauth.model.dto.UserDto; | ||
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 | ||
*/ | ||
|
||
@Slf4j | ||
@Controller | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/users") | ||
public class UserController { | ||
private final UserService userService; | ||
|
||
@GetMapping | ||
public ApiResponse<List<UserDto>> findAll(UserDto.SearchQuery userDto){ | ||
return new ApiResponse<>(userService.findAll()); | ||
} | ||
|
||
@PostMapping | ||
public void save(UserDto.InsertUser user) { | ||
userService.create(user); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/resumers/server/oauth/enums/ExceptionType.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,31 @@ | ||
package com.resumers.server.oauth.enums; | ||
|
||
import lombok.Getter; | ||
|
||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/31 | ||
*/ | ||
|
||
@Getter | ||
public enum ExceptionType { | ||
/* | ||
* BadRequest 400 | ||
* Unauthorized 401 | ||
* Forbidden 403 | ||
* Not Found 404 | ||
* Server 500 | ||
*/ | ||
|
||
USER_NOT_FOUND(400, 1000, "존재하지 않는 유저입니다"); | ||
|
||
private Integer httpStatusCode; | ||
private Integer code; | ||
private String value; | ||
|
||
ExceptionType(Integer httpStatusCode, Integer code, String value) { | ||
this.httpStatusCode = httpStatusCode; | ||
this.code = code; | ||
this.value = value; | ||
} | ||
} |
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,9 @@ | ||
package com.resumers.server.oauth.enums; | ||
|
||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/09 | ||
*/ | ||
public enum RoleType { | ||
USER, ADMIN | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/resumers/server/oauth/exception/CustomException.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,28 @@ | ||
package com.resumers.server.oauth.exception; | ||
|
||
import com.resumers.server.oauth.enums.ExceptionType; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/31 | ||
*/ | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class CustomException extends RuntimeException{ | ||
private ExceptionType type; | ||
private String message; | ||
|
||
public CustomException(ExceptionType type) { | ||
super(type.getValue()); | ||
this.type = type; | ||
} | ||
|
||
public CustomException(ExceptionType type, String message) { | ||
super(type.getValue()); | ||
this.type = type; | ||
this.message = message; | ||
} | ||
} |
40 changes: 39 additions & 1 deletion
40
src/main/java/com/resumers/server/oauth/exception/ExceptionHandler.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,46 @@ | ||
package com.resumers.server.oauth.exception; | ||
|
||
import com.component.MessageComponent; | ||
import com.resumers.server.oauth.model.dto.ApiResponse; | ||
import com.resumers.server.oauth.model.dto.EmptyObject; | ||
import com.resumers.server.oauth.model.dto.ErrorResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.web.servlet.error.ErrorAttributes; | ||
import org.springframework.boot.web.servlet.error.ErrorController; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import org.springframework.web.context.request.WebRequest; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/03 | ||
*/ | ||
public class ExceptionHandler { | ||
|
||
@Slf4j | ||
@RestController | ||
@RestControllerAdvice | ||
@RequiredArgsConstructor | ||
public class ExceptionHandler implements ErrorController { | ||
|
||
private final ErrorAttributes errorAttributes; | ||
private final MessageComponent message; | ||
|
||
@Override | ||
public String getErrorPath() { | ||
return "/error"; | ||
} | ||
|
||
private Map<String, Object> getErrorAttribute(WebRequest webRequest) { | ||
return errorAttributes.getErrorAttributes(webRequest, true); | ||
} | ||
|
||
@org.springframework.web.bind.annotation.ExceptionHandler(value = CustomException.class) | ||
public ResponseEntity<ApiResponse<EmptyObject>> customException(WebRequest webRequest, CustomException e) { | ||
return ResponseEntity.status(e.getType().getHttpStatusCode()).body(new ApiResponse<>(new ErrorResponse(e.getType().getCode(), getErrorAttribute(webRequest), e.getMessage()))); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/resumers/server/oauth/model/dto/ApiResponse.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,71 @@ | ||
package com.resumers.server.oauth.model.dto; | ||
|
||
import lombok.Data; | ||
import org.slf4j.MDC; | ||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/31 | ||
*/ | ||
|
||
@Data | ||
public class ApiResponse<T> { | ||
private MetaResponse meta; | ||
private T data; | ||
private ErrorResponse error; | ||
private String traceId; | ||
|
||
public ApiResponse() { | ||
this.meta = new MetaResponse(); | ||
this.data = (T) EmptyObject.OBJECT; | ||
this.error = new ErrorResponse(); | ||
setTraceId(); | ||
} | ||
|
||
public ApiResponse(MetaResponse meta) { | ||
this.meta = meta; | ||
this.data = (T) EmptyObject.LIST; | ||
this.error = new ErrorResponse(); | ||
setTraceId(); | ||
} | ||
|
||
public ApiResponse(T data) { | ||
if (data == null) { | ||
this.data = (T) EmptyObject.OBJECT; | ||
this.meta = new MetaResponse(); | ||
} else { | ||
this.data = data; | ||
this.meta = new MetaResponse(1L); | ||
} | ||
this.error = new ErrorResponse(); | ||
setTraceId(); | ||
} | ||
|
||
public ApiResponse(ErrorResponse error) { | ||
this.meta = new MetaResponse(); | ||
this.data = (T) EmptyObject.OBJECT; | ||
this.error = error; | ||
setTraceId(); | ||
} | ||
|
||
public ApiResponse(Long totalCount, T data) { | ||
this.meta = new MetaResponse(totalCount); | ||
|
||
if (data == null) { | ||
this.data = (T) EmptyObject.LIST; | ||
} else { | ||
this.data = data; | ||
} | ||
|
||
this.error = new ErrorResponse(); | ||
setTraceId(); | ||
} | ||
|
||
private void setTraceId() { | ||
try { | ||
this.traceId = MDC.get("TRACE_ID"); | ||
} catch (NullPointerException e) { | ||
this.traceId = ""; | ||
} | ||
} | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
src/main/java/com/resumers/server/oauth/model/dto/EmptyObject.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,16 @@ | ||
package com.resumers.server.oauth.model.dto; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/31 | ||
*/ | ||
|
||
@JsonSerialize | ||
public class EmptyObject { | ||
public static EmptyObject OBJECT = new EmptyObject(); | ||
public static List LIST = new ArrayList(); | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
src/main/java/com/resumers/server/oauth/model/dto/ErrorResponse.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,35 @@ | ||
package com.resumers.server.oauth.model.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.LocalDateTime; | ||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/31 | ||
*/ | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class ErrorResponse { | ||
private Integer status; | ||
private String error; | ||
private String message; | ||
private LocalDateTime timeStamp; | ||
|
||
public ErrorResponse(int status, Map<String, Object> errorAttribute, String message) { | ||
this.status = status; | ||
this.message = message; | ||
this.error = (String) errorAttribute.get("error"); | ||
this.timeStamp = new Timestamp(((Date) errorAttribute.get("timestamp")).getTime()).toLocalDateTime(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/resumers/server/oauth/model/dto/MetaResponse.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,17 @@ | ||
package com.resumers.server.oauth.model.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Created by sehajyang | ||
* DateTime : 2020/10/31 | ||
*/ | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class MetaResponse { | ||
private Long total; | ||
} |
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 { | ||
} | ||
} |
Oops, something went wrong.