diff options
| author | realtradam <[email protected]> | 2024-07-23 20:47:31 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2024-07-23 20:47:31 -0400 |
| commit | 1e18e0ad7a47536be92384bbf815e0923a06698d (patch) | |
| tree | b07405ecdef4f05a96b6c4348930cbee976554cb /src/main/java/com/blog/web/models | |
| parent | 56c59e3b98fe554c4e1484e208e4be5c30f09a04 (diff) | |
| download | spring-blog-1e18e0ad7a47536be92384bbf815e0923a06698d.tar.gz spring-blog-1e18e0ad7a47536be92384bbf815e0923a06698d.zip | |
split front and back end, add react to project
Diffstat (limited to 'src/main/java/com/blog/web/models')
| -rw-r--r-- | src/main/java/com/blog/web/models/Article.java | 104 | ||||
| -rw-r--r-- | src/main/java/com/blog/web/models/Role.java | 36 | ||||
| -rw-r--r-- | src/main/java/com/blog/web/models/UserEntity.java | 72 |
3 files changed, 0 insertions, 212 deletions
diff --git a/src/main/java/com/blog/web/models/Article.java b/src/main/java/com/blog/web/models/Article.java deleted file mode 100644 index b54907a..0000000 --- a/src/main/java/com/blog/web/models/Article.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.blog.web.models; - -import com.blog.web.dto.ArticleDto; -import jakarta.persistence.*; -import org.hibernate.annotations.CreationTimestamp; -import org.hibernate.annotations.UpdateTimestamp; - -import java.time.LocalDateTime; - -@Entity -public class Article { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - private String title; - private String photoUrl; - private String content; - @CreationTimestamp - private LocalDateTime createdOn; - @UpdateTimestamp - private LocalDateTime updatedOn; - @ManyToOne - @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) { - this.id = id; - this.title = title; - this.photoUrl = photoUrl; - this.content = content; - this.createdBy = createdBy; - this.createdOn = createdOn; - this.updatedOn = updatedOn; - } - - public Article() { - } - - public Article(ArticleDto articleDto) { - this.id = articleDto.getId(); - this.title = articleDto.getTitle(); - this.photoUrl = articleDto.getPhotoUrl(); - this.content = articleDto.getContent(); - this.createdBy = articleDto.getCreatedBy(); - this.createdOn = articleDto.getCreatedOn(); - this.updatedOn = articleDto.getUpdatedOn(); - } - - public long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getPhotoUrl() { - return photoUrl; - } - - public void setPhotoUrl(String photoUrl) { - this.photoUrl = photoUrl; - } - - public LocalDateTime getCreatedOn() { - return createdOn; - } - - public void setCreatedOn(LocalDateTime createdOn) { - this.createdOn = createdOn; - } - - public LocalDateTime getUpdatedOn() { - return updatedOn; - } - - public void setUpdatedOn(LocalDateTime updatedOn) { - this.updatedOn = updatedOn; - } - - public UserEntity getCreatedBy() { - return createdBy; - } - - public void setCreatedBy(UserEntity createdBy) { - this.createdBy = createdBy; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } -} diff --git a/src/main/java/com/blog/web/models/Role.java b/src/main/java/com/blog/web/models/Role.java deleted file mode 100644 index 2b7143f..0000000 --- a/src/main/java/com/blog/web/models/Role.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.blog.web.models; - -import jakarta.persistence.*; - -import java.util.ArrayList; -import java.util.List; - -@Entity(name = "roles") -public class Role { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - private String name; - @ManyToMany(mappedBy = "roles") - private List<UserEntity> users = new ArrayList<>(); - - public long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List<UserEntity> getUsers() { - return users; - } -} diff --git a/src/main/java/com/blog/web/models/UserEntity.java b/src/main/java/com/blog/web/models/UserEntity.java deleted file mode 100644 index bf45b21..0000000 --- a/src/main/java/com/blog/web/models/UserEntity.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.blog.web.models; - -import jakarta.persistence.*; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.User; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -@Entity(name = "users") -// Named UserEntity to prevent conflicts with Java User object -public class UserEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - private String username; - 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 final List<Role> roles = new ArrayList<>(); - - 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())); - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public List<Role> getRoles() { - return roles; - } - - public void setRoles(List<Role> roles) { - this.roles.clear(); - this.roles.addAll(roles); - } -} |
