summaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/blog/web/models
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2024-07-20 00:51:37 -0400
committerrealtradam <[email protected]>2024-07-20 00:51:37 -0400
commit5e2eab6f32bc76918aa17791b688d1df27d6ddfc (patch)
tree420a0bcb5091d1e220fa8c42565a507897e11ec4 /src/main/java/com/blog/web/models
parenta6a60a5e774eed9d84f522fc452b67ee52e033cb (diff)
downloadspring-blog-5e2eab6f32bc76918aa17791b688d1df27d6ddfc.tar.gz
spring-blog-5e2eab6f32bc76918aa17791b688d1df27d6ddfc.zip
code cleanup
Diffstat (limited to 'src/main/java/com/blog/web/models')
-rw-r--r--src/main/java/com/blog/web/models/Article.java13
-rw-r--r--src/main/java/com/blog/web/models/UserEntity.java21
2 files changed, 9 insertions, 25 deletions
diff --git a/src/main/java/com/blog/web/models/Article.java b/src/main/java/com/blog/web/models/Article.java
index 42d27a1..ed4ac1c 100644
--- a/src/main/java/com/blog/web/models/Article.java
+++ b/src/main/java/com/blog/web/models/Article.java
@@ -23,15 +23,7 @@ public class Article {
@JoinColumn(name = "created_by", nullable = false)
private UserEntity createdBy;
- public Article(
- Long id,
- String title,
- String photoUrl,
- String content,
- UserEntity createdBy,
- LocalDateTime createdOn,
- LocalDateTime updatedOn
- ) {
+ public Article(Long id, String title, String photoUrl, String content, UserEntity createdBy, LocalDateTime createdOn, LocalDateTime updatedOn) {
this.id = id;
this.title = title;
this.photoUrl = photoUrl;
@@ -41,7 +33,8 @@ public class Article {
this.updatedOn = updatedOn;
}
- public Article() {};
+ public Article() {
+ }
public Article(ArticleDto articleDto) {
this.id = articleDto.getId();
diff --git a/src/main/java/com/blog/web/models/UserEntity.java b/src/main/java/com/blog/web/models/UserEntity.java
index d121580..c94db6b 100644
--- a/src/main/java/com/blog/web/models/UserEntity.java
+++ b/src/main/java/com/blog/web/models/UserEntity.java
@@ -18,25 +18,15 @@ public class UserEntity {
private String email;
private String password;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
- @JoinTable(
- name = "user_roles",
- joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
- inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")}
- )
- private List<Role> roles = new ArrayList<>();
+ @JoinTable(name = "user_roles", joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")})
+ private final List<Role> roles = new ArrayList<>();
- public boolean equals(UserEntity user)
- {
+ public boolean equals(UserEntity user) {
return this.id == user.getId();
}
public User toSecurityUser() {
- return new User(
- this.getEmail(),
- this.getPassword(),
- this.getRoles().stream().map((role) -> new SimpleGrantedAuthority(role.getName()))
- .collect(Collectors.toList())
- );
+ return new User(this.getEmail(), this.getPassword(), this.getRoles().stream().map((role) -> new SimpleGrantedAuthority(role.getName())).collect(Collectors.toList()));
}
public Long getId() {
@@ -76,6 +66,7 @@ public class UserEntity {
}
public void setRoles(List<Role> roles) {
- this.roles = roles;
+ this.roles.clear();
+ this.roles.addAll(roles);
}
}