-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/12 check my profile #17
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8aa5d65
chore : pull from feat/8
lejuho f44eb0f
feat : ์ ์ ์ฌ์ง ์
๋ก๋ ๋ฐ ai ๊ฒฐ๊ณผ๋ฌผ ๋ฐํ api ๊ตฌํ
lejuho 6cad136
chore : spotless ์ ์ฉ
lejuho c73fc4f
Merge branch 'feat/13-upload-image-and-return-ai' into develop
lejuho fab6328
feat : ๋ด ํ๋กํ ์กฐํ api ๊ตฌํ
lejuho 9ab1798
feat : ์ ์ ๊ฒ์ ์คํจ ์ ์์ธ ํด๋์ค ๋ฐ GlobalExceptionHandler ๊ตฌํ
lejuho b860c19
chore : ์์ธ์ฒ๋ฆฌ ๋ฐ ๋ก์ง, ํ
์คํธ ์ฝ๋ ์์
lejuho 708d4e6
chore : CI/CD ํ
์คํธ ํ๊ฒฝ๋ณ์ ์ญ์
lejuho e28fdda
chore : CI/CD ์์ ๋ฐ UserController ํ
์คํธ ์์
lejuho 09e1de8
chore : spotless ์ ์ฉ
lejuho 036ba69
chore : DynamicPropertySource ์ค์ ์์
lejuho e19db6a
chore : User ๊ฒฝํ์น ํ๋ ํตํฉ(์จ๋)
lejuho 9e8476a
chore : spotless ์ ์ฉ
lejuho b8e36c9
fix : UserServiceTest ์์
lejuho 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 hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/cp_main_be/global/GlobalExceptionHandler.java
This file contains hidden or 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,19 @@ | ||
| package com.example.cp_main_be.global; | ||
|
|
||
| import com.example.cp_main_be.global.exception.UserNotFoundException; | ||
| import com.example.cp_main_be.util.ApiResponse; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
|
||
| @RestControllerAdvice | ||
| public class GlobalExceptionHandler { | ||
|
|
||
| @ExceptionHandler(UserNotFoundException.class) | ||
| public ResponseEntity<ApiResponse<Object>> handleUserNotFoundException(UserNotFoundException e) { | ||
| ApiResponse<Object> response = ApiResponse.failure("USER_NOT_FOUND", e.getMessage()); | ||
|
|
||
| return new ResponseEntity<>(response, HttpStatus.NOT_FOUND); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/example/cp_main_be/global/exception/UserNotFoundException.java
This file contains hidden or 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,7 @@ | ||
| package com.example.cp_main_be.global.exception; | ||
|
|
||
| public class UserNotFoundException extends RuntimeException { | ||
| public UserNotFoundException(String message) { | ||
| super(message); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
3 changes: 2 additions & 1 deletion
3
src/main/java/com/example/cp_main_be/user/dto/request/UserRequest.java
This file contains hidden or 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,13 +1,14 @@ | ||
| package com.example.cp_main_be.user.dto.request; | ||
|
|
||
| import java.util.UUID; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public class UserRequest { | ||
|
|
||
| private final Long userUuid; | ||
| private final UUID userUuid; | ||
| private final Long userId; | ||
| private final String username; | ||
| } |
This file contains hidden or 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 hidden or 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
24 changes: 15 additions & 9 deletions
24
src/test/java/com/example/cp_main_be/config/AbstractContainerBaseTest.java
This file contains hidden or 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,34 +1,40 @@ | ||
| package com.example.cp_main_be.config; | ||
|
|
||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.test.context.DynamicPropertyRegistry; | ||
| import org.springframework.test.context.DynamicPropertySource; | ||
| import org.testcontainers.containers.PostgreSQLContainer; | ||
| import org.testcontainers.junit.jupiter.Container; | ||
| import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
|
||
| @SpringBootTest | ||
| @Testcontainers // 1. ์ด ํด๋์ค๊ฐ Testcontainers๋ฅผ ์ฌ์ฉํจ์ ๋ช ์ | ||
| public abstract class AbstractContainerBaseTest { | ||
|
|
||
| // 2. static์ผ๋ก ์ปจํ ์ด๋๋ฅผ ์ ์ํฉ๋๋ค. (ํ ์คํธ ์ ์ฒด์ ๋จ ํ๋๋ง ์์ฑ) | ||
| private static final PostgreSQLContainer<?> postgresqlContainer = | ||
| @Container | ||
| public static final PostgreSQLContainer<?> postgresqlContainer = | ||
| new PostgreSQLContainer<>("postgres:15-alpine") // ์ฌ์ฉํ PostgreSQL ์ด๋ฏธ์ง | ||
| .withDatabaseName("testdb") // ์ฌ์ฉํ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ด๋ฆ | ||
| .withUsername("testuser") // ์ฌ์ฉ์ ์ด๋ฆ | ||
| .withPassword("testpass"); // ๋น๋ฐ๋ฒํธ | ||
|
|
||
| // 3. ์ปจํ ์ด๋๋ฅผ static ๋ธ๋ก์์ ์๋์ผ๋ก ์์ํฉ๋๋ค. (JUnit 5 ํ์ฅ๊ธฐ๋ฅ์ ์๋์์๋ณด๋ค ์์ ์ ) | ||
| static { | ||
| postgresqlContainer.start(); | ||
| } | ||
|
|
||
| // 4. Spring ์ปจํ ์คํธ๊ฐ ๋ก๋๋๊ธฐ ์ ์, ๋์ ์ผ๋ก ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ์ ๋ณด๋ฅผ ์ค์ ํฉ๋๋ค. | ||
| @DynamicPropertySource | ||
| static void setProperties(DynamicPropertyRegistry registry) { | ||
| // ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ์ ๋ณด ์ค์ | ||
| registry.add("spring.datasource.url", postgresqlContainer::getJdbcUrl); | ||
| registry.add("spring.datasource.username", postgresqlContainer::getUsername); | ||
| registry.add("spring.datasource.password", postgresqlContainer::getPassword); | ||
| registry.add("spring.datasource.driver-class-name", postgresqlContainer::getDriverClassName); | ||
| registry.add("spring.jpa.hibernate.ddl-auto", () -> "create-drop"); // ํ ์คํธ๊ฐ ๋๋๋ฉด ์คํค๋ง๋ฅผ ์ญ์ ํ๋๋ก ์ค์ | ||
| registry.add("spring.jpa.hibernate.ddl-auto", () -> "create-drop"); | ||
|
|
||
| // 3. ๋๋ฝ๋ ๋ค๋ฅธ ํ๋กํผํฐ๋ค์ ์ฌ๊ธฐ์ ์ถ๊ฐํด์ผ ํฉ๋๋ค! | ||
| // ์ด ๊ฐ๋ค์ด ์์ผ๋ฉด Spring Context๊ฐ ๋ก๋๋์ง ๋ชปํฉ๋๋ค. | ||
| registry.add("cloudflare.r2.endpoint", () -> "http://localhost:9000"); // ํ ์คํธ์ฉ ๋๋ฏธ๊ฐ | ||
| registry.add("cloudflare.r2.bucket", () -> "test-bucket"); | ||
| registry.add("cloudflare.r2.access-key", () -> "test-key"); | ||
| registry.add("cloudflare.r2.secret-key", () -> "test-secret"); | ||
|
|
||
| registry.add("replicate.api.token", () -> "dummy-token"); | ||
| registry.add("replicate.api.url", () -> "https://api.replicate.com/test"); | ||
| } | ||
| } |
92 changes: 56 additions & 36 deletions
92
src/test/java/com/example/cp_main_be/user/presentation/UserControllerTest.java
This file contains hidden or 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,70 +1,90 @@ | ||
| package com.example.cp_main_be.user.presentation; | ||
|
|
||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
|
||
| import com.example.cp_main_be.config.AbstractContainerBaseTest; | ||
| import com.example.cp_main_be.user.domain.User; | ||
| import com.example.cp_main_be.user.domain.UserStatus; | ||
| import com.example.cp_main_be.user.service.UserService; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import com.example.cp_main_be.user.domain.repository.UserRepository; | ||
| import com.example.cp_main_be.user.dto.request.UserRequest; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import java.util.UUID; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.dao.DataIntegrityViolationException; | ||
| import org.springframework.test.context.DynamicPropertyRegistry; | ||
| import org.springframework.test.context.DynamicPropertySource; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
| import org.springframework.test.web.servlet.ResultActions; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @SpringBootTest | ||
| @AutoConfigureMockMvc | ||
| @Transactional | ||
| class UserControllerTest extends AbstractContainerBaseTest { | ||
|
|
||
| @Autowired private UserService userService; | ||
| @Autowired private MockMvc mockMvc; | ||
|
|
||
| @DynamicPropertySource | ||
| static void properties(DynamicPropertyRegistry registry) { | ||
| registry.add("replicate.api.token", () -> "dummy-token-for-user-test"); | ||
| } | ||
| @Autowired private ObjectMapper objectMapper; | ||
|
|
||
| @Autowired private UserRepository userRepository; | ||
|
|
||
| @DisplayName("๋๋ค์์ ๋ฐ์ ์ ์ ๋ฅผ ๋ฑ๋กํ๋ค.") | ||
| @Test | ||
| public void ํ์_์์ฑ์_uuid๊ฐ_์๋์ผ๋ก_์๊ธฐ๋๊ฐ() throws Exception { | ||
| void register() throws Exception { | ||
| // given | ||
| User user = new User(); | ||
| UserRequest userRequest = new UserRequest(UUID.randomUUID(), 1L, "test"); | ||
| String requestBody = objectMapper.writeValueAsString(userRequest); | ||
|
|
||
| // when | ||
| user.setUsername("test"); | ||
| userService.saveUser(user); | ||
| ResultActions result = | ||
| mockMvc.perform( | ||
| post("/api/v1/register/nickname") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(requestBody)); | ||
|
|
||
| // then | ||
| // System.out.println("user.getUuid = " + user.getUuid()); | ||
| Assertions.assertNotNull(user.getUuid()); | ||
| result | ||
| .andDo(print()) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.success").value(true)) | ||
| .andExpect(jsonPath("$.data.username").value("test")) | ||
| .andExpect(jsonPath("$.data.uuid").isNotEmpty()); | ||
| } | ||
|
|
||
| @DisplayName("UUID๋ก ์ ์ ์ ๋ณด๋ฅผ ์กฐํํ๋ค.") | ||
| @Test | ||
| public void ์ ์ _์ด๋ฆ์ด_์์ผ๋ฉด_์ค๋ฅ() throws Exception { | ||
| void getUserInfo_success() throws Exception { | ||
| // given | ||
| User user = new User(); | ||
| // ํ ์คํธ๋ฅผ ์ํด ๋ฏธ๋ฆฌ ์ ์ ๋ฅผ ํ ๋ช ์ ์ฅ | ||
| User savedUser = userRepository.save(User.builder().username("existing-user").build()); | ||
| UUID userUuid = savedUser.getUuid(); | ||
|
|
||
| // when | ||
| user.setEmail("test@example.com"); | ||
| user.setPasswordHash("hashedpassword"); | ||
| user.setLevel(1L); // '1L' ๋์ '1'๋ก ๋ณ๊ฒฝํ์ฌ ๋ถํ์ํ ๊ฒฝ๊ณ ์ ๊ฑฐ | ||
| user.setExperiencePoints(0); | ||
| user.setTemperatureScore(0); | ||
| user.setStatus(UserStatus.ACTIVE); | ||
| ResultActions result = mockMvc.perform(get("/api/v1/users/{uuid}", userUuid)); | ||
|
|
||
| // then | ||
| Assertions.assertThrows( | ||
| DataIntegrityViolationException.class, | ||
| () -> { | ||
| userService.saveUser(user); | ||
| }); | ||
| result | ||
| .andDo(print()) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.success").value(true)) | ||
| .andExpect(jsonPath("$.data.username").value("existing-user")) | ||
| .andExpect(jsonPath("$.data.uuid").value(userUuid.toString())); | ||
| } | ||
|
|
||
| @DisplayName("์กด์ฌํ์ง ์๋ UUID๋ก ์ ์ ์ ๋ณด๋ฅผ ์กฐํํ๋ฉด 404 ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.") | ||
| @Test | ||
| public void ์ ์ ์์ฑ์ฑ๊ณต() throws Exception { | ||
| void getUserInfo_fail_whenUserNotFound() throws Exception { | ||
| // given | ||
| User user = new User(); | ||
| UUID nonExistentUuid = UUID.randomUUID(); | ||
|
|
||
| // when | ||
| user.setUsername("test"); | ||
| userService.saveUser(user); | ||
| User user1 = userService.findUserById(user.getId()); | ||
| ResultActions result = mockMvc.perform(get("/api/v1/users/{uuid}", nonExistentUuid)); | ||
|
|
||
| // then | ||
| Assertions.assertEquals(user.getId(), user1.getId()); | ||
| result.andDo(print()).andExpect(status().isNotFound()); // UserNotFoundException์ด 404๋ก ๋ณํ๋๋์ง ํ์ธ | ||
| } | ||
| } |
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.
์ฌ๊ธฐ ๊ธฐ๋ณธ ๊ฒฝํ์น๋ ๊ธฐ๋ณธ ์จ๋ ์ ์๊ฐ ๋ค๋ฅด๊ฒ ํด๋์ผ์ ๊ฑฐ ๊ฐ์๋ฐ, ํ๋๋ก ํต์ผ ํด์ฃผ์ธ์
๋ณ๊ฐ ๊ฒฝํ์น๊ฐ ์๋๊ณ ํ๋์ ์ฒด์ ๋ก๋ง ์ด์๋ ๊ฑฐ์์
Uh oh!
There was an error while loading. Please reload this page.
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.
experiencePoints ์ญ์ ํ๊ณ temperaturescore๋ก ํต์ผํ์ด๋ค
Uh oh!
There was an error while loading. Please reload this page.
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.
๊ทผ๋ฐ ๋ฏธ์ํ๋ฐ โ์จ๋โ๊ฐ ์๋๋ผ โ๊ฝโ ์ ์์ด๊ธดํด
์๋ ์จ๋๋ ๊ฐ์ ์๊ณ ๊ฝ์ผ๋ก ํ๊ธฐ๋ก ํ์ด
FlowerScore๋ก ํต์ผํ์ค๊น์..?