Skip to content

Commit

Permalink
merge: conflict 확인
Browse files Browse the repository at this point in the history
  • Loading branch information
waterricecake committed Jul 27, 2023
2 parents 98fadf8 + 58b016e commit a6b9993
Show file tree
Hide file tree
Showing 47 changed files with 648 additions and 179 deletions.
10 changes: 5 additions & 5 deletions backend/src/docs/asciidoc/docs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ include::{snippets}/city-controller-test/get-cities/http-request.adoc[]
==== 응답
include::{snippets}/city-controller-test/get-cities/http-response.adoc[]

== 경비 API
== 카테고리 API

=== 경비 조회 (/trips/:tripId/expense)
=== 경비 카테고리 조회 (GET /categories)

==== 요청
include::{snippets}/Expense-controller-test/get-expenses/http-request.adoc[]
include::{snippets}/category-controller-test/get-expense-categories/http-request.adoc[]

==== 응답
include::{snippets}/Expense-controller-test/get-expenses/http-response.adoc[]
include::{snippets}/Expense-controller-test/get-expenses/response-fields.adoc[]
include::{snippets}/category-controller-test/get-expense-categories/http-response.adoc[]
include::{snippets}/category-controller-test/get-expense-categories/response-fields.adoc[]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hanglog.category;
package hanglog.category.domain;

import static lombok.AccessLevel.PROTECTED;

Expand All @@ -24,8 +24,8 @@ public class Category extends BaseEntity {
private Long id;

@Column(nullable = false, length = 50)
private String korName;
private String engName;

@Column(nullable = false, length = 50)
private String engName;
private String korName;
}
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();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hanglog.category;
package hanglog.category.dto;

import hanglog.category.domain.Category;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -8,14 +9,12 @@
public class CategoryResponse {

private final Long id;
private final String korName;
private final String engName;
private final String name;

public static CategoryResponse of(final Category category) {
return new CategoryResponse(
category.getId(),
category.getKorName(),
category.getEngName()
category.getKorName()
);
}
}
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);
}
}

This file was deleted.

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();
}
}
2 changes: 1 addition & 1 deletion backend/src/main/java/hanglog/expense/Expense.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import hanglog.category.Category;
import hanglog.category.domain.Category;
import hanglog.global.BaseEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hanglog.expense.dto.response;

import hanglog.category.Category;

import hanglog.category.domain.Category;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hanglog.expense.dto.response;

import hanglog.category.Category;

import hanglog.category.domain.Category;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import java.util.Map;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@RequiredArgsConstructor
public class DayLogInExpenseResponse {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hanglog.expense.dto.response;

import hanglog.category.Category;

import hanglog.category.domain.Category;
import hanglog.expense.Currencies;
import hanglog.trip.domain.DayLog;
import hanglog.trip.domain.Trip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static hanglog.global.exception.ExceptionCode.NOT_FOUND_TRIP_ID;

import hanglog.category.Category;
import hanglog.category.domain.Category;
import hanglog.expense.Currencies;
import hanglog.expense.Currency;
import hanglog.expense.Expense;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/java/hanglog/trip/domain/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import hanglog.category.Category;
import hanglog.category.domain.Category;
import hanglog.global.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hanglog.trip.dto.response;

import hanglog.category.CategoryResponse;
import hanglog.category.dto.CategoryResponse;
import hanglog.expense.Expense;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hanglog.trip.dto.response;

import hanglog.category.CategoryResponse;
import hanglog.category.dto.CategoryResponse;
import hanglog.trip.domain.Place;
import java.math.BigDecimal;
import lombok.Getter;
Expand Down
4 changes: 2 additions & 2 deletions backend/src/main/java/hanglog/trip/service/ItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import static hanglog.global.exception.ExceptionCode.NOT_FOUND_TRIP_ITEM_ID;
import static hanglog.global.exception.ExceptionCode.NOT_FOUNT_IMAGE_URL;

import hanglog.category.Category;
import hanglog.category.repository.CategoryRepository;
import hanglog.category.domain.Category;
import hanglog.category.domain.repository.CategoryRepository;
import hanglog.expense.Expense;
import hanglog.global.exception.BadRequestException;
import hanglog.global.type.StatusType;
Expand Down
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", "기타")
);
}
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);
}
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hanglog.expense.presentation;

import static hanglog.category.fixture.CategoryFixture.CULTURE;
import static hanglog.category.fixture.CategoryFixture.EXPENSE_CATEGORIES;
import static hanglog.expense.fixture.CurrenciesFixture.DEFAULT_CURRENCIES;
import static hanglog.trip.fixture.CityFixture.LONDON;
import static hanglog.trip.fixture.CityFixture.TOKYO;
Expand Down Expand Up @@ -44,7 +44,7 @@ void getExpenses() throws Exception {
LONDON_TRIP,
10000,
List.of(new TripCity(LONDON_TRIP, LONDON), new TripCity(LONDON_TRIP, TOKYO)),
Map.of(CULTURE, 1000),
Map.of(EXPENSE_CATEGORIES.get(1), 1000),
DEFAULT_CURRENCIES,
Map.of(LONDON_DAY, 1000)
);
Expand Down
Loading

0 comments on commit a6b9993

Please sign in to comment.