Skip to content

Commit 771de1a

Browse files
committed
Small changes to refactor the solution
1 parent 5677f80 commit 771de1a

File tree

2 files changed

+6
-62
lines changed

2 files changed

+6
-62
lines changed

examples/spring-boot-demo/implementation/src/main/java/com/example/demo/entity/Film.java

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,7 @@
1414
* Task 8.2: Add entity fields (filmId, title) with proper annotations ✅
1515
*/
1616
@Table("film")
17-
public class Film {
18-
19-
@Id
20-
@Column("film_id")
21-
private Integer filmId;
22-
23-
@Column("title")
24-
private String title;
25-
26-
// Default constructor
27-
public Film() {}
28-
29-
// Constructor with all fields
30-
public Film(Integer filmId, String title) {
31-
this.filmId = filmId;
32-
this.title = title;
33-
}
34-
35-
// Getters and setters
36-
public Integer getFilmId() {
37-
return filmId;
38-
}
39-
40-
public void setFilmId(Integer filmId) {
41-
this.filmId = filmId;
42-
}
43-
44-
public String getTitle() {
45-
return title;
46-
}
47-
48-
public void setTitle(String title) {
49-
this.title = title;
50-
}
51-
52-
@Override
53-
public boolean equals(Object obj) {
54-
if (this == obj) return true;
55-
if (obj == null || getClass() != obj.getClass()) return false;
56-
57-
Film film = (Film) obj;
58-
return filmId != null ? filmId.equals(film.filmId) : film.filmId == null &&
59-
title != null ? title.equals(film.title) : film.title == null;
60-
}
61-
62-
@Override
63-
public int hashCode() {
64-
int result = filmId != null ? filmId.hashCode() : 0;
65-
result = 31 * result + (title != null ? title.hashCode() : 0);
66-
return result;
67-
}
68-
69-
@Override
70-
public String toString() {
71-
return "Film{" +
72-
"filmId=" + filmId +
73-
", title='" + title + '\'' +
74-
'}';
75-
}
76-
}
17+
public record Film(
18+
@Id @Column("film_id") Integer filmId,
19+
@Column("title") String title
20+
) {}

examples/spring-boot-demo/implementation/src/main/java/com/example/demo/service/FilmService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public List<Map<String, Object>> findFilmsByStartingLetter(String letter) {
7676
*/
7777
private Map<String, Object> filmToMap(Film film) {
7878
Map<String, Object> filmMap = new HashMap<>();
79-
filmMap.put("film_id", film.getFilmId());
80-
filmMap.put("title", film.getTitle());
79+
filmMap.put("film_id", film.filmId());
80+
filmMap.put("title", film.title());
8181
return filmMap;
8282
}
8383
}

0 commit comments

Comments
 (0)