-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from dnd-side-project/feature/wedding-info-api
feat: wedding api
- Loading branch information
Showing
14 changed files
with
728 additions
and
1 deletion.
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
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'] |
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
61 changes: 61 additions & 0 deletions
61
src/main/java/com/dnd/weddingmap/domain/wedding/Wedding.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,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; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/dnd/weddingmap/domain/wedding/controller/WeddingController.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,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
19
src/main/java/com/dnd/weddingmap/domain/wedding/dto/BudgetDto.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,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; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/dnd/weddingmap/domain/wedding/dto/WeddingDayDto.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,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; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/dnd/weddingmap/domain/wedding/repository/WeddingRepository.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,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> { | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/dnd/weddingmap/domain/wedding/service/WeddingService.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,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); | ||
} |
Oops, something went wrong.