Skip to content

Commit 4e9c42b

Browse files
committed
Use RegisterStudentRequest in application service
1 parent 3f4db1d commit 4e9c42b

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

apps/main/tv/codely/apps/mooc/backend/controller/students/StudentsPutController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.springframework.web.bind.annotation.PutMapping;
77
import org.springframework.web.bind.annotation.RequestBody;
88
import org.springframework.web.bind.annotation.RestController;
9+
import tv.codely.mooc.students.application.register.RegisterStudentRequest;
910
import tv.codely.mooc.students.application.register.StudentRegistrar;
1011

1112
@RestController
@@ -19,7 +20,7 @@ public StudentsPutController(StudentRegistrar registrar) {
1920

2021
@PutMapping(value = "/students/{id}")
2122
public ResponseEntity<String> index(@PathVariable String id, @RequestBody Request request) {
22-
registrar.register(id, request.name(), request.surname(), request.email());
23+
registrar.register(new RegisterStudentRequest(id, request.name(), request.surname(), request.email()));
2324
return new ResponseEntity<>(HttpStatus.CREATED);
2425
}
2526
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package tv.codely.mooc.students.application.register;
2+
3+
public final class RegisterStudentRequest {
4+
private final String id;
5+
private final String name;
6+
private final String surname;
7+
private final String email;
8+
9+
public RegisterStudentRequest(String id, String name, String surname, String email) {
10+
this.id = id;
11+
this.name = name;
12+
this.surname = surname;
13+
this.email = email;
14+
}
15+
16+
public String id() {
17+
return id;
18+
}
19+
20+
public String name() {
21+
return name;
22+
}
23+
24+
public String surname() {
25+
return surname;
26+
}
27+
28+
public String email() {
29+
return email;
30+
}
31+
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package tv.codely.mooc.students.application.register;
22

3-
import tv.codely.mooc.students.domain.*;
3+
import tv.codely.mooc.students.domain.Student;
4+
import tv.codely.mooc.students.domain.StudentId;
5+
import tv.codely.mooc.students.domain.StudentRepository;
46
import tv.codely.shared.domain.Service;
57

68
@Service
@@ -11,8 +13,8 @@ public StudentRegistrar(StudentRepository repository) {
1113
this.repository = repository;
1214
}
1315

14-
public void register(String id, String name, String surname, String email) {
15-
Student student = Student.create(new StudentId(id), name, surname, email);
16+
public void register(RegisterStudentRequest request) {
17+
Student student = Student.create(new StudentId(request.id()), request.name(), request.surname(), request.email());
1618
repository.register(student);
1719
}
1820
}

src/mooc/test/tv/codely/mooc/students/application/register/StudentRegistrarTestShould.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ void register_a_valid_student() {
1414
StudentRepository repository = mock(StudentRepository.class);
1515
StudentRegistrar registrar = new StudentRegistrar(repository);
1616

17-
StudentId id = new StudentId(UuidMother.random());
18-
String name = "name";
19-
String surname = "surname";
20-
String email = "email";
17+
StudentId id = new StudentId(UuidMother.random());
18+
String name = "name";
19+
String surname = "surname";
20+
String email = "email";
21+
22+
RegisterStudentRequest request = new RegisterStudentRequest(id.value(), name, surname, email);
2123

2224
Student student = new Student(id, name, surname, email);
2325

24-
registrar.register(id.value(), student.name(), student.surname(), student.email());
26+
registrar.register(request);
2527

2628
verify(repository, atLeastOnce()).register(student);
2729
}

0 commit comments

Comments
 (0)