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