@@ -8,7 +8,6 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters ;
import io.swagger.v3.oas.annotations.tags.Tag ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.http.ResponseEntity ;
import org.springframework.web.bind.annotation.* ;
import java.util.List ;
@@ -33,12 +32,12 @@ public class MarkdownController {
@Parameter ( name = " id " , description = " 文件ID " , required = true )
} )
@GetMapping ( " /{id} " )
public ResponseEntity < String > getMarkdownContent ( @PathVariable Long id ) {
public R < String > getMarkdownContent ( @PathVariable Long id ) {
MarkdownFile file = markdownFileService . getMarkdownById ( id ) ;
if ( file ! = null ) {
return ResponseEntity . ok ( file . getContent ( ) ) ;
return R. success ( file . getContent ( ) ) ;
}
return ResponseEntity . notFound ( ) . bu ild ( ) ;
return R. fa il ( ) ;
}
@Operation ( summary = " 创建markdown文件 " )
@@ -49,7 +48,7 @@ public class MarkdownController {
@Parameter ( name = " content " , description = " 内容 " , required = true )
} )
@PostMapping
public ResponseEntity < MarkdownFile > createMarkdown (
public R < MarkdownFile > createMarkdown (
@RequestParam Long groupingId ,
@RequestParam String title ,
@RequestParam String fileName ,
@@ -58,7 +57,7 @@ public class MarkdownController {
MarkdownFile file = markdownFileService . createMarkdownFile (
groupingId , title , fileName , content ) ;
return ResponseEntity . ok ( file ) ;
return R. success ( file ) ;
}
@Operation ( summary = " 更新Markdown文件 " )
@@ -67,39 +66,38 @@ public class MarkdownController {
@Parameter ( name = " content " , description = " Markdown文件内容 " , required = true )
} )
@PostMapping ( " /{id} " )
public ResponseEntity < MarkdownFile > updateMarkdown (
public R < MarkdownFile > updateMarkdown (
@PathVariable Long id ,
@RequestBody String content ) {
MarkdownFile file = markdownFileService . updateMarkdownContent ( id , content ) ;
if ( file ! = null ) {
return ResponseEntity . ok ( file ) ;
return R. success ( file ) ;
}
return ResponseEntity . notFound ( ) . bu ild ( ) ;
return R. fa il ( ) ;
}
@Operation ( summary = " 获取所有Markdown文件 " )
@GetMapping
public ResponseEntity < List < MarkdownFile > > getAllMarkdownFiles ( ) {
// 固定用户ID=1, 因为是个人笔记
public R < List < MarkdownFile > > getAllMarkdownFiles ( ) {
List < MarkdownFile > files = markdownFileService . getAllMarkdownFiles ( ) ;
return ResponseEntity . ok ( files ) ;
return R. success ( files ) ;
}
@Operation ( summary = " 删除Markdown文件 " )
@DeleteMapping ( " /{id} " )
public ResponseEntity < Void > deleteMarkdown ( @PathVariable Long id ) {
public R < Void > deleteMarkdown ( @PathVariable Long id ) {
if ( markdownFileService . deleteMarkdownFile ( id ) ) {
return ResponseEntity . noContent ( ) . build ( ) ;
return R. success ( ) ;
}
return ResponseEntity . notFound ( ) . bu ild ( ) ;
return R. fa il ( ) ;
}
@Operation ( summary = " 根据分组ID获取Markdown文件 " )
@GetMapping ( " /grouping/{groupingId} " )
public ResponseEntity < List < MarkdownFile > > getFilesByGroupingId ( @PathVariable String groupingId ) {
public R < List < MarkdownFile > > getFilesByGroupingId ( @PathVariable String groupingId ) {
List < MarkdownFile > files = markdownFileService . getFilesByGroupingId ( groupingId ) ;
return ResponseEntity . ok ( files ) ;
return R. success ( files ) ;
}
}