Skip to content

Commit

Permalink
refactor(wedding): change total budget to budget
Browse files Browse the repository at this point in the history
  • Loading branch information
junghoon-vans committed Feb 28, 2023
1 parent e3c9ba1 commit 37017c0
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 60 deletions.
8 changes: 4 additions & 4 deletions src/docs/asciidoc/api/wedding.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ operation::wedding/get-wedding-day[snippets='http-request,http-response,response

operation::wedding/modify-wedding-day[snippets='http-request,request-fields,http-response,response-fields']

=== 예산 조회
=== 결혼 예산 조회

사용자의 예산을 조회합니다.
사용자의 결혼 예산을 조회합니다.

operation::wedding/get-budget[snippets='http-request,http-response,response-fields']

=== 예산 수정
=== 결혼 예산 수정

사용자의 예산을 수정합니다.
사용자의 결혼 예산을 수정합니다.

operation::wedding/modify-budget[snippets='http-request,request-fields,http-response,response-fields']
12 changes: 6 additions & 6 deletions src/main/java/com/dnd/weddingmap/domain/wedding/Wedding.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ public class Wedding extends BaseTimeEntity {
private LocalDate weddingDay;

@Column(nullable = false)
private Long totalBudget;
private Long budget;

public Wedding(Member member, LocalDate weddingDay) {
this.weddingMembers.add(member);
this.weddingDay = weddingDay;
this.totalBudget = 0L;
this.budget = 0L;
}

@Builder
public Wedding(Long id, Member member, LocalDate weddingDay, Long totalBudget) {
public Wedding(Long id, Member member, LocalDate weddingDay, Long budget) {
this.id = id;
this.weddingMembers.add(member);
this.weddingDay = weddingDay;
this.totalBudget = totalBudget;
this.budget = budget;
}

public void removeMember(Member member) {
Expand All @@ -55,7 +55,7 @@ public void setWeddingDay(LocalDate weddingDay) {
this.weddingDay = weddingDay;
}

public void setTotalBudget(Long totalBudget) {
this.totalBudget = totalBudget;
public void setBudget(Long budget) {
this.budget = budget;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dnd.weddingmap.domain.wedding.controller;

import com.dnd.weddingmap.domain.oauth.CustomUserDetails;
import com.dnd.weddingmap.domain.wedding.dto.TotalBudgetDto;
import com.dnd.weddingmap.domain.wedding.dto.BudgetDto;
import com.dnd.weddingmap.domain.wedding.dto.WeddingDayDto;
import com.dnd.weddingmap.domain.wedding.service.WeddingService;
import com.dnd.weddingmap.global.response.SuccessResponse;
Expand Down Expand Up @@ -50,18 +50,18 @@ public ResponseEntity<SuccessResponse> modifyWeddingDay(
}

@GetMapping("/budget")
public ResponseEntity<SuccessResponse> getTotalBudget(
public ResponseEntity<SuccessResponse> getBudget(
@AuthenticationPrincipal CustomUserDetails user) {
TotalBudgetDto totalBudgetDto = weddingService.getTotalBudget(user.getId());
BudgetDto budgetDto = weddingService.getBudget(user.getId());
return ResponseEntity.ok()
.body(SuccessResponse.builder().message("총 예산 조회 성공").data(totalBudgetDto).build());
.body(SuccessResponse.builder().message("총 예산 조회 성공").data(budgetDto).build());
}

@PutMapping("/budget")
public ResponseEntity<SuccessResponse> modifyTotalBudget(
public ResponseEntity<SuccessResponse> modifyBudget(
@AuthenticationPrincipal CustomUserDetails user,
@RequestBody @Valid TotalBudgetDto totalBudgetDto) {
weddingService.modifyTotalBudget(user.getId(), totalBudgetDto);
@RequestBody @Valid BudgetDto budgetDto) {
weddingService.modifyBudget(user.getId(), budgetDto);
return ResponseEntity.ok().body(SuccessResponse.builder().message("총 예산 수정 성공").build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
@Getter
@Setter
@NoArgsConstructor
public class TotalBudgetDto {
public class BudgetDto {

Long totalBudget;
Long budget;

@Builder
public TotalBudgetDto(Long totalBudget) {
this.totalBudget = totalBudget;
public BudgetDto(Long budget) {
this.budget = budget;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dnd.weddingmap.domain.wedding.service;

import com.dnd.weddingmap.domain.wedding.dto.TotalBudgetDto;
import com.dnd.weddingmap.domain.wedding.dto.BudgetDto;
import com.dnd.weddingmap.domain.wedding.dto.WeddingDayDto;

public interface WeddingService {
Expand Down Expand Up @@ -35,20 +35,20 @@ public interface WeddingService {
WeddingDayDto getWeddingDay(Long memberId);

/**
* 회원의 총예산을 수정한다.
* 회원의 결혼 예산을 수정한다.
*
* @param memberId 총예산을 수정할 회원 ID
* @param totalBudgetDto 총예산 정보를 담은 DTO
* @param memberId 결혼 예산을 수정할 회원 ID
* @param budgetDto 결혼 예산 정보를 담은 DTO
* @Exception IllegalStateException 결혼이 존재하지 않는 경우 발생
*/
void modifyTotalBudget(Long memberId, TotalBudgetDto totalBudgetDto);
void modifyBudget(Long memberId, BudgetDto budgetDto);

/**
* 회원의 총예산을 조회한다.
* 회원의 결혼 예산을 조회한다.
*
* @param memberId 총예산을 조회할 회원 ID
* @return 회원의 총예산 정보를 담은 DTO
* @param memberId 결혼 예산을 조회할 회원 ID
* @return 회원의 결혼 예산 정보를 담은 DTO
* @Exception IllegalStateException 결혼이 존재하지 않는 경우 발생
*/
TotalBudgetDto getTotalBudget(Long memberId);
BudgetDto getBudget(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.dnd.weddingmap.domain.member.Member;
import com.dnd.weddingmap.domain.member.MemberRepository;
import com.dnd.weddingmap.domain.wedding.Wedding;
import com.dnd.weddingmap.domain.wedding.dto.TotalBudgetDto;
import com.dnd.weddingmap.domain.wedding.dto.BudgetDto;
import com.dnd.weddingmap.domain.wedding.dto.WeddingDayDto;
import com.dnd.weddingmap.domain.wedding.repository.WeddingRepository;
import com.dnd.weddingmap.domain.wedding.service.WeddingService;
Expand Down Expand Up @@ -70,7 +70,7 @@ public WeddingDayDto getWeddingDay(Long memberId) {

@Override
@Transactional
public void modifyTotalBudget(Long memberId, TotalBudgetDto totalBudgetDto) {
public void modifyBudget(Long memberId, BudgetDto budgetDto) {

Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 회원입니다."));
Expand All @@ -80,13 +80,13 @@ public void modifyTotalBudget(Long memberId, TotalBudgetDto totalBudgetDto) {
}

Wedding wedding = member.getWedding();
wedding.setTotalBudget(totalBudgetDto.getTotalBudget());
wedding.setBudget(budgetDto.getBudget());
weddingRepository.save(wedding);
}

@Override
@Transactional
public TotalBudgetDto getTotalBudget(Long memberId) {
public BudgetDto getBudget(Long memberId) {

Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 회원입니다."));
Expand All @@ -95,8 +95,8 @@ public TotalBudgetDto getTotalBudget(Long memberId) {
throw new IllegalStateException("결혼이 등록되어 있지 않습니다.");
}

return TotalBudgetDto.builder()
.totalBudget(member.getWedding().getTotalBudget())
return BudgetDto.builder()
.budget(member.getWedding().getBudget())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `wedding` RENAME COLUMN `total_budget` TO `budget`;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import com.dnd.weddingmap.docs.springrestdocs.AbstractRestDocsTests;
import com.dnd.weddingmap.domain.jwt.JwtTokenProvider;
import com.dnd.weddingmap.domain.wedding.dto.TotalBudgetDto;
import com.dnd.weddingmap.domain.wedding.dto.BudgetDto;
import com.dnd.weddingmap.domain.wedding.dto.WeddingDayDto;
import com.dnd.weddingmap.domain.wedding.service.WeddingService;
import com.dnd.weddingmap.global.WithMockOAuth2User;
Expand Down Expand Up @@ -114,11 +114,11 @@ void modifyWeddingDay() throws Exception {
}

@Test
@DisplayName(" 예산 조회 테스트")
@DisplayName("결혼 예산 조회 테스트")
@WithMockOAuth2User
void getTotalBudget() throws Exception {
void getBudget() throws Exception {
// given
given(weddingService.getTotalBudget(any())).willReturn(new TotalBudgetDto(1000000L));
given(weddingService.getBudget(any())).willReturn(new BudgetDto(1000000L));

// when
ResultActions result = mockMvc.perform(
Expand All @@ -130,26 +130,26 @@ void getTotalBudget() throws Exception {
requestHeaders(headerWithName(HttpHeaders.AUTHORIZATION).description("액세스 토큰")),
responseFields(fieldWithPath("status").description("응답 상태 코드"),
fieldWithPath("message").description("응답 메시지"),
fieldWithPath("data.totalBudget").description(" 예산"))));
fieldWithPath("data.budget").description("결혼 예산"))));
}

@Test
@DisplayName(" 예산 수정 테스트")
@DisplayName("결혼 예산 수정 테스트")
@WithMockOAuth2User
void modifyTotalBudget() throws Exception {
void modifyBudget() throws Exception {
// given
TotalBudgetDto totalBudgetDto = new TotalBudgetDto(1000000L);
BudgetDto budgetDto = new BudgetDto(1000000L);

// when
ResultActions result = mockMvc.perform(
put("/api/v1/wedding/budget").contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, ACCESS_TOKEN_PREFIX + "ACCESS_TOKEN")
.content(objectMapper.writeValueAsString(totalBudgetDto)));
.content(objectMapper.writeValueAsString(budgetDto)));

// then
result.andExpect(status().isOk()).andDo(document("wedding/modify-budget",
requestHeaders(headerWithName(HttpHeaders.AUTHORIZATION).description("액세스 토큰")),
requestFields(fieldWithPath("totalBudget").description("총 예산")),
requestFields(fieldWithPath("budget").description("총 예산")),
responseFields(fieldWithPath("status").description("응답 상태 코드"),
fieldWithPath("message").description("응답 메시지"),
fieldWithPath("data").description("데이터").ignored())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.dnd.weddingmap.domain.member.Member;
import com.dnd.weddingmap.domain.member.MemberRepository;
import com.dnd.weddingmap.domain.wedding.Wedding;
import com.dnd.weddingmap.domain.wedding.dto.TotalBudgetDto;
import com.dnd.weddingmap.domain.wedding.dto.BudgetDto;
import com.dnd.weddingmap.domain.wedding.dto.WeddingDayDto;
import com.dnd.weddingmap.domain.wedding.repository.WeddingRepository;
import com.dnd.weddingmap.domain.wedding.service.impl.WeddingServiceImpl;
Expand Down Expand Up @@ -126,11 +126,11 @@ void getWeddingDay() {
}

@Test
@DisplayName("총예산을 수정한다.")
void modifyTotalBudget() {
@DisplayName("결혼 예산을 수정한다.")
void modifyBudget() {
// given
TotalBudgetDto totalBudgetDto = TotalBudgetDto.builder()
.totalBudget(1000000L)
BudgetDto budgetDto = BudgetDto.builder()
.budget(1000000L)
.build();

given(memberRepository.findById(memberId))
Expand All @@ -139,30 +139,30 @@ void modifyTotalBudget() {
.willReturn(Optional.ofNullable(wedding));

// when
weddingService.modifyTotalBudget(memberId, totalBudgetDto);
weddingService.modifyBudget(memberId, budgetDto);

// then
Wedding savedWedding = weddingRepository.findById(1L).get();
assertEquals(savedWedding.getTotalBudget(), totalBudgetDto.getTotalBudget());
assertEquals(savedWedding.getBudget(), budgetDto.getBudget());
}

@Test
@DisplayName("총예산을 조회한다.")
void getTotalBudget() {
@DisplayName("결혼 예산을 조회한다.")
void getBudget() {
// given
given(memberRepository.findById(memberId))
.willReturn(Optional.ofNullable(registeredMember));

TotalBudgetDto requestDto = TotalBudgetDto.builder()
.totalBudget(1000000L)
BudgetDto requestDto = BudgetDto.builder()
.budget(1000000L)
.build();
weddingService.modifyTotalBudget(memberId, requestDto);
weddingService.modifyBudget(memberId, requestDto);

// when

TotalBudgetDto responseDto = weddingService.getTotalBudget(memberId);
BudgetDto responseDto = weddingService.getBudget(memberId);

// then
assertEquals(responseDto.getTotalBudget(), requestDto.getTotalBudget());
assertEquals(responseDto.getBudget(), requestDto.getBudget());
}
}

0 comments on commit 37017c0

Please sign in to comment.