-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
store생성하기 #104
Merged
Merged
store생성하기 #104
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
삼항연산자를 많이 쓰시는 것 같아요! 그런데 이곳에 사용하신 이유가 궁금해요. Review에서 profile이 없으면 안되지 않을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트하면서 memberProfile이없어서 그런데 나중에는 없앨 예정입니다.
주석으로 적어둘게요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵!