Skip to content
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

fix: shopId null일때 처리하기 #341

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ default Owner getById(Long ownerId) {
return findById(ownerId).orElseThrow(() -> OwnerNotFoundException.withDetail("ownerId: " + ownerId));
}

Optional<Owner> findByUserId(Long userId);

default Owner getByUserId(Long userId) {
return findByUserId(userId).orElseThrow(() -> OwnerNotFoundException.withDetail("userId: " + userId));
}

Owner save(Owner owner);

Optional<Owner> findByCompanyRegistrationNumber(String companyRegistrationNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,22 @@ public void register(OwnerRegisterRequest request) {
}
Owner owner = request.toOwner(passwordEncoder);
Owner saved = ownerRepository.save(owner);
var shop = shopRepository.findById(request.shopId())
.orElse(null);
ownerShopRedisRepository.save(OwnerShop.builder()
.ownerId(owner.getId())
.shopId(shop == null ? null : shop.getId())
.build());
ownerShopRedisRepository.save(OwnerShop.builder()
.build());
if (request.shopId() != null) {
var shop = shopRepository.getById(request.shopId());
ownerShopRedisRepository.save(OwnerShop.builder()
.ownerId(owner.getId())
.shopId(shop.getId())
.build());
ownerShopRedisRepository.save(OwnerShop.builder()
.build());
} else {
ownerShopRedisRepository.save(OwnerShop.builder()
.ownerId(owner.getId())
.build());
ownerShopRedisRepository.save(OwnerShop.builder()
.build());
}

Comment on lines +89 to +104
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good~

eventPublisher.publishEvent(new OwnerRegisterEvent(saved));
}

Expand Down
16 changes: 8 additions & 8 deletions src/test/java/in/koreatech/koin/acceptance/OwnerApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void register() {
"name": "최준호",
"password": "a0240120305812krlakdsflsa;1235",
"phone_number": "010-0000-0000",
"shop_id": 0,
"shop_id": null,
"shop_name": "기분좋은 뷔짱"
}
""")
Expand Down Expand Up @@ -309,7 +309,7 @@ void registerNotAllowedFileUrl() {
"name": "최준호",
"password": "a0240120305812krlakdsflsa;1235",
"phone_number": "010-0000-0000",
"shop_id": 0,
"shop_id": null,
"shop_name": "기분좋은 뷔짱"
}
""")
Expand Down Expand Up @@ -338,7 +338,7 @@ void registerNotAllowedCompanyNumber() {
"name": "최준호",
"password": "a0240120305812krlakdsflsa;1235",
"phone_number": "010-0000-0000",
"shop_id": 0,
"shop_id": null,
"shop_name": "기분좋은 뷔짱"
}
""")
Expand Down Expand Up @@ -367,7 +367,7 @@ void registerWithoutName() {
"name": "",
"password": "a0240120305812krlakdsflsa;1235",
"phone_number": "010-0000-0000",
"shop_id": 0,
"shop_id": null,
"shop_name": "기분좋은 뷔짱"
}
""")
Expand Down Expand Up @@ -403,7 +403,7 @@ void registerWithExistShop() {

RestAssured
.given()
.body("""
.body(String.format("""
{
"attachment_urls": [
{
Expand All @@ -415,10 +415,10 @@ void registerWithExistShop() {
"name": "주노",
"password": "a0240120305812krlakdsflsa;1235",
"phone_number": "010-0000-0000",
"shop_id": 1,
"shop_id": %d,
"shop_name": "기분좋은 뷔짱"
}
""")
""", shopRequest.getId()))
.contentType(ContentType.JSON)
.when()
.post("/owners/register")
Expand Down Expand Up @@ -452,7 +452,7 @@ void registerWithNotExistShop() {
"name": "주노",
"password": "a0240120305812krlakdsflsa;1235",
"phone_number": "010-0000-0000",
"shop_id": 0,
"shop_id": null,
"shop_name": "기분좋은 뷔짱"
}
""")
Expand Down
Loading