[230319] 결제완료 command 개발
- 각 폴더 구조 생성 - 도메인 Event 구조 생성 - kafka message sender 테스트까지 확인 - 결제 완료 예시 application service
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.example.user.domain;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
@Entity
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class Cash {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn
|
||||
private User user;
|
||||
|
||||
@CreatedDate
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@LastModifiedDate
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Cash of(BigDecimal amount, User user) {
|
||||
return new Cash(UUID.fromString("cash").toString(), amount, user, null, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.example.user.domain;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
@Entity
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
private String userId;
|
||||
|
||||
private BigDecimal balance;
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
|
||||
private List<Cash> cashes = new ArrayList<>();
|
||||
|
||||
@CreatedDate
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@LastModifiedDate
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void increaseBalance(BigDecimal amount) {
|
||||
balance = balance.add(amount);
|
||||
}
|
||||
|
||||
public String addNewCash(Cash cash) {
|
||||
this.cashes.add(cash);
|
||||
return cash.getId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.user.domain;
|
||||
|
||||
public interface UserRepository {
|
||||
|
||||
User getByIdOrDefault(String id);
|
||||
|
||||
String save(User user);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.user.infra.persistence;
|
||||
|
||||
import com.example.user.domain.User;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface UserJpaRepositroy extends CrudRepository<User, String> {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.example.user.infra.persistence;
|
||||
|
||||
import com.example.user.domain.User;
|
||||
import com.example.user.domain.UserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class UserRepositoryImpl implements UserRepository {
|
||||
|
||||
private final UserJpaRepositroy jpaRepository;
|
||||
|
||||
@Override
|
||||
public String save(User user) {
|
||||
return jpaRepository.save(user).getUserId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getByIdOrDefault(String id) {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user