-
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 #5 from DO-SOPT-APP3-Airbnb/feature/1
닉네임 조회 기능 구현
- Loading branch information
Showing
25 changed files
with
234 additions
and
2 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 |
---|---|---|
|
@@ -24,5 +24,5 @@ jobs: | |
shell: bash | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew build | ||
run: ./gradlew build -x test | ||
shell: bash |
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 |
---|---|---|
|
@@ -37,3 +37,4 @@ out/ | |
.vscode/ | ||
|
||
src/main/resources/application-secret.properties | ||
src/main/resources/application-dev.yaml |
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
4 changes: 4 additions & 0 deletions
4
src/main/java/com/app3/server/common/config/JpaAuditingConfig.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,4 @@ | ||
package com.app3.server.common.config; | ||
|
||
public class JpaAuditingConfig { | ||
} |
Empty file.
Empty file.
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 com.app3.server.common.dto; | ||
|
||
import com.app3.server.common.exception.enums.SuccessType; | ||
|
||
public record ApiResponse<T> ( | ||
int status, | ||
String message, | ||
T data | ||
) { | ||
public static <T> ApiResponse<T> success(SuccessType successType, T data) { | ||
return new ApiResponse(successType.getHttpStatus().value(), successType.getMessage(), data); | ||
} | ||
|
||
public static ApiResponse error(int httpStatus, String message) { | ||
|
||
return new ApiResponse(httpStatus, message, ""); | ||
} | ||
} |
Empty file.
24 changes: 24 additions & 0 deletions
24
src/main/java/com/app3/server/common/exception/GlobalExceptionHandler.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,24 @@ | ||
package com.app3.server.common.exception; | ||
|
||
import com.app3.server.common.dto.ApiResponse; | ||
import com.app3.server.common.exception.model.NotFoundException; | ||
import com.app3.server.common.exception.model.SoptException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
@ExceptionHandler(NotFoundException.class) | ||
protected ApiResponse handleNotFoundException(final NotFoundException e) { | ||
return ApiResponse.error(e.getHttpStatus(), e.getMessage()); | ||
} | ||
|
||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
@ExceptionHandler({SoptException.class}) | ||
protected ApiResponse handleSoptException(final SoptException e) { | ||
return ApiResponse.error(e.getHttpStatus(), e.getMessage()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/app3/server/common/exception/enums/ErrorType.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.app3.server.common.exception.enums; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ErrorType { | ||
USER_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 유저을 찾을 수 없습니다."), | ||
REGION_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "지역 이미지를 찾을 수 없습니다"), | ||
|
||
INTERNAL_SERVER_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류입니다."); | ||
private final HttpStatus httpStatus; | ||
private final String message; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/app3/server/common/exception/enums/SuccessType.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.app3.server.common.exception.enums; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum SuccessType { | ||
|
||
USER_SEARCH_SUCCESS(HttpStatus.OK, "유저 닉네임 조회에 성공하였습니다."), | ||
REGION_SEARCH_SUCCESS(HttpStatus.OK, "지역 이미지 조회에 성공하였습니다.") | ||
; | ||
|
||
private final HttpStatus httpStatus; | ||
private final String message; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/app3/server/common/exception/model/NotFoundException.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,10 @@ | ||
package com.app3.server.common.exception.model; | ||
|
||
import com.app3.server.common.exception.enums.ErrorType; | ||
|
||
public class NotFoundException extends SoptException{ | ||
|
||
public NotFoundException(final ErrorType errorType) { | ||
super(errorType); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/app3/server/common/exception/model/SoptException.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,14 @@ | ||
package com.app3.server.common.exception.model; | ||
|
||
import com.app3.server.common.exception.enums.ErrorType; | ||
public class SoptException extends RuntimeException{ | ||
private final ErrorType error; | ||
|
||
public SoptException(final ErrorType error){ | ||
super(error.getMessage()); | ||
this.error = error; | ||
} | ||
public int getHttpStatus(){ | ||
return error.getHttpStatus().value(); | ||
} | ||
} |
Empty file.
31 changes: 31 additions & 0 deletions
31
src/main/java/com/app3/server/user/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,31 @@ | ||
package com.app3.server.user.controller; | ||
|
||
import com.app3.server.common.dto.ApiResponse; | ||
import com.app3.server.common.exception.enums.SuccessType; | ||
import com.app3.server.user.controller.dto.response.UserGetResponse; | ||
import com.app3.server.user.domain.User; | ||
import com.app3.server.user.repository.UserJpaRepository; | ||
import com.app3.server.user.service.UserService; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/user") | ||
@RequiredArgsConstructor | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
// 목록 조회 | ||
@GetMapping("/{id}") | ||
public ApiResponse<User> getUserProfile(@PathVariable Long id) { | ||
return ApiResponse.success(SuccessType.USER_SEARCH_SUCCESS, userService.getUserById(id)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/app3/server/user/controller/dto/response/UserGetResponse.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,15 @@ | ||
package com.app3.server.user.controller.dto.response; | ||
|
||
import com.app3.server.user.domain.User; | ||
|
||
public record UserGetResponse ( | ||
String nickname | ||
) { | ||
public static UserGetResponse of(User user) { | ||
return new UserGetResponse( | ||
user.getNickname() | ||
); | ||
} | ||
} | ||
|
||
|
Empty file.
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.app3.server.user.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class User { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private String nickname; | ||
|
||
|
||
@Builder | ||
public User(String nickname) { | ||
this.nickname = nickname; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
src/main/java/com/app3/server/user/repository/UserJpaRepository.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 com.app3.server.user.repository; | ||
|
||
|
||
import com.app3.server.user.domain.User; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface UserJpaRepository extends JpaRepository<User, Long> { | ||
} |
Empty file.
26 changes: 26 additions & 0 deletions
26
src/main/java/com/app3/server/user/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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.app3.server.user.service; | ||
|
||
import com.app3.server.common.exception.enums.ErrorType; | ||
import com.app3.server.common.exception.model.NotFoundException; | ||
import com.app3.server.user.controller.dto.response.UserGetResponse; | ||
import com.app3.server.user.domain.User; | ||
import com.app3.server.user.repository.UserJpaRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Transactional | ||
@Service | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
private final UserJpaRepository userJpaRepository; | ||
|
||
public User getUserById(Long id) { | ||
return userJpaRepository.findById(id) | ||
.orElseThrow(() -> new NotFoundException(ErrorType.USER_NOT_FOUND_EXCEPTION)); | ||
} | ||
} | ||
|
Empty file.
Empty file.
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,15 @@ | ||
spring: | ||
datasource: | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: jdbc:mysql://localhost:3306/demo?serverTimezone=UTC&characterEncoding=UTF-8 | ||
username: root | ||
password: sb03sb04!! | ||
|
||
config: | ||
activate: | ||
on-profile: dev | ||
|
||
jpa: | ||
database-platform: org.hibernate.dialect.MySQL8Dialect | ||
hibernate: | ||
ddl-auto: create |