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

added data validation and global exception handler #4

Merged
merged 3 commits into from
Sep 28, 2023

Conversation

BlueVioletTeti
Copy link
Owner

No description provided.

private String author;
@NotNull
private String isbn;

Choose a reason for hiding this comment

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

you can use ISBN annotation

Copy link

@vovasalyha vovasalyha left a comment

Choose a reason for hiding this comment

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

GJ. Let's improve it a bit

pom.xml Outdated
@@ -71,6 +71,12 @@
<artifactId>liquibase-maven-plugin</artifactId>
<version>4.23.1</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>

Choose a reason for hiding this comment

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

In Spring Boot it's better to choose starters over concrete dependencies, so I suggest to use validation starter

import java.math.BigDecimal;
import lombok.Data;

@Data
public class CreateBookRequestDto {
@NotNull
private String title;

Choose a reason for hiding this comment

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

Validate the size of title to not allow empty titles and to not exceed the maximum size set by DB schema, the same for author field

private String author;
@NotNull
private String isbn;

Choose a reason for hiding this comment

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

isbn has other validation rule except of not null (see Oleg's suggestion)

) {
Map<String, Object> body = new LinkedHashMap<>();
body.put("timestamp", LocalDateTime.now());
body.put("status", HttpStatus.BAD_REQUEST);

Choose a reason for hiding this comment

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

Usually invalid arguments it's 422 response code. Also, define the common response format for the application and create a class with exception response body.

Base automatically changed from dev-data-jpa to master September 12, 2023 18:01
Copy link

@nacenik nacenik left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@BlueVioletTeti BlueVioletTeti merged commit 7f77cef into master Sep 28, 2023
2 checks passed
@BlueVioletTeti BlueVioletTeti deleted the dev-data-validation branch September 28, 2023 09:27
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.

4 participants