lckt-server/api/v1/notice/notice.go
2025-05-10 03:34:25 +08:00

189 lines
5.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package notice
import (
"git.echol.cn/loser/lckt/global"
"git.echol.cn/loser/lckt/model/common/response"
"git.echol.cn/loser/lckt/model/notice"
noticeReq "git.echol.cn/loser/lckt/model/notice/request"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
type NoticeApi struct{}
// CreateNotice 创建通知
// @Tags Notice
// @Summary 创建通知
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body notice.Notice true "创建通知"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /not/createNotice [post]
func (notApi *NoticeApi) CreateNotice(c *gin.Context) {
// 创建业务用Context
ctx := c.Request.Context()
var not notice.Notice
err := c.ShouldBindJSON(&not)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = notService.CreateNotice(ctx, &not)
if err != nil {
global.GVA_LOG.Error("创建失败!", zap.Error(err))
response.FailWithMessage("创建失败:"+err.Error(), c)
return
}
response.OkWithMessage("创建成功", c)
}
// DeleteNotice 删除通知
// @Tags Notice
// @Summary 删除通知
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body notice.Notice true "删除通知"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /not/deleteNotice [delete]
func (notApi *NoticeApi) DeleteNotice(c *gin.Context) {
// 创建业务用Context
ctx := c.Request.Context()
ID := c.Query("ID")
err := notService.DeleteNotice(ctx, ID)
if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败:"+err.Error(), c)
return
}
response.OkWithMessage("删除成功", c)
}
// DeleteNoticeByIds 批量删除通知
// @Tags Notice
// @Summary 批量删除通知
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /not/deleteNoticeByIds [delete]
func (notApi *NoticeApi) DeleteNoticeByIds(c *gin.Context) {
// 创建业务用Context
ctx := c.Request.Context()
IDs := c.QueryArray("IDs[]")
err := notService.DeleteNoticeByIds(ctx, IDs)
if err != nil {
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
response.FailWithMessage("批量删除失败:"+err.Error(), c)
return
}
response.OkWithMessage("批量删除成功", c)
}
// UpdateNotice 更新通知
// @Tags Notice
// @Summary 更新通知
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body notice.Notice true "更新通知"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /not/updateNotice [put]
func (notApi *NoticeApi) UpdateNotice(c *gin.Context) {
// 从ctx获取标准context进行业务行为
ctx := c.Request.Context()
var not notice.Notice
err := c.ShouldBindJSON(&not)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = notService.UpdateNotice(ctx, not)
if err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败:"+err.Error(), c)
return
}
response.OkWithMessage("更新成功", c)
}
// FindNotice 用id查询通知
// @Tags Notice
// @Summary 用id查询通知
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param ID query uint true "用id查询通知"
// @Success 200 {object} response.Response{data=notice.Notice,msg=string} "查询成功"
// @Router /not/findNotice [get]
func (notApi *NoticeApi) FindNotice(c *gin.Context) {
// 创建业务用Context
ctx := c.Request.Context()
ID := c.Query("ID")
renot, err := notService.GetNotice(ctx, ID)
if err != nil {
global.GVA_LOG.Error("查询失败!", zap.Error(err))
response.FailWithMessage("查询失败:"+err.Error(), c)
return
}
response.OkWithData(renot, c)
}
// GetNoticeList 分页获取通知列表
// @Tags Notice
// @Summary 分页获取通知列表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data query noticeReq.NoticeSearch true "分页获取通知列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /not/getNoticeList [get]
func (notApi *NoticeApi) GetNoticeList(c *gin.Context) {
// 创建业务用Context
ctx := c.Request.Context()
var pageInfo noticeReq.NoticeSearch
err := c.ShouldBindQuery(&pageInfo)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
list, total, err := notService.GetNoticeInfoList(ctx, pageInfo)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败:"+err.Error(), c)
return
}
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
// GetNoticePublic 不需要鉴权的通知接口
// @Tags Notice
// @Summary 不需要鉴权的通知接口
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /not/getNoticePublic [get]
func (notApi *NoticeApi) GetNoticePublic(c *gin.Context) {
// 创建业务用Context
ctx := c.Request.Context()
// 此接口不需要鉴权
// 示例为返回了一个固定的消息接口一般本接口用于C端服务需要自己实现业务逻辑
notService.GetNoticePublic(ctx)
response.OkWithDetailed(gin.H{
"info": "不需要鉴权的通知接口信息",
}, "获取成功", c)
}