|
@@ -11,6 +11,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
@@ -36,10 +37,38 @@ public class AdminArticleController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/create")
|
|
@PostMapping("/create")
|
|
|
- public Result<String> create(@RequestBody Article article,
|
|
|
|
|
|
|
+ public Result<Map<String, Object>> create(@RequestBody Map<String, Object> body,
|
|
|
@RequestAttribute("userId") Long adminId) {
|
|
@RequestAttribute("userId") Long adminId) {
|
|
|
|
|
+ Article article = new Article();
|
|
|
|
|
+ article.setTitle((String) body.get("title"));
|
|
|
|
|
+ article.setContent((String) body.get("content"));
|
|
|
|
|
+ if (body.get("categoryId") != null) {
|
|
|
|
|
+ article.setCategoryId(Long.valueOf(body.get("categoryId").toString()));
|
|
|
|
|
+ }
|
|
|
|
|
+ article.setSummary((String) body.get("summary"));
|
|
|
|
|
+ article.setCoverImage((String) body.get("coverImage"));
|
|
|
|
|
+ article.setTags((String) body.get("tags"));
|
|
|
|
|
+ article.setAuthor((String) body.get("author"));
|
|
|
|
|
+ if (body.get("readTime") != null) {
|
|
|
|
|
+ article.setReadTime(Integer.valueOf(body.get("readTime").toString()));
|
|
|
|
|
+ }
|
|
|
|
|
+ // relatedDimensions may come as array from frontend
|
|
|
|
|
+ Object rd = body.get("relatedDimensions");
|
|
|
|
|
+ if (rd instanceof List) {
|
|
|
|
|
+ article.setRelatedDimensions(String.join(",", (List<String>) rd));
|
|
|
|
|
+ } else if (rd instanceof String) {
|
|
|
|
|
+ article.setRelatedDimensions((String) rd);
|
|
|
|
|
+ }
|
|
|
|
|
+ article.setVisibility((String) body.get("visibility"));
|
|
|
|
|
+ article.setVisibleTo((String) body.get("visibleTo"));
|
|
|
|
|
+ article.setArticleType((String) body.get("articleType"));
|
|
|
|
|
+ if (body.get("status") != null) {
|
|
|
|
|
+ article.setStatus((String) body.get("status"));
|
|
|
|
|
+ }
|
|
|
articleService.create(article, adminId);
|
|
articleService.create(article, adminId);
|
|
|
- return Result.success("创建成功");
|
|
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("id", article.getId());
|
|
|
|
|
+ return Result.success(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/update")
|
|
@PostMapping("/update")
|
|
@@ -48,6 +77,19 @@ public class AdminArticleController {
|
|
|
return Result.success("更新成功");
|
|
return Result.success("更新成功");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @PostMapping("/detail")
|
|
|
|
|
+ public Result<Article> detail(@RequestBody Map<String, Object> body) {
|
|
|
|
|
+ if (body.get("id") == null) {
|
|
|
|
|
+ return Result.error("缺少文章ID");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long id = Long.valueOf(body.get("id").toString());
|
|
|
|
|
+ Article article = articleService.getById(id);
|
|
|
|
|
+ if (article == null) {
|
|
|
|
|
+ return Result.error("文章不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.success(article);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@PostMapping("/delete")
|
|
@PostMapping("/delete")
|
|
|
public Result<String> delete(@RequestBody Map<String, Object> body) {
|
|
public Result<String> delete(@RequestBody Map<String, Object> body) {
|
|
|
Long id = Long.valueOf(body.get("id").toString());
|
|
Long id = Long.valueOf(body.get("id").toString());
|
|
@@ -57,6 +99,9 @@ public class AdminArticleController {
|
|
|
|
|
|
|
|
@PostMapping("/publish")
|
|
@PostMapping("/publish")
|
|
|
public Result<String> publish(@RequestBody Map<String, Object> body) {
|
|
public Result<String> publish(@RequestBody Map<String, Object> body) {
|
|
|
|
|
+ if (body.get("id") == null) {
|
|
|
|
|
+ return Result.error("缺少文章ID");
|
|
|
|
|
+ }
|
|
|
Long id = Long.valueOf(body.get("id").toString());
|
|
Long id = Long.valueOf(body.get("id").toString());
|
|
|
String status = (String) body.get("status");
|
|
String status = (String) body.get("status");
|
|
|
articleService.toggleStatus(id, status);
|
|
articleService.toggleStatus(id, status);
|