File tree Expand file tree Collapse file tree 2 files changed +47
-14
lines changed
src/mooc/main/tv/codely/mooc/courses_counter/application/increment Expand file tree Collapse file tree 2 files changed +47
-14
lines changed Original file line number Diff line number Diff line change 1+ function create_course() {
2+ eventId=$( uuidgen)
3+ courseId=$( uuidgen)
4+ courseName=$( shuf -n3 /usr/share/dict/words | xargs)
5+ courseDuration=$(( 1 + RANDOM % 1000 ))
6+
7+ curl -X POST --location " http://localhost:8030/domain-events" \
8+ -H " Content-Type: application/json" \
9+ -d ' {
10+ "eventName": "course.created",
11+ "eventRaw": {
12+ "data": {
13+ "id": "' " $eventId " ' ",
14+ "type": "course.created",
15+ "occurred_on": "2023-11-14 10:00:00",
16+ "attributes": {
17+ "id": "' " $courseId " ' ",
18+ "name": "' " $courseName " ' ",
19+ "duration": "' " $courseDuration " ' days"
20+ }
21+ },
22+ "meta": {
23+ }
24+ }
25+ }'
26+
27+ echo " Created: $courseName "
28+ }
29+
30+ while true ; do
31+ create_course &
32+ sleep 0.001
33+ done
Original file line number Diff line number Diff line change 88
99@ Service
1010public final class CoursesCounterIncrementer {
11- private CoursesCounterRepository repository ;
12- private UuidGenerator uuidGenerator ;
11+ private CoursesCounterRepository repository ;
12+ private UuidGenerator uuidGenerator ;
1313
14- public CoursesCounterIncrementer (CoursesCounterRepository repository , UuidGenerator uuidGenerator ) {
15- this .repository = repository ;
16- this .uuidGenerator = uuidGenerator ;
17- }
14+ public CoursesCounterIncrementer (CoursesCounterRepository repository , UuidGenerator uuidGenerator ) {
15+ this .repository = repository ;
16+ this .uuidGenerator = uuidGenerator ;
17+ }
1818
19- public void increment (CourseId id ) {
20- CoursesCounter counter = repository .search ()
21- .orElseGet (() -> CoursesCounter .initialize (uuidGenerator .generate ()));
19+ public void increment (CourseId id ) {
20+ CoursesCounter counter = repository .search ()
21+ .orElseGet (() -> CoursesCounter .initialize (uuidGenerator .generate ()));
2222
23- if (!counter .hasIncremented (id )) {
24- counter .increment (id );
23+ if (!counter .hasIncremented (id )) {
24+ counter .increment (id );
2525
26- repository .save (counter );
27- }
28- }
26+ repository .save (counter );
27+ }
28+ }
2929}
You can’t perform that action at this time.
0 commit comments