-
Notifications
You must be signed in to change notification settings - Fork 0
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 #27 from Kakaotech-18-Ecommerce/SCRUM-40-buyer-ser…
…vice-develop [Feat] Buyer 서비스 개발
- Loading branch information
Showing
5 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/com/kakaoteck/golagola/domain/buyer/controller/BuyerController.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,37 @@ | ||
package com.kakaoteck.golagola.domain.buyer.controller; | ||
|
||
import com.kakaoteck.golagola.domain.buyer.dto.BuyerRequest; | ||
import com.kakaoteck.golagola.domain.buyer.dto.BuyerResponse; | ||
import com.kakaoteck.golagola.domain.buyer.entity.Buyer; | ||
import com.kakaoteck.golagola.domain.buyer.service.BuyerService; | ||
import com.kakaoteck.golagola.global.common.ApiResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/buyer") | ||
public class BuyerController { | ||
|
||
private final BuyerService buyerService; | ||
|
||
@Operation(summary = "구매자 마이페이지 조회", description = "구매자의 정보를 조회합니다.") | ||
@GetMapping("/mypage") | ||
public ApiResponse<BuyerResponse> getMyPage( | ||
@AuthenticationPrincipal Buyer buyer | ||
) { | ||
return ApiResponse.onSuccess(BuyerService.getMyPage(buyer)); | ||
} | ||
|
||
@Operation(summary = "구매자 마이페이지 수정", description = "구매자의 정보를 수정합니다.") | ||
@PutMapping("/mypage") | ||
public ApiResponse<BuyerResponse> updateProfile( | ||
@AuthenticationPrincipal Buyer buyer, | ||
@RequestBody BuyerRequest.MyPagePutDto request | ||
) { | ||
return ApiResponse.onSuccess(buyerService.updateMyPage(buyer, request)); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/kakaoteck/golagola/domain/buyer/dto/BuyerRequest.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,25 @@ | ||
package com.kakaoteck.golagola.domain.buyer.dto; | ||
|
||
import com.kakaoteck.golagola.global.common.enums.Gender; | ||
import com.kakaoteck.golagola.global.common.enums.Role; | ||
import lombok.Builder; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record BuyerRequest( | ||
String nickname, | ||
String realName, | ||
Gender gender, | ||
String email, | ||
String address, | ||
String phoneNum, | ||
Role role, | ||
LocalDate registerDate) { | ||
|
||
@Builder | ||
public record MyPagePutDto( | ||
String nickname, | ||
String address, | ||
String phoneNum | ||
) {} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/kakaoteck/golagola/domain/buyer/dto/BuyerResponse.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.kakaoteck.golagola.domain.buyer.dto; | ||
|
||
import com.kakaoteck.golagola.global.common.enums.Gender; | ||
import com.kakaoteck.golagola.global.common.enums.Role; | ||
import lombok.Builder; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Builder | ||
public record BuyerResponse( | ||
String nickname, | ||
String realName, | ||
Gender gender, | ||
String email, | ||
String address, | ||
String phoneNum, | ||
Role role, | ||
LocalDate registerDate | ||
) { | ||
} |
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
48 changes: 48 additions & 0 deletions
48
src/main/java/com/kakaoteck/golagola/domain/buyer/service/BuyerService.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,48 @@ | ||
package com.kakaoteck.golagola.domain.buyer.service; | ||
|
||
import com.kakaoteck.golagola.domain.buyer.dto.BuyerRequest; | ||
import com.kakaoteck.golagola.domain.buyer.dto.BuyerResponse; | ||
import com.kakaoteck.golagola.domain.buyer.entity.Buyer; | ||
import com.kakaoteck.golagola.domain.buyer.repository.BuyerRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
@Slf4j | ||
public class BuyerService { | ||
|
||
private final BuyerRepository buyerRepository; | ||
|
||
public static BuyerResponse getMyPage(Buyer buyer) { | ||
return BuyerResponse.builder() | ||
.email(buyer.getEmail()) | ||
.role(buyer.getRole()) | ||
.address(buyer.getAddress()) | ||
.registerDate(buyer.getRegisterDate()) | ||
.realName(buyer.getRealName()) | ||
.gender(buyer.getGender()) | ||
.phoneNum(buyer.getPhoneNum()) | ||
.nickname(buyer.getNickname()) | ||
.build(); | ||
} | ||
|
||
public BuyerResponse updateMyPage(Buyer buyer, BuyerRequest.MyPagePutDto request) { | ||
buyer.updateProfile(request); | ||
Buyer savedBuyer = buyerRepository.save(buyer); | ||
return BuyerResponse.builder() | ||
.email(savedBuyer.getEmail()) | ||
.role(savedBuyer.getRole()) | ||
.address(savedBuyer.getAddress()) | ||
.registerDate(savedBuyer.getRegisterDate()) | ||
.realName(savedBuyer.getRealName()) | ||
.gender(savedBuyer.getGender()) | ||
.phoneNum(savedBuyer.getPhoneNum()) | ||
.nickname(savedBuyer.getNickname()) | ||
.build(); | ||
|
||
} | ||
} |