Skip to content

Commit

Permalink
Merge pull request #122 from dnd-side-project/feature/wedding-info-api
Browse files Browse the repository at this point in the history
feat: wedding api
  • Loading branch information
junghoon-vans authored Feb 28, 2023
2 parents 216b532 + d6ed3c0 commit cb3bde4
Show file tree
Hide file tree
Showing 14 changed files with 728 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/docs/asciidoc/api/wedding.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
== 결혼 API
:doctype: book
:source-highlighter: highlightjs
:toc: left
:toclevels: 2
:seclinks:

결혼을 등록하고 관련된 정보를 조회, 수정하는 API를 제공합니다.
결혼 정보는 결혼일과 결혼 예산으로 구성되어 있습니다.

=== 결혼 등록

온보딩 과정에서 결혼을 등록합니다. 결혼일을 전달해야 하며 기본적으로 결혼 예산은 0원으로 설정됩니다.

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

=== 결혼일 조회

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

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

=== 결혼일 수정

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

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']
1 change: 1 addition & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
include::api/OAuth2.adoc[]
include::api/Authorization.adoc[]
include::api/Member.adoc[]
include::api/wedding.adoc[]
include::api/checklist/checklist.adoc[]
include::api/checklist/checklistItem.adoc[]
include::api/checklist/checklistSubItem.adoc[]
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/dnd/weddingmap/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import com.dnd.weddingmap.domain.common.BaseTimeEntity;
import com.dnd.weddingmap.domain.oauth.OAuth2Provider;
import com.dnd.weddingmap.domain.wedding.Wedding;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -45,21 +49,27 @@ public class Member extends BaseTimeEntity {
@Enumerated(value = EnumType.STRING)
private Gender gender;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "wedding_id")
private Wedding wedding;

@Builder
public Member(
Long id,
String name,
String email,
String profileImage,
Role role,
OAuth2Provider oauth2Provider
OAuth2Provider oauth2Provider,
Wedding wedding
) {
this.id = id;
this.name = name;
this.email = email;
this.profileImage = profileImage;
this.role = role;
this.oauth2Provider = oauth2Provider;
this.wedding = wedding;
}

public void setGender(Gender gender) {
Expand All @@ -70,6 +80,10 @@ public void setProfileImage(String profileImage) {
this.profileImage = profileImage;
}

public void setWedding(Wedding wedding) {
this.wedding = wedding;
}

public Member update(String name, String profileImage) {
this.name = name;
this.profileImage = profileImage;
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/com/dnd/weddingmap/domain/wedding/Wedding.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.dnd.weddingmap.domain.wedding;

import com.dnd.weddingmap.domain.common.BaseTimeEntity;
import com.dnd.weddingmap.domain.member.Member;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@NoArgsConstructor
public class Wedding extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToMany(mappedBy = "wedding")
private List<Member> weddingMembers = new ArrayList<>();

@Column(nullable = false)
private LocalDate weddingDay;

@Column(nullable = false)
private Long budget;

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

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

public void removeMember(Member member) {
this.weddingMembers.remove(member);
}

public void setWeddingDay(LocalDate weddingDay) {
this.weddingDay = weddingDay;
}

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

import com.dnd.weddingmap.domain.oauth.CustomUserDetails;
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;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/wedding")
public class WeddingController {

private final WeddingService weddingService;

@PostMapping
public ResponseEntity<SuccessResponse> registerWedding(
@AuthenticationPrincipal CustomUserDetails user,
@RequestBody @Valid WeddingDayDto weddingDayDto) {
weddingService.registerWedding(user.getId(), weddingDayDto);
return ResponseEntity.status(HttpStatus.CREATED).body(
SuccessResponse.builder().message("결혼 등록 성공").httpStatus(HttpStatus.CREATED).build());
}

@GetMapping("/day")
public ResponseEntity<SuccessResponse> getWeddingDay(
@AuthenticationPrincipal CustomUserDetails user) {
WeddingDayDto weddingDayDto = weddingService.getWeddingDay(user.getId());
return ResponseEntity.ok()
.body(SuccessResponse.builder().message("결혼일 조회 성공").data(weddingDayDto).build());
}

@PutMapping("/day")
public ResponseEntity<SuccessResponse> modifyWeddingDay(
@AuthenticationPrincipal CustomUserDetails user,
@RequestBody @Valid WeddingDayDto weddingDayDto) {
weddingService.modifyWeddingDay(user.getId(), weddingDayDto);
return ResponseEntity.ok().body(SuccessResponse.builder().message("결혼일 수정 성공").build());
}

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

@PutMapping("/budget")
public ResponseEntity<SuccessResponse> modifyBudget(
@AuthenticationPrincipal CustomUserDetails user,
@RequestBody @Valid BudgetDto budgetDto) {
weddingService.modifyBudget(user.getId(), budgetDto);
return ResponseEntity.ok().body(SuccessResponse.builder().message("결혼 예산 수정 성공").build());
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/dnd/weddingmap/domain/wedding/dto/BudgetDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.dnd.weddingmap.domain.wedding.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
public class BudgetDto {

Long budget;

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

import java.time.LocalDate;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
public class WeddingDayDto {

LocalDate weddingDay;

@Builder
public WeddingDayDto(LocalDate weddingDay) {
this.weddingDay = weddingDay;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.dnd.weddingmap.domain.wedding.repository;

import com.dnd.weddingmap.domain.wedding.Wedding;
import org.springframework.data.jpa.repository.JpaRepository;

public interface WeddingRepository extends JpaRepository<Wedding, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.dnd.weddingmap.domain.wedding.service;

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

public interface WeddingService {

/**
* 결혼 등록을 진행한다.
*
* @param memberId 결혼을 등록할 회원 ID
* @param weddingDayDto 결혼일 정보를 담은 DTO
* @return 등록된 결혼 ID
* @Exception IllegalStateException 결혼이 이미 존재하는 경우 발생
*/
Long registerWedding(Long memberId, WeddingDayDto weddingDayDto);


/**
* 회원의 결혼일을 수정한다.
*
* @param memberId 결혼일을 수정할 회원 ID
* @param weddingDayDto 결혼일 정보를 담은 DTO
* @Exception IllegalStateException 결혼이 존재하지 않는 경우 발생
*/
void modifyWeddingDay(Long memberId, WeddingDayDto weddingDayDto);

/**
* 회원의 결혼일을 조회한다.
*
* @param memberId 결혼일을 조회할 회원 ID
* @return 회원의 결혼일 정보를 담은 DTO
* @Exception IllegalStateException 결혼이 존재하지 않는 경우 발생
*/
WeddingDayDto getWeddingDay(Long memberId);

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

/**
* 회원의 결혼 예산을 조회한다.
*
* @param memberId 결혼 예산을 조회할 회원 ID
* @return 회원의 결혼 예산 정보를 담은 DTO
* @Exception IllegalStateException 결혼이 존재하지 않는 경우 발생
*/
BudgetDto getBudget(Long memberId);
}
Loading

0 comments on commit cb3bde4

Please sign in to comment.