feat: 添加SysNoticeHandler通知管理API
This commit is contained in:
+63
@@ -0,0 +1,63 @@
|
|||||||
|
package cn.novalon.manage.sys.handler.notice;
|
||||||
|
|
||||||
|
import cn.novalon.manage.sys.core.domain.SysNotice;
|
||||||
|
import cn.novalon.manage.sys.core.service.ISysNoticeService;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/notices")
|
||||||
|
public class SysNoticeHandler {
|
||||||
|
|
||||||
|
private final ISysNoticeService noticeService;
|
||||||
|
|
||||||
|
public SysNoticeHandler(ISysNoticeService noticeService) {
|
||||||
|
this.noticeService = noticeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public Flux<SysNotice> getAllNotices() {
|
||||||
|
return noticeService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public Mono<ResponseEntity<SysNotice>> getNoticeById(@PathVariable Long id) {
|
||||||
|
return noticeService.findById(id)
|
||||||
|
.map(ResponseEntity::ok)
|
||||||
|
.defaultIfEmpty(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/status/{status}")
|
||||||
|
public Flux<SysNotice> getNoticesByStatus(@PathVariable String status) {
|
||||||
|
return noticeService.findByStatus(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public Mono<ResponseEntity<SysNotice>> createNotice(@RequestBody SysNotice notice) {
|
||||||
|
return noticeService.save(notice)
|
||||||
|
.map(n -> ResponseEntity.status(HttpStatus.CREATED).body(n));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public Mono<ResponseEntity<SysNotice>> updateNotice(@PathVariable Long id, @RequestBody SysNotice notice) {
|
||||||
|
return noticeService.findById(id)
|
||||||
|
.flatMap(existing -> {
|
||||||
|
existing.setNoticeTitle(notice.getNoticeTitle());
|
||||||
|
existing.setNoticeType(notice.getNoticeType());
|
||||||
|
existing.setNoticeContent(notice.getNoticeContent());
|
||||||
|
existing.setStatus(notice.getStatus());
|
||||||
|
return noticeService.save(existing);
|
||||||
|
})
|
||||||
|
.map(ResponseEntity::ok)
|
||||||
|
.defaultIfEmpty(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public Mono<ResponseEntity<Void>> deleteNotice(@PathVariable Long id) {
|
||||||
|
return noticeService.deleteById(id)
|
||||||
|
.then(Mono.just(ResponseEntity.noContent().build()));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user