帖子post重提交
Change-Id: Ib28dc79d604faf43233c720031a4f18d84b22688
diff --git a/src/main/java/com/pt5/pthouduan/controller/PostController.java b/src/main/java/com/pt5/pthouduan/controller/PostController.java
index a3a9017..c497d87 100644
--- a/src/main/java/com/pt5/pthouduan/controller/PostController.java
+++ b/src/main/java/com/pt5/pthouduan/controller/PostController.java
@@ -23,7 +23,7 @@
* @author
* @since 2025-05-10
*/
-@CrossOrigin(origins = "http://localhost:5173")
+@CrossOrigin(origins = {"http://localhost:5173", "http://localhost:3000"})
@Controller
@RequestMapping("/post")
public class PostController {
@@ -49,7 +49,7 @@
post.setPostContent(post_content);
post.setTags(tags);
post.setRannge(rannge);
- post.setIsSticky(is_pinned != null && is_pinned);
+ post.setIsPinned(is_pinned != null && is_pinned);
post.setPostCreatedTime(LocalDateTime.now());
post.setUpdatedTime(LocalDateTime.now());
post.setLikes(0);
@@ -146,4 +146,18 @@
public List<Post> findPinnedPosts() {
return postService.findPinnedPosts();
}
+
+
+
+ // 添加切换置顶状态的新端点
+ @PutMapping("/togglePin/{postid}")
+ @ResponseBody
+ public Boolean togglePinStatus(@PathVariable Integer postid) {
+ Post post = postService.getById(postid);
+ if (post == null) return null;
+
+ boolean newStatus = !post.getIsPinned();
+ boolean result = postService.setPinnedStatus(postid, newStatus);
+ return result ? newStatus : null; // ✅ 返回新状态
+ }
}