-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
코드 리뷰~ #4
Open
parksooo
wants to merge
5
commits into
main
Choose a base branch
from
3-code-review
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
코드 리뷰~ #4
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ba7c924
[feat] : review member, location
parksooo 5e95967
[feat] : review Group, GroupMember
iko-ilko 2ff3936
[feat] : review Api, Search, OAuthToken
leeesooha 24cbdf4
[feat] : review Join, Exception
leeesooha a3e383e
[feat] : review Security, Jwt, Oauth, Logout
leeesooha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
build/ | ||
out/ | ||
.gradle | ||
.idea | ||
|
||
src/main/resources/application-db.yml | ||
src/main/resources/application.properties | ||
src/main/resources/application.yml |
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,18 @@ | ||
package kr.where.backend; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.retry.annotation.EnableRetry; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@EnableRetry | ||
@SpringBootApplication | ||
public class BackendApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(BackendApplication.class, args); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/kr/where/backend/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,16 @@ | ||
package kr.where.backend.exception; | ||
|
||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@ToString | ||
public class CustomException extends RuntimeException{ | ||
private final int errorCode; | ||
private final String errorMessage; | ||
|
||
public <T extends Enum<T> & ErrorCode> CustomException(final T errorType) { | ||
errorCode = errorType.getErrorCode(); | ||
errorMessage = errorType.getErrorMessage(); | ||
} | ||
} |
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,6 @@ | ||
package kr.where.backend.exception; | ||
|
||
public interface ErrorCode { | ||
int getErrorCode(); | ||
String getErrorMessage(); | ||
} |
132 changes: 132 additions & 0 deletions
132
src/main/java/kr/where/backend/exception/ExceptionHandleController.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,132 @@ | ||
package kr.where.backend.exception; | ||
|
||
import kr.where.backend.auth.authUser.exception.AuthUserException; | ||
import kr.where.backend.exception.httpError.HttpResourceErrorCode; | ||
import kr.where.backend.exception.httpError.HttpResourceException; | ||
import kr.where.backend.group.exception.GroupException; | ||
import kr.where.backend.group.exception.GroupMemberException; | ||
import kr.where.backend.join.exception.JoinException; | ||
import kr.where.backend.jwt.exception.JwtException; | ||
import kr.where.backend.member.exception.MemberException; | ||
import kr.where.backend.api.exception.JsonException; | ||
import kr.where.backend.api.exception.RequestException; | ||
import kr.where.backend.oauthtoken.exception.OAuthTokenException; | ||
import kr.where.backend.search.exception.SearchException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.http.converter.HttpMessageNotReadableException; | ||
import org.springframework.web.HttpRequestMethodNotSupportedException; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.MissingServletRequestParameterException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
@Slf4j | ||
public class ExceptionHandleController { | ||
|
||
@ExceptionHandler({MemberException.NoMemberException.class, GroupException.NoGroupException.class}) | ||
public ResponseEntity<String> handleNoResultException(final CustomException e) { | ||
log.info(e.toString()); | ||
|
||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.toString()); | ||
} | ||
|
||
@ExceptionHandler({MemberException.DuplicatedMemberException.class, GroupException.DuplicatedGroupNameException.class, | ||
GroupMemberException.class}) | ||
public ResponseEntity<String> handleDuplicatedException(final CustomException e) { | ||
log.info(e.toString()); | ||
|
||
return ResponseEntity.status(HttpStatus.CONFLICT).body(e.toString()); | ||
} | ||
|
||
@ExceptionHandler(GroupException.CannotModifyGroupException.class) | ||
public ResponseEntity<String> handleCannotModifiedException(final CustomException e) { | ||
log.info(e.toString()); | ||
|
||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.toString()); | ||
} | ||
|
||
@ExceptionHandler(OAuthTokenException.class) | ||
public ResponseEntity<String> handleOAuthTokenException(final CustomException e) { | ||
log.info(e.toString()); | ||
|
||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.toString()); | ||
} | ||
|
||
@ExceptionHandler(JwtException.class) | ||
public ResponseEntity<String> handleJwtTokenException(final CustomException e) { | ||
log.info(e.toString()); | ||
|
||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.toString()); | ||
} | ||
|
||
@ExceptionHandler(RequestException.class) | ||
public ResponseEntity<String> handleBadRequestException(final CustomException e) { | ||
log.info(e.toString()); | ||
|
||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.toString()); | ||
} | ||
|
||
@ExceptionHandler(JsonException.class) | ||
public ResponseEntity<String> handleJsonException(final CustomException e) { | ||
log.info(e.toString()); | ||
|
||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.toString()); | ||
} | ||
|
||
@ExceptionHandler(JoinException.class) | ||
public ResponseEntity<String> handleJoinException(final CustomException e) { | ||
log.info(e.toString()); | ||
|
||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.toString()); | ||
} | ||
|
||
@ExceptionHandler(SearchException.class) | ||
public ResponseEntity<String> handleSearchException(final CustomException e) { | ||
log.info(e.toString()); | ||
|
||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.toString()); | ||
} | ||
|
||
@ExceptionHandler(AuthUserException.class) | ||
public ResponseEntity<String> handleAuthUserException(final CustomException e) { | ||
log.info(e.toString()); | ||
|
||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.toString()); | ||
} | ||
|
||
@ExceptionHandler(MissingServletRequestParameterException.class) | ||
public ResponseEntity<String> handleMissingParameterException() { | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(HttpResourceException.of(HttpResourceErrorCode.NO_PARAMETERS)); | ||
} | ||
|
||
@ExceptionHandler(HttpMessageNotReadableException.class) | ||
public ResponseEntity<String> handleNoRequestBodyException() { | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(HttpResourceException.of(HttpResourceErrorCode.NO_REQUEST_BODY)); | ||
} | ||
|
||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class) | ||
public ResponseEntity<String> handleUnsupportedMethodException() { | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(HttpResourceException.of(HttpResourceErrorCode.NO_SUPPORTED_METHOD)); | ||
} | ||
|
||
@ExceptionHandler(MethodArgumentNotValidException.class) | ||
public ResponseEntity<String> handleMethodArgumentNotValidException() { | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(HttpResourceException.of(HttpResourceErrorCode.NOT_METHOD_VALID_ARGUMENT)); | ||
} | ||
|
||
@ExceptionHandler(RuntimeException.class) | ||
public ResponseEntity<String> handleNoResourceException() { | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("관리자에게 요청하세요."); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/kr/where/backend/exception/httpError/HttpResourceErrorCode.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,18 @@ | ||
package kr.where.backend.exception.httpError; | ||
|
||
import kr.where.backend.exception.ErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum HttpResourceErrorCode implements ErrorCode { | ||
|
||
NO_PARAMETERS(1700, "파라미터가 없는 Api 요청입니다."), | ||
NO_REQUEST_BODY(1701, "Request body가 없는 Api 요청입니다."), | ||
NO_SUPPORTED_METHOD(1702, "지원하지 않는 Http Method 요청입니다."), | ||
NOT_METHOD_VALID_ARGUMENT(1703, "Method에 맞는 arguments가 없습니다"); | ||
|
||
private final int errorCode; | ||
private final String errorMessage; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/kr/where/backend/exception/httpError/HttpResourceException.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,11 @@ | ||
package kr.where.backend.exception.httpError; | ||
|
||
import kr.where.backend.exception.ErrorCode; | ||
|
||
public class HttpResourceException { | ||
public static String of(final ErrorCode errorCode) { | ||
return "CustomException(errorCode=" + errorCode.getErrorCode() + | ||
", " + "errorMessage=" + | ||
errorCode.getErrorMessage() + ")"; | ||
} | ||
} |
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,88 @@ | ||
package kr.where.backend.location; | ||
|
||
import jakarta.persistence.*; | ||
import kr.where.backend.member.Member; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Slf4j | ||
public class Location { | ||
|
||
@Id | ||
@Column(name = "location_id", nullable = false) | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long locationId; | ||
|
||
@OneToOne(mappedBy = "location", fetch = FetchType.LAZY) | ||
private Member member; | ||
|
||
@Column(length = 30) | ||
private String customLocation; | ||
|
||
@Column(length = 10) | ||
private String imacLocation; | ||
|
||
private LocalDateTime customUpdatedAt; | ||
|
||
private LocalDateTime imacUpdatedAt; | ||
|
||
public Location(final Member member, final String imacLocation) { | ||
this.member = member; | ||
this.imacLocation = imacLocation; | ||
this.imacUpdatedAt = LocalDateTime.now(); | ||
} | ||
|
||
public Location(final String imacLocation) { | ||
this.imacLocation = imacLocation; | ||
this.imacUpdatedAt = LocalDateTime.now(); | ||
} | ||
|
||
public void setMember(Member member) { | ||
this.member = member; | ||
} | ||
|
||
public void setCustomLocation(final String customLocation) { | ||
this.customLocation = customLocation; | ||
this.customUpdatedAt = LocalDateTime.now(); | ||
} | ||
|
||
public void setImacLocation(final String imacLocation) { | ||
this.imacLocation = imacLocation; | ||
this.imacUpdatedAt = LocalDateTime.now(); | ||
} | ||
|
||
public void initLocation() { | ||
this.imacLocation = null; | ||
this.imacUpdatedAt = LocalDateTime.now(); | ||
this.customLocation = null; | ||
this.customUpdatedAt = LocalDateTime.now(); | ||
} | ||
|
||
public String getLocation() { | ||
if (!this.member.isAgree()) { | ||
return this.imacLocation; | ||
} else { | ||
if (customLocation == null && imacLocation == null) { | ||
return null; | ||
} else if (customLocation == null) { | ||
return imacLocation; | ||
} else if (imacLocation == null) { | ||
return customLocation; | ||
} else { | ||
if (customUpdatedAt.isAfter(imacUpdatedAt)) { | ||
return customLocation; | ||
} else { | ||
return imacLocation; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/kr/where/backend/location/LocationController.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,54 @@ | ||
package kr.where.backend.location; | ||
|
||
import jakarta.validation.Valid; | ||
import kr.where.backend.auth.authUser.AuthUser; | ||
import kr.where.backend.location.dto.ResponseLocationDTO; | ||
import kr.where.backend.location.dto.UpdateCustomLocationDTO; | ||
import kr.where.backend.location.swagger.LocationApiDocs; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@Slf4j | ||
@RequestMapping("/v3/location") | ||
@RequiredArgsConstructor | ||
public class LocationController implements LocationApiDocs { | ||
|
||
private final LocationService locationService; | ||
|
||
/** | ||
* 수동자리 업데이트 | ||
* | ||
* @param updateCustomLocation | ||
* @return ResponseEntity(responseLocationDTO) | ||
*/ | ||
@PostMapping("/custom") | ||
public ResponseEntity<ResponseLocationDTO> updateCustomLocation(@RequestBody @Valid final UpdateCustomLocationDTO updateCustomLocation) { | ||
final AuthUser authUser = AuthUser.of(); | ||
final ResponseLocationDTO responseLocationDto = locationService.updateCustomLocation(updateCustomLocation, | ||
authUser); | ||
|
||
return ResponseEntity.ok(responseLocationDto); | ||
} | ||
|
||
/** | ||
* 수동자리 초기화(삭제) | ||
* | ||
* @return ResponseEntity(responseLocationDTO) | ||
*/ | ||
@DeleteMapping("/custom") | ||
public ResponseEntity<ResponseLocationDTO> deleteCustomLocation() { | ||
final AuthUser authUser = AuthUser.of(); | ||
final ResponseLocationDTO responseLocationDto = locationService.deleteCustomLocation(authUser); | ||
|
||
return ResponseEntity.ok(responseLocationDto); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/kr/where/backend/location/LocationRepository.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,11 @@ | ||
package kr.where.backend.location; | ||
|
||
import kr.where.backend.member.Member; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface LocationRepository extends JpaRepository<Location, Long> { | ||
Location findByMember(Member member); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수동자리 업데이트는 유저가 수동으로 자리 설정 할 때 호출되는 api인가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 맞습니다~