dto + dao
This commit is contained in:
parent
e656fe0664
commit
db18f20ff6
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
3828
data.trace.db
3828
data.trace.db
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@
|
|||||||
|
package com.webproglabs.lab1.dao;
|
||||||
|
|
||||||
|
import com.webproglabs.lab1.models.Comment;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface CommentRepository extends JpaRepository<Comment, Long> {
|
||||||
|
List<Comment> findByTextLike(String text);
|
||||||
|
Optional<Comment> findById(Long Id);
|
||||||
|
}
|
12
src/main/java/com/webproglabs/lab1/dao/PostRepository.java
Normal file
12
src/main/java/com/webproglabs/lab1/dao/PostRepository.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package com.webproglabs.lab1.dao;
|
||||||
|
|
||||||
|
import com.webproglabs.lab1.models.Post;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface PostRepository extends JpaRepository<Post, Long> {
|
||||||
|
List<Post> findByTextLike(String text);
|
||||||
|
Optional<Post> findById(Long Id);
|
||||||
|
}
|
10
src/main/java/com/webproglabs/lab1/dao/TopicRepository.java
Normal file
10
src/main/java/com/webproglabs/lab1/dao/TopicRepository.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package com.webproglabs.lab1.dao;
|
||||||
|
|
||||||
|
import com.webproglabs.lab1.models.Topic;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface TopicRepository extends JpaRepository<Topic, Long> {
|
||||||
|
Optional<Topic> findById(Long Id);
|
||||||
|
}
|
13
src/main/java/com/webproglabs/lab1/dao/UserRepository.java
Normal file
13
src/main/java/com/webproglabs/lab1/dao/UserRepository.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package com.webproglabs.lab1.dao;
|
||||||
|
|
||||||
|
import com.webproglabs.lab1.models.User;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
|
List<User> findByLoginLike(String login);
|
||||||
|
User findOneByLoginIgnoreCase(String login);
|
||||||
|
Optional<User> findById(Long Id);
|
||||||
|
}
|
26
src/main/java/com/webproglabs/lab1/dto/CommentDto.java
Normal file
26
src/main/java/com/webproglabs/lab1/dto/CommentDto.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package com.webproglabs.lab1.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.webproglabs.lab1.models.Comment;
|
||||||
|
|
||||||
|
public class CommentDto {
|
||||||
|
private Long id;
|
||||||
|
private String text;
|
||||||
|
private String authorLogin;
|
||||||
|
|
||||||
|
public CommentDto(Comment comment) {
|
||||||
|
this.id = comment.getId();
|
||||||
|
this.text = comment.getText();
|
||||||
|
this.authorLogin = comment.getOwner().getLogin();
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public String getText() {return text;}
|
||||||
|
public void setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
public String getAuthor() {return authorLogin;}
|
||||||
|
}
|
33
src/main/java/com/webproglabs/lab1/dto/PostDto.java
Normal file
33
src/main/java/com/webproglabs/lab1/dto/PostDto.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.webproglabs.lab1.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.webproglabs.lab1.models.Comment;
|
||||||
|
import com.webproglabs.lab1.models.Post;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PostDto {
|
||||||
|
private Long id;
|
||||||
|
private String text;
|
||||||
|
private List<CommentDto> comments = new ArrayList<>();
|
||||||
|
private String authorLogin;
|
||||||
|
|
||||||
|
public PostDto(Post post){
|
||||||
|
this.id = post.getId();
|
||||||
|
this.text = post.getText();
|
||||||
|
for(Comment comment: post.getComments()){
|
||||||
|
comments.add(new CommentDto(comment));
|
||||||
|
}
|
||||||
|
this.authorLogin = post.getAuthor().getLogin();
|
||||||
|
}
|
||||||
|
public PostDto(){}
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public String getText() {return text;}
|
||||||
|
public List<CommentDto> getComments() {return comments;}
|
||||||
|
public String getAuthor() {return authorLogin;}
|
||||||
|
}
|
48
src/main/java/com/webproglabs/lab1/dto/TopicDto.java
Normal file
48
src/main/java/com/webproglabs/lab1/dto/TopicDto.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package com.webproglabs.lab1.dto;
|
||||||
|
|
||||||
|
import com.webproglabs.lab1.models.Comment;
|
||||||
|
import com.webproglabs.lab1.models.Post;
|
||||||
|
import com.webproglabs.lab1.models.Topic;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TopicDto {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private List<PostDto> posts = new ArrayList<>();
|
||||||
|
|
||||||
|
public TopicDto(Topic topic) {
|
||||||
|
this.id = topic.getId();
|
||||||
|
this.name = topic.getName();
|
||||||
|
this.description = topic.getDescription();
|
||||||
|
for(Post post: topic.getPosts()){
|
||||||
|
posts.add(new PostDto(post));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PostDto> getPosts() {
|
||||||
|
return posts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
48
src/main/java/com/webproglabs/lab1/dto/UserDto.java
Normal file
48
src/main/java/com/webproglabs/lab1/dto/UserDto.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package com.webproglabs.lab1.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.webproglabs.lab1.models.Comment;
|
||||||
|
import com.webproglabs.lab1.models.Post;
|
||||||
|
import com.webproglabs.lab1.models.User;
|
||||||
|
import com.webproglabs.lab1.models.UserRole;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UserDto {
|
||||||
|
private Long id;
|
||||||
|
private String login;
|
||||||
|
private String password;
|
||||||
|
private List<CommentDto> comments = new ArrayList<>();
|
||||||
|
private List<PostDto> posts = new ArrayList<>();
|
||||||
|
private UserRole role;
|
||||||
|
|
||||||
|
|
||||||
|
public UserDto(){}
|
||||||
|
|
||||||
|
public UserDto(User user){
|
||||||
|
this.id = user.getId();
|
||||||
|
this.login = user.getLogin();
|
||||||
|
this.password = user.getPassword();
|
||||||
|
this.role = user.getRole();
|
||||||
|
for(Comment comment: user.getComments()){
|
||||||
|
comments.add(new CommentDto(comment));
|
||||||
|
}
|
||||||
|
for (Post post: user.getPosts()) {
|
||||||
|
posts.add(new PostDto(post));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public String getLogin() {return login;}
|
||||||
|
public void setLogin(String login) {this.login = login;}
|
||||||
|
public String getPassword() {return password;}
|
||||||
|
public UserRole getRole() {return role;}
|
||||||
|
public void setPassword(String password) {this.password = password;}
|
||||||
|
|
||||||
|
public List<CommentDto> getComments() {return comments;}
|
||||||
|
public List<PostDto> getPosts() {return posts;}
|
||||||
|
}
|
@ -53,6 +53,10 @@ public class User {
|
|||||||
return login;
|
return login;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserRole getRole() {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
public void setLogin(String login) {
|
public void setLogin(String login) {
|
||||||
this.login = login;
|
this.login = login;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user