Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.showcase.synapse.product
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.product
Commits
d6b92f6c
Commit
d6b92f6c
authored
Sep 07, 2023
by
lemin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
c
parent
548c2768
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
203 additions
and
23 deletions
+203
-23
ChannelAggregate.java
.../showcase/synapse/product/aggregate/ChannelAggregate.java
+36
-0
ProductAggregate.java
.../showcase/synapse/product/aggregate/ProductAggregate.java
+5
-6
CreateChannelCommand.java
...howcase/synapse/product/command/CreateChannelCommand.java
+20
-0
ProductController.java
...howcase/synapse/product/controller/ProductController.java
+36
-11
ChannelCreateDto.java
...va/com/showcase/synapse/product/dto/ChannelCreateDto.java
+16
-0
ProductCreateDto.java
...va/com/showcase/synapse/product/dto/ProductCreateDto.java
+4
-1
ChannelEntity.java
...va/com/showcase/synapse/product/entity/ChannelEntity.java
+6
-1
ProductEntity.java
...va/com/showcase/synapse/product/entity/ProductEntity.java
+1
-1
ChannelCreatedEvent.java
...m/showcase/synapse/product/event/ChannelCreatedEvent.java
+14
-0
ProductEventHandler.java
...se/synapse/product/event/handler/ProductEventHandler.java
+21
-3
GetChannelQuery.java
...a/com/showcase/synapse/product/query/GetChannelQuery.java
+5
-0
ProductQueryHandler.java
...se/synapse/product/query/handler/ProductQueryHandler.java
+10
-0
ChannelRepository.java
...howcase/synapse/product/repository/ChannelRepository.java
+8
-0
ProductService.java
.../com/showcase/synapse/product/service/ProductService.java
+21
-0
No files found.
src/main/java/com/showcase/synapse/product/aggregate/ChannelAggregate.java
0 → 100644
View file @
d6b92f6c
package
com
.
showcase
.
synapse
.
product
.
aggregate
;
import
static
org
.
axonframework
.
modelling
.
command
.
AggregateLifecycle
.
apply
;
import
org.axonframework.commandhandling.CommandHandler
;
import
org.axonframework.eventsourcing.EventSourcingHandler
;
import
org.axonframework.modelling.command.AggregateIdentifier
;
import
org.axonframework.spring.stereotype.Aggregate
;
import
com.showcase.synapse.product.command.CreateChannelCommand
;
import
com.showcase.synapse.product.event.ChannelCreatedEvent
;
import
lombok.NoArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
@Aggregate
@NoArgsConstructor
@Slf4j
public
class
ChannelAggregate
{
@AggregateIdentifier
private
Integer
id
;
@CommandHandler
public
ChannelAggregate
(
CreateChannelCommand
command
)
{
log
.
info
(
"[ChannelAggregate(CreateChannelCommand) > apply new ChannelCreatedEvent]"
);
apply
(
new
ChannelCreatedEvent
(
command
.
getId
(),
command
.
getName
(),
command
.
getDiscountRate
()));
}
@EventSourcingHandler
public
void
createChannel
(
ChannelCreatedEvent
event
)
{
this
.
id
=
event
.
getId
();
}
}
src/main/java/com/showcase/synapse/product/aggregate/ProductAggregate.java
View file @
d6b92f6c
package
com
.
showcase
.
synapse
.
product
.
aggregate
;
package
com
.
showcase
.
synapse
.
product
.
aggregate
;
import
lombok.NoArgsConstructor
;
import
static
org
.
axonframework
.
modelling
.
command
.
AggregateLifecycle
.
apply
;
import
lombok.extern.slf4j.Slf4j
;
import
org.axonframework.commandhandling.CommandHandler
;
import
org.axonframework.commandhandling.CommandHandler
;
import
org.axonframework.eventsourcing.EventSourcingHandler
;
import
org.axonframework.eventsourcing.EventSourcingHandler
;
...
@@ -9,14 +8,14 @@ import org.axonframework.modelling.command.AggregateIdentifier;
...
@@ -9,14 +8,14 @@ import org.axonframework.modelling.command.AggregateIdentifier;
import
org.axonframework.spring.stereotype.Aggregate
;
import
org.axonframework.spring.stereotype.Aggregate
;
import
com.showcase.synapse.product.command.ChangeQuantityCommand
;
import
com.showcase.synapse.product.command.ChangeQuantityCommand
;
import
com.showcase.synapse.product.command.CreateChannelCommand
;
import
com.showcase.synapse.product.command.CreateProductCommand
;
import
com.showcase.synapse.product.command.CreateProductCommand
;
import
com.showcase.synapse.product.event.ChannelCreatedEvent
;
import
com.showcase.synapse.product.event.ProductCreatedEvent
;
import
com.showcase.synapse.product.event.ProductCreatedEvent
;
import
com.showcase.synapse.product.event.ProductQuantityChangedEvent
;
import
com.showcase.synapse.product.event.ProductQuantityChangedEvent
;
import
com.showcase.synapse.product.saga.ProductSaga
;
import
java.math.BigDecimal
;
import
static
org
.
axonframework
.
modelling
.
command
.
AggregateLifecycle
.
apply
;
import
lombok.NoArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
@Aggregate
@Aggregate
@NoArgsConstructor
@NoArgsConstructor
...
...
src/main/java/com/showcase/synapse/product/command/CreateChannelCommand.java
0 → 100644
View file @
d6b92f6c
package
com
.
showcase
.
synapse
.
product
.
command
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
org.axonframework.modelling.command.TargetAggregateIdentifier
;
import
java.math.BigDecimal
;
import
javax.persistence.Column
;
@AllArgsConstructor
@Getter
public
class
CreateChannelCommand
{
@TargetAggregateIdentifier
private
final
Integer
id
;
private
final
String
name
;
private
final
BigDecimal
discountRate
;
}
src/main/java/com/showcase/synapse/product/controller/ProductController.java
View file @
d6b92f6c
package
com
.
showcase
.
synapse
.
product
.
controller
;
package
com
.
showcase
.
synapse
.
product
.
controller
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.showcase.synapse.product.dto.ChannelCreateDto
;
import
com.showcase.synapse.product.dto.ProductCreateDto
;
import
com.showcase.synapse.product.dto.ProductCreateDto
;
import
com.showcase.synapse.product.entity.ChannelEntity
;
import
com.showcase.synapse.product.entity.ProductEntity
;
import
com.showcase.synapse.product.entity.ProductEntity
;
import
com.showcase.synapse.product.service.ProductService
;
import
com.showcase.synapse.product.service.ProductService
;
import
java.math.BigDecimal
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
@RestController
@RestController
@RequestMapping
(
"/api/msa
/product
"
)
@RequestMapping
(
"/api/msa"
)
@CrossOrigin
(
origins
=
"*"
)
@CrossOrigin
(
origins
=
"*"
)
public
class
ProductController
{
public
class
ProductController
{
...
@@ -24,18 +30,25 @@ public class ProductController {
...
@@ -24,18 +30,25 @@ public class ProductController {
this
.
productService
=
productService
;
this
.
productService
=
productService
;
}
}
@GetMapping
(
"/"
)
@GetMapping
(
"/
product
"
)
public
ResponseEntity
<
List
<
ProductEntity
>>
getProducts
()
throws
ExecutionException
,
InterruptedException
{
public
ResponseEntity
<
List
<
ProductEntity
>>
getProducts
()
throws
ExecutionException
,
InterruptedException
{
List
<
ProductEntity
>
productEntities
=
productService
.
getProducts
();
List
<
ProductEntity
>
productEntities
=
productService
.
getProducts
();
return
ResponseEntity
.
ok
(
productEntities
);
return
ResponseEntity
.
ok
(
productEntities
);
}
}
@PostMapping
(
"/"
)
@GetMapping
(
"/channel"
)
public
ResponseEntity
<
List
<
ChannelEntity
>>
getChannels
()
throws
ExecutionException
,
InterruptedException
{
List
<
ChannelEntity
>
channelEntity
=
productService
.
getChannels
();
return
ResponseEntity
.
ok
(
channelEntity
);
}
@PostMapping
(
"/product"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
productCreate
(
@RequestBody
ProductCreateDto
productCreateDto
)
{
public
ResponseEntity
<
Map
<
String
,
String
>>
productCreate
(
@RequestBody
ProductCreateDto
productCreateDto
)
{
String
productId
=
productService
.
createProduct
(
productCreateDto
.
getName
(),
String
productId
=
productService
.
createProduct
(
productCreateDto
.
getName
(),
productCreateDto
.
getComment
(),
productCreateDto
.
getComment
(),
BigDecimal
.
valueOf
(
productCreateDto
.
getPrice
()
),
productCreateDto
.
getPrice
(
),
productCreateDto
.
getChannel
());
productCreateDto
.
getChannel
());
HashMap
<
String
,
String
>
m
=
new
HashMap
<>();
HashMap
<
String
,
String
>
m
=
new
HashMap
<>();
m
.
put
(
"productId"
,
productId
);
m
.
put
(
"productId"
,
productId
);
...
@@ -43,4 +56,16 @@ public class ProductController {
...
@@ -43,4 +56,16 @@ public class ProductController {
return
ResponseEntity
.
ok
(
m
);
return
ResponseEntity
.
ok
(
m
);
}
}
@PostMapping
(
"/channel"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
channelCreate
(
@RequestBody
ChannelCreateDto
channelCreateDto
)
{
int
channelId
=
productService
.
createChannel
(
channelCreateDto
.
getId
(),
channelCreateDto
.
getName
(),
channelCreateDto
.
getDiscountRate
());
HashMap
<
String
,
String
>
m
=
new
HashMap
<>();
m
.
put
(
"channelId"
,
String
.
valueOf
(
channelId
));
m
.
put
(
"name"
,
channelCreateDto
.
getName
());
return
ResponseEntity
.
ok
(
m
);
}
}
}
src/main/java/com/showcase/synapse/product/dto/ChannelCreateDto.java
0 → 100644
View file @
d6b92f6c
package
com
.
showcase
.
synapse
.
product
.
dto
;
import
java.math.BigDecimal
;
import
javax.persistence.Column
;
import
lombok.Getter
;
import
lombok.Setter
;
@Getter
@Setter
public
class
ChannelCreateDto
{
private
int
id
;
private
String
name
;
private
BigDecimal
discountRate
;
}
src/main/java/com/showcase/synapse/product/dto/ProductCreateDto.java
View file @
d6b92f6c
package
com
.
showcase
.
synapse
.
product
.
dto
;
package
com
.
showcase
.
synapse
.
product
.
dto
;
import
java.math.BigDecimal
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
...
@@ -8,7 +10,8 @@ import lombok.Setter;
...
@@ -8,7 +10,8 @@ import lombok.Setter;
public
class
ProductCreateDto
{
public
class
ProductCreateDto
{
private
String
name
;
private
String
name
;
private
String
comment
;
private
String
comment
;
private
int
price
;
private
BigDecimal
price
;
private
int
channel
;
private
int
channel
;
private
BigDecimal
discountRate
;
}
}
src/main/java/com/showcase/synapse/product/entity/ChannelEntity.java
View file @
d6b92f6c
package
com
.
showcase
.
synapse
.
product
.
entity
;
package
com
.
showcase
.
synapse
.
product
.
entity
;
import
java.math.BigDecimal
;
import
javax.persistence.Column
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GeneratedValue
;
...
@@ -18,10 +20,13 @@ import lombok.Setter;
...
@@ -18,10 +20,13 @@ import lombok.Setter;
@NoArgsConstructor
@NoArgsConstructor
public
class
ChannelEntity
{
public
class
ChannelEntity
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
@Id
@Column
(
name
=
"channel_id"
)
@Column
(
name
=
"channel_id"
)
private
Integer
id
;
private
Integer
id
;
@Column
(
name
=
"name"
)
@Column
(
name
=
"name"
)
private
String
name
;
private
String
name
;
@Column
(
name
=
"discount_rate"
)
private
BigDecimal
discountRate
;
}
}
src/main/java/com/showcase/synapse/product/entity/ProductEntity.java
View file @
d6b92f6c
...
@@ -18,7 +18,7 @@ import lombok.Setter;
...
@@ -18,7 +18,7 @@ import lombok.Setter;
@Setter
@Setter
@AllArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor
public
class
ProductEntity
{
public
class
ProductEntity
{
@Id
@Id
private
String
id
;
private
String
id
;
...
...
src/main/java/com/showcase/synapse/product/event/ChannelCreatedEvent.java
0 → 100644
View file @
d6b92f6c
package
com
.
showcase
.
synapse
.
product
.
event
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
java.math.BigDecimal
;
@AllArgsConstructor
@Getter
public
class
ChannelCreatedEvent
{
private
Integer
id
;
private
String
name
;
private
BigDecimal
discountRate
;
}
src/main/java/com/showcase/synapse/product/event/handler/ProductEventHandler.java
View file @
d6b92f6c
package
com
.
showcase
.
synapse
.
product
.
event
.
handler
;
package
com
.
showcase
.
synapse
.
product
.
event
.
handler
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.axonframework.eventhandling.EventHandler
;
import
org.axonframework.eventhandling.EventHandler
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
com.showcase.synapse.product.entity.ChannelEntity
;
import
com.showcase.synapse.product.entity.ChannelEntity
;
import
com.showcase.synapse.product.entity.ProductEntity
;
import
com.showcase.synapse.product.entity.ProductEntity
;
import
com.showcase.synapse.product.event.ChannelCreatedEvent
;
import
com.showcase.synapse.product.event.ProductCreatedEvent
;
import
com.showcase.synapse.product.event.ProductCreatedEvent
;
import
com.showcase.synapse.product.event.ProductQuantityChangedEvent
;
import
com.showcase.synapse.product.event.ProductQuantityChangedEvent
;
import
com.showcase.synapse.product.repository.ChannelRepository
;
import
com.showcase.synapse.product.repository.ProductRepository
;
import
com.showcase.synapse.product.repository.ProductRepository
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
@Component
@Component
@AllArgsConstructor
@AllArgsConstructor
@Slf4j
@Slf4j
public
class
ProductEventHandler
{
public
class
ProductEventHandler
{
private
final
ProductRepository
productRepository
;
private
final
ProductRepository
productRepository
;
private
final
ChannelRepository
channelRepository
;
@EventHandler
@EventHandler
protected
void
saveProduct
(
ProductCreatedEvent
productCreatedEvent
)
{
protected
void
saveProduct
(
ProductCreatedEvent
productCreatedEvent
)
{
...
@@ -36,6 +40,20 @@ public class ProductEventHandler {
...
@@ -36,6 +40,20 @@ public class ProductEventHandler {
}
}
@EventHandler
protected
void
saveChannel
(
ChannelCreatedEvent
channelCreatedEvent
)
{
log
.
info
(
"ChannelCreatedEvent 이벤트 받음?"
);
log
.
info
(
"ProductEventHandler > [ChannelCreatedEvent] channelCreatedEvent"
);
ChannelEntity
channelEntity
=
new
ChannelEntity
();
channelEntity
.
setId
(
channelCreatedEvent
.
getId
());
channelEntity
.
setName
(
channelCreatedEvent
.
getName
());
channelEntity
.
setDiscountRate
(
channelCreatedEvent
.
getDiscountRate
());
channelRepository
.
save
(
channelEntity
);
}
@EventHandler
@EventHandler
protected
void
changeQuantity
(
ProductQuantityChangedEvent
productQuantityChangedEvent
)
{
protected
void
changeQuantity
(
ProductQuantityChangedEvent
productQuantityChangedEvent
)
{
log
.
info
(
"ProductQuantityChangedEvent 이벤트 받음?"
);
log
.
info
(
"ProductQuantityChangedEvent 이벤트 받음?"
);
...
...
src/main/java/com/showcase/synapse/product/query/GetChannelQuery.java
0 → 100644
View file @
d6b92f6c
package
com
.
showcase
.
synapse
.
product
.
query
;
public
class
GetChannelQuery
{
}
src/main/java/com/showcase/synapse/product/query/handler/ProductQueryHandler.java
View file @
d6b92f6c
...
@@ -5,8 +5,11 @@ import java.util.List;
...
@@ -5,8 +5,11 @@ import java.util.List;
import
org.axonframework.queryhandling.QueryHandler
;
import
org.axonframework.queryhandling.QueryHandler
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
com.showcase.synapse.product.entity.ChannelEntity
;
import
com.showcase.synapse.product.entity.ProductEntity
;
import
com.showcase.synapse.product.entity.ProductEntity
;
import
com.showcase.synapse.product.query.GetChannelQuery
;
import
com.showcase.synapse.product.query.GetProductsQuery
;
import
com.showcase.synapse.product.query.GetProductsQuery
;
import
com.showcase.synapse.product.repository.ChannelRepository
;
import
com.showcase.synapse.product.repository.ProductRepository
;
import
com.showcase.synapse.product.repository.ProductRepository
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
...
@@ -18,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -18,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
public
class
ProductQueryHandler
{
public
class
ProductQueryHandler
{
private
final
ProductRepository
productRepository
;
private
final
ProductRepository
productRepository
;
private
final
ChannelRepository
channelRepository
;
@QueryHandler
@QueryHandler
protected
List
<
ProductEntity
>
on
(
GetProductsQuery
query
)
{
protected
List
<
ProductEntity
>
on
(
GetProductsQuery
query
)
{
...
@@ -25,4 +29,10 @@ public class ProductQueryHandler {
...
@@ -25,4 +29,10 @@ public class ProductQueryHandler {
return
productRepository
.
findAll
();
return
productRepository
.
findAll
();
}
}
@QueryHandler
protected
List
<
ChannelEntity
>
on
(
GetChannelQuery
query
)
{
log
.
info
(
"---channel query---"
);
return
channelRepository
.
findAll
();
}
}
}
src/main/java/com/showcase/synapse/product/repository/ChannelRepository.java
0 → 100644
View file @
d6b92f6c
package
com
.
showcase
.
synapse
.
product
.
repository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
com.showcase.synapse.product.entity.ChannelEntity
;
public
interface
ChannelRepository
extends
JpaRepository
<
ChannelEntity
,
String
>
{
}
src/main/java/com/showcase/synapse/product/service/ProductService.java
View file @
d6b92f6c
...
@@ -10,8 +10,11 @@ import org.axonframework.messaging.responsetypes.ResponseTypes;
...
@@ -10,8 +10,11 @@ import org.axonframework.messaging.responsetypes.ResponseTypes;
import
org.axonframework.queryhandling.QueryGateway
;
import
org.axonframework.queryhandling.QueryGateway
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.showcase.synapse.product.command.CreateChannelCommand
;
import
com.showcase.synapse.product.command.CreateProductCommand
;
import
com.showcase.synapse.product.command.CreateProductCommand
;
import
com.showcase.synapse.product.entity.ChannelEntity
;
import
com.showcase.synapse.product.entity.ProductEntity
;
import
com.showcase.synapse.product.entity.ProductEntity
;
import
com.showcase.synapse.product.query.GetChannelQuery
;
import
com.showcase.synapse.product.query.GetProductsQuery
;
import
com.showcase.synapse.product.query.GetProductsQuery
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -42,9 +45,27 @@ public class ProductService {
...
@@ -42,9 +45,27 @@ public class ProductService {
return
returnValue
;
return
returnValue
;
}
}
public
int
createChannel
(
int
id
,
String
name
,
BigDecimal
discountRate
)
{
log
.
info
(
"[@Service createChannel] new CreateChannelCommand"
);
// command생성
CreateChannelCommand
createChannelCommand
=
new
CreateChannelCommand
(
id
,
name
,
discountRate
);
System
.
out
.
println
(
"test"
);
// 여기
// 생성한 command전송(비동기)
int
returnValue
=
commandGateway
.
sendAndWait
(
createChannelCommand
);
System
.
out
.
printf
(
"returnValue: %s \n"
,
returnValue
);
return
returnValue
;
}
public
List
<
ProductEntity
>
getProducts
()
throws
ExecutionException
,
InterruptedException
{
public
List
<
ProductEntity
>
getProducts
()
throws
ExecutionException
,
InterruptedException
{
return
queryGateway
.
query
(
new
GetProductsQuery
(),
return
queryGateway
.
query
(
new
GetProductsQuery
(),
ResponseTypes
.
multipleInstancesOf
(
ProductEntity
.
class
)).
get
();
ResponseTypes
.
multipleInstancesOf
(
ProductEntity
.
class
)).
get
();
}
}
public
List
<
ChannelEntity
>
getChannels
()
throws
ExecutionException
,
InterruptedException
{
return
queryGateway
.
query
(
new
GetChannelQuery
(),
ResponseTypes
.
multipleInstancesOf
(
ChannelEntity
.
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