forked from jhipster/generator-jhipster-micronaut
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AdminUserDTO and the PublicUserResource - to separate the publicl…
…y accessible user information from the private one. Porting jhipster/generator-jhipster#12374
- Loading branch information
Showing
13 changed files
with
356 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
generators/server/templates/src/main/java/package/service/dto/AdminUserDTO.java.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package <%=packageName%>.service.dto; | ||
|
||
import <%=packageName%>.config.Constants; | ||
|
||
import <%=packageName%>.domain.Authority; | ||
import <%=packageName%>.domain.User; | ||
import io.micronaut.core.annotation.Introspected; | ||
|
||
import javax.validation.constraints.Email; | ||
import javax.validation.constraints.NotBlank; | ||
|
||
import javax.validation.constraints.*; | ||
import java.time.Instant; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* A DTO representing a user, with their authorities. | ||
*/ | ||
@Introspected | ||
public class <%= asDto('AdminUser') %> { | ||
|
||
private <%= userPkType %> id; | ||
|
||
@NotBlank | ||
@Pattern(regexp = Constants.LOGIN_REGEX) | ||
@Size(min = 1, max = 50) | ||
private String login; | ||
|
||
@Size(max = 50) | ||
private String firstName; | ||
|
||
@Size(max = 50) | ||
private String lastName; | ||
|
||
@Size(min = 5, max = 254) | ||
private String email; | ||
|
||
@Size(max = 256) | ||
private String imageUrl; | ||
|
||
private boolean activated = false; | ||
|
||
@Size(min = 2, max = 6) | ||
private String langKey; | ||
|
||
private String createdBy; | ||
|
||
private Instant createdDate; | ||
|
||
private String lastModifiedBy; | ||
|
||
private Instant lastModifiedDate; | ||
|
||
private Set<String> authorities; | ||
|
||
public <%= asDto('AdminUser') %>() { | ||
// Empty constructor needed for Jackson. | ||
} | ||
|
||
public <%= asDto('AdminUser') %>(User user) { | ||
this.id = user.getId(); | ||
this.login = user.getLogin(); | ||
this.firstName = user.getFirstName(); | ||
this.lastName = user.getLastName(); | ||
this.email = user.getEmail(); | ||
this.activated = user.getActivated(); | ||
this.imageUrl = user.getImageUrl(); | ||
this.langKey = user.getLangKey(); | ||
this.createdDate = user.getCreatedDate(); | ||
this.lastModifiedDate = user.getLastModifiedDate(); | ||
this.authorities = user.getAuthorities().stream() | ||
.map(Authority::getName) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
public <%= userPkType %> getId() { | ||
return id; | ||
} | ||
|
||
public void setId(<%= userPkType %> id) { | ||
this.id = id; | ||
} | ||
|
||
public String getLogin() { | ||
return login; | ||
} | ||
|
||
public void setLogin(String login) { | ||
this.login = login; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
public String getImageUrl() { | ||
return imageUrl; | ||
} | ||
|
||
public void setImageUrl(String imageUrl) { | ||
this.imageUrl = imageUrl; | ||
} | ||
|
||
public boolean isActivated() { | ||
return activated; | ||
} | ||
|
||
public void setActivated(boolean activated) { | ||
this.activated = activated; | ||
} | ||
|
||
public String getLangKey() { | ||
return langKey; | ||
} | ||
|
||
public void setLangKey(String langKey) { | ||
this.langKey = langKey; | ||
} | ||
|
||
public Instant getCreatedDate() { | ||
return createdDate; | ||
} | ||
|
||
public void setCreatedDate(Instant createdDate) { | ||
this.createdDate = createdDate; | ||
} | ||
|
||
public Instant getLastModifiedDate() { | ||
return lastModifiedDate; | ||
} | ||
|
||
public void setLastModifiedDate(Instant lastModifiedDate) { | ||
this.lastModifiedDate = lastModifiedDate; | ||
} | ||
|
||
public Set<String> getAuthorities() { | ||
return authorities; | ||
} | ||
|
||
public void setAuthorities(Set<String> authorities) { | ||
this.authorities = authorities; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "<%= asDto('AdminUser') %>{" + | ||
"login='" + login + '\'' + | ||
", firstName='" + firstName + '\'' + | ||
", lastName='" + lastName + '\'' + | ||
", email='" + email + '\'' + | ||
", imageUrl='" + imageUrl + '\'' + | ||
", activated=" + activated + | ||
", langKey='" + langKey + '\'' + | ||
", createdBy=" + createdBy + | ||
", createdDate=" + createdDate + | ||
", lastModifiedBy='" + lastModifiedBy + '\'' + | ||
", lastModifiedDate=" + lastModifiedDate + | ||
", authorities=" + authorities + | ||
"}"; | ||
} | ||
} |
Oops, something went wrong.