-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 벌레 내역 관련 Entity 생성 * feat: 아이템 구매 API 구현 * refactor: Bug -> Wallet 네이밍 수정 * refactor: Bug로 네이밍 재수정 * refactor: Entity 생성 로직 Mapper로 이동 * fix: isDefault nullable 하도록 수정 * fix: 레벨 1부터 시작하도록 수정 * test: 아이템 구매 Service 테스트 * test: 아이템 Entity 테스트 * test: 벌레 Entity 테스트 * test: 아이템 구매 Controller 테스트 * style: decrease로 메서드 네이밍 수정 * feat: 해당 벌레 타입의 개수 증가 메서드 추가 * chore: Table 어노테이션 추가 * test: 벌레 개수 증가 테스트
- Loading branch information
Showing
21 changed files
with
534 additions
and
7 deletions.
There are no files selected for viewing
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
64 changes: 64 additions & 0 deletions
64
src/main/java/com/moabam/api/domain/entity/BugHistory.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,64 @@ | ||
package com.moabam.api.domain.entity; | ||
|
||
import static com.moabam.global.error.model.ErrorMessage.*; | ||
import static java.util.Objects.*; | ||
|
||
import com.moabam.api.domain.entity.enums.BugActionType; | ||
import com.moabam.api.domain.entity.enums.BugType; | ||
import com.moabam.global.common.entity.BaseTimeEntity; | ||
import com.moabam.global.error.exception.BadRequestException; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@Table(name = "bug_history") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class BugHistory extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private Long id; | ||
|
||
@Column(name = "member_id", updatable = false, nullable = false) | ||
private Long memberId; | ||
|
||
@Enumerated(value = EnumType.STRING) | ||
@Column(name = "bug_type", nullable = false) | ||
private BugType bugType; | ||
|
||
@Enumerated(value = EnumType.STRING) | ||
@Column(name = "action_type", nullable = false) | ||
private BugActionType actionType; | ||
|
||
@Column(name = "quantity", nullable = false) | ||
private int quantity; | ||
|
||
@Builder | ||
private BugHistory(Long memberId, BugType bugType, BugActionType actionType, int quantity) { | ||
this.memberId = requireNonNull(memberId); | ||
this.bugType = requireNonNull(bugType); | ||
this.actionType = requireNonNull(actionType); | ||
this.quantity = validateQuantity(quantity); | ||
} | ||
|
||
private int validateQuantity(int quantity) { | ||
if (quantity < 0) { | ||
throw new BadRequestException(INVALID_QUANTITY); | ||
} | ||
|
||
return quantity; | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/moabam/api/domain/entity/enums/BugActionType.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,10 @@ | ||
package com.moabam.api.domain.entity.enums; | ||
|
||
public enum BugActionType { | ||
|
||
REWARD, | ||
CHARGE, | ||
USE, | ||
REFUND, | ||
COUPON; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/moabam/api/domain/entity/enums/BugType.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,12 @@ | ||
package com.moabam.api.domain.entity.enums; | ||
|
||
public enum BugType { | ||
|
||
MORNING, | ||
NIGHT, | ||
GOLDEN; | ||
|
||
public boolean isGoldenBug() { | ||
return this == GOLDEN; | ||
} | ||
} |
16 changes: 14 additions & 2 deletions
16
src/main/java/com/moabam/api/domain/entity/enums/ItemType.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 |
---|---|---|
@@ -1,7 +1,19 @@ | ||
package com.moabam.api.domain.entity.enums; | ||
|
||
import java.util.List; | ||
|
||
public enum ItemType { | ||
|
||
MORNING, | ||
NIGHT; | ||
MORNING(List.of(BugType.MORNING, BugType.GOLDEN)), | ||
NIGHT(List.of(BugType.NIGHT, BugType.GOLDEN)); | ||
|
||
private final List<BugType> purchasableBugTypes; | ||
|
||
ItemType(List<BugType> purchasableBugTypes) { | ||
this.purchasableBugTypes = purchasableBugTypes; | ||
} | ||
|
||
public boolean isPurchasableBy(BugType bugType) { | ||
return this.purchasableBugTypes.contains(bugType); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/moabam/api/domain/repository/BugHistoryRepository.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,9 @@ | ||
package com.moabam.api.domain.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.moabam.api.domain.entity.BugHistory; | ||
|
||
public interface BugHistoryRepository extends JpaRepository<BugHistory, Long> { | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.moabam.api.dto; | ||
|
||
import com.moabam.api.domain.entity.enums.BugType; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record PurchaseItemRequest( | ||
@NotNull BugType bugType | ||
) { | ||
|
||
} |
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
Oops, something went wrong.