Skip to content

Commit

Permalink
fix: shopId null일때 처리하기 (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
Choi-JJunho authored Apr 8, 2024
1 parent 525a9e7 commit 0806381
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
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());
}

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

0 comments on commit 0806381

Please sign in to comment.