Skip to content

Commit 00aab06

Browse files
committed
refactor applied to ignore case in search by name
1 parent a480d00 commit 00aab06

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/main/java/com/example/apiRest/dto/FilmsDTO.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class FilmsDTO implements Serializable {
2323

2424
@ApiModelProperty(value = "Field is string")
2525
@NotBlank(message = "Field name can not be blank")
26-
@Length(min = 3,max = 50,message = "The field name must have between 3 and 50 character ")
26+
@Length(min = 3, max = 50, message = "The field name must have between 3 and 50 character ")
2727
private String name;
2828

2929
@ApiModelProperty(value = "Field is string")
@@ -51,7 +51,7 @@ public String getName() {
5151
}
5252

5353
public void setName(String name) {
54-
this.name = name;
54+
this.name = name.toLowerCase();
5555
}
5656

5757
public String getGenre() {
@@ -69,10 +69,11 @@ public int getYear() {
6969
public void setYear(int year) {
7070
this.year = year;
7171
}
72+
7273
@Override
7374
public String toString() {
7475
return "FilmsDTO [id=" + ", nome=" + name + ", genre=" + genre
75-
+ ", year=" + year + "]";
76+
+ ", year=" + year + "]";
7677
}
7778

7879
}

src/main/java/com/example/apiRest/service/FilmsService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public List<DetailsFilmsDTOResponse> getAllFilms() {
3232
}
3333

3434
public List<DetailsFilmsDTOResponse> getFilmByName(String nameFilm) {
35-
films = filmsRepository.findByName(nameFilm);
35+
films = filmsRepository.findByName(nameFilm.toLowerCase());
36+
System.out.println(films);
3637
if (films.isEmpty()) {
3738
throw new FilmsDoesNotExistException("There are no films that meet this search");
3839
}

src/main/resources/data.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
INSERT INTO TB_FILMS(name, genre, release_year) VALUES('Inception', 'thriller', 2010);
2-
--INSERT INTO TB_FILMS(name, genre, release_year) VALUES('Forrest Gump', 'drama', 1992);
3-
--INSERT INTO TB_FILMS(name, genre, release_year) VALUES('Enter the Dragon', 'adventure', 1973);
4-
--INSERT INTO TB_FILMS(name, genre, release_year) VALUES('Enter the Dragon 2', 'adventure', 1974);
5-
--INSERT INTO TB_FILMS(name, genre, release_year) VALUES('Enter the Dragon 3', 'adventure', 1977);
1+
INSERT INTO TB_FILMS(name, genre, release_year) VALUES('inception', 'thriller', 2010);
2+
INSERT INTO TB_FILMS(name, genre, release_year) VALUES('forrest gump', 'drama', 1992);
3+
INSERT INTO TB_FILMS(name, genre, release_year) VALUES('enter the dragon', 'adventure', 1973);
4+
INSERT INTO TB_FILMS(name, genre, release_year) VALUES('enter the dragon 2', 'adventure', 1974);
5+
INSERT INTO TB_FILMS(name, genre, release_year) VALUES('enter the dragon 3', 'adventure', 1977);

0 commit comments

Comments
 (0)