Update NoticeController.java

cyj
pbvfus8to 8 months ago
parent 9f4ca94cbb
commit 05438d025a

@ -29,49 +29,70 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
/** /**
*
*
* `Swagger`便使
*
* @author lanhai * @author lanhai
*/ */
@RestController @RestController
@RequestMapping("/shop/notice") @RequestMapping("/shop/notice")
@Tag(name = "公告管理接口") @Tag(name = "公告管理接口")
// 使用 @AllArgsConstructor 注解,由 lombok 自动生成包含所有成员变量的构造函数,用于依赖注入
@AllArgsConstructor @AllArgsConstructor
public class NoticeController { public class NoticeController {
// 通过构造函数注入NoticeService用于调用业务层方法来获取公告相关的数据
private NoticeService noticeService; private NoticeService noticeService;
/** /**
* *
* DTO
*
* @return ServerResponseEntity<List<NoticeDto>>DTO
*/ */
@GetMapping("/topNoticeList") @GetMapping("/topNoticeList")
@Operation(summary = "置顶公告列表信息" , description = "获取所有置顶公告列表信息") @Operation(summary = "置顶公告列表信息", description = "获取所有置顶公告列表信息")
// 使用 @Operation 注解在Swagger文档中对该接口进行描述包括接口的简要总结和详细描述信息
public ServerResponseEntity<List<NoticeDto>> getTopNoticeList() { public ServerResponseEntity<List<NoticeDto>> getTopNoticeList() {
// 调用服务层方法获取公告列表数据(这里获取的是所有的公告列表,后续可根据业务逻辑判断哪些是置顶的)
List<Notice> noticeList = noticeService.listNotice(); List<Notice> noticeList = noticeService.listNotice();
// 使用 hutool 工具类的方法将Notice类型的列表转换为NoticeDto类型的列表用于传输给前端展示的数据格式转换
List<NoticeDto> noticeDtoList = BeanUtil.copyToList(noticeList, NoticeDto.class); List<NoticeDto> noticeDtoList = BeanUtil.copyToList(noticeList, NoticeDto.class);
return ServerResponseEntity.success(noticeDtoList); return ServerResponseEntity.success(noticeDtoList);
} }
/** /**
* *
* IDDTO
*
* @param id ID @PathVariable
* @return ServerResponseEntity<NoticeDto>IDDTO
*/ */
@GetMapping("/info/{id}") @GetMapping("/info/{id}")
@Operation(summary = "公告详情" , description = "获取公告id公告详情") @Operation(summary = "公告详情", description = "获取公告id公告详情")
public ServerResponseEntity<NoticeDto> getNoticeById(@PathVariable("id") Long id) { public ServerResponseEntity<NoticeDto> getNoticeById(@PathVariable("id") Long id) {
// 调用服务层方法根据ID获取公告详情数据
Notice notice = noticeService.getNoticeById(id); Notice notice = noticeService.getNoticeById(id);
// 使用 hutool 工具类的方法将Notice对象转换为NoticeDto对象用于传输给前端展示的数据格式转换
NoticeDto noticeDto = BeanUtil.copyProperties(notice, NoticeDto.class); NoticeDto noticeDto = BeanUtil.copyProperties(notice, NoticeDto.class);
return ServerResponseEntity.success(noticeDto); return ServerResponseEntity.success(noticeDto);
} }
/** /**
* *
*
*
* @param page
* @return ServerResponseEntity<IPage<NoticeDto>>DTO
*/ */
@GetMapping("/noticeList") @GetMapping("/noticeList")
@Operation(summary = "公告列表信息" , description = "获取所有公告列表信息") @Operation(summary = "公告列表信息", description = "获取所有公告列表信息")
@Parameters({ @Parameters({
}) })
// 使用 @Parameters 注解在Swagger文档中可以对接口的参数进行详细描述这里目前没有添加具体参数描述内容
public ServerResponseEntity<IPage<NoticeDto>> pageNotice(PageParam<NoticeDto> page) { public ServerResponseEntity<IPage<NoticeDto>> pageNotice(PageParam<NoticeDto> page) {
return ServerResponseEntity.success(noticeService.pageNotice(page)); return ServerResponseEntity.success(noticeService.pageNotice(page));
} }
} }
Loading…
Cancel
Save