generated from CodelyTV/java-basic-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add register student use case #60
Draft
OctaviPascual
wants to merge
9
commits into
CodelyTV:main
Choose a base branch
from
OctaviPascual:register-student
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3f4db1d
Add register student use case
OctaviPascual 4e9c42b
Use RegisterStudentRequest in application service
OctaviPascual b1582b2
Use Value Objects for Student
OctaviPascual aab00a0
Use ObjectMother for Student fields
OctaviPascual b3c1984
Add semantics to StudentRegistrar test
OctaviPascual ef2f366
Add hibernate to Student
OctaviPascual 586c0d2
Add Student repository integration test
OctaviPascual 5bd2db5
Raise event on Student registered
OctaviPascual 2249b13
Migrate register Student use case to command
OctaviPascual File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/mooc/main/tv/codely/mooc/students/domain/StudentEmail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package tv.codely.mooc.students.domain; | ||
|
||
import tv.codely.shared.domain.EmailValueObject; | ||
|
||
public final class StudentEmail extends EmailValueObject { | ||
public StudentEmail(String email) { | ||
super(email); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/mooc/main/tv/codely/mooc/students/domain/StudentName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package tv.codely.mooc.students.domain; | ||
|
||
import tv.codely.shared.domain.StringValueObject; | ||
|
||
public final class StudentName extends StringValueObject { | ||
public StudentName(String value) { | ||
super(value); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/mooc/main/tv/codely/mooc/students/domain/StudentSurname.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package tv.codely.mooc.students.domain; | ||
|
||
import tv.codely.shared.domain.StringValueObject; | ||
|
||
public final class StudentSurname extends StringValueObject { | ||
public StudentSurname(String value) { | ||
super(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
package tv.codely.mooc.students.infrastructure; | ||
|
||
import tv.codely.mooc.students.domain.Student; | ||
import tv.codely.mooc.students.domain.StudentId; | ||
import tv.codely.mooc.students.domain.StudentRepository; | ||
import tv.codely.mooc.students.domain.*; | ||
import tv.codely.shared.domain.Service; | ||
import tv.codely.shared.domain.UuidGenerator; | ||
|
||
|
@@ -20,11 +18,22 @@ public InMemoryStudentRepository(UuidGenerator generator) { | |
@Override | ||
public List<Student> searchAll() { | ||
return Arrays.asList( | ||
new Student(new StudentId(generator.generate()), "name", "surname", "[email protected]"), | ||
new Student(new StudentId(generator.generate()), "Other name", "Other surname", "[email protected]") | ||
new Student( | ||
new StudentId(generator.generate()), | ||
new StudentName("name"), | ||
new StudentSurname("surname"), | ||
new StudentEmail("[email protected]") | ||
), | ||
new Student( | ||
new StudentId(generator.generate()), | ||
new StudentName("Other name"), | ||
new StudentSurname("Other surname"), | ||
new StudentEmail("[email protected]") | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
public void register(Student student) {} | ||
public void register(Student student) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/shared/main/tv/codely/shared/domain/EmailValueObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package tv.codely.shared.domain; | ||
|
||
import org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator; | ||
|
||
import java.util.Objects; | ||
|
||
public abstract class EmailValueObject { | ||
private static final EmailValidator emailValidator = new EmailValidator(); | ||
private final String email; | ||
|
||
public EmailValueObject(String email) { | ||
ensureValidEmail(email); | ||
this.email = email; | ||
} | ||
|
||
public String value() { | ||
return email; | ||
} | ||
|
||
private void ensureValidEmail(String value) { | ||
if (!emailValidator.isValid(value, null)) { | ||
throw new InvalidEmail(value); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.value(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof EmailValueObject)) { | ||
return false; | ||
} | ||
EmailValueObject that = (EmailValueObject) o; | ||
return Objects.equals(email, that.email); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package tv.codely.shared.domain; | ||
|
||
public final class InvalidEmail extends DomainError { | ||
public InvalidEmail(String email) { | ||
super("invalid_email", String.format("The email <%s> is invalid", email)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better approach would be to create an
EmailValidator
interface to not contaminate our domain with this dependency, but I tried to do it and I didn't manage to inject the implementation into this abstract class. Is it possible to do it?