Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2c816d7

Browse files
Added DTO folder in the MVCPractice section of a small course on Java EE
1 parent 023e51b commit 2c816d7

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package AirportSimulator.DTO;
2+
3+
import lombok.Builder;
4+
import lombok.Value;
5+
6+
/*
7+
Все DTO объекты должны быть имутабельны,
8+
поэтому применяем Lombok аннотацию @Value
9+
*/
10+
@Value
11+
@Builder
12+
public class CreateUserDto {
13+
/*
14+
К сожалению все параметры из нашего запроса приходят
15+
в формате ключ-значение при этом оба в формате String,
16+
т.е. нам в дальнейшем придется провести преобразования,
17+
например даты в понятный для базы данных вид. Данные
18+
неудобства в профессиональных фреймворках реализованы
19+
за нас.
20+
*/
21+
String name;
22+
String birthday;
23+
String email;
24+
String password;
25+
String role;
26+
String gender;
27+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package AirportSimulator.DTO;
2+
3+
import java.util.Objects;
4+
5+
public class FlightDto {
6+
private final Long id;
7+
private final String description;
8+
9+
public FlightDto(Long id, String description) {
10+
this.id = id;
11+
this.description = description;
12+
}
13+
14+
public Long getId() {
15+
return id;
16+
}
17+
18+
public String getDescription() {
19+
return description;
20+
}
21+
22+
@Override
23+
public boolean equals(Object o) {
24+
if (this == o) return true;
25+
if (o == null || getClass() != o.getClass()) return false;
26+
FlightDto flightDto = (FlightDto) o;
27+
return Objects.equals(id, flightDto.id) &&
28+
Objects.equals(description, flightDto.description);
29+
}
30+
31+
@Override
32+
public int hashCode() {
33+
return Objects.hash(id, description);
34+
}
35+
36+
@Override
37+
public String toString() {
38+
return "FlightDto{" +
39+
"id=" + id +
40+
", description='" + description + '\'' +
41+
'}';
42+
}
43+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package AirportSimulator.DTO;
2+
3+
import java.util.Objects;
4+
5+
public class TicketDto {
6+
private final Long id;
7+
private final Long flight_id;
8+
private final String seat_no;
9+
10+
public TicketDto(Long id, Long flight_id, String seat_no) {
11+
this.id = id;
12+
this.flight_id = flight_id;
13+
this.seat_no = seat_no;
14+
}
15+
16+
public Long getId() {
17+
return id;
18+
}
19+
20+
public Long getFlight_id() {
21+
return flight_id;
22+
}
23+
24+
public String getSeat_no() {
25+
return seat_no;
26+
}
27+
28+
@Override
29+
public boolean equals(Object o) {
30+
if (this == o) return true;
31+
if (o == null || getClass() != o.getClass()) return false;
32+
TicketDto ticketDto = (TicketDto) o;
33+
return Objects.equals(id, ticketDto.id) &&
34+
Objects.equals(flight_id, ticketDto.flight_id) &&
35+
Objects.equals(seat_no, ticketDto.seat_no);
36+
}
37+
38+
@Override
39+
public int hashCode() {
40+
return Objects.hash(id, flight_id, seat_no);
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return "TicketDto{" +
46+
"id=" + id +
47+
", flight_id=" + flight_id +
48+
", seat_no='" + seat_no + '\'' +
49+
'}';
50+
}
51+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package AirportSimulator.DTO;
2+
/* Применим Lombok чтобы не писать рутинный код */
3+
import lombok.Builder;
4+
import lombok.Value;
5+
6+
@Value
7+
@Builder
8+
public class UserDto {
9+
Long id;
10+
String mail;
11+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /