-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: store 생성 * refactor: store를 product에서 빼기 * chore: confilct 나면서 이상한 잡버그 수정
- Loading branch information
Showing
20 changed files
with
486 additions
and
25 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/poomasi/domain/auth/signup/service/SignupService.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 poomasi.domain.auth.signup.service; | ||
|
||
import jdk.jfr.Description; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import poomasi.domain.member.dto.request.SignupRequest; | ||
import poomasi.domain.member.dto.response.SignUpResponse; | ||
import poomasi.domain.member.entity.LoginType; | ||
import poomasi.domain.member.repository.MemberRepository; | ||
import poomasi.domain.member.entity.Member; | ||
import poomasi.global.error.BusinessException; | ||
|
||
import static poomasi.domain.member.entity.Role.ROLE_CUSTOMER; | ||
import static poomasi.domain.member.entity.Role.ROLE_FARMER; | ||
import static poomasi.global.error.BusinessError.*; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class SignupService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final PasswordEncoder passwordEncoder; | ||
|
||
@Description("카카오톡으로 먼저 회원가입이 되어 있는 경우, 계정 연동을 진행합니다. ") | ||
@Transactional | ||
public SignUpResponse signUp(SignupRequest signupRequest) { | ||
String email = signupRequest.email(); | ||
String password = signupRequest.password(); | ||
|
||
memberRepository.findByEmail(email) | ||
.ifPresent(member -> { throw new BusinessException(DUPLICATE_MEMBER_EMAIL); }); | ||
|
||
Member newMember = Member.builder() | ||
.email(email) | ||
.password(passwordEncoder.encode(password)) | ||
.loginType(LoginType.LOCAL) | ||
.role(ROLE_FARMER) | ||
.build(); | ||
memberRepository.save(newMember); | ||
return new SignUpResponse(email, "회원 가입 성공"); | ||
} | ||
} | ||
|
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
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
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
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
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
41 changes: 41 additions & 0 deletions
41
src/main/java/poomasi/domain/store/controller/StoreController.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,41 @@ | ||
package poomasi.domain.store.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.annotation.Secured; | ||
import org.springframework.stereotype.Controller; | ||
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 poomasi.domain.store.dto.StoreRegisterRequest; | ||
import poomasi.domain.store.service.StoreService; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/store") | ||
public class StoreController { | ||
|
||
private final StoreService storeService; | ||
|
||
@Secured("ROLE_FARMER") | ||
@PostMapping("") | ||
public ResponseEntity<?> addStore(@RequestBody StoreRegisterRequest storeRegisterRequest) { | ||
storeService.addStore(storeRegisterRequest); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@Secured("ROLE_FARMER") | ||
@GetMapping("") | ||
public ResponseEntity<?> getStore() { | ||
return ResponseEntity.ok(storeService.getStore()); | ||
} | ||
|
||
@Secured("ROLE_FARMER") | ||
@PutMapping("") | ||
public ResponseEntity<?> updateStore(@RequestBody StoreRegisterRequest storeRegisterRequest) { | ||
storeService.updateStore(storeRegisterRequest); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
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,7 @@ | ||
package poomasi.domain.store.dto; | ||
|
||
public record StoreFeeRequest( | ||
Integer fee | ||
) { | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/poomasi/domain/store/dto/StoreRegisterRequest.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,29 @@ | ||
package poomasi.domain.store.dto; | ||
|
||
import org.hibernate.annotations.Comment; | ||
import poomasi.domain.member.entity.Member; | ||
import poomasi.domain.store.entity.Store; | ||
|
||
public record StoreRegisterRequest( | ||
String name, | ||
String address, | ||
String phone, | ||
String ownerPhone, | ||
@Comment("사업자 번호") | ||
String businessNumber, | ||
@Comment("배송비") | ||
Integer shipingFee | ||
) { | ||
|
||
public Store toEntity(Member member) { | ||
return Store.builder() | ||
.name(name) | ||
.address(address) | ||
.phone(phone) | ||
.ownerPhone(ownerPhone) | ||
.businessNumber(businessNumber) | ||
.shipingFee(shipingFee) | ||
.owner(member) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.