Skip to content

Commit

Permalink
Fix | CAKK-56 | git 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
lcomment authored Aug 28, 2024
1 parent ea6d0fc commit 11d0a26
Showing 1 changed file with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import com.cakk.common.enums.ReturnCode;
import com.cakk.common.exception.CakkException;
import com.cakk.domain.mysql.dto.param.shop.CakeShopUpdateParam;
import com.cakk.domain.mysql.dto.param.shop.UpdateShopAddressParam;
import com.cakk.domain.mysql.entity.audit.AuditEntity;
import com.cakk.domain.mysql.entity.cake.Cake;
import com.cakk.domain.mysql.entity.user.BusinessInformation;
import com.cakk.domain.mysql.entity.user.User;
import com.cakk.domain.mysql.mapper.CakeShopHeartMapper;
import com.cakk.domain.mysql.mapper.CakeShopLikeMapper;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down Expand Up @@ -83,6 +88,12 @@ public class CakeShop extends AuditEntity {
@OneToMany(mappedBy = "cakeShop", cascade = CascadeType.PERSIST)
private Set<Cake> cakes = new HashSet<>();

@OneToMany(mappedBy = "cakeShop", cascade = CascadeType.PERSIST, orphanRemoval = true)
private Set<CakeShopHeart> shopHearts = new HashSet<>();

@OneToMany(mappedBy = "cakeShop", cascade = CascadeType.PERSIST, orphanRemoval = true)
private Set<CakeShopLike> shopLikes = new HashSet<>();

@Builder
public CakeShop(
String shopName,
Expand All @@ -103,15 +114,48 @@ public CakeShop(
this.likeCount = 0;
}

public void increaseLikeCount() {
public void like(final User user) {
if (isLikedOverMaxBy(user)) {
throw new CakkException(ReturnCode.MAX_CAKE_SHOP_LIKE);
}

shopLikes.add(CakeShopLikeMapper.supplyCakeShopLikeBy(this, user));
this.increaseLikeCount();
}

public void heart(final User user) {
shopHearts.add(CakeShopHeartMapper.supplyCakeShopHeartBy(this, user));
this.increaseHeartCount();
}

public void unHeart(final User user) {
shopHearts.removeIf(it -> it.getUser().equals(user));
this.decreaseHeartCount();
}

public boolean isLikedOverMaxBy(final User user) {
long count = shopLikes.stream().map(it -> it.getUser().equals(user)).count();

return count >= 50;
}

public boolean isHeartedBy(final User user) {
return shopHearts.stream().anyMatch(it -> it.getUser().equals(user));
}

private void increaseLikeCount() {
this.likeCount++;
}

public void increaseHeartCount() {
private void increaseHeartCount() {
this.heartCount++;
}

public void decreaseHeartCount() {
private void decreaseHeartCount() {
if (this.heartCount == 0) {
throw new CakkException(ReturnCode.INTERNAL_SERVER_ERROR);
}

this.heartCount--;
}

Expand Down

0 comments on commit 11d0a26

Please sign in to comment.