Commit 0bbe393da7f117487144d74b221c9ae5d3883317
1 parent
b4808f61
feature: lesen und schreiben mittels REST/Jackson
Showing
6 changed files
with
39 additions
and
12 deletions
src/main/java/net/ziemers/swxercise/lg/user/Profile.java
... | ... | @@ -4,6 +4,7 @@ import javax.persistence.Entity; |
4 | 4 | import javax.validation.constraints.NotNull; |
5 | 5 | |
6 | 6 | import net.ziemers.swxercise.db.BaseEntity; |
7 | +import net.ziemers.swxercise.lg.user.enums.PasswordHashType; | |
7 | 8 | |
8 | 9 | @Entity |
9 | 10 | public class Profile extends BaseEntity { |
... | ... | @@ -14,6 +15,9 @@ public class Profile extends BaseEntity { |
14 | 15 | @NotNull |
15 | 16 | private String passwordHash; |
16 | 17 | |
18 | + @NotNull | |
19 | + private PasswordHashType passwordHashType = PasswordHashType.Unknown; | |
20 | + | |
17 | 21 | private String mailaddress; |
18 | 22 | |
19 | 23 | public Profile() { |
... | ... | @@ -34,14 +38,22 @@ public class Profile extends BaseEntity { |
34 | 38 | this.username = username; |
35 | 39 | } |
36 | 40 | |
37 | - public String getPasswordHash() { | |
41 | + private String getPasswordHash() { | |
38 | 42 | return passwordHash; |
39 | 43 | } |
40 | 44 | |
41 | - public void setPasswordHash(String passwordHash) { | |
45 | + private void setPasswordHash(String passwordHash) { | |
42 | 46 | this.passwordHash = passwordHash; |
43 | 47 | } |
44 | 48 | |
49 | + private PasswordHashType getPasswordHashType() { | |
50 | + return passwordHashType; | |
51 | + } | |
52 | + | |
53 | + private void setPasswordHashType(PasswordHashType passwordHashType) { | |
54 | + this.passwordHashType = passwordHashType; | |
55 | + } | |
56 | + | |
45 | 57 | public String getMailaddress() { |
46 | 58 | return mailaddress; |
47 | 59 | } | ... | ... |
src/main/java/net/ziemers/swxercise/lg/user/User.java
src/main/java/net/ziemers/swxercise/lg/user/enums/PasswordHashType.java
0 → 100644
src/main/java/net/ziemers/swxercise/lg/user/service/UserService.java
... | ... | @@ -6,7 +6,9 @@ import javax.ejb.Stateless; |
6 | 6 | import javax.inject.Inject; |
7 | 7 | |
8 | 8 | import net.ziemers.swxercise.db.dao.GenericDao; |
9 | +import net.ziemers.swxercise.lg.user.Profile; | |
9 | 10 | import net.ziemers.swxercise.lg.user.User; |
11 | +import net.ziemers.swxercise.lg.user.dto.UserDto; | |
10 | 12 | |
11 | 13 | @Stateless |
12 | 14 | public class UserService { |
... | ... | @@ -20,7 +22,13 @@ public class UserService { |
20 | 22 | return genericDao.findAll(User.class); |
21 | 23 | } |
22 | 24 | |
23 | - public Long saveUser(final User user) { | |
25 | + public Long saveUser(final UserDto userDto) { | |
26 | + final Profile profile = new Profile(userDto.getUsername(), userDto.getPassword()); | |
27 | + | |
28 | + // wir füllen das User-Objekt mit Method Chaining | |
29 | + final User user = new User(userDto.getFirstname(), userDto.getLastname()) | |
30 | + .withProfile(profile); | |
31 | + | |
24 | 32 | return genericDao.save(user); |
25 | 33 | } |
26 | 34 | ... | ... |
src/main/java/net/ziemers/swxercise/ui/RestViewController.java renamed to src/main/java/net/ziemers/swxercise/ui/UserViewController.java
... | ... | @@ -13,8 +13,8 @@ import net.ziemers.swxercise.lg.user.dto.UserDto; |
13 | 13 | import net.ziemers.swxercise.lg.user.service.UserService; |
14 | 14 | |
15 | 15 | @ApplicationScoped |
16 | -@Path(RestViewController.webContextPath) | |
17 | -public class RestViewController { | |
16 | +@Path(UserViewController.webContextPath) | |
17 | +public class UserViewController { | |
18 | 18 | |
19 | 19 | static final String webContextPath = "/users"; |
20 | 20 | |
... | ... | @@ -53,12 +53,7 @@ public class RestViewController { |
53 | 53 | @Consumes(MediaType.APPLICATION_JSON) |
54 | 54 | @Produces({MediaType.TEXT_PLAIN}) |
55 | 55 | public String postUser(UserDto userDto) throws Exception { |
56 | - final User user = new User(userDto.getFirstname(), userDto.getLastname()); | |
57 | - final Profile profile = new Profile(userDto.getUsername(), userDto.getPassword()); | |
58 | - | |
59 | - // TODO hierfür benötigen wir einen Mapper | |
60 | - user.setProfile(profile); | |
61 | - userService.saveUser(user); | |
56 | + userService.saveUser(userDto); | |
62 | 57 | |
63 | 58 | return "Ok"; |
64 | 59 | } | ... | ... |
src/test/java/net/ziemers/swxercise/ui/RestViewControllerTest.java