Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.showcase.synapse.sales
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
com.showcase.synapse
com.showcase.synapse.sales
Commits
6a32dc2c
Commit
6a32dc2c
authored
Sep 11, 2023
by
lemin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sales commit
parent
84664387
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
100 additions
and
47 deletions
+100
-47
SalesAggregate.java
.../com/showcase/synapse/sales/aggregate/SalesAggregate.java
+13
-13
ChangeSalesQuantityCommand.java
...ase/synapse/sales/command/ChangeSalesQuantityCommand.java
+1
-1
CreateSalesCommand.java
...om/showcase/synapse/sales/command/CreateSalesCommand.java
+1
-1
SalesController.java
...om/showcase/synapse/sales/controller/SalesController.java
+9
-9
SalesCreateDto.java
...n/java/com/showcase/synapse/sales/dto/SalesCreateDto.java
+1
-1
SalesEntity.java
...n/java/com/showcase/synapse/sales/entity/SalesEntity.java
+1
-1
SalesStatus.java
...in/java/com/showcase/synapse/sales/enums/SalesStatus.java
+1
-1
SalesCreatedEvent.java
...a/com/showcase/synapse/sales/event/SalesCreatedEvent.java
+1
-1
SalesQuantityChangedEvent.java
...owcase/synapse/sales/event/SalesQuantityChangedEvent.java
+1
-1
SalesEventHandler.java
...owcase/synapse/sales/event/handler/SalesEventHandler.java
+45
-0
GetSalesQuery.java
.../java/com/showcase/synapse/sales/query/GetSalesQuery.java
+1
-1
SalesQueryHandler.java
...owcase/synapse/sales/query/handler/SalesQueryHandler.java
+6
-6
SalesRepository.java
...om/showcase/synapse/sales/repository/SalesRepository.java
+8
-0
SalesSaga.java
src/main/java/com/showcase/synapse/sales/saga/SalesSaga.java
+1
-1
SalesService.java
...java/com/showcase/synapse/sales/service/SalesService.java
+10
-10
No files found.
src/main/java/com/showcase/synapse/sales/aggregate/
Product
Aggregate.java
→
src/main/java/com/showcase/synapse/sales/aggregate/
Sales
Aggregate.java
View file @
6a32dc2c
...
...
@@ -8,11 +8,11 @@ import org.axonframework.eventsourcing.EventSourcingHandler;
import
org.axonframework.modelling.command.AggregateIdentifier
;
import
org.axonframework.spring.stereotype.Aggregate
;
import
com.showcase.synapse.sales.command.ChangeQuantityCommand
;
import
com.showcase.synapse.sales.command.Create
Product
Command
;
import
com.showcase.synapse.sales.event.
Product
CreatedEvent
;
import
com.showcase.synapse.sales.event.
Product
QuantityChangedEvent
;
import
com.showcase.synapse.sales.saga.
Product
Saga
;
import
com.showcase.synapse.sales.command.Change
Sales
QuantityCommand
;
import
com.showcase.synapse.sales.command.Create
Sales
Command
;
import
com.showcase.synapse.sales.event.
Sales
CreatedEvent
;
import
com.showcase.synapse.sales.event.
Sales
QuantityChangedEvent
;
import
com.showcase.synapse.sales.saga.
Sales
Saga
;
import
java.math.BigDecimal
;
...
...
@@ -21,7 +21,7 @@ import static org.axonframework.modelling.command.AggregateLifecycle.apply;
@Aggregate
@NoArgsConstructor
@Slf4j
public
class
Product
Aggregate
{
public
class
Sales
Aggregate
{
@AggregateIdentifier
private
String
id
;
...
...
@@ -29,26 +29,26 @@ public class ProductAggregate {
@CommandHandler
public
ProductAggregate
(
CreateProduct
Command
command
)
{
log
.
info
(
"[
ProductAggregate(CreateProductCommand) > apply new Product
CreatedEvent]"
);
apply
(
new
Product
CreatedEvent
(
command
.
getId
(),
command
.
getName
(),
command
.
getComment
(),
command
.
getPrice
()));
public
SalesAggregate
(
CreateSales
Command
command
)
{
log
.
info
(
"[
SalesAggregate(CreateSalesCommand) > apply new Sales
CreatedEvent]"
);
apply
(
new
Sales
CreatedEvent
(
command
.
getId
(),
command
.
getName
(),
command
.
getComment
(),
command
.
getPrice
()));
}
@EventSourcingHandler
public
void
createProduct
(
Product
CreatedEvent
event
)
{
public
void
createProduct
(
Sales
CreatedEvent
event
)
{
this
.
id
=
event
.
getProductId
();
// this.quantiy = event.getQuantity();
}
@CommandHandler
public
void
changeQuantity
(
ChangeQuantityCommand
command
)
{
public
void
changeQuantity
(
Change
Sales
QuantityCommand
command
)
{
log
.
info
(
"[@CommandHandler ProductchangeQuantity]"
);
// if(this.quantiy < command.getQuantity()) throw new IllegalArgumentException("tfy ");
// apply(new
Product
QuantityChangedEvent(command.getProductId(), this.quantiy - command.getQuantity()));
// apply(new
Sales
QuantityChangedEvent(command.getProductId(), this.quantiy - command.getQuantity()));
}
@EventSourcingHandler
public
void
changeQuantity
(
Product
QuantityChangedEvent
event
)
{
public
void
changeQuantity
(
Sales
QuantityChangedEvent
event
)
{
// this.quantiy = event.getQuantity();
}
...
...
src/main/java/com/showcase/synapse/sales/command/ChangeQuantityCommand.java
→
src/main/java/com/showcase/synapse/sales/command/Change
Sales
QuantityCommand.java
View file @
6a32dc2c
...
...
@@ -7,7 +7,7 @@ import lombok.Getter;
@AllArgsConstructor
@Getter
public
class
ChangeQuantityCommand
{
public
class
Change
Sales
QuantityCommand
{
@TargetAggregateIdentifier
private
String
productId
;
...
...
src/main/java/com/showcase/synapse/sales/command/Create
Product
Command.java
→
src/main/java/com/showcase/synapse/sales/command/Create
Sales
Command.java
View file @
6a32dc2c
...
...
@@ -8,7 +8,7 @@ import java.math.BigDecimal;
@AllArgsConstructor
@Getter
public
class
Create
Product
Command
{
public
class
Create
Sales
Command
{
@TargetAggregateIdentifier
private
final
String
id
;
...
...
src/main/java/com/showcase/synapse/sales/controller/
Product
Controller.java
→
src/main/java/com/showcase/synapse/sales/controller/
Sales
Controller.java
View file @
6a32dc2c
...
...
@@ -3,9 +3,9 @@ package com.showcase.synapse.sales.controller;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
com.showcase.synapse.sales.dto.
Product
CreateDto
;
import
com.showcase.synapse.sales.entity.
Product
Entity
;
import
com.showcase.synapse.sales.service.
Product
Service
;
import
com.showcase.synapse.sales.dto.
Sales
CreateDto
;
import
com.showcase.synapse.sales.entity.
Sales
Entity
;
import
com.showcase.synapse.sales.service.
Sales
Service
;
import
java.math.BigDecimal
;
import
java.util.HashMap
;
...
...
@@ -16,23 +16,23 @@ import java.util.concurrent.ExecutionException;
@RestController
@RequestMapping
(
"/api/msa/product"
)
@CrossOrigin
(
origins
=
"*"
)
public
class
Product
Controller
{
public
class
Sales
Controller
{
final
Product
Service
productService
;
final
Sales
Service
productService
;
public
ProductController
(
Product
Service
productService
)
{
public
SalesController
(
Sales
Service
productService
)
{
this
.
productService
=
productService
;
}
@GetMapping
(
"/"
)
public
ResponseEntity
<
List
<
Product
Entity
>>
getProducts
()
throws
ExecutionException
,
InterruptedException
{
List
<
Product
Entity
>
productEntities
=
productService
.
getProducts
();
public
ResponseEntity
<
List
<
Sales
Entity
>>
getProducts
()
throws
ExecutionException
,
InterruptedException
{
List
<
Sales
Entity
>
productEntities
=
productService
.
getProducts
();
return
ResponseEntity
.
ok
(
productEntities
);
}
@PostMapping
(
"/"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
productCreate
(
@RequestBody
Product
CreateDto
productCreateDto
)
{
public
ResponseEntity
<
Map
<
String
,
String
>>
productCreate
(
@RequestBody
Sales
CreateDto
productCreateDto
)
{
String
productId
=
productService
.
createProduct
(
productCreateDto
.
getName
(),
productCreateDto
.
getComment
(),
BigDecimal
.
valueOf
(
productCreateDto
.
getPrice
()));
...
...
src/main/java/com/showcase/synapse/sales/dto/
Product
CreateDto.java
→
src/main/java/com/showcase/synapse/sales/dto/
Sales
CreateDto.java
View file @
6a32dc2c
...
...
@@ -5,7 +5,7 @@ import lombok.Setter;
@Getter
@Setter
public
class
Product
CreateDto
{
public
class
Sales
CreateDto
{
private
String
name
;
private
String
comment
;
private
int
price
;
...
...
src/main/java/com/showcase/synapse/sales/entity/
Product
Entity.java
→
src/main/java/com/showcase/synapse/sales/entity/
Sales
Entity.java
View file @
6a32dc2c
...
...
@@ -14,7 +14,7 @@ import java.math.BigDecimal;
@Setter
@AllArgsConstructor
@NoArgsConstructor
public
class
Product
Entity
{
public
class
Sales
Entity
{
@Id
private
String
id
;
private
String
name
;
...
...
src/main/java/com/showcase/synapse/sales/enums/
Order
Status.java
→
src/main/java/com/showcase/synapse/sales/enums/
Sales
Status.java
View file @
6a32dc2c
package
com
.
showcase
.
synapse
.
sales
.
enums
;
public
enum
Order
Status
{
public
enum
Sales
Status
{
CREATED
,
CANCELED
}
src/main/java/com/showcase/synapse/sales/event/
Product
CreatedEvent.java
→
src/main/java/com/showcase/synapse/sales/event/
Sales
CreatedEvent.java
View file @
6a32dc2c
...
...
@@ -7,7 +7,7 @@ import java.math.BigDecimal;
@AllArgsConstructor
@Getter
public
class
Product
CreatedEvent
{
public
class
Sales
CreatedEvent
{
private
String
productId
;
private
String
name
;
private
String
comment
;
...
...
src/main/java/com/showcase/synapse/sales/event/
Product
QuantityChangedEvent.java
→
src/main/java/com/showcase/synapse/sales/event/
Sales
QuantityChangedEvent.java
View file @
6a32dc2c
...
...
@@ -5,7 +5,7 @@ import lombok.Getter;
@AllArgsConstructor
@Getter
public
class
Product
QuantityChangedEvent
{
public
class
Sales
QuantityChangedEvent
{
private
String
productId
;
private
int
quantity
;
}
src/main/java/com/showcase/synapse/sales/event/handler/
Product
EventHandler.java
→
src/main/java/com/showcase/synapse/sales/event/handler/
Sales
EventHandler.java
View file @
6a32dc2c
...
...
@@ -5,24 +5,24 @@ import lombok.extern.slf4j.Slf4j;
import
org.axonframework.eventhandling.EventHandler
;
import
org.springframework.stereotype.Component
;
import
com.showcase.synapse.sales.entity.
Product
Entity
;
import
com.showcase.synapse.sales.event.
Product
CreatedEvent
;
import
com.showcase.synapse.sales.event.
Product
QuantityChangedEvent
;
import
com.showcase.synapse.sales.repository.
Product
Repository
;
import
com.showcase.synapse.sales.entity.
Sales
Entity
;
import
com.showcase.synapse.sales.event.
Sales
CreatedEvent
;
import
com.showcase.synapse.sales.event.
Sales
QuantityChangedEvent
;
import
com.showcase.synapse.sales.repository.
Sales
Repository
;
@Component
@AllArgsConstructor
@Slf4j
public
class
Product
EventHandler
{
public
class
Sales
EventHandler
{
private
final
Product
Repository
productRepository
;
private
final
Sales
Repository
productRepository
;
@EventHandler
protected
void
saveProduct
(
Product
CreatedEvent
productCreatedEvent
)
{
protected
void
saveProduct
(
Sales
CreatedEvent
productCreatedEvent
)
{
log
.
info
(
"
Product
CreatedEvent 이벤트 받음?"
);
log
.
info
(
"
ProductEventHandler > [Product
CreatedEvent] productCreatedEvent"
);
ProductEntity
productEntity
=
new
Product
Entity
();
log
.
info
(
"
Sales
CreatedEvent 이벤트 받음?"
);
log
.
info
(
"
SalesEventHandler > [Sales
CreatedEvent] productCreatedEvent"
);
SalesEntity
productEntity
=
new
Sales
Entity
();
productEntity
.
setId
(
productCreatedEvent
.
getProductId
());
productEntity
.
setName
(
productCreatedEvent
.
getName
());
productEntity
.
setComment
(
productCreatedEvent
.
getComment
());
...
...
@@ -33,10 +33,10 @@ public class ProductEventHandler {
}
@EventHandler
protected
void
changeQuantity
(
Product
QuantityChangedEvent
productQuantityChangedEvent
)
{
log
.
info
(
"
Product
QuantityChangedEvent 이벤트 받음?"
);
log
.
info
(
"[
Product
QuantityChangedEvent]"
);
Product
Entity
productEntity
=
productRepository
.
findById
(
productQuantityChangedEvent
.
getProductId
()).
get
();
protected
void
changeQuantity
(
Sales
QuantityChangedEvent
productQuantityChangedEvent
)
{
log
.
info
(
"
Sales
QuantityChangedEvent 이벤트 받음?"
);
log
.
info
(
"[
Sales
QuantityChangedEvent]"
);
Sales
Entity
productEntity
=
productRepository
.
findById
(
productQuantityChangedEvent
.
getProductId
()).
get
();
// log.info("[{}] quantity:{}", productEntity.getName(), productEntity.getQuentity());
// productEntity.setQuentity(productQuantityChangedEvent.getQuantity());
productRepository
.
save
(
productEntity
);
...
...
src/main/java/com/showcase/synapse/sales/query/Get
Product
sQuery.java
→
src/main/java/com/showcase/synapse/sales/query/Get
Sale
sQuery.java
View file @
6a32dc2c
package
com
.
showcase
.
synapse
.
sales
.
query
;
public
class
Get
Product
sQuery
{
public
class
Get
Sale
sQuery
{
}
src/main/java/com/showcase/synapse/sales/query/handler/
Product
QueryHandler.java
→
src/main/java/com/showcase/synapse/sales/query/handler/
Sales
QueryHandler.java
View file @
6a32dc2c
...
...
@@ -5,9 +5,9 @@ import java.util.List;
import
org.axonframework.queryhandling.QueryHandler
;
import
org.springframework.stereotype.Component
;
import
com.showcase.synapse.sales.entity.
Product
Entity
;
import
com.showcase.synapse.sales.query.Get
Product
sQuery
;
import
com.showcase.synapse.sales.repository.
Product
Repository
;
import
com.showcase.synapse.sales.entity.
Sales
Entity
;
import
com.showcase.synapse.sales.query.Get
Sale
sQuery
;
import
com.showcase.synapse.sales.repository.
Sales
Repository
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -15,12 +15,12 @@ import lombok.extern.slf4j.Slf4j;
@Component
@RequiredArgsConstructor
@Slf4j
public
class
Product
QueryHandler
{
public
class
Sales
QueryHandler
{
private
final
Product
Repository
productRepository
;
private
final
Sales
Repository
productRepository
;
@QueryHandler
protected
List
<
ProductEntity
>
on
(
GetProduct
sQuery
query
)
{
protected
List
<
SalesEntity
>
on
(
GetSale
sQuery
query
)
{
log
.
info
(
"---product query---"
);
return
productRepository
.
findAll
();
}
...
...
src/main/java/com/showcase/synapse/sales/repository/
Product
Repository.java
→
src/main/java/com/showcase/synapse/sales/repository/
Sales
Repository.java
View file @
6a32dc2c
package
com
.
showcase
.
synapse
.
sales
.
repository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
com.showcase.synapse.sales.entity.
Product
Entity
;
import
com.showcase.synapse.sales.entity.
Sales
Entity
;
public
interface
ProductRepository
extends
JpaRepository
<
Product
Entity
,
String
>
{
public
interface
SalesRepository
extends
JpaRepository
<
Sales
Entity
,
String
>
{
}
src/main/java/com/showcase/synapse/sales/saga/
Product
Saga.java
→
src/main/java/com/showcase/synapse/sales/saga/
Sales
Saga.java
View file @
6a32dc2c
...
...
@@ -8,7 +8,7 @@ import lombok.extern.slf4j.Slf4j;
//@Saga
@Slf4j
public
class
Product
Saga
{
public
class
Sales
Saga
{
@Autowired
private
transient
CommandGateway
commandGateway
;
...
...
src/main/java/com/showcase/synapse/sales/service/
Product
Service.java
→
src/main/java/com/showcase/synapse/sales/service/
Sales
Service.java
View file @
6a32dc2c
...
...
@@ -10,28 +10,28 @@ import org.axonframework.messaging.responsetypes.ResponseTypes;
import
org.axonframework.queryhandling.QueryGateway
;
import
org.springframework.stereotype.Service
;
import
com.showcase.synapse.sales.command.Create
Product
Command
;
import
com.showcase.synapse.sales.entity.
Product
Entity
;
import
com.showcase.synapse.sales.query.Get
Product
sQuery
;
import
com.showcase.synapse.sales.command.Create
Sales
Command
;
import
com.showcase.synapse.sales.entity.
Sales
Entity
;
import
com.showcase.synapse.sales.query.Get
Sale
sQuery
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
@Service
public
class
Product
Service
{
public
class
Sales
Service
{
private
final
CommandGateway
commandGateway
;
private
final
QueryGateway
queryGateway
;
public
Product
Service
(
CommandGateway
commandGateway
,
QueryGateway
queryGateway
)
{
public
Sales
Service
(
CommandGateway
commandGateway
,
QueryGateway
queryGateway
)
{
this
.
commandGateway
=
commandGateway
;
this
.
queryGateway
=
queryGateway
;
}
public
String
createProduct
(
String
name
,
String
comment
,
BigDecimal
price
)
{
log
.
info
(
"[@Service createProduct] new Create
Product
Command"
);
log
.
info
(
"[@Service createProduct] new Create
Sales
Command"
);
// command생성
Create
ProductCommand
createProductCommand
=
new
CreateProduct
Command
(
Create
SalesCommand
createProductCommand
=
new
CreateSales
Command
(
UUID
.
randomUUID
().
toString
(),
name
,
comment
,
price
);
System
.
out
.
println
(
"test"
);
...
...
@@ -42,9 +42,9 @@ public class ProductService {
return
returnValue
;
}
public
List
<
Product
Entity
>
getProducts
()
throws
ExecutionException
,
InterruptedException
{
return
queryGateway
.
query
(
new
Get
Product
sQuery
(),
ResponseTypes
.
multipleInstancesOf
(
Product
Entity
.
class
)).
get
();
public
List
<
Sales
Entity
>
getProducts
()
throws
ExecutionException
,
InterruptedException
{
return
queryGateway
.
query
(
new
Get
Sale
sQuery
(),
ResponseTypes
.
multipleInstancesOf
(
Sales
Entity
.
class
)).
get
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment