-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
648 additions
and
179 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
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
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/hanglog/category/domain/repository/CategoryRepository.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,12 @@ | ||
package hanglog.category.domain.repository; | ||
|
||
import hanglog.category.domain.Category; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface CategoryRepository extends JpaRepository<Category, Long> { | ||
|
||
@Query("SELECT c FROM Category c WHERE MOD(c.id, 100) = 0") | ||
List<Category> findExpenseCategory(); | ||
} |
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
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/hanglog/category/presentation/CategoryController.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 hanglog.category.presentation; | ||
|
||
import hanglog.category.dto.CategoryResponse; | ||
import hanglog.category.service.CategoryService; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/categories") | ||
public class CategoryController { | ||
|
||
private final CategoryService categoryService; | ||
|
||
@GetMapping | ||
public ResponseEntity<List<CategoryResponse>> getExpenseCategories() { | ||
final List<CategoryResponse> categoryResponses = categoryService.getExpenseCategories(); | ||
return ResponseEntity.ok(categoryResponses); | ||
} | ||
} |
7 changes: 0 additions & 7 deletions
7
backend/src/main/java/hanglog/category/repository/CategoryRepository.java
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/hanglog/category/service/CategoryService.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 hanglog.category.service; | ||
|
||
import hanglog.category.domain.Category; | ||
import hanglog.category.domain.repository.CategoryRepository; | ||
import hanglog.category.dto.CategoryResponse; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class CategoryService { | ||
|
||
private final CategoryRepository categoryRepository; | ||
|
||
public List<CategoryResponse> getExpenseCategories() { | ||
final List<Category> expenseCategories = categoryRepository.findExpenseCategory(); | ||
return expenseCategories.stream() | ||
.map(CategoryResponse::of) | ||
.toList(); | ||
} | ||
} |
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
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/hanglog/expense/dto/response/CategoriesInExpenseResponse.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
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/hanglog/expense/dto/response/CategoryInExpenseResponse.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
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
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/hanglog/expense/dto/response/ExpenseGetResponse.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
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
2 changes: 1 addition & 1 deletion
2
backend/src/main/java/hanglog/trip/dto/response/ExpenseResponse.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
2 changes: 1 addition & 1 deletion
2
backend/src/main/java/hanglog/trip/dto/response/PlaceResponse.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
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
17 changes: 10 additions & 7 deletions
17
backend/src/test/java/hanglog/category/fixture/CategoryFixture.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,13 +1,16 @@ | ||
package hanglog.category.fixture; | ||
|
||
import hanglog.category.Category; | ||
import hanglog.category.domain.Category; | ||
import java.util.List; | ||
|
||
public class CategoryFixture { | ||
|
||
public static final Category FOOD = new Category(100L, "음식", "food"); | ||
public static final Category CULTURE = new Category(200L, "문화", "culture"); | ||
public static final Category SHOPPING = new Category(300L, "쇼핑", "shopping"); | ||
public static final Category LODGING = new Category(400L, "숙박", "lodging"); | ||
public static final Category TRANSPORT = new Category(500L, "교통", "transport"); | ||
public static final Category ETC = new Category(600L, "기타", "etc"); | ||
public static final List<Category> EXPENSE_CATEGORIES = List.of( | ||
new Category(100L, "food", "음식"), | ||
new Category(200L, "culture", "문화"), | ||
new Category(300L, "shopping", "쇼핑"), | ||
new Category(400L, "accommodation", "숙박"), | ||
new Category(500L, "transportation", "교통"), | ||
new Category(600L, "etc", "기타") | ||
); | ||
} |
76 changes: 76 additions & 0 deletions
76
backend/src/test/java/hanglog/category/presentation/CategoryControllerTest.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,76 @@ | ||
package hanglog.category.presentation; | ||
|
||
import static hanglog.category.fixture.CategoryFixture.EXPENSE_CATEGORIES; | ||
import static hanglog.trip.restdocs.RestDocsConfiguration.field; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import hanglog.category.dto.CategoryResponse; | ||
import hanglog.category.service.CategoryService; | ||
import hanglog.trip.restdocs.RestDocsTest; | ||
import java.util.List; | ||
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.restdocs.AutoConfigureRestDocs; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; | ||
import org.springframework.restdocs.payload.JsonFieldType; | ||
import org.springframework.test.web.servlet.MvcResult; | ||
|
||
@WebMvcTest(CategoryController.class) | ||
@MockBean(JpaMetamodelMappingContext.class) | ||
@AutoConfigureRestDocs | ||
class CategoryControllerTest extends RestDocsTest { | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@MockBean | ||
private CategoryService categoryService; | ||
|
||
@DisplayName("경비 구분에 필요한 상위 카테고리 정보를 반환한다.") | ||
@Test | ||
void getExpenseCategories() throws Exception { | ||
// given | ||
final List<CategoryResponse> expectResponses = EXPENSE_CATEGORIES.stream() | ||
.map(CategoryResponse::of) | ||
.toList(); | ||
|
||
when(categoryService.getExpenseCategories()) | ||
.thenReturn(expectResponses); | ||
|
||
// when & then | ||
final MvcResult mvcResult = mockMvc.perform(RestDocumentationRequestBuilders.get("/categories") | ||
.contentType(APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andDo(restDocs.document( | ||
responseFields( | ||
fieldWithPath("[].id") | ||
.type(JsonFieldType.NUMBER) | ||
.description("카테고리 ID") | ||
.attributes(field("constraint", "양의 정수")), | ||
fieldWithPath("[].name") | ||
.type(JsonFieldType.STRING) | ||
.description("카테고리 한글명") | ||
.attributes(field("constraint", "50자 이하의 문자열")) | ||
) | ||
)) | ||
.andReturn(); | ||
|
||
final List<CategoryResponse> actualResponses = objectMapper.readValue( | ||
mvcResult.getResponse().getContentAsString(), | ||
new TypeReference<>() { | ||
} | ||
); | ||
assertThat(actualResponses).usingRecursiveComparison().isEqualTo(expectResponses); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
backend/src/test/java/hanglog/category/service/CategoryServiceTest.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,45 @@ | ||
package hanglog.category.service; | ||
|
||
import static hanglog.category.fixture.CategoryFixture.EXPENSE_CATEGORIES; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.BDDMockito.given; | ||
|
||
import hanglog.category.domain.repository.CategoryRepository; | ||
import hanglog.category.dto.CategoryResponse; | ||
import java.util.List; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@Transactional | ||
class CategoryServiceTest { | ||
|
||
@InjectMocks | ||
private CategoryService categoryService; | ||
|
||
@Mock | ||
private CategoryRepository categoryRepository; | ||
|
||
@DisplayName("경비 구분에 필요한 상위 카테고리 정보를 반환한다.") | ||
@Test | ||
void getExpenseCategories() { | ||
// given | ||
final List<CategoryResponse> expectResponses = EXPENSE_CATEGORIES.stream() | ||
.map(CategoryResponse::of) | ||
.toList(); | ||
|
||
given(categoryRepository.findExpenseCategory()) | ||
.willReturn(EXPENSE_CATEGORIES); | ||
|
||
// when | ||
final List<CategoryResponse> actualResponses = categoryService.getExpenseCategories(); | ||
|
||
// then | ||
assertThat(actualResponses).usingRecursiveComparison().isEqualTo(expectResponses); | ||
} | ||
} |
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
Oops, something went wrong.