-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathCoursesPutController.java
More file actions
73 lines (60 loc) · 2.16 KB
/
CoursesPutController.java
File metadata and controls
73 lines (60 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package tv.codely.apps.mooc.backend.controller.courses;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import tv.codely.mooc.courses.application.create.CreateCourseCommand;
import tv.codely.mooc.courses.application.update.RenameCourseCommand;
import tv.codely.shared.domain.DomainError;
import tv.codely.shared.domain.bus.command.CommandBus;
import tv.codely.shared.domain.bus.command.CommandHandlerExecutionError;
import tv.codely.shared.domain.bus.query.QueryBus;
import tv.codely.shared.infrastructure.spring.ApiController;
import java.util.HashMap;
@RestController
public final class CoursesPutController extends ApiController {
public CoursesPutController(
QueryBus queryBus,
CommandBus commandBus
) {
super(queryBus, commandBus);
}
@PutMapping(value = "/courses/{id}")
public ResponseEntity<String> index(
@PathVariable String id,
@RequestBody Request request
) throws CommandHandlerExecutionError {
dispatch(new CreateCourseCommand(id, request.name(), request.duration()));
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping(value = "/courses/{id}/renameCourse")
public ResponseEntity<String> renameCourse(
@PathVariable String id,
@RequestBody Request request
) throws CommandHandlerExecutionError {
dispatch(new RenameCourseCommand(id, request.name()));
return new ResponseEntity<>(HttpStatus.OK);
}
@Override
public HashMap<Class<? extends DomainError>, HttpStatus> errorMapping() {
return null;
}
}
final class Request {
private String name;
private String duration;
public void setDuration(String duration) {
this.duration = duration;
}
public void setName(String name) {
this.name = name;
}
String name() {
return name;
}
String duration() {
return duration;
}
}