Skip to content

Commit 4fba494

Browse files
committed
Simplify command/query bus
1 parent 64bdb21 commit 4fba494

File tree

23 files changed

+53
-60
lines changed

23 files changed

+53
-60
lines changed

apps/main/tv/codely/apps/backoffice/backend/controller/courses/CoursesGetController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import tv.codely.shared.domain.bus.command.CommandBus;
99
import tv.codely.shared.domain.bus.query.QueryBus;
1010
import tv.codely.shared.domain.bus.query.QueryHandlerExecutionError;
11-
import tv.codely.shared.domain.bus.query.QueryNotRegisteredError;
1211
import tv.codely.shared.infrastructure.spring.ApiController;
1312

1413
import java.io.Serializable;
@@ -28,7 +27,7 @@ public CoursesGetController(QueryBus queryBus, CommandBus commandBus) {
2827
@GetMapping("/courses")
2928
public List<HashMap<String, String>> index(
3029
@RequestParam HashMap<String, Serializable> params
31-
) throws QueryNotRegisteredError, QueryHandlerExecutionError {
30+
) throws QueryHandlerExecutionError {
3231
BackofficeCoursesResponse courses = ask(
3332
new SearchBackofficeCoursesByCriteriaQuery(
3433
parseFilters(params),

apps/main/tv/codely/apps/backoffice/backend/middleware/BasicHttpAuthMiddleware.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import tv.codely.backoffice.auth.domain.InvalidAuthUsername;
66
import tv.codely.shared.domain.bus.command.CommandBus;
77
import tv.codely.shared.domain.bus.command.CommandHandlerExecutionError;
8-
import tv.codely.shared.domain.bus.command.CommandNotRegisteredError;
98

109
import javax.servlet.*;
1110
import javax.servlet.http.HttpServletRequest;
@@ -55,7 +54,7 @@ private void authenticate(
5554
request.setAttribute("authentication_username", user);
5655

5756
chain.doFilter(request, response);
58-
} catch (InvalidAuthUsername | InvalidAuthCredentials | CommandHandlerExecutionError | CommandNotRegisteredError error) {
57+
} catch (InvalidAuthUsername | InvalidAuthCredentials | CommandHandlerExecutionError error) {
5958
setInvalidCredentials(response);
6059
}
6160
}

apps/main/tv/codely/apps/backoffice/frontend/controller/courses/CoursesGetWebController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import tv.codely.mooc.courses_counter.application.find.FindCoursesCounterQuery;
99
import tv.codely.shared.domain.bus.query.QueryBus;
1010
import tv.codely.shared.domain.bus.query.QueryHandlerExecutionError;
11-
import tv.codely.shared.domain.bus.query.QueryNotRegisteredError;
1211

1312
import java.io.Serializable;
1413
import java.util.HashMap;
@@ -27,7 +26,7 @@ public CoursesGetWebController(QueryBus bus) {
2726
public ModelAndView index(
2827
@ModelAttribute("inputs") HashMap<String, Serializable> inputs,
2928
@ModelAttribute("errors") HashMap<String, List<String>> errors
30-
) throws QueryNotRegisteredError, QueryHandlerExecutionError {
29+
) throws QueryHandlerExecutionError {
3130
CoursesCounterResponse counterResponse = bus.ask(new FindCoursesCounterQuery());
3231

3332
return new ModelAndView("pages/courses/courses", new HashMap<String, Serializable>() {{

apps/main/tv/codely/apps/backoffice/frontend/controller/courses/CoursesPostWebController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import tv.codely.mooc.courses.application.create.CreateCourseCommand;
1010
import tv.codely.shared.domain.bus.command.CommandBus;
1111
import tv.codely.shared.domain.bus.command.CommandHandlerExecutionError;
12-
import tv.codely.shared.domain.bus.command.CommandNotRegisteredError;
1312
import tv.codely.shared.infrastructure.validation.ValidationResponse;
1413
import tv.codely.shared.infrastructure.validation.Validator;
1514

@@ -33,7 +32,7 @@ public CoursesPostWebController(CommandBus bus) {
3332
public RedirectView index(
3433
@RequestParam HashMap<String, Serializable> request,
3534
RedirectAttributes attributes
36-
) throws Exception, CommandHandlerExecutionError {
35+
) throws Exception {
3736
ValidationResponse validationResponse = Validator.validate(request, rules);
3837

3938
return validationResponse.hasErrors()
@@ -52,7 +51,7 @@ private RedirectView redirectWithErrors(
5251
return new RedirectView("/courses");
5352
}
5453

55-
private RedirectView createCourse(HashMap<String, Serializable> request) throws CommandNotRegisteredError, CommandHandlerExecutionError {
54+
private RedirectView createCourse(HashMap<String, Serializable> request) throws CommandHandlerExecutionError {
5655
bus.dispatch(new CreateCourseCommand(
5756
request.get("id").toString(),
5857
request.get("name").toString(),

apps/main/tv/codely/apps/mooc/backend/controller/courses/CourseGetController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import org.springframework.web.bind.annotation.RestController;
88
import tv.codely.mooc.courses.application.CourseResponse;
99
import tv.codely.mooc.courses.application.find.FindCourseQuery;
10+
import tv.codely.mooc.courses.domain.CourseNotExist;
1011
import tv.codely.shared.domain.DomainError;
1112
import tv.codely.shared.domain.bus.command.CommandBus;
1213
import tv.codely.shared.domain.bus.query.QueryBus;
1314
import tv.codely.shared.domain.bus.query.QueryHandlerExecutionError;
14-
import tv.codely.shared.domain.bus.query.QueryNotRegisteredError;
1515
import tv.codely.shared.infrastructure.spring.ApiController;
1616

1717
import java.io.Serializable;
@@ -27,7 +27,7 @@ public CourseGetController(
2727
}
2828

2929
@GetMapping("/courses/{id}")
30-
public ResponseEntity<HashMap<String, Serializable>> index(@PathVariable String id) throws QueryHandlerExecutionError, QueryNotRegisteredError {
30+
public ResponseEntity<HashMap<String, Serializable>> index(@PathVariable String id) throws QueryHandlerExecutionError {
3131
CourseResponse course = ask(new FindCourseQuery(id));
3232

3333
return ResponseEntity.ok().body(new HashMap<String, Serializable>() {{
@@ -39,6 +39,8 @@ public ResponseEntity<HashMap<String, Serializable>> index(@PathVariable String
3939

4040
@Override
4141
protected HashMap<Class<? extends DomainError>, HttpStatus> errorMapping() {
42-
return null;
42+
return new HashMap<Class<? extends DomainError>, HttpStatus>() {{
43+
put(CourseNotExist.class, HttpStatus.NOT_FOUND);
44+
}};
4345
}
4446
}

apps/main/tv/codely/apps/mooc/backend/controller/courses/CoursesPutController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import tv.codely.shared.domain.DomainError;
1111
import tv.codely.shared.domain.bus.command.CommandBus;
1212
import tv.codely.shared.domain.bus.command.CommandHandlerExecutionError;
13-
import tv.codely.shared.domain.bus.command.CommandNotRegisteredError;
1413
import tv.codely.shared.domain.bus.query.QueryBus;
1514
import tv.codely.shared.infrastructure.spring.ApiController;
1615

@@ -29,7 +28,7 @@ public CoursesPutController(
2928
public ResponseEntity<String> index(
3029
@PathVariable String id,
3130
@RequestBody Request request
32-
) throws CommandNotRegisteredError, CommandHandlerExecutionError {
31+
) throws CommandHandlerExecutionError {
3332
dispatch(new CreateCourseCommand(id, request.name(), request.duration()));
3433

3534
return new ResponseEntity<>(HttpStatus.CREATED);

apps/main/tv/codely/apps/mooc/backend/controller/courses_counter/CoursesCounterGetController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import tv.codely.shared.domain.bus.command.CommandBus;
1010
import tv.codely.shared.domain.bus.query.QueryBus;
1111
import tv.codely.shared.domain.bus.query.QueryHandlerExecutionError;
12-
import tv.codely.shared.domain.bus.query.QueryNotRegisteredError;
1312
import tv.codely.shared.infrastructure.spring.ApiController;
1413

1514
import java.util.HashMap;
@@ -21,7 +20,7 @@ public CoursesCounterGetController(QueryBus queryBus, CommandBus commandBus) {
2120
}
2221

2322
@GetMapping("/courses-counter")
24-
public HashMap<String, Integer> index() throws QueryNotRegisteredError, QueryHandlerExecutionError {
23+
public HashMap<String, Integer> index() throws QueryHandlerExecutionError {
2524
CoursesCounterResponse response = ask(new FindCoursesCounterQuery());
2625

2726
return new HashMap<String, Integer>() {{

apps/main/tv/codely/apps/mooc/backend/controller/notifications/NewsletterNotificationPutController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public NewsletterNotificationPutController(
2727
@PutMapping(value = "/newsletter/{id}")
2828
public ResponseEntity<String> index(
2929
@PathVariable String id
30-
) throws CommandNotRegisteredError, CommandHandlerExecutionError {
30+
) throws CommandHandlerExecutionError {
3131
dispatch(new SendNewCoursesNewsletterCommand(id));
3232

3333
return new ResponseEntity<>(HttpStatus.CREATED);

src/mooc/main/tv/codely/mooc/courses/application/find/FindCourseQueryHandler.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ public FindCourseQueryHandler(CourseFinder finder) {
1515
}
1616

1717
@Override
18-
public CourseResponse handle(FindCourseQuery query) {
19-
try {
20-
return finder.find(new CourseId(query.id()));
21-
} catch (CourseNotExist error) {
22-
return null;
23-
}
18+
public CourseResponse handle(FindCourseQuery query) throws CourseNotExist {
19+
return finder.find(new CourseId(query.id()));
2420
}
2521
}

src/mooc/main/tv/codely/mooc/notifications/application/send_new_courses_newsletter/NewCoursesNewsletterSender.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import tv.codely.shared.domain.UuidGenerator;
1212
import tv.codely.shared.domain.bus.event.EventBus;
1313
import tv.codely.shared.domain.bus.query.QueryBus;
14-
import tv.codely.shared.domain.bus.query.QueryHandlerExecutionError;
15-
import tv.codely.shared.domain.bus.query.QueryNotRegisteredError;
1614

1715
@Service
1816
public final class NewCoursesNewsletterSender {
@@ -34,7 +32,7 @@ public NewCoursesNewsletterSender(
3432
this.eventBus = eventBus;
3533
}
3634

37-
public void send() throws QueryNotRegisteredError, QueryHandlerExecutionError {
35+
public void send() {
3836
CoursesResponse courses = queryBus.ask(new SearchLastCoursesQuery(TOTAL_COURSES));
3937

4038
if (courses.courses().size() > 0) {

0 commit comments

Comments
 (0)