parent
43faab805b
commit
5ae9206bd0
@ -0,0 +1,124 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="Palette2"> |
||||
<group name="Swing"> |
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> |
||||
</item> |
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> |
||||
</item> |
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> |
||||
</item> |
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true"> |
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> |
||||
</item> |
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> |
||||
<initial-values> |
||||
<property name="text" value="Button" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
||||
<initial-values> |
||||
<property name="text" value="RadioButton" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
||||
<initial-values> |
||||
<property name="text" value="CheckBox" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> |
||||
<initial-values> |
||||
<property name="text" value="Label" /> |
||||
</initial-values> |
||||
</item> |
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
||||
<preferred-size width="150" height="-1" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
||||
<preferred-size width="150" height="-1" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
||||
<preferred-size width="150" height="-1" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
||||
<preferred-size width="150" height="50" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
||||
<preferred-size width="200" height="200" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
||||
<preferred-size width="200" height="200" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> |
||||
</item> |
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> |
||||
<preferred-size width="-1" height="20" /> |
||||
</default-constraints> |
||||
</item> |
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> |
||||
</item> |
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> |
||||
</item> |
||||
</group> |
||||
</component> |
||||
</project> |
After Width: | Height: | Size: 9.8 KiB |
@ -0,0 +1,44 @@ |
||||
package org.example.controllers; |
||||
|
||||
//import org.example.models.Author;
|
||||
import org.example.models.Post; |
||||
import org.example.models.User; |
||||
import org.example.repositories.PostRepository; |
||||
import org.example.services.PostService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
@RestController |
||||
@RequestMapping("/posts") |
||||
public class PostController { |
||||
|
||||
private final PostService postService; |
||||
private final PostRepository postRepository; |
||||
|
||||
@Autowired |
||||
public PostController(PostService postService, PostRepository postRepository) { |
||||
this.postService = postService; |
||||
this.postRepository = postRepository; |
||||
} |
||||
|
||||
@GetMapping("/getAllPosts") |
||||
public List<Post> getAllPost(){ |
||||
return postService.getAllPost(); |
||||
} |
||||
|
||||
@PostMapping |
||||
public Post createPost( |
||||
|
||||
@RequestParam("title") String title, |
||||
@RequestParam("content") String content, |
||||
@RequestParam(value = "imageFile", required = false) MultipartFile imageFile, |
||||
@RequestParam(value = "videoFile", required = false) MultipartFile videoFile) throws IOException { |
||||
|
||||
return postService.createPost(title, content, imageFile, videoFile); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,37 @@ |
||||
package org.example.models; |
||||
|
||||
import org.springframework.data.neo4j.core.schema.GeneratedValue; |
||||
import org.springframework.data.neo4j.core.schema.Id; |
||||
import org.springframework.data.neo4j.core.schema.Node; |
||||
|
||||
@Node |
||||
public class Image { |
||||
@Id |
||||
private Long id; |
||||
private String filename; |
||||
private String contentType; |
||||
|
||||
public Long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(Long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getFilename() { |
||||
return filename; |
||||
} |
||||
|
||||
public void setFilename(String filename) { |
||||
this.filename = filename; |
||||
} |
||||
|
||||
public String getContentType() { |
||||
return contentType; |
||||
} |
||||
|
||||
public void setContentType(String contentType) { |
||||
this.contentType = contentType; |
||||
} |
||||
} |
@ -0,0 +1,81 @@ |
||||
package org.example.models; |
||||
|
||||
|
||||
import lombok.Getter; |
||||
import org.springframework.data.neo4j.core.schema.GeneratedValue; |
||||
import org.springframework.data.neo4j.core.schema.Id; |
||||
import org.springframework.data.neo4j.core.schema.Node; |
||||
import org.springframework.data.neo4j.core.schema.Relationship; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.UUID; |
||||
|
||||
@Getter |
||||
@Node |
||||
public class Post { |
||||
@Id |
||||
@GeneratedValue |
||||
private Long id; |
||||
private String title; |
||||
private String content; |
||||
|
||||
|
||||
@Relationship(type = "HAS_IMAGE", direction = Relationship.Direction.OUTGOING) |
||||
private List<Image> images = new ArrayList<>(); |
||||
|
||||
@Relationship(type = "HAS_VIDEO", direction = Relationship.Direction.OUTGOING) |
||||
private List<Video> videos = new ArrayList<>(); |
||||
|
||||
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 getContent() { |
||||
return content; |
||||
} |
||||
|
||||
public void setContent(String content) { |
||||
this.content = content; |
||||
} |
||||
|
||||
public List<Image> getImages() { |
||||
return images; |
||||
} |
||||
|
||||
public void setImages(List<Image> images) { |
||||
this.images = images; |
||||
} |
||||
|
||||
public List<Video> getVideos() { |
||||
return videos; |
||||
} |
||||
|
||||
public void setVideos(List<Video> videos) { |
||||
this.videos = videos; |
||||
} |
||||
|
||||
@Relationship(type = "createPost", direction = Relationship.Direction.INCOMING) |
||||
private User creator; |
||||
|
||||
public User getCreator() { |
||||
return creator; |
||||
} |
||||
|
||||
public void setCreator(User creator) { |
||||
this.creator = creator; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,37 @@ |
||||
package org.example.models; |
||||
|
||||
import org.springframework.data.neo4j.core.schema.Id; |
||||
import org.springframework.data.neo4j.core.schema.Node; |
||||
|
||||
@Node |
||||
public class Video { |
||||
|
||||
@Id |
||||
private Long id; |
||||
private String filename; |
||||
private String contentType; |
||||
|
||||
public Long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(Long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getFilename() { |
||||
return filename; |
||||
} |
||||
|
||||
public void setFilename(String filename) { |
||||
this.filename = filename; |
||||
} |
||||
|
||||
public String getContentType() { |
||||
return contentType; |
||||
} |
||||
|
||||
public void setContentType(String contentType) { |
||||
this.contentType = contentType; |
||||
} |
||||
} |
@ -0,0 +1,18 @@ |
||||
package org.example.queryresults; |
||||
|
||||
import org.example.models.User; |
||||
|
||||
public class PostQueryResult { |
||||
private User user; |
||||
|
||||
public PostQueryResult() { |
||||
} |
||||
|
||||
public User getUser() { |
||||
return user; |
||||
} |
||||
|
||||
public void setUser(User user) { |
||||
this.user = user; |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
package org.example.repositories; |
||||
|
||||
import org.example.controllers.UserController; |
||||
import org.example.models.Post; |
||||
import org.example.queryresults.PostQueryResult; |
||||
import org.springframework.data.neo4j.repository.Neo4jRepository; |
||||
import org.springframework.data.neo4j.repository.query.Query; |
||||
import org.springframework.data.repository.query.Param; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
import java.util.List; |
||||
import java.util.UUID; |
||||
|
||||
@Repository |
||||
public interface PostRepository extends Neo4jRepository<Post,Long> { |
||||
@Query("MATCH (post:Post) return post") |
||||
List<Post> getAllPost(); |
||||
// @Query("MATCH (user:User {username: $username}), (post:Post ) " +" WHERE ID(post)=$postId "+
|
||||
// "CREATE (user)-[:createPost]->(post) Return user,post")
|
||||
// void createPostRelationship(@Param("username") String username,@Param("postId") Long postId);
|
||||
@Query("MATCH (user:User {username: $username}),(post:Post )"+"where ID(post)=$postId"+ " CREATE (user)-[:createPost ]->(post)"+ |
||||
"RETURN user, post") |
||||
PostQueryResult createPostRelationship(@Param("username") String username,@Param("postId") Long postId); |
||||
} |
@ -0,0 +1,119 @@ |
||||
package org.example.services; |
||||
|
||||
//import org.example.models.Author;
|
||||
import org.example.controllers.UserController; |
||||
import org.example.models.Image; |
||||
import org.example.models.Post; |
||||
import org.example.models.User; |
||||
import org.example.models.Video; |
||||
import org.example.queryresults.PostQueryResult; |
||||
import org.example.repositories.PostRepository; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.io.IOException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
import java.security.Principal; |
||||
import java.util.List; |
||||
import java.util.UUID; |
||||
|
||||
@Service |
||||
public class PostService { |
||||
|
||||
private final PostRepository postRepository; |
||||
private final UserController userController; |
||||
private String username; |
||||
|
||||
|
||||
@Autowired |
||||
public PostService(PostRepository postRepository, UserController userController) { |
||||
this.postRepository = postRepository; |
||||
this.userController = userController; |
||||
} |
||||
|
||||
public List<Post> getAllPost(){ |
||||
return postRepository.getAllPost(); |
||||
} |
||||
|
||||
public Post createPost(String title, String content, MultipartFile imageFile, MultipartFile videoFile) throws IOException { |
||||
Post post = new Post(); |
||||
post.setTitle(title); |
||||
post.setContent(content); |
||||
|
||||
if (imageFile != null) { |
||||
Image image = saveImageFile(imageFile, "images"); |
||||
post.getImages().add(image); |
||||
} |
||||
|
||||
if (videoFile != null) { |
||||
Video video = saveVideoFile(videoFile, "videos"); |
||||
post.getVideos().add(video); |
||||
} |
||||
|
||||
username=userController.username; |
||||
|
||||
Post post1= postRepository.save(post); |
||||
Long postId=post1.getId(); |
||||
System.out.println(username+" "+post.getContent()+" "+postId); |
||||
postRepository.createPostRelationship(username,postId); |
||||
return post1; |
||||
} |
||||
|
||||
private Image saveImageFile(MultipartFile file, String folder) throws IOException { |
||||
// Tạo đường dẫn thư mục nếu nó chưa tồn tại
|
||||
Path directoryPath = Paths.get(folder); |
||||
if (!Files.exists(directoryPath)) { |
||||
Files.createDirectories(directoryPath); |
||||
} |
||||
|
||||
// Tạo tên tệp an toàn
|
||||
String originalFilename = file.getOriginalFilename(); |
||||
String safeFilename = UUID.randomUUID().toString() + "_" + originalFilename; |
||||
|
||||
// Đường dẫn đầy đủ đến tệp
|
||||
Path filePath = Paths.get(folder, safeFilename); |
||||
|
||||
// Sao chép tệp từ MultipartFile vào đường dẫn
|
||||
Files.copy(file.getInputStream(), filePath); |
||||
|
||||
// Tạo đối tượng Video và lưu thông tin
|
||||
Image image = new Image(); |
||||
image.setFilename(safeFilename); |
||||
image.setContentType(file.getContentType()); |
||||
|
||||
// Lưu video vào hệ thống hoặc cơ sở dữ liệu
|
||||
|
||||
return image; |
||||
} |
||||
|
||||
private Video saveVideoFile(MultipartFile file, String folder) throws IOException { |
||||
// Tạo đường dẫn thư mục nếu nó chưa tồn tại
|
||||
Path directoryPath = Paths.get(folder); |
||||
if (!Files.exists(directoryPath)) { |
||||
Files.createDirectories(directoryPath); |
||||
} |
||||
|
||||
// Tạo tên tệp an toàn
|
||||
String originalFilename = file.getOriginalFilename(); |
||||
String safeFilename = UUID.randomUUID().toString() + "_" + originalFilename; |
||||
|
||||
// Đường dẫn đầy đủ đến tệp
|
||||
Path filePath = Paths.get(folder, safeFilename); |
||||
|
||||
// Sao chép tệp từ MultipartFile vào đường dẫn
|
||||
Files.copy(file.getInputStream(), filePath); |
||||
|
||||
// Tạo đối tượng Video và lưu thông tin
|
||||
Video video = new Video(); |
||||
video.setFilename(safeFilename); |
||||
video.setContentType(file.getContentType()); |
||||
|
||||
// Lưu video vào hệ thống hoặc cơ sở dữ liệu
|
||||
|
||||
return video; |
||||
} |
||||
|
||||
} |
Binary file not shown.
Loading…
Reference in new issue