Skip to content
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

the dishes are done #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

the dishes are done #10

wants to merge 1 commit into from

Conversation

bpmericle
Copy link
Contributor

No description provided.

Copy link

@SleepyFalcon SleepyFalcon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has a lot of little issues that can be fixed easy. I also was thinking that we could refactor the controllers to be more descriptive. Along with adding in a new Exception called: InvalidEmailException for the email endpoint. We should also package our exceptions in a exception folder.

logger.info("Preloading " + repository.save(new Contact("Selina Kyle")));
logger.info("Preloading " + repository.save(new Contact("Oswald Cobblepot")));
logger.info("Preloading " + repository.save(new Contact("Edward Nygma")));
logger.info("Preloading " + repository.save(new Contact("Bruce Wayne", "[email protected]")));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this next to your logger object.
private final String TEST_EMAIL_TAG = "@gothamcity.com";
Then you should use this for each new Contact:
logger.info("Preloading " + repository.save(new Contact("Bruce Wayne", "bwayne".concat(TEST_EMAIL_TAG))));

I would add in this to cut down on redundancy. They all look like they are using the same email tag.

@@ -45,12 +55,13 @@ public boolean equals(Object o) {
return false;
Contact contact = (Contact) o;
return Objects.equals(this.id, contact.id) &&
Objects.equals(this.name, contact.name);
Objects.equals(this.name, contact.name) &&
Objects.equals(this.name, contact.email);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objects.equals(this.email, contact.email);

You missed the email value here.

@@ -45,12 +55,13 @@ public boolean equals(Object o) {
return false;
Contact contact = (Contact) o;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you want to cast an Object to your Contact while inside the same class? I would of liked to understand why we should be doing it this way.

return this.email;
}

public void setEmail(String email) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public void setEmail(final String email) {

(This is nit-picky) Should build all setters with final tags.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

option @Getter @Setter beans

}

@Override
public int hashCode() {
return Objects.hash(this.id, this.name);
return Objects.hash(this.id, this.name, this.email);
}

@Override

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't reach it exactly here.... but your toString() should also look like this..
String.format("Contact {id=%s, name=\"%s\", email=\"%s\"}", this.id, this.name, this.email);


Optional<List<Contact>> contacts = repository.findByEmailContaining(email);
if (contacts.get().isEmpty()) {
throw new RuntimeException(String.format("no contacts with email [%s] found.", email));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new RuntimeException(String.format("no contacts with email [%s] found.", email));
See last comment about custom exceptions.

@@ -44,6 +46,20 @@
.orElseThrow(() -> new ContactNotFoundException(name));
}

@GetMapping("/query")
public List<Contact> getByEmail(@RequestParam final String email) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public List<Contact> getByEmail(@RequestParam @NotBlank final String email) {
Add in the @NotBlank to keep with consistency. Just like how the getByName Mapping is.
If this is done you can remove the Objects.isNull(email) in the if block below.

or we can change it to look like this:
public List<Contact> getByEmail(@ApiParam(value = "Contact's email", required = true, example = "[email protected]") @NotNull(message = "Contact's email can not be null") @PathVariable(name = "email") final String email) {

@@ -44,6 +46,20 @@
.orElseThrow(() -> new ContactNotFoundException(name));
}

@GetMapping("/query")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add in @ApiResponcses({...}) and @ResponseStatus(HttpStatus.OK) to all of our endpoints that we have so far. Any other Mapping we would want to change it to something else. depending on the Http curl request.

We could also change the names of the endpoints to be more fitting for each also. Maybe something that looks like this? @GetMapping("/query/{email}")

@@ -14,4 +14,6 @@
* @return zero or more Contacts
*/
Optional<List<Contact>> findByNameContainingIgnoreCase(final String name);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should add in comments here like there is for the name.

@@ -44,6 +46,20 @@
.orElseThrow(() -> new ContactNotFoundException(name));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add in comments like how the other endpoints are

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

1 similar comment
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants