feat: 添加通知微服务,支持站内通知已读状态
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package notification
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/notification/api/internal/logic/notification"
|
||||
"juwan-backend/app/notification/api/internal/svc"
|
||||
"juwan-backend/app/notification/api/internal/types"
|
||||
)
|
||||
|
||||
// 获取通知列表
|
||||
func ListNotificationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PageReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := notification.NewListNotificationsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListNotifications(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package notification
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/notification/api/internal/logic/notification"
|
||||
"juwan-backend/app/notification/api/internal/svc"
|
||||
"juwan-backend/app/notification/api/internal/types"
|
||||
)
|
||||
|
||||
// 全部已读
|
||||
func ReadAllNotificationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.EmptyResp
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := notification.NewReadAllNotificationsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ReadAllNotifications(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package notification
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/notification/api/internal/logic/notification"
|
||||
"juwan-backend/app/notification/api/internal/svc"
|
||||
"juwan-backend/app/notification/api/internal/types"
|
||||
)
|
||||
|
||||
// 标记已读
|
||||
func ReadNotificationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PathId
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := notification.NewReadNotificationLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ReadNotification(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
notification "juwan-backend/app/notification/api/internal/handler/notification"
|
||||
"juwan-backend/app/notification/api/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 获取通知列表
|
||||
Method: http.MethodGet,
|
||||
Path: "/notifications",
|
||||
Handler: notification.ListNotificationsHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 标记已读
|
||||
Method: http.MethodPut,
|
||||
Path: "/notifications/:id/read",
|
||||
Handler: notification.ReadNotificationHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 全部已读
|
||||
Method: http.MethodPut,
|
||||
Path: "/notifications/read-all",
|
||||
Handler: notification.ReadAllNotificationsHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/v1"),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user