|
@@ -0,0 +1,106 @@
|
|
|
+package system
|
|
|
+
|
|
|
+import (
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
+ "server/dao"
|
|
|
+ "server/global"
|
|
|
+ "server/model/common/response"
|
|
|
+ "strconv"
|
|
|
+)
|
|
|
+
|
|
|
+type NoticeApi struct{}
|
|
|
+
|
|
|
+func (na *NoticeApi) QueryUserUnreadNotice(c *gin.Context) {
|
|
|
+ id := c.Query("id")
|
|
|
+ userId, err := strconv.Atoi(id)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("参数错误", c)
|
|
|
+ global.GVA_LOG.Error("QueryUserUnreadNotice ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ noticeList, err := noticeService.QueryUserUnreadNotice(userId)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("查询失败", c)
|
|
|
+ global.GVA_LOG.Error("QueryUserUnreadNotice ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.OkWithData(noticeList, c)
|
|
|
+}
|
|
|
+
|
|
|
+func (na *NoticeApi) QueryAllNotices(c *gin.Context) {
|
|
|
+ noticeList, err := noticeService.QueryAllNotices()
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("查询失败", c)
|
|
|
+ global.GVA_LOG.Error("QueryAllNotices ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.OkWithData(noticeList, c)
|
|
|
+}
|
|
|
+
|
|
|
+func (na *NoticeApi) CreateNotice(c *gin.Context) {
|
|
|
+ var notice dao.Notice
|
|
|
+ err := c.ShouldBindJSON(¬ice)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("参数错误", c)
|
|
|
+ global.GVA_LOG.Error("CreateNotice ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = noticeService.CreateNotice(notice)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("创建失败", c)
|
|
|
+ global.GVA_LOG.Error("CreateNotice ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.OkWithMessage("创建成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+func (na *NoticeApi) ReadNotice(c *gin.Context) {
|
|
|
+ id := c.Query("id")
|
|
|
+ noticeId, err := strconv.Atoi(id)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("参数错误", c)
|
|
|
+ global.GVA_LOG.Error("ReadNotice ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = noticeService.ReadNotice(noticeId)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("标记已读失败", c)
|
|
|
+ global.GVA_LOG.Error("ReadNotice ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.OkWithMessage("标记已读成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+func (na *NoticeApi) UpdateNotice(c *gin.Context) {
|
|
|
+ var notice dao.Notice
|
|
|
+ err := c.ShouldBindJSON(¬ice)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("参数解析失败", c)
|
|
|
+ global.GVA_LOG.Error("UpdateNotice ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = noticeService.UpdateNotice(notice)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("更新失败", c)
|
|
|
+ global.GVA_LOG.Error("UpdateNotice ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.OkWithMessage("更新成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+func (na *NoticeApi) DeleteNotice(c *gin.Context) {
|
|
|
+ var notice dao.Notice
|
|
|
+ err := c.ShouldBindJSON(¬ice)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("参数解析失败", c)
|
|
|
+ global.GVA_LOG.Error("DeleteNotice ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = noticeService.DeleteNotice(notice)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("删除失败", c)
|
|
|
+ global.GVA_LOG.Error("DeleteNotice ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.OkWithMessage("删除成功", c)
|
|
|
+}
|