-
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 #39 from Kakaotech-18-Ecommerce/SCRUM-41-seller-se…
…rvice-develop [Feat] Seller API 개발
- Loading branch information
Showing
6 changed files
with
145 additions
and
12 deletions.
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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/kakaoteck/golagola/domain/seller/controller/SellerController.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,40 @@ | ||
package com.kakaoteck.golagola.domain.seller.controller; | ||
|
||
import com.kakaoteck.golagola.domain.seller.dto.SellerRequest; | ||
import com.kakaoteck.golagola.domain.seller.dto.SellerResponse; | ||
import com.kakaoteck.golagola.domain.seller.entity.Seller; | ||
import com.kakaoteck.golagola.domain.seller.repository.SellerRepository; | ||
import com.kakaoteck.golagola.domain.seller.service.SellerService; | ||
import com.kakaoteck.golagola.global.common.ApiResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/seller") | ||
@CrossOrigin("*") | ||
public class SellerController { | ||
|
||
private final SellerService sellerService; | ||
private final SellerRepository sellerRepository; | ||
|
||
@Operation(summary = "판매자 마이페이지 조회", description = "판매자의 정보를 조회합니다.") | ||
@GetMapping("/mypage") | ||
public ApiResponse<SellerResponse> getMyPage(@AuthenticationPrincipal Seller seller) { | ||
return ApiResponse.onSuccess(sellerService.getMyPage(seller)); | ||
} | ||
|
||
@Operation(summary = "판매자 마이페이지 수정", description = "판매자의 정보를 수정합니다.") | ||
@PutMapping("/mypage") | ||
public ApiResponse<SellerResponse> updateProfile( | ||
@AuthenticationPrincipal Seller seller, | ||
@RequestBody SellerRequest.MyPagePutDto request | ||
) { | ||
return ApiResponse.onSuccess(sellerService.updateMyPage(seller, request)); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/kakaoteck/golagola/domain/seller/dto/SellerRequest.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,26 @@ | ||
package com.kakaoteck.golagola.domain.seller.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 SellerRequest( | ||
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/seller/dto/SellerResponse.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.seller.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 SellerResponse( | ||
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
47 changes: 47 additions & 0 deletions
47
src/main/java/com/kakaoteck/golagola/domain/seller/service/SellerService.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,47 @@ | ||
package com.kakaoteck.golagola.domain.seller.service; | ||
|
||
import com.kakaoteck.golagola.domain.seller.dto.SellerRequest; | ||
import com.kakaoteck.golagola.domain.seller.dto.SellerResponse; | ||
import com.kakaoteck.golagola.domain.seller.entity.Seller; | ||
import com.kakaoteck.golagola.domain.seller.repository.SellerRepository; | ||
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 SellerService { | ||
|
||
private final SellerRepository sellerRepository; | ||
|
||
public SellerResponse getMyPage(Seller seller) { | ||
return SellerResponse.builder() | ||
.email(seller.getEmail()) | ||
.role(seller.getRole()) | ||
.address(seller.getAddress()) | ||
.registerDate(seller.getRegisterDate()) | ||
.realName(seller.getRealName()) | ||
.gender(seller.getGender()) | ||
.phoneNum(seller.getPhoneNum()) | ||
.nickname(seller.getNickname()) | ||
.build(); | ||
} | ||
|
||
public SellerResponse updateMyPage(Seller seller, SellerRequest.MyPagePutDto request) { | ||
seller.updateProfile(request); | ||
Seller savedSeller = sellerRepository.save(seller); | ||
return SellerResponse.builder() | ||
.email(savedSeller.getEmail()) | ||
.role(savedSeller.getRole()) | ||
.address(savedSeller.getAddress()) | ||
.registerDate(savedSeller.getRegisterDate()) | ||
.realName(savedSeller.getRealName()) | ||
.gender(savedSeller.getGender()) | ||
.phoneNum(savedSeller.getPhoneNum()) | ||
.nickname(savedSeller.getNickname()) | ||
.build(); | ||
} | ||
} |