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 967cc6e

Browse files
Added Mapper folder in the MVCPractice section of a small course on Java EE
1 parent bb51fb1 commit 967cc6e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package AirportSimulator.Mapper;
2+
3+
import AirportSimulator.DTO.CreateUserDto;
4+
import AirportSimulator.Entity.EntityEnum.Gender;
5+
import AirportSimulator.Entity.EntityEnum.Role;
6+
import AirportSimulator.Entity.User;
7+
import AirportSimulator.Util.LocalDateFormatter;
8+
import lombok.AccessLevel;
9+
import lombok.NoArgsConstructor;
10+
11+
/* Конструктор без аргументов с параметрами доступа PRIVATE */
12+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
13+
public class CreateUserMapper implements Mapper<CreateUserDto, User> {
14+
15+
private static final CreateUserMapper INSTANCE = new CreateUserMapper();
16+
17+
public static CreateUserMapper getInstance() {
18+
return INSTANCE;
19+
}
20+
/*
21+
Для преобразования полученной из формы регистрации даты (String)
22+
из строки в дату удобную для понимания базой данных LocalDate
23+
применяем самописный утиллитный класс LocalDateFormatter
24+
*/
25+
@Override
26+
public User mapFrom(CreateUserDto object) {
27+
return User.builder().
28+
name(object.getName()).
29+
birthday(LocalDateFormatter.format(object.getBirthday())).
30+
email(object.getEmail()).
31+
password(object.getPassword()).
32+
gender(Gender.valueOf(object.getGender())).
33+
role(Role.valueOf(object.getRole())).
34+
build();
35+
}
36+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package AirportSimulator.Mapper;
2+
3+
public interface Mapper <F, T> {
4+
T mapFrom(F object);
5+
}

0 commit comments

Comments
(0)

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