feat: 添加通知微服务,支持站内通知已读状态
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
Name: notifi-api
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 8888
|
||||||
|
|
||||||
|
Prometheus:
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 4001
|
||||||
|
Path: /metrics
|
||||||
|
|
||||||
|
# ===== DEV CONFIG =====
|
||||||
|
NotificationRpcConf:
|
||||||
|
Endpoints:
|
||||||
|
- notification-rpc:8080
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
rest.RestConf
|
||||||
|
NotificationRpcConf zrpc.RpcClientConf
|
||||||
|
}
|
||||||
@@ -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"),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package notification
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/api/internal/types"
|
||||||
|
"juwan-backend/app/notification/rpc/notificationservice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func formatUnix(ts int64) string {
|
||||||
|
if ts <= 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return time.Unix(ts, 0).UTC().Format(time.RFC3339)
|
||||||
|
}
|
||||||
|
|
||||||
|
func toAPINotification(n *notificationservice.Notifications) types.Notification {
|
||||||
|
return types.Notification{
|
||||||
|
Id: n.GetId(),
|
||||||
|
Type: n.GetType(),
|
||||||
|
Title: n.GetTitle(),
|
||||||
|
Content: n.GetContent(),
|
||||||
|
Read: n.GetRead(),
|
||||||
|
Link: n.GetLink(),
|
||||||
|
CreatedAt: formatUnix(n.GetCreatedAt()),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.10.1
|
||||||
|
|
||||||
|
package notification
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/api/internal/svc"
|
||||||
|
"juwan-backend/app/notification/api/internal/types"
|
||||||
|
"juwan-backend/app/notification/rpc/notificationservice"
|
||||||
|
"juwan-backend/common/utils/contextj"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListNotificationsLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取通知列表
|
||||||
|
func NewListNotificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListNotificationsLogic {
|
||||||
|
return &ListNotificationsLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListNotificationsLogic) ListNotifications(req *types.PageReq) (resp *types.NotificationListResp, err error) {
|
||||||
|
uid, err := contextj.UserIDFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
limit := req.Limit
|
||||||
|
if limit <= 0 {
|
||||||
|
limit = 20
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := l.svcCtx.NotificationRpc.SearchNotifications(l.ctx, ¬ificationservice.SearchNotificationsReq{
|
||||||
|
Offset: req.Offset,
|
||||||
|
Limit: limit,
|
||||||
|
UserId: &uid,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items := make([]types.Notification, 0, len(out.GetNotifications()))
|
||||||
|
for _, item := range out.GetNotifications() {
|
||||||
|
items = append(items, toAPINotification(item))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.NotificationListResp{
|
||||||
|
Items: items,
|
||||||
|
Meta: types.PageMeta{
|
||||||
|
Total: int64(len(items)),
|
||||||
|
Offset: req.Offset,
|
||||||
|
Limit: limit,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.10.1
|
||||||
|
|
||||||
|
package notification
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/api/internal/svc"
|
||||||
|
"juwan-backend/app/notification/api/internal/types"
|
||||||
|
"juwan-backend/app/notification/rpc/notificationservice"
|
||||||
|
"juwan-backend/common/utils/contextj"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ReadAllNotificationsLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 全部已读
|
||||||
|
func NewReadAllNotificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReadAllNotificationsLogic {
|
||||||
|
return &ReadAllNotificationsLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ReadAllNotificationsLogic) ReadAllNotifications(req *types.EmptyResp) (resp *types.EmptyResp, err error) {
|
||||||
|
uid, err := contextj.UserIDFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
unread := false
|
||||||
|
out, err := l.svcCtx.NotificationRpc.SearchNotifications(l.ctx, ¬ificationservice.SearchNotificationsReq{
|
||||||
|
Offset: 0,
|
||||||
|
Limit: 100,
|
||||||
|
UserId: &uid,
|
||||||
|
Read: &unread,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
read := true
|
||||||
|
now := time.Now().Unix()
|
||||||
|
for _, item := range out.GetNotifications() {
|
||||||
|
_, err = l.svcCtx.NotificationRpc.UpdateNotifications(l.ctx, ¬ificationservice.UpdateNotificationsReq{
|
||||||
|
Id: item.GetId(),
|
||||||
|
Read: &read,
|
||||||
|
UpdatedAt: &now,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.EmptyResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.10.1
|
||||||
|
|
||||||
|
package notification
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/api/internal/svc"
|
||||||
|
"juwan-backend/app/notification/api/internal/types"
|
||||||
|
"juwan-backend/app/notification/rpc/notificationservice"
|
||||||
|
"juwan-backend/common/utils/contextj"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ReadNotificationLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标记已读
|
||||||
|
func NewReadNotificationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReadNotificationLogic {
|
||||||
|
return &ReadNotificationLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ReadNotificationLogic) ReadNotification(req *types.PathId) (resp *types.EmptyResp, err error) {
|
||||||
|
uid, err := contextj.UserIDFrom(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
current, err := l.svcCtx.NotificationRpc.GetNotificationsById(l.ctx, ¬ificationservice.GetNotificationsByIdReq{Id: req.Id})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if current.GetNotifications() == nil {
|
||||||
|
return nil, errors.New("notification not found")
|
||||||
|
}
|
||||||
|
if current.GetNotifications().GetUserId() != uid {
|
||||||
|
return nil, errors.New("notification not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
read := true
|
||||||
|
now := time.Now().Unix()
|
||||||
|
_, err = l.svcCtx.NotificationRpc.UpdateNotifications(l.ctx, ¬ificationservice.UpdateNotificationsReq{
|
||||||
|
Id: req.Id,
|
||||||
|
Read: &read,
|
||||||
|
UpdatedAt: &now,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.EmptyResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/notification/api/internal/config"
|
||||||
|
"juwan-backend/app/notification/rpc/notificationservice"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServiceContext struct {
|
||||||
|
Config config.Config
|
||||||
|
NotificationRpc notificationservice.NotificationService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
return &ServiceContext{
|
||||||
|
Config: c,
|
||||||
|
NotificationRpc: notificationservice.NewNotificationService(zrpc.MustNewClient(c.NotificationRpcConf)),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.10.1
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
type EmptyResp struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type Notification struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
Read bool `json:"read"`
|
||||||
|
Link string `json:"link,optional"`
|
||||||
|
CreatedAt string `json:"createdAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type NotificationListResp struct {
|
||||||
|
Items []Notification `json:"items"`
|
||||||
|
Meta PageMeta `json:"meta"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PageMeta struct {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
Offset int64 `json:"offset"`
|
||||||
|
Limit int64 `json:"limit"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PageReq struct {
|
||||||
|
Offset int64 `form:"offset,default=0"`
|
||||||
|
Limit int64 `form:"limit,default=20"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PathId struct {
|
||||||
|
Id int64 `path:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SimpleUser struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserProfile struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
|
Role string `json:"role"` // consumer, player, owner, admin
|
||||||
|
VerifiedRoles []string `json:"verifiedRoles"`
|
||||||
|
VerificationStatus map[string]string `json:"verificationStatus"`
|
||||||
|
Phone string `json:"phone,optional"`
|
||||||
|
Bio string `json:"bio,optional"`
|
||||||
|
CreatedAt string `json:"createdAt"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl 1.10.1
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/api/internal/config"
|
||||||
|
"juwan-backend/app/notification/api/internal/handler"
|
||||||
|
"juwan-backend/app/notification/api/internal/svc"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configFile = flag.String("f", "etc/notifi-api.yaml", "the config file")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var c config.Config
|
||||||
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
|
server.Start()
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
Name: pb.rpc
|
||||||
|
ListenOn: 0.0.0.0:8080
|
||||||
|
|
||||||
|
Prometheus:
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 4001
|
||||||
|
Path: /metrics
|
||||||
|
|
||||||
|
# ===== DEV CONF =====
|
||||||
|
SnowflakeRpcConf:
|
||||||
|
Endpoints:
|
||||||
|
- snowflake:8080
|
||||||
|
|
||||||
|
DB:
|
||||||
|
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||||
|
|
||||||
|
CacheConf:
|
||||||
|
- Host: "${REDIS_HOST}:${REDIS_PORT}"
|
||||||
|
Type: node
|
||||||
|
|
||||||
|
Log:
|
||||||
|
Level: debug
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
zrpc.RpcServerConf
|
||||||
|
|
||||||
|
SnowflakeRpcConf zrpc.RpcClientConf
|
||||||
|
DB struct {
|
||||||
|
Master string
|
||||||
|
Slaves string
|
||||||
|
}
|
||||||
|
CacheConf cache.CacheConf
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/notification/rpc/pb"
|
||||||
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AddNotificationsLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAddNotificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddNotificationsLogic {
|
||||||
|
return &AddNotificationsLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AddNotificationsLogic) AddNotifications(in *pb.AddNotificationsReq) (*pb.AddNotificationsResp, error) {
|
||||||
|
if in.GetUserId() <= 0 {
|
||||||
|
return nil, errors.New("userId is required")
|
||||||
|
}
|
||||||
|
if in.GetType() == "" {
|
||||||
|
return nil, errors.New("type is required")
|
||||||
|
}
|
||||||
|
if in.GetTitle() == "" {
|
||||||
|
return nil, errors.New("title is required")
|
||||||
|
}
|
||||||
|
if in.GetContent() == "" {
|
||||||
|
return nil, errors.New("content is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("create notification id failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
created, err := l.svcCtx.NotificationModelRW.Notifications.Create().
|
||||||
|
SetID(idResp.Id).
|
||||||
|
SetUserID(in.GetUserId()).
|
||||||
|
SetType(in.GetType()).
|
||||||
|
SetTitle(in.GetTitle()).
|
||||||
|
SetContent(in.GetContent()).
|
||||||
|
SetNillableLink(in.Link).
|
||||||
|
Save(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("addNotifications err: %v", err)
|
||||||
|
return nil, errors.New("add notification failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.AddNotificationsResp{Id: created.ID}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/notification/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DelNotificationsLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDelNotificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelNotificationsLogic {
|
||||||
|
return &DelNotificationsLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *DelNotificationsLogic) DelNotifications(in *pb.DelNotificationsReq) (*pb.DelNotificationsResp, error) {
|
||||||
|
err := l.svcCtx.NotificationModelRW.Notifications.DeleteOneID(in.GetId()).Exec(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("delNotifications err: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.DelNotificationsResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/notification/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetNotificationsByIdLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetNotificationsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetNotificationsByIdLogic {
|
||||||
|
return &GetNotificationsByIdLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetNotificationsByIdLogic) GetNotificationsById(in *pb.GetNotificationsByIdReq) (*pb.GetNotificationsByIdResp, error) {
|
||||||
|
n, err := l.svcCtx.NotificationModelRO.Notifications.Get(l.ctx, in.GetId())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.GetNotificationsByIdResp{Notifications: entNotificationToPb(n)}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models"
|
||||||
|
"juwan-backend/app/notification/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
func entNotificationToPb(n *models.Notifications) *pb.Notifications {
|
||||||
|
out := &pb.Notifications{
|
||||||
|
Id: n.ID,
|
||||||
|
UserId: n.UserID,
|
||||||
|
Type: n.Type,
|
||||||
|
Title: n.Title,
|
||||||
|
Content: n.Content,
|
||||||
|
Read: n.Read,
|
||||||
|
CreatedAt: n.CreatedAt.Unix(),
|
||||||
|
UpdatedAt: n.UpdatedAt.Unix(),
|
||||||
|
}
|
||||||
|
if n.Link != nil {
|
||||||
|
out.Link = *n.Link
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/notifications"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/notification/rpc/pb"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SearchNotificationsLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSearchNotificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchNotificationsLogic {
|
||||||
|
return &SearchNotificationsLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *SearchNotificationsLogic) SearchNotifications(in *pb.SearchNotificationsReq) (*pb.SearchNotificationsResp, error) {
|
||||||
|
limit := in.GetLimit()
|
||||||
|
if limit <= 0 {
|
||||||
|
limit = 20
|
||||||
|
}
|
||||||
|
if limit > 100 {
|
||||||
|
return nil, errors.New("limit too large")
|
||||||
|
}
|
||||||
|
offset := in.GetOffset()
|
||||||
|
if offset < 0 {
|
||||||
|
offset = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
query := l.svcCtx.NotificationModelRO.Notifications.Query()
|
||||||
|
if in.Id != nil {
|
||||||
|
query = query.Where(notifications.IDEQ(in.GetId()))
|
||||||
|
}
|
||||||
|
if in.UserId != nil {
|
||||||
|
query = query.Where(notifications.UserIDEQ(in.GetUserId()))
|
||||||
|
}
|
||||||
|
if in.Type != nil {
|
||||||
|
query = query.Where(notifications.TypeEQ(in.GetType()))
|
||||||
|
}
|
||||||
|
if in.Read != nil {
|
||||||
|
query = query.Where(notifications.ReadEQ(in.GetRead()))
|
||||||
|
}
|
||||||
|
|
||||||
|
list, err := query.
|
||||||
|
Order(notifications.ByCreatedAt(sql.OrderDesc()), notifications.ByID(sql.OrderDesc())).
|
||||||
|
Offset(int(offset)).
|
||||||
|
Limit(int(limit)).
|
||||||
|
All(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("searchNotifications err: %v", err)
|
||||||
|
return nil, errors.New("search notifications failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
out := make([]*pb.Notifications, len(list))
|
||||||
|
for i, n := range list {
|
||||||
|
out[i] = entNotificationToPb(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.SearchNotificationsResp{Notifications: out}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/notification/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateNotificationsLogic struct {
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
logx.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUpdateNotificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateNotificationsLogic {
|
||||||
|
return &UpdateNotificationsLogic{
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UpdateNotificationsLogic) UpdateNotifications(in *pb.UpdateNotificationsReq) (*pb.UpdateNotificationsResp, error) {
|
||||||
|
updater := l.svcCtx.NotificationModelRW.Notifications.UpdateOneID(in.GetId())
|
||||||
|
if in.Read != nil {
|
||||||
|
updater = updater.SetRead(in.GetRead())
|
||||||
|
}
|
||||||
|
if in.Type != nil {
|
||||||
|
updater = updater.SetType(in.GetType())
|
||||||
|
}
|
||||||
|
if in.Title != nil {
|
||||||
|
updater = updater.SetTitle(in.GetTitle())
|
||||||
|
}
|
||||||
|
if in.Content != nil {
|
||||||
|
updater = updater.SetContent(in.GetContent())
|
||||||
|
}
|
||||||
|
if in.Link != nil {
|
||||||
|
updater = updater.SetLink(in.GetLink())
|
||||||
|
}
|
||||||
|
if in.UpdatedAt != nil {
|
||||||
|
updater = updater.SetUpdatedAt(time.Unix(in.GetUpdatedAt(), 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := updater.Save(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("updateNotifications err: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.UpdateNotificationsResp{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,341 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/migrate"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/notifications"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Client is the client that holds all ent builders.
|
||||||
|
type Client struct {
|
||||||
|
config
|
||||||
|
// Schema is the client for creating, migrating and dropping schema.
|
||||||
|
Schema *migrate.Schema
|
||||||
|
// Notifications is the client for interacting with the Notifications builders.
|
||||||
|
Notifications *NotificationsClient
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient creates a new client configured with the given options.
|
||||||
|
func NewClient(opts ...Option) *Client {
|
||||||
|
client := &Client{config: newConfig(opts...)}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) init() {
|
||||||
|
c.Schema = migrate.NewSchema(c.driver)
|
||||||
|
c.Notifications = NewNotificationsClient(c.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// config is the configuration for the client and its builder.
|
||||||
|
config struct {
|
||||||
|
// driver used for executing database requests.
|
||||||
|
driver dialect.Driver
|
||||||
|
// debug enable a debug logging.
|
||||||
|
debug bool
|
||||||
|
// log used for logging on debug mode.
|
||||||
|
log func(...any)
|
||||||
|
// hooks to execute on mutations.
|
||||||
|
hooks *hooks
|
||||||
|
// interceptors to execute on queries.
|
||||||
|
inters *inters
|
||||||
|
}
|
||||||
|
// Option function to configure the client.
|
||||||
|
Option func(*config)
|
||||||
|
)
|
||||||
|
|
||||||
|
// newConfig creates a new config for the client.
|
||||||
|
func newConfig(opts ...Option) config {
|
||||||
|
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
||||||
|
cfg.options(opts...)
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
// options applies the options on the config object.
|
||||||
|
func (c *config) options(opts ...Option) {
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(c)
|
||||||
|
}
|
||||||
|
if c.debug {
|
||||||
|
c.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug enables debug logging on the ent.Driver.
|
||||||
|
func Debug() Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.debug = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log sets the logging function for debug mode.
|
||||||
|
func Log(fn func(...any)) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.log = fn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Driver configures the client driver.
|
||||||
|
func Driver(driver dialect.Driver) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.driver = driver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open opens a database/sql.DB specified by the driver name and
|
||||||
|
// the data source name, and returns a new client attached to it.
|
||||||
|
// Optional parameters can be added for configuring the client.
|
||||||
|
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
|
||||||
|
switch driverName {
|
||||||
|
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
|
||||||
|
drv, err := sql.Open(driverName, dataSourceName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewClient(append(options, Driver(drv))...), nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
||||||
|
var ErrTxStarted = errors.New("models: cannot start a transaction within a transaction")
|
||||||
|
|
||||||
|
// Tx returns a new transactional client. The provided context
|
||||||
|
// is used until the transaction is committed or rolled back.
|
||||||
|
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, ErrTxStarted
|
||||||
|
}
|
||||||
|
tx, err := newTx(ctx, c.driver)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("models: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = tx
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
Notifications: NewNotificationsClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeginTx returns a transactional client with specified options.
|
||||||
|
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, errors.New("ent: cannot start a transaction within a transaction")
|
||||||
|
}
|
||||||
|
tx, err := c.driver.(interface {
|
||||||
|
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
|
||||||
|
}).BeginTx(ctx, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
Notifications: NewNotificationsClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||||
|
//
|
||||||
|
// client.Debug().
|
||||||
|
// Notifications.
|
||||||
|
// Query().
|
||||||
|
// Count(ctx)
|
||||||
|
func (c *Client) Debug() *Client {
|
||||||
|
if c.debug {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
client := &Client{config: cfg}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes the database connection and prevents new queries from starting.
|
||||||
|
func (c *Client) Close() error {
|
||||||
|
return c.driver.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds the mutation hooks to all the entity clients.
|
||||||
|
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||||
|
func (c *Client) Use(hooks ...Hook) {
|
||||||
|
c.Notifications.Use(hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds the query interceptors to all the entity clients.
|
||||||
|
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||||
|
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.Notifications.Intercept(interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate implements the ent.Mutator interface.
|
||||||
|
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
switch m := m.(type) {
|
||||||
|
case *NotificationsMutation:
|
||||||
|
return c.Notifications.mutate(ctx, m)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("models: unknown mutation type %T", m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationsClient is a client for the Notifications schema.
|
||||||
|
type NotificationsClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewNotificationsClient returns a client for the Notifications from the given config.
|
||||||
|
func NewNotificationsClient(c config) *NotificationsClient {
|
||||||
|
return &NotificationsClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `notifications.Hooks(f(g(h())))`.
|
||||||
|
func (c *NotificationsClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Notifications = append(c.hooks.Notifications, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `notifications.Intercept(f(g(h())))`.
|
||||||
|
func (c *NotificationsClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.Notifications = append(c.inters.Notifications, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a Notifications entity.
|
||||||
|
func (c *NotificationsClient) Create() *NotificationsCreate {
|
||||||
|
mutation := newNotificationsMutation(c.config, OpCreate)
|
||||||
|
return &NotificationsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Notifications entities.
|
||||||
|
func (c *NotificationsClient) CreateBulk(builders ...*NotificationsCreate) *NotificationsCreateBulk {
|
||||||
|
return &NotificationsCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *NotificationsClient) MapCreateBulk(slice any, setFunc func(*NotificationsCreate, int)) *NotificationsCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &NotificationsCreateBulk{err: fmt.Errorf("calling to NotificationsClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*NotificationsCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &NotificationsCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Notifications.
|
||||||
|
func (c *NotificationsClient) Update() *NotificationsUpdate {
|
||||||
|
mutation := newNotificationsMutation(c.config, OpUpdate)
|
||||||
|
return &NotificationsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *NotificationsClient) UpdateOne(_m *Notifications) *NotificationsUpdateOne {
|
||||||
|
mutation := newNotificationsMutation(c.config, OpUpdateOne, withNotifications(_m))
|
||||||
|
return &NotificationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *NotificationsClient) UpdateOneID(id int64) *NotificationsUpdateOne {
|
||||||
|
mutation := newNotificationsMutation(c.config, OpUpdateOne, withNotificationsID(id))
|
||||||
|
return &NotificationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Notifications.
|
||||||
|
func (c *NotificationsClient) Delete() *NotificationsDelete {
|
||||||
|
mutation := newNotificationsMutation(c.config, OpDelete)
|
||||||
|
return &NotificationsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *NotificationsClient) DeleteOne(_m *Notifications) *NotificationsDeleteOne {
|
||||||
|
return c.DeleteOneID(_m.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *NotificationsClient) DeleteOneID(id int64) *NotificationsDeleteOne {
|
||||||
|
builder := c.Delete().Where(notifications.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &NotificationsDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Notifications.
|
||||||
|
func (c *NotificationsClient) Query() *NotificationsQuery {
|
||||||
|
return &NotificationsQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeNotifications},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Notifications entity by its id.
|
||||||
|
func (c *NotificationsClient) Get(ctx context.Context, id int64) (*Notifications, error) {
|
||||||
|
return c.Query().Where(notifications.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *NotificationsClient) GetX(ctx context.Context, id int64) *Notifications {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *NotificationsClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Notifications
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *NotificationsClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.Notifications
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *NotificationsClient) mutate(ctx context.Context, m *NotificationsMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&NotificationsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&NotificationsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&NotificationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&NotificationsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("models: unknown Notifications mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// hooks and interceptors per client, for fast access.
|
||||||
|
type (
|
||||||
|
hooks struct {
|
||||||
|
Notifications []ent.Hook
|
||||||
|
}
|
||||||
|
inters struct {
|
||||||
|
Notifications []ent.Interceptor
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -0,0 +1,608 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/notifications"
|
||||||
|
"reflect"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ent aliases to avoid import conflicts in user's code.
|
||||||
|
type (
|
||||||
|
Op = ent.Op
|
||||||
|
Hook = ent.Hook
|
||||||
|
Value = ent.Value
|
||||||
|
Query = ent.Query
|
||||||
|
QueryContext = ent.QueryContext
|
||||||
|
Querier = ent.Querier
|
||||||
|
QuerierFunc = ent.QuerierFunc
|
||||||
|
Interceptor = ent.Interceptor
|
||||||
|
InterceptFunc = ent.InterceptFunc
|
||||||
|
Traverser = ent.Traverser
|
||||||
|
TraverseFunc = ent.TraverseFunc
|
||||||
|
Policy = ent.Policy
|
||||||
|
Mutator = ent.Mutator
|
||||||
|
Mutation = ent.Mutation
|
||||||
|
MutateFunc = ent.MutateFunc
|
||||||
|
)
|
||||||
|
|
||||||
|
type clientCtxKey struct{}
|
||||||
|
|
||||||
|
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||||
|
func FromContext(ctx context.Context) *Client {
|
||||||
|
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContext returns a new context with the given Client attached.
|
||||||
|
func NewContext(parent context.Context, c *Client) context.Context {
|
||||||
|
return context.WithValue(parent, clientCtxKey{}, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
type txCtxKey struct{}
|
||||||
|
|
||||||
|
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||||
|
func TxFromContext(ctx context.Context) *Tx {
|
||||||
|
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTxContext returns a new context with the given Tx attached.
|
||||||
|
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||||
|
return context.WithValue(parent, txCtxKey{}, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrderFunc applies an ordering on the sql selector.
|
||||||
|
// Deprecated: Use Asc/Desc functions or the package builders instead.
|
||||||
|
type OrderFunc func(*sql.Selector)
|
||||||
|
|
||||||
|
var (
|
||||||
|
initCheck sync.Once
|
||||||
|
columnCheck sql.ColumnCheck
|
||||||
|
)
|
||||||
|
|
||||||
|
// checkColumn checks if the column exists in the given table.
|
||||||
|
func checkColumn(t, c string) error {
|
||||||
|
initCheck.Do(func() {
|
||||||
|
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||||
|
notifications.Table: notifications.ValidColumn,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return columnCheck(t, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asc applies the given fields in ASC order.
|
||||||
|
func Asc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Asc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desc applies the given fields in DESC order.
|
||||||
|
func Desc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Desc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||||
|
type AggregateFunc func(*sql.Selector) string
|
||||||
|
|
||||||
|
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||||
|
//
|
||||||
|
// GroupBy(field1, field2).
|
||||||
|
// Aggregate(models.As(models.Sum(field1), "sum_field1"), (models.As(models.Sum(field2), "sum_field2")).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.As(fn(s), end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count applies the "count" aggregation function on each group.
|
||||||
|
func Count() AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.Count("*")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Max applies the "max" aggregation function on the given field of each group.
|
||||||
|
func Max(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Max(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||||
|
func Mean(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Avg(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Min applies the "min" aggregation function on the given field of each group.
|
||||||
|
func Min(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Min(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||||
|
func Sum(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Sum(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidationError returns when validating a field or edge fails.
|
||||||
|
type ValidationError struct {
|
||||||
|
Name string // Field or edge name.
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *ValidationError) Error() string {
|
||||||
|
return e.err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ValidationError) Unwrap() error {
|
||||||
|
return e.err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidationError returns a boolean indicating whether the error is a validation error.
|
||||||
|
func IsValidationError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ValidationError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||||
|
type NotFoundError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotFoundError) Error() string {
|
||||||
|
return "models: " + e.label + " not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||||
|
func IsNotFound(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotFoundError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaskNotFound masks not found error.
|
||||||
|
func MaskNotFound(err error) error {
|
||||||
|
if IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||||
|
type NotSingularError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotSingularError) Error() string {
|
||||||
|
return "models: " + e.label + " not singular"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||||
|
func IsNotSingular(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotSingularError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||||
|
type NotLoadedError struct {
|
||||||
|
edge string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotLoadedError) Error() string {
|
||||||
|
return "models: " + e.edge + " edge was not loaded"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||||
|
func IsNotLoaded(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotLoadedError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConstraintError returns when trying to create/update one or more entities and
|
||||||
|
// one or more of their constraints failed. For example, violation of edge or
|
||||||
|
// field uniqueness.
|
||||||
|
type ConstraintError struct {
|
||||||
|
msg string
|
||||||
|
wrap error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ConstraintError) Error() string {
|
||||||
|
return "models: constraint failed: " + e.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ConstraintError) Unwrap() error {
|
||||||
|
return e.wrap
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||||
|
func IsConstraintError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ConstraintError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// selector embedded by the different Select/GroupBy builders.
|
||||||
|
type selector struct {
|
||||||
|
label string
|
||||||
|
flds *[]string
|
||||||
|
fns []AggregateFunc
|
||||||
|
scan func(context.Context, any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanX is like Scan, but panics if an error occurs.
|
||||||
|
func (s *selector) ScanX(ctx context.Context, v any) {
|
||||||
|
if err := s.scan(ctx, v); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Strings(ctx context.Context) ([]string, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Strings is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []string
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringsX is like Strings, but panics if an error occurs.
|
||||||
|
func (s *selector) StringsX(ctx context.Context) []string {
|
||||||
|
v, err := s.Strings(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) String(ctx context.Context) (_ string, err error) {
|
||||||
|
var v []string
|
||||||
|
if v, err = s.Strings(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Strings returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringX is like String, but panics if an error occurs.
|
||||||
|
func (s *selector) StringX(ctx context.Context) string {
|
||||||
|
v, err := s.String(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Ints(ctx context.Context) ([]int, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Ints is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []int
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntsX is like Ints, but panics if an error occurs.
|
||||||
|
func (s *selector) IntsX(ctx context.Context) []int {
|
||||||
|
v, err := s.Ints(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Int(ctx context.Context) (_ int, err error) {
|
||||||
|
var v []int
|
||||||
|
if v, err = s.Ints(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Ints returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntX is like Int, but panics if an error occurs.
|
||||||
|
func (s *selector) IntX(ctx context.Context) int {
|
||||||
|
v, err := s.Int(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Float64s is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []float64
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64sX is like Float64s, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64sX(ctx context.Context) []float64 {
|
||||||
|
v, err := s.Float64s(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
|
||||||
|
var v []float64
|
||||||
|
if v, err = s.Float64s(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Float64s returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64X is like Float64, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64X(ctx context.Context) float64 {
|
||||||
|
v, err := s.Float64(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("models: Bools is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []bool
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolsX is like Bools, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolsX(ctx context.Context) []bool {
|
||||||
|
v, err := s.Bools(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
|
||||||
|
var v []bool
|
||||||
|
if v, err = s.Bools(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("models: Bools returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolX is like Bool, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolX(ctx context.Context) bool {
|
||||||
|
v, err := s.Bool(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// withHooks invokes the builder operation with the given hooks, if any.
|
||||||
|
func withHooks[V Value, M any, PM interface {
|
||||||
|
*M
|
||||||
|
Mutation
|
||||||
|
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
|
||||||
|
if len(hooks) == 0 {
|
||||||
|
return exec(ctx)
|
||||||
|
}
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutationT, ok := any(m).(PM)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
// Set the mutation to the builder.
|
||||||
|
*mutation = *mutationT
|
||||||
|
return exec(ctx)
|
||||||
|
})
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
if hooks[i] == nil {
|
||||||
|
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = hooks[i](mut)
|
||||||
|
}
|
||||||
|
v, err := mut.Mutate(ctx, mutation)
|
||||||
|
if err != nil {
|
||||||
|
return value, err
|
||||||
|
}
|
||||||
|
nv, ok := v.(V)
|
||||||
|
if !ok {
|
||||||
|
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
|
||||||
|
}
|
||||||
|
return nv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
|
||||||
|
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
|
||||||
|
if ent.QueryFromContext(ctx) == nil {
|
||||||
|
qc.Op = op
|
||||||
|
ctx = ent.NewQueryContext(ctx, qc)
|
||||||
|
}
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierAll[V Value, Q interface {
|
||||||
|
sqlAll(context.Context, ...queryHook) (V, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlAll(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierCount[Q interface {
|
||||||
|
sqlCount(context.Context) (int, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlCount(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
rv, err := qr.Query(ctx, q)
|
||||||
|
if err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
vt, ok := rv.(V)
|
||||||
|
if !ok {
|
||||||
|
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
|
||||||
|
}
|
||||||
|
return vt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
|
||||||
|
sqlScan(context.Context, Q1, any) error
|
||||||
|
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
|
||||||
|
rv := reflect.ValueOf(v)
|
||||||
|
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q1)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
|
||||||
|
return rv.Elem().Interface(), nil
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
})
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
vv, err := qr.Query(ctx, rootQuery)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch rv2 := reflect.ValueOf(vv); {
|
||||||
|
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
|
||||||
|
case rv.Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2.Elem())
|
||||||
|
case rv.Elem().Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// queryHook describes an internal hook for the different sqlAll methods.
|
||||||
|
type queryHook func(context.Context, *sqlgraph.QuerySpec)
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package enttest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models"
|
||||||
|
// required by schema hooks.
|
||||||
|
_ "juwan-backend/app/notification/rpc/internal/models/runtime"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/migrate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// TestingT is the interface that is shared between
|
||||||
|
// testing.T and testing.B and used by enttest.
|
||||||
|
TestingT interface {
|
||||||
|
FailNow()
|
||||||
|
Error(...any)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Option configures client creation.
|
||||||
|
Option func(*options)
|
||||||
|
|
||||||
|
options struct {
|
||||||
|
opts []models.Option
|
||||||
|
migrateOpts []schema.MigrateOption
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// WithOptions forwards options to client creation.
|
||||||
|
func WithOptions(opts ...models.Option) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.opts = append(o.opts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMigrateOptions forwards options to auto migration.
|
||||||
|
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOptions(opts []Option) *options {
|
||||||
|
o := &options{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(o)
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open calls models.Open and auto-run migration.
|
||||||
|
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *models.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c, err := models.Open(driverName, dataSourceName, o.opts...)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient calls models.NewClient and auto-run migration.
|
||||||
|
func NewClient(t TestingT, opts ...Option) *models.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c := models.NewClient(o.opts...)
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
func migrateSchema(t TestingT, c *models.Client, o *options) {
|
||||||
|
tables, err := schema.CopyTables(migrate.Tables)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate ./schema
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package hook
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The NotificationsFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Notifications mutator.
|
||||||
|
type NotificationsFunc func(context.Context, *models.NotificationsMutation) (models.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f NotificationsFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||||
|
if mv, ok := m.(*models.NotificationsMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.NotificationsMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Condition is a hook condition function.
|
||||||
|
type Condition func(context.Context, models.Mutation) bool
|
||||||
|
|
||||||
|
// And groups conditions with the AND operator.
|
||||||
|
func And(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
if !first(ctx, m) || !second(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if !cond(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups conditions with the OR operator.
|
||||||
|
func Or(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
if first(ctx, m) || second(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not negates a given condition.
|
||||||
|
func Not(cond Condition) Condition {
|
||||||
|
return func(ctx context.Context, m models.Mutation) bool {
|
||||||
|
return !cond(ctx, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasOp is a condition testing mutation operation.
|
||||||
|
func HasOp(op models.Op) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
return m.Op().Is(op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||||
|
func HasAddedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||||
|
func HasClearedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasFields is a condition validating `.Field` on fields.
|
||||||
|
func HasFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m models.Mutation) bool {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If executes the given hook under condition.
|
||||||
|
//
|
||||||
|
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||||
|
func If(hk models.Hook, cond Condition) models.Hook {
|
||||||
|
return func(next models.Mutator) models.Mutator {
|
||||||
|
return models.MutateFunc(func(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return hk(next).Mutate(ctx, m)
|
||||||
|
}
|
||||||
|
return next.Mutate(ctx, m)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// On executes the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.On(Log, models.Delete|models.Create)
|
||||||
|
func On(hk models.Hook, op models.Op) models.Hook {
|
||||||
|
return If(hk, HasOp(op))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unless skips the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.Unless(Log, models.Update|models.UpdateOne)
|
||||||
|
func Unless(hk models.Hook, op models.Op) models.Hook {
|
||||||
|
return If(hk, Not(HasOp(op)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FixedError is a hook returning a fixed error.
|
||||||
|
func FixedError(err error) models.Hook {
|
||||||
|
return func(models.Mutator) models.Mutator {
|
||||||
|
return models.MutateFunc(func(context.Context, models.Mutation) (models.Value, error) {
|
||||||
|
return nil, err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reject returns a hook that rejects all operations that match op.
|
||||||
|
//
|
||||||
|
// func (T) Hooks() []models.Hook {
|
||||||
|
// return []models.Hook{
|
||||||
|
// Reject(models.Delete|models.Update),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
func Reject(op models.Op) models.Hook {
|
||||||
|
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||||
|
return On(hk, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chain acts as a list of hooks and is effectively immutable.
|
||||||
|
// Once created, it will always hold the same set of hooks in the same order.
|
||||||
|
type Chain struct {
|
||||||
|
hooks []models.Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewChain creates a new chain of hooks.
|
||||||
|
func NewChain(hooks ...models.Hook) Chain {
|
||||||
|
return Chain{append([]models.Hook(nil), hooks...)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hook chains the list of hooks and returns the final hook.
|
||||||
|
func (c Chain) Hook() models.Hook {
|
||||||
|
return func(mutator models.Mutator) models.Mutator {
|
||||||
|
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||||
|
mutator = c.hooks[i](mutator)
|
||||||
|
}
|
||||||
|
return mutator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append extends a chain, adding the specified hook
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Append(hooks ...models.Hook) Chain {
|
||||||
|
newHooks := make([]models.Hook, 0, len(c.hooks)+len(hooks))
|
||||||
|
newHooks = append(newHooks, c.hooks...)
|
||||||
|
newHooks = append(newHooks, hooks...)
|
||||||
|
return Chain{newHooks}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extend extends a chain, adding the specified chain
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Extend(chain Chain) Chain {
|
||||||
|
return c.Append(chain.hooks...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||||
|
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||||
|
// for the ids of each entity (table).
|
||||||
|
// Note that this option cannot be applied on tables that already exist.
|
||||||
|
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||||
|
// WithDropColumn sets the drop column option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old columns
|
||||||
|
// that were used for both fields and edges. This defaults to false.
|
||||||
|
WithDropColumn = schema.WithDropColumn
|
||||||
|
// WithDropIndex sets the drop index option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old indexes
|
||||||
|
// that were defined in the schema. This defaults to false.
|
||||||
|
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||||
|
// and therefore, it's recommended to enable this option to get more
|
||||||
|
// flexibility in the schema changes.
|
||||||
|
WithDropIndex = schema.WithDropIndex
|
||||||
|
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||||
|
WithForeignKeys = schema.WithForeignKeys
|
||||||
|
)
|
||||||
|
|
||||||
|
// Schema is the API for creating, migrating and dropping a schema.
|
||||||
|
type Schema struct {
|
||||||
|
drv dialect.Driver
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSchema creates a new schema client.
|
||||||
|
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||||
|
|
||||||
|
// Create creates all schema resources.
|
||||||
|
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, s, Tables, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates all table resources using the given schema driver.
|
||||||
|
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
|
||||||
|
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ent/migrate: %w", err)
|
||||||
|
}
|
||||||
|
return migrate.Create(ctx, tables...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||||
|
//
|
||||||
|
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
|
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// NotificationsColumns holds the columns for the "notifications" table.
|
||||||
|
NotificationsColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "user_id", Type: field.TypeInt64},
|
||||||
|
{Name: "type", Type: field.TypeString, Size: 20},
|
||||||
|
{Name: "title", Type: field.TypeString, Size: 200},
|
||||||
|
{Name: "content", Type: field.TypeString},
|
||||||
|
{Name: "read", Type: field.TypeBool, Default: false},
|
||||||
|
{Name: "link", Type: field.TypeString, Nullable: true, Size: 500},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
|
}
|
||||||
|
// NotificationsTable holds the schema information for the "notifications" table.
|
||||||
|
NotificationsTable = &schema.Table{
|
||||||
|
Name: "notifications",
|
||||||
|
Columns: NotificationsColumns,
|
||||||
|
PrimaryKey: []*schema.Column{NotificationsColumns[0]},
|
||||||
|
Indexes: []*schema.Index{
|
||||||
|
{
|
||||||
|
Name: "notifications_user_id_created_at",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{NotificationsColumns[1], NotificationsColumns[7]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "notifications_user_id_read_created_at",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{NotificationsColumns[1], NotificationsColumns[5], NotificationsColumns[7]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "notifications_user_id_type_created_at",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{NotificationsColumns[1], NotificationsColumns[2], NotificationsColumns[7]},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// Tables holds all the tables in the schema.
|
||||||
|
Tables = []*schema.Table{
|
||||||
|
NotificationsTable,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
}
|
||||||
@@ -0,0 +1,796 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/notifications"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/predicate"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Operation types.
|
||||||
|
OpCreate = ent.OpCreate
|
||||||
|
OpDelete = ent.OpDelete
|
||||||
|
OpDeleteOne = ent.OpDeleteOne
|
||||||
|
OpUpdate = ent.OpUpdate
|
||||||
|
OpUpdateOne = ent.OpUpdateOne
|
||||||
|
|
||||||
|
// Node types.
|
||||||
|
TypeNotifications = "Notifications"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NotificationsMutation represents an operation that mutates the Notifications nodes in the graph.
|
||||||
|
type NotificationsMutation struct {
|
||||||
|
config
|
||||||
|
op Op
|
||||||
|
typ string
|
||||||
|
id *int64
|
||||||
|
user_id *int64
|
||||||
|
adduser_id *int64
|
||||||
|
_type *string
|
||||||
|
title *string
|
||||||
|
content *string
|
||||||
|
read *bool
|
||||||
|
link *string
|
||||||
|
created_at *time.Time
|
||||||
|
updated_at *time.Time
|
||||||
|
clearedFields map[string]struct{}
|
||||||
|
done bool
|
||||||
|
oldValue func(context.Context) (*Notifications, error)
|
||||||
|
predicates []predicate.Notifications
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ent.Mutation = (*NotificationsMutation)(nil)
|
||||||
|
|
||||||
|
// notificationsOption allows management of the mutation configuration using functional options.
|
||||||
|
type notificationsOption func(*NotificationsMutation)
|
||||||
|
|
||||||
|
// newNotificationsMutation creates new mutation for the Notifications entity.
|
||||||
|
func newNotificationsMutation(c config, op Op, opts ...notificationsOption) *NotificationsMutation {
|
||||||
|
m := &NotificationsMutation{
|
||||||
|
config: c,
|
||||||
|
op: op,
|
||||||
|
typ: TypeNotifications,
|
||||||
|
clearedFields: make(map[string]struct{}),
|
||||||
|
}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(m)
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
// withNotificationsID sets the ID field of the mutation.
|
||||||
|
func withNotificationsID(id int64) notificationsOption {
|
||||||
|
return func(m *NotificationsMutation) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
once sync.Once
|
||||||
|
value *Notifications
|
||||||
|
)
|
||||||
|
m.oldValue = func(ctx context.Context) (*Notifications, error) {
|
||||||
|
once.Do(func() {
|
||||||
|
if m.done {
|
||||||
|
err = errors.New("querying old values post mutation is not allowed")
|
||||||
|
} else {
|
||||||
|
value, err = m.Client().Notifications.Get(ctx, id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return value, err
|
||||||
|
}
|
||||||
|
m.id = &id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// withNotifications sets the old Notifications of the mutation.
|
||||||
|
func withNotifications(node *Notifications) notificationsOption {
|
||||||
|
return func(m *NotificationsMutation) {
|
||||||
|
m.oldValue = func(context.Context) (*Notifications, error) {
|
||||||
|
return node, nil
|
||||||
|
}
|
||||||
|
m.id = &node.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||||
|
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||||
|
func (m NotificationsMutation) Client() *Client {
|
||||||
|
client := &Client{config: m.config}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||||
|
// it returns an error otherwise.
|
||||||
|
func (m NotificationsMutation) Tx() (*Tx, error) {
|
||||||
|
if _, ok := m.driver.(*txDriver); !ok {
|
||||||
|
return nil, errors.New("models: mutation is not running in a transaction")
|
||||||
|
}
|
||||||
|
tx := &Tx{config: m.config}
|
||||||
|
tx.init()
|
||||||
|
return tx, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the value of the id field. Note that this
|
||||||
|
// operation is only accepted on creation of Notifications entities.
|
||||||
|
func (m *NotificationsMutation) SetID(id int64) {
|
||||||
|
m.id = &id
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||||
|
// if it was provided to the builder or after it was returned from the database.
|
||||||
|
func (m *NotificationsMutation) ID() (id int64, exists bool) {
|
||||||
|
if m.id == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *m.id, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||||
|
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||||
|
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||||
|
// or updated by the mutation.
|
||||||
|
func (m *NotificationsMutation) IDs(ctx context.Context) ([]int64, error) {
|
||||||
|
switch {
|
||||||
|
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||||
|
id, exists := m.ID()
|
||||||
|
if exists {
|
||||||
|
return []int64{id}, nil
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
|
case m.op.Is(OpUpdate | OpDelete):
|
||||||
|
return m.Client().Notifications.Query().Where(m.predicates...).IDs(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (m *NotificationsMutation) SetUserID(i int64) {
|
||||||
|
m.user_id = &i
|
||||||
|
m.adduser_id = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserID returns the value of the "user_id" field in the mutation.
|
||||||
|
func (m *NotificationsMutation) UserID() (r int64, exists bool) {
|
||||||
|
v := m.user_id
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldUserID returns the old "user_id" field's value of the Notifications entity.
|
||||||
|
// If the Notifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *NotificationsMutation) OldUserID(ctx context.Context) (v int64, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldUserID requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.UserID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddUserID adds i to the "user_id" field.
|
||||||
|
func (m *NotificationsMutation) AddUserID(i int64) {
|
||||||
|
if m.adduser_id != nil {
|
||||||
|
*m.adduser_id += i
|
||||||
|
} else {
|
||||||
|
m.adduser_id = &i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedUserID returns the value that was added to the "user_id" field in this mutation.
|
||||||
|
func (m *NotificationsMutation) AddedUserID() (r int64, exists bool) {
|
||||||
|
v := m.adduser_id
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetUserID resets all changes to the "user_id" field.
|
||||||
|
func (m *NotificationsMutation) ResetUserID() {
|
||||||
|
m.user_id = nil
|
||||||
|
m.adduser_id = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetType sets the "type" field.
|
||||||
|
func (m *NotificationsMutation) SetType(s string) {
|
||||||
|
m._type = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetType returns the value of the "type" field in the mutation.
|
||||||
|
func (m *NotificationsMutation) GetType() (r string, exists bool) {
|
||||||
|
v := m._type
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldType returns the old "type" field's value of the Notifications entity.
|
||||||
|
// If the Notifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *NotificationsMutation) OldType(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldType is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldType requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldType: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Type, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetType resets all changes to the "type" field.
|
||||||
|
func (m *NotificationsMutation) ResetType() {
|
||||||
|
m._type = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTitle sets the "title" field.
|
||||||
|
func (m *NotificationsMutation) SetTitle(s string) {
|
||||||
|
m.title = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Title returns the value of the "title" field in the mutation.
|
||||||
|
func (m *NotificationsMutation) Title() (r string, exists bool) {
|
||||||
|
v := m.title
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldTitle returns the old "title" field's value of the Notifications entity.
|
||||||
|
// If the Notifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *NotificationsMutation) OldTitle(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldTitle is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldTitle requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldTitle: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Title, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetTitle resets all changes to the "title" field.
|
||||||
|
func (m *NotificationsMutation) ResetTitle() {
|
||||||
|
m.title = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContent sets the "content" field.
|
||||||
|
func (m *NotificationsMutation) SetContent(s string) {
|
||||||
|
m.content = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Content returns the value of the "content" field in the mutation.
|
||||||
|
func (m *NotificationsMutation) Content() (r string, exists bool) {
|
||||||
|
v := m.content
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldContent returns the old "content" field's value of the Notifications entity.
|
||||||
|
// If the Notifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *NotificationsMutation) OldContent(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldContent is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldContent requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldContent: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Content, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetContent resets all changes to the "content" field.
|
||||||
|
func (m *NotificationsMutation) ResetContent() {
|
||||||
|
m.content = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRead sets the "read" field.
|
||||||
|
func (m *NotificationsMutation) SetRead(b bool) {
|
||||||
|
m.read = &b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read returns the value of the "read" field in the mutation.
|
||||||
|
func (m *NotificationsMutation) Read() (r bool, exists bool) {
|
||||||
|
v := m.read
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldRead returns the old "read" field's value of the Notifications entity.
|
||||||
|
// If the Notifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *NotificationsMutation) OldRead(ctx context.Context) (v bool, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldRead is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldRead requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldRead: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Read, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetRead resets all changes to the "read" field.
|
||||||
|
func (m *NotificationsMutation) ResetRead() {
|
||||||
|
m.read = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLink sets the "link" field.
|
||||||
|
func (m *NotificationsMutation) SetLink(s string) {
|
||||||
|
m.link = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Link returns the value of the "link" field in the mutation.
|
||||||
|
func (m *NotificationsMutation) Link() (r string, exists bool) {
|
||||||
|
v := m.link
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldLink returns the old "link" field's value of the Notifications entity.
|
||||||
|
// If the Notifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *NotificationsMutation) OldLink(ctx context.Context) (v *string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldLink is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldLink requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldLink: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Link, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLink clears the value of the "link" field.
|
||||||
|
func (m *NotificationsMutation) ClearLink() {
|
||||||
|
m.link = nil
|
||||||
|
m.clearedFields[notifications.FieldLink] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkCleared returns if the "link" field was cleared in this mutation.
|
||||||
|
func (m *NotificationsMutation) LinkCleared() bool {
|
||||||
|
_, ok := m.clearedFields[notifications.FieldLink]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetLink resets all changes to the "link" field.
|
||||||
|
func (m *NotificationsMutation) ResetLink() {
|
||||||
|
m.link = nil
|
||||||
|
delete(m.clearedFields, notifications.FieldLink)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (m *NotificationsMutation) SetCreatedAt(t time.Time) {
|
||||||
|
m.created_at = &t
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt returns the value of the "created_at" field in the mutation.
|
||||||
|
func (m *NotificationsMutation) CreatedAt() (r time.Time, exists bool) {
|
||||||
|
v := m.created_at
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldCreatedAt returns the old "created_at" field's value of the Notifications entity.
|
||||||
|
// If the Notifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *NotificationsMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.CreatedAt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetCreatedAt resets all changes to the "created_at" field.
|
||||||
|
func (m *NotificationsMutation) ResetCreatedAt() {
|
||||||
|
m.created_at = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (m *NotificationsMutation) SetUpdatedAt(t time.Time) {
|
||||||
|
m.updated_at = &t
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt returns the value of the "updated_at" field in the mutation.
|
||||||
|
func (m *NotificationsMutation) UpdatedAt() (r time.Time, exists bool) {
|
||||||
|
v := m.updated_at
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldUpdatedAt returns the old "updated_at" field's value of the Notifications entity.
|
||||||
|
// If the Notifications object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *NotificationsMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.UpdatedAt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetUpdatedAt resets all changes to the "updated_at" field.
|
||||||
|
func (m *NotificationsMutation) ResetUpdatedAt() {
|
||||||
|
m.updated_at = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the NotificationsMutation builder.
|
||||||
|
func (m *NotificationsMutation) Where(ps ...predicate.Notifications) {
|
||||||
|
m.predicates = append(m.predicates, ps...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereP appends storage-level predicates to the NotificationsMutation builder. Using this method,
|
||||||
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||||
|
func (m *NotificationsMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||||
|
p := make([]predicate.Notifications, len(ps))
|
||||||
|
for i := range ps {
|
||||||
|
p[i] = ps[i]
|
||||||
|
}
|
||||||
|
m.Where(p...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Op returns the operation name.
|
||||||
|
func (m *NotificationsMutation) Op() Op {
|
||||||
|
return m.op
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOp allows setting the mutation operation.
|
||||||
|
func (m *NotificationsMutation) SetOp(op Op) {
|
||||||
|
m.op = op
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type returns the node type of this mutation (Notifications).
|
||||||
|
func (m *NotificationsMutation) Type() string {
|
||||||
|
return m.typ
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields returns all fields that were changed during this mutation. Note that in
|
||||||
|
// order to get all numeric fields that were incremented/decremented, call
|
||||||
|
// AddedFields().
|
||||||
|
func (m *NotificationsMutation) Fields() []string {
|
||||||
|
fields := make([]string, 0, 8)
|
||||||
|
if m.user_id != nil {
|
||||||
|
fields = append(fields, notifications.FieldUserID)
|
||||||
|
}
|
||||||
|
if m._type != nil {
|
||||||
|
fields = append(fields, notifications.FieldType)
|
||||||
|
}
|
||||||
|
if m.title != nil {
|
||||||
|
fields = append(fields, notifications.FieldTitle)
|
||||||
|
}
|
||||||
|
if m.content != nil {
|
||||||
|
fields = append(fields, notifications.FieldContent)
|
||||||
|
}
|
||||||
|
if m.read != nil {
|
||||||
|
fields = append(fields, notifications.FieldRead)
|
||||||
|
}
|
||||||
|
if m.link != nil {
|
||||||
|
fields = append(fields, notifications.FieldLink)
|
||||||
|
}
|
||||||
|
if m.created_at != nil {
|
||||||
|
fields = append(fields, notifications.FieldCreatedAt)
|
||||||
|
}
|
||||||
|
if m.updated_at != nil {
|
||||||
|
fields = append(fields, notifications.FieldUpdatedAt)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// Field returns the value of a field with the given name. The second boolean
|
||||||
|
// return value indicates that this field was not set, or was not defined in the
|
||||||
|
// schema.
|
||||||
|
func (m *NotificationsMutation) Field(name string) (ent.Value, bool) {
|
||||||
|
switch name {
|
||||||
|
case notifications.FieldUserID:
|
||||||
|
return m.UserID()
|
||||||
|
case notifications.FieldType:
|
||||||
|
return m.GetType()
|
||||||
|
case notifications.FieldTitle:
|
||||||
|
return m.Title()
|
||||||
|
case notifications.FieldContent:
|
||||||
|
return m.Content()
|
||||||
|
case notifications.FieldRead:
|
||||||
|
return m.Read()
|
||||||
|
case notifications.FieldLink:
|
||||||
|
return m.Link()
|
||||||
|
case notifications.FieldCreatedAt:
|
||||||
|
return m.CreatedAt()
|
||||||
|
case notifications.FieldUpdatedAt:
|
||||||
|
return m.UpdatedAt()
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldField returns the old value of the field from the database. An error is
|
||||||
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||||
|
// database failed.
|
||||||
|
func (m *NotificationsMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||||
|
switch name {
|
||||||
|
case notifications.FieldUserID:
|
||||||
|
return m.OldUserID(ctx)
|
||||||
|
case notifications.FieldType:
|
||||||
|
return m.OldType(ctx)
|
||||||
|
case notifications.FieldTitle:
|
||||||
|
return m.OldTitle(ctx)
|
||||||
|
case notifications.FieldContent:
|
||||||
|
return m.OldContent(ctx)
|
||||||
|
case notifications.FieldRead:
|
||||||
|
return m.OldRead(ctx)
|
||||||
|
case notifications.FieldLink:
|
||||||
|
return m.OldLink(ctx)
|
||||||
|
case notifications.FieldCreatedAt:
|
||||||
|
return m.OldCreatedAt(ctx)
|
||||||
|
case notifications.FieldUpdatedAt:
|
||||||
|
return m.OldUpdatedAt(ctx)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unknown Notifications field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetField sets the value of a field with the given name. It returns an error if
|
||||||
|
// the field is not defined in the schema, or if the type mismatched the field
|
||||||
|
// type.
|
||||||
|
func (m *NotificationsMutation) SetField(name string, value ent.Value) error {
|
||||||
|
switch name {
|
||||||
|
case notifications.FieldUserID:
|
||||||
|
v, ok := value.(int64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetUserID(v)
|
||||||
|
return nil
|
||||||
|
case notifications.FieldType:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetType(v)
|
||||||
|
return nil
|
||||||
|
case notifications.FieldTitle:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetTitle(v)
|
||||||
|
return nil
|
||||||
|
case notifications.FieldContent:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetContent(v)
|
||||||
|
return nil
|
||||||
|
case notifications.FieldRead:
|
||||||
|
v, ok := value.(bool)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetRead(v)
|
||||||
|
return nil
|
||||||
|
case notifications.FieldLink:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetLink(v)
|
||||||
|
return nil
|
||||||
|
case notifications.FieldCreatedAt:
|
||||||
|
v, ok := value.(time.Time)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetCreatedAt(v)
|
||||||
|
return nil
|
||||||
|
case notifications.FieldUpdatedAt:
|
||||||
|
v, ok := value.(time.Time)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetUpdatedAt(v)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown Notifications field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||||
|
// this mutation.
|
||||||
|
func (m *NotificationsMutation) AddedFields() []string {
|
||||||
|
var fields []string
|
||||||
|
if m.adduser_id != nil {
|
||||||
|
fields = append(fields, notifications.FieldUserID)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||||
|
// with the given name. The second boolean return value indicates that this field
|
||||||
|
// was not set, or was not defined in the schema.
|
||||||
|
func (m *NotificationsMutation) AddedField(name string) (ent.Value, bool) {
|
||||||
|
switch name {
|
||||||
|
case notifications.FieldUserID:
|
||||||
|
return m.AddedUserID()
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddField adds the value to the field with the given name. It returns an error if
|
||||||
|
// the field is not defined in the schema, or if the type mismatched the field
|
||||||
|
// type.
|
||||||
|
func (m *NotificationsMutation) AddField(name string, value ent.Value) error {
|
||||||
|
switch name {
|
||||||
|
case notifications.FieldUserID:
|
||||||
|
v, ok := value.(int64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.AddUserID(v)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown Notifications numeric field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearedFields returns all nullable fields that were cleared during this
|
||||||
|
// mutation.
|
||||||
|
func (m *NotificationsMutation) ClearedFields() []string {
|
||||||
|
var fields []string
|
||||||
|
if m.FieldCleared(notifications.FieldLink) {
|
||||||
|
fields = append(fields, notifications.FieldLink)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||||
|
// cleared in this mutation.
|
||||||
|
func (m *NotificationsMutation) FieldCleared(name string) bool {
|
||||||
|
_, ok := m.clearedFields[name]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearField clears the value of the field with the given name. It returns an
|
||||||
|
// error if the field is not defined in the schema.
|
||||||
|
func (m *NotificationsMutation) ClearField(name string) error {
|
||||||
|
switch name {
|
||||||
|
case notifications.FieldLink:
|
||||||
|
m.ClearLink()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown Notifications nullable field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetField resets all changes in the mutation for the field with the given name.
|
||||||
|
// It returns an error if the field is not defined in the schema.
|
||||||
|
func (m *NotificationsMutation) ResetField(name string) error {
|
||||||
|
switch name {
|
||||||
|
case notifications.FieldUserID:
|
||||||
|
m.ResetUserID()
|
||||||
|
return nil
|
||||||
|
case notifications.FieldType:
|
||||||
|
m.ResetType()
|
||||||
|
return nil
|
||||||
|
case notifications.FieldTitle:
|
||||||
|
m.ResetTitle()
|
||||||
|
return nil
|
||||||
|
case notifications.FieldContent:
|
||||||
|
m.ResetContent()
|
||||||
|
return nil
|
||||||
|
case notifications.FieldRead:
|
||||||
|
m.ResetRead()
|
||||||
|
return nil
|
||||||
|
case notifications.FieldLink:
|
||||||
|
m.ResetLink()
|
||||||
|
return nil
|
||||||
|
case notifications.FieldCreatedAt:
|
||||||
|
m.ResetCreatedAt()
|
||||||
|
return nil
|
||||||
|
case notifications.FieldUpdatedAt:
|
||||||
|
m.ResetUpdatedAt()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unknown Notifications field %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||||
|
func (m *NotificationsMutation) AddedEdges() []string {
|
||||||
|
edges := make([]string, 0, 0)
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||||
|
// name in this mutation.
|
||||||
|
func (m *NotificationsMutation) AddedIDs(name string) []ent.Value {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||||
|
func (m *NotificationsMutation) RemovedEdges() []string {
|
||||||
|
edges := make([]string, 0, 0)
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||||
|
// the given name in this mutation.
|
||||||
|
func (m *NotificationsMutation) RemovedIDs(name string) []ent.Value {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||||
|
func (m *NotificationsMutation) ClearedEdges() []string {
|
||||||
|
edges := make([]string, 0, 0)
|
||||||
|
return edges
|
||||||
|
}
|
||||||
|
|
||||||
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||||
|
// was cleared in this mutation.
|
||||||
|
func (m *NotificationsMutation) EdgeCleared(name string) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||||
|
// if that edge is not defined in the schema.
|
||||||
|
func (m *NotificationsMutation) ClearEdge(name string) error {
|
||||||
|
return fmt.Errorf("unknown Notifications unique edge %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||||
|
// It returns an error if the edge is not defined in the schema.
|
||||||
|
func (m *NotificationsMutation) ResetEdge(name string) error {
|
||||||
|
return fmt.Errorf("unknown Notifications edge %s", name)
|
||||||
|
}
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/notifications"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Notifications is the model entity for the Notifications schema.
|
||||||
|
type Notifications struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// UserID holds the value of the "user_id" field.
|
||||||
|
UserID int64 `json:"user_id,omitempty"`
|
||||||
|
// Type holds the value of the "type" field.
|
||||||
|
Type string `json:"type,omitempty"`
|
||||||
|
// Title holds the value of the "title" field.
|
||||||
|
Title string `json:"title,omitempty"`
|
||||||
|
// Content holds the value of the "content" field.
|
||||||
|
Content string `json:"content,omitempty"`
|
||||||
|
// Read holds the value of the "read" field.
|
||||||
|
Read bool `json:"read,omitempty"`
|
||||||
|
// Link holds the value of the "link" field.
|
||||||
|
Link *string `json:"link,omitempty"`
|
||||||
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*Notifications) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case notifications.FieldRead:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case notifications.FieldID, notifications.FieldUserID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case notifications.FieldType, notifications.FieldTitle, notifications.FieldContent, notifications.FieldLink:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case notifications.FieldCreatedAt, notifications.FieldUpdatedAt:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the Notifications fields.
|
||||||
|
func (_m *Notifications) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case notifications.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
_m.ID = int64(value.Int64)
|
||||||
|
case notifications.FieldUserID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.UserID = value.Int64
|
||||||
|
}
|
||||||
|
case notifications.FieldType:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field type", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Type = value.String
|
||||||
|
}
|
||||||
|
case notifications.FieldTitle:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field title", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Title = value.String
|
||||||
|
}
|
||||||
|
case notifications.FieldContent:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field content", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Content = value.String
|
||||||
|
}
|
||||||
|
case notifications.FieldRead:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field read", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Read = value.Bool
|
||||||
|
}
|
||||||
|
case notifications.FieldLink:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field link", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Link = new(string)
|
||||||
|
*_m.Link = value.String
|
||||||
|
}
|
||||||
|
case notifications.FieldCreatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case notifications.FieldUpdatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
_m.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the Notifications.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (_m *Notifications) Value(name string) (ent.Value, error) {
|
||||||
|
return _m.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this Notifications.
|
||||||
|
// Note that you need to call Notifications.Unwrap() before calling this method if this Notifications
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (_m *Notifications) Update() *NotificationsUpdateOne {
|
||||||
|
return NewNotificationsClient(_m.config).UpdateOne(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the Notifications entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (_m *Notifications) Unwrap() *Notifications {
|
||||||
|
_tx, ok := _m.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("models: Notifications is not a transactional entity")
|
||||||
|
}
|
||||||
|
_m.config.driver = _tx.drv
|
||||||
|
return _m
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (_m *Notifications) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("Notifications(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||||
|
builder.WriteString("user_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("type=")
|
||||||
|
builder.WriteString(_m.Type)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("title=")
|
||||||
|
builder.WriteString(_m.Title)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("content=")
|
||||||
|
builder.WriteString(_m.Content)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("read=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Read))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.Link; v != nil {
|
||||||
|
builder.WriteString("link=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationsSlice is a parsable slice of Notifications.
|
||||||
|
type NotificationsSlice []*Notifications
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package notifications
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the notifications type in the database.
|
||||||
|
Label = "notifications"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldUserID holds the string denoting the user_id field in the database.
|
||||||
|
FieldUserID = "user_id"
|
||||||
|
// FieldType holds the string denoting the type field in the database.
|
||||||
|
FieldType = "type"
|
||||||
|
// FieldTitle holds the string denoting the title field in the database.
|
||||||
|
FieldTitle = "title"
|
||||||
|
// FieldContent holds the string denoting the content field in the database.
|
||||||
|
FieldContent = "content"
|
||||||
|
// FieldRead holds the string denoting the read field in the database.
|
||||||
|
FieldRead = "read"
|
||||||
|
// FieldLink holds the string denoting the link field in the database.
|
||||||
|
FieldLink = "link"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// Table holds the table name of the notifications in the database.
|
||||||
|
Table = "notifications"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for notifications fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldUserID,
|
||||||
|
FieldType,
|
||||||
|
FieldTitle,
|
||||||
|
FieldContent,
|
||||||
|
FieldRead,
|
||||||
|
FieldLink,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// TypeValidator is a validator for the "type" field. It is called by the builders before save.
|
||||||
|
TypeValidator func(string) error
|
||||||
|
// TitleValidator is a validator for the "title" field. It is called by the builders before save.
|
||||||
|
TitleValidator func(string) error
|
||||||
|
// DefaultRead holds the default value on creation for the "read" field.
|
||||||
|
DefaultRead bool
|
||||||
|
// LinkValidator is a validator for the "link" field. It is called by the builders before save.
|
||||||
|
LinkValidator func(string) error
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the Notifications queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUserID orders the results by the user_id field.
|
||||||
|
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByType orders the results by the type field.
|
||||||
|
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByTitle orders the results by the title field.
|
||||||
|
func ByTitle(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldTitle, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByContent orders the results by the content field.
|
||||||
|
func ByContent(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldContent, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByRead orders the results by the read field.
|
||||||
|
func ByRead(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldRead, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByLink orders the results by the link field.
|
||||||
|
func ByLink(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldLink, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
@@ -0,0 +1,510 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package notifications
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/predicate"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||||
|
func UserID(v int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type applies equality check predicate on the "type" field. It's identical to TypeEQ.
|
||||||
|
func Type(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
|
||||||
|
func Title(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Content applies equality check predicate on the "content" field. It's identical to ContentEQ.
|
||||||
|
func Content(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read applies equality check predicate on the "read" field. It's identical to ReadEQ.
|
||||||
|
func Read(v bool) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldRead, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Link applies equality check predicate on the "link" field. It's identical to LinkEQ.
|
||||||
|
func Link(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||||
|
func UserIDEQ(v int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||||
|
func UserIDNEQ(v int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDIn applies the In predicate on the "user_id" field.
|
||||||
|
func UserIDIn(vs ...int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||||
|
func UserIDNotIn(vs ...int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNotIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDGT applies the GT predicate on the "user_id" field.
|
||||||
|
func UserIDGT(v int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGT(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDGTE applies the GTE predicate on the "user_id" field.
|
||||||
|
func UserIDGTE(v int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGTE(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDLT applies the LT predicate on the "user_id" field.
|
||||||
|
func UserIDLT(v int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLT(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDLTE applies the LTE predicate on the "user_id" field.
|
||||||
|
func UserIDLTE(v int64) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLTE(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeEQ applies the EQ predicate on the "type" field.
|
||||||
|
func TypeEQ(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeNEQ applies the NEQ predicate on the "type" field.
|
||||||
|
func TypeNEQ(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNEQ(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeIn applies the In predicate on the "type" field.
|
||||||
|
func TypeIn(vs ...string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldIn(FieldType, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeNotIn applies the NotIn predicate on the "type" field.
|
||||||
|
func TypeNotIn(vs ...string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNotIn(FieldType, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeGT applies the GT predicate on the "type" field.
|
||||||
|
func TypeGT(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGT(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeGTE applies the GTE predicate on the "type" field.
|
||||||
|
func TypeGTE(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGTE(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeLT applies the LT predicate on the "type" field.
|
||||||
|
func TypeLT(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLT(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeLTE applies the LTE predicate on the "type" field.
|
||||||
|
func TypeLTE(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLTE(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeContains applies the Contains predicate on the "type" field.
|
||||||
|
func TypeContains(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldContains(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeHasPrefix applies the HasPrefix predicate on the "type" field.
|
||||||
|
func TypeHasPrefix(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldHasPrefix(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeHasSuffix applies the HasSuffix predicate on the "type" field.
|
||||||
|
func TypeHasSuffix(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldHasSuffix(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeEqualFold applies the EqualFold predicate on the "type" field.
|
||||||
|
func TypeEqualFold(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEqualFold(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeContainsFold applies the ContainsFold predicate on the "type" field.
|
||||||
|
func TypeContainsFold(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldContainsFold(FieldType, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleEQ applies the EQ predicate on the "title" field.
|
||||||
|
func TitleEQ(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleNEQ applies the NEQ predicate on the "title" field.
|
||||||
|
func TitleNEQ(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNEQ(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleIn applies the In predicate on the "title" field.
|
||||||
|
func TitleIn(vs ...string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldIn(FieldTitle, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleNotIn applies the NotIn predicate on the "title" field.
|
||||||
|
func TitleNotIn(vs ...string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNotIn(FieldTitle, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleGT applies the GT predicate on the "title" field.
|
||||||
|
func TitleGT(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGT(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleGTE applies the GTE predicate on the "title" field.
|
||||||
|
func TitleGTE(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGTE(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleLT applies the LT predicate on the "title" field.
|
||||||
|
func TitleLT(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLT(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleLTE applies the LTE predicate on the "title" field.
|
||||||
|
func TitleLTE(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLTE(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleContains applies the Contains predicate on the "title" field.
|
||||||
|
func TitleContains(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldContains(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
|
||||||
|
func TitleHasPrefix(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldHasPrefix(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
|
||||||
|
func TitleHasSuffix(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldHasSuffix(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleEqualFold applies the EqualFold predicate on the "title" field.
|
||||||
|
func TitleEqualFold(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEqualFold(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
|
||||||
|
func TitleContainsFold(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldContainsFold(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentEQ applies the EQ predicate on the "content" field.
|
||||||
|
func ContentEQ(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentNEQ applies the NEQ predicate on the "content" field.
|
||||||
|
func ContentNEQ(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNEQ(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentIn applies the In predicate on the "content" field.
|
||||||
|
func ContentIn(vs ...string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldIn(FieldContent, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentNotIn applies the NotIn predicate on the "content" field.
|
||||||
|
func ContentNotIn(vs ...string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNotIn(FieldContent, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentGT applies the GT predicate on the "content" field.
|
||||||
|
func ContentGT(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGT(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentGTE applies the GTE predicate on the "content" field.
|
||||||
|
func ContentGTE(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGTE(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLT applies the LT predicate on the "content" field.
|
||||||
|
func ContentLT(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLT(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentLTE applies the LTE predicate on the "content" field.
|
||||||
|
func ContentLTE(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLTE(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentContains applies the Contains predicate on the "content" field.
|
||||||
|
func ContentContains(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldContains(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentHasPrefix applies the HasPrefix predicate on the "content" field.
|
||||||
|
func ContentHasPrefix(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldHasPrefix(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentHasSuffix applies the HasSuffix predicate on the "content" field.
|
||||||
|
func ContentHasSuffix(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldHasSuffix(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentEqualFold applies the EqualFold predicate on the "content" field.
|
||||||
|
func ContentEqualFold(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEqualFold(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContentContainsFold applies the ContainsFold predicate on the "content" field.
|
||||||
|
func ContentContainsFold(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldContainsFold(FieldContent, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadEQ applies the EQ predicate on the "read" field.
|
||||||
|
func ReadEQ(v bool) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldRead, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadNEQ applies the NEQ predicate on the "read" field.
|
||||||
|
func ReadNEQ(v bool) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNEQ(FieldRead, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkEQ applies the EQ predicate on the "link" field.
|
||||||
|
func LinkEQ(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkNEQ applies the NEQ predicate on the "link" field.
|
||||||
|
func LinkNEQ(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNEQ(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkIn applies the In predicate on the "link" field.
|
||||||
|
func LinkIn(vs ...string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldIn(FieldLink, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkNotIn applies the NotIn predicate on the "link" field.
|
||||||
|
func LinkNotIn(vs ...string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNotIn(FieldLink, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkGT applies the GT predicate on the "link" field.
|
||||||
|
func LinkGT(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGT(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkGTE applies the GTE predicate on the "link" field.
|
||||||
|
func LinkGTE(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGTE(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkLT applies the LT predicate on the "link" field.
|
||||||
|
func LinkLT(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLT(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkLTE applies the LTE predicate on the "link" field.
|
||||||
|
func LinkLTE(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLTE(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkContains applies the Contains predicate on the "link" field.
|
||||||
|
func LinkContains(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldContains(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkHasPrefix applies the HasPrefix predicate on the "link" field.
|
||||||
|
func LinkHasPrefix(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldHasPrefix(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkHasSuffix applies the HasSuffix predicate on the "link" field.
|
||||||
|
func LinkHasSuffix(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldHasSuffix(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkIsNil applies the IsNil predicate on the "link" field.
|
||||||
|
func LinkIsNil() predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldIsNull(FieldLink))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkNotNil applies the NotNil predicate on the "link" field.
|
||||||
|
func LinkNotNil() predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNotNull(FieldLink))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkEqualFold applies the EqualFold predicate on the "link" field.
|
||||||
|
func LinkEqualFold(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEqualFold(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkContainsFold applies the ContainsFold predicate on the "link" field.
|
||||||
|
func LinkContainsFold(v string) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldContainsFold(FieldLink, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.Notifications) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.Notifications) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.Notifications) predicate.Notifications {
|
||||||
|
return predicate.Notifications(sql.NotPredicates(p))
|
||||||
|
}
|
||||||
@@ -0,0 +1,349 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/notifications"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NotificationsCreate is the builder for creating a Notifications entity.
|
||||||
|
type NotificationsCreate struct {
|
||||||
|
config
|
||||||
|
mutation *NotificationsMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (_c *NotificationsCreate) SetUserID(v int64) *NotificationsCreate {
|
||||||
|
_c.mutation.SetUserID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetType sets the "type" field.
|
||||||
|
func (_c *NotificationsCreate) SetType(v string) *NotificationsCreate {
|
||||||
|
_c.mutation.SetType(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTitle sets the "title" field.
|
||||||
|
func (_c *NotificationsCreate) SetTitle(v string) *NotificationsCreate {
|
||||||
|
_c.mutation.SetTitle(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContent sets the "content" field.
|
||||||
|
func (_c *NotificationsCreate) SetContent(v string) *NotificationsCreate {
|
||||||
|
_c.mutation.SetContent(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRead sets the "read" field.
|
||||||
|
func (_c *NotificationsCreate) SetRead(v bool) *NotificationsCreate {
|
||||||
|
_c.mutation.SetRead(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableRead sets the "read" field if the given value is not nil.
|
||||||
|
func (_c *NotificationsCreate) SetNillableRead(v *bool) *NotificationsCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetRead(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLink sets the "link" field.
|
||||||
|
func (_c *NotificationsCreate) SetLink(v string) *NotificationsCreate {
|
||||||
|
_c.mutation.SetLink(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableLink sets the "link" field if the given value is not nil.
|
||||||
|
func (_c *NotificationsCreate) SetNillableLink(v *string) *NotificationsCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetLink(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (_c *NotificationsCreate) SetCreatedAt(v time.Time) *NotificationsCreate {
|
||||||
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (_c *NotificationsCreate) SetNillableCreatedAt(v *time.Time) *NotificationsCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetCreatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_c *NotificationsCreate) SetUpdatedAt(v time.Time) *NotificationsCreate {
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (_c *NotificationsCreate) SetNillableUpdatedAt(v *time.Time) *NotificationsCreate {
|
||||||
|
if v != nil {
|
||||||
|
_c.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (_c *NotificationsCreate) SetID(v int64) *NotificationsCreate {
|
||||||
|
_c.mutation.SetID(v)
|
||||||
|
return _c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the NotificationsMutation object of the builder.
|
||||||
|
func (_c *NotificationsCreate) Mutation() *NotificationsMutation {
|
||||||
|
return _c.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Notifications in the database.
|
||||||
|
func (_c *NotificationsCreate) Save(ctx context.Context) (*Notifications, error) {
|
||||||
|
_c.defaults()
|
||||||
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (_c *NotificationsCreate) SaveX(ctx context.Context) *Notifications {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *NotificationsCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *NotificationsCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := _c.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_c *NotificationsCreate) defaults() {
|
||||||
|
if _, ok := _c.mutation.Read(); !ok {
|
||||||
|
v := notifications.DefaultRead
|
||||||
|
_c.mutation.SetRead(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
|
v := notifications.DefaultCreatedAt()
|
||||||
|
_c.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
v := notifications.DefaultUpdatedAt()
|
||||||
|
_c.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_c *NotificationsCreate) check() error {
|
||||||
|
if _, ok := _c.mutation.UserID(); !ok {
|
||||||
|
return &ValidationError{Name: "user_id", err: errors.New(`models: missing required field "Notifications.user_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.GetType(); !ok {
|
||||||
|
return &ValidationError{Name: "type", err: errors.New(`models: missing required field "Notifications.type"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.GetType(); ok {
|
||||||
|
if err := notifications.TypeValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "type", err: fmt.Errorf(`models: validator failed for field "Notifications.type": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Title(); !ok {
|
||||||
|
return &ValidationError{Name: "title", err: errors.New(`models: missing required field "Notifications.title"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.Title(); ok {
|
||||||
|
if err := notifications.TitleValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "title", err: fmt.Errorf(`models: validator failed for field "Notifications.title": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Content(); !ok {
|
||||||
|
return &ValidationError{Name: "content", err: errors.New(`models: missing required field "Notifications.content"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.Read(); !ok {
|
||||||
|
return &ValidationError{Name: "read", err: errors.New(`models: missing required field "Notifications.read"`)}
|
||||||
|
}
|
||||||
|
if v, ok := _c.mutation.Link(); ok {
|
||||||
|
if err := notifications.LinkValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "link", err: fmt.Errorf(`models: validator failed for field "Notifications.link": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "Notifications.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "updated_at", err: errors.New(`models: missing required field "Notifications.updated_at"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_c *NotificationsCreate) sqlSave(ctx context.Context) (*Notifications, error) {
|
||||||
|
if err := _c.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := _c.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != _node.ID {
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int64(id)
|
||||||
|
}
|
||||||
|
_c.mutation.id = &_node.ID
|
||||||
|
_c.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_c *NotificationsCreate) createSpec() (*Notifications, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Notifications{config: _c.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(notifications.Table, sqlgraph.NewFieldSpec(notifications.FieldID, field.TypeInt64))
|
||||||
|
)
|
||||||
|
if id, ok := _c.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = id
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.UserID(); ok {
|
||||||
|
_spec.SetField(notifications.FieldUserID, field.TypeInt64, value)
|
||||||
|
_node.UserID = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.GetType(); ok {
|
||||||
|
_spec.SetField(notifications.FieldType, field.TypeString, value)
|
||||||
|
_node.Type = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Title(); ok {
|
||||||
|
_spec.SetField(notifications.FieldTitle, field.TypeString, value)
|
||||||
|
_node.Title = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Content(); ok {
|
||||||
|
_spec.SetField(notifications.FieldContent, field.TypeString, value)
|
||||||
|
_node.Content = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Read(); ok {
|
||||||
|
_spec.SetField(notifications.FieldRead, field.TypeBool, value)
|
||||||
|
_node.Read = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.Link(); ok {
|
||||||
|
_spec.SetField(notifications.FieldLink, field.TypeString, value)
|
||||||
|
_node.Link = &value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(notifications.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(notifications.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationsCreateBulk is the builder for creating many Notifications entities in bulk.
|
||||||
|
type NotificationsCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*NotificationsCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Notifications entities in the database.
|
||||||
|
func (_c *NotificationsCreateBulk) Save(ctx context.Context) ([]*Notifications, error) {
|
||||||
|
if _c.err != nil {
|
||||||
|
return nil, _c.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||||
|
nodes := make([]*Notifications, len(_c.builders))
|
||||||
|
mutators := make([]Mutator, len(_c.builders))
|
||||||
|
for i := range _c.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := _c.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*NotificationsMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int64(id)
|
||||||
|
}
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_c *NotificationsCreateBulk) SaveX(ctx context.Context) []*Notifications {
|
||||||
|
v, err := _c.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *NotificationsCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := _c.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *NotificationsCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := _c.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/notifications"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/predicate"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NotificationsDelete is the builder for deleting a Notifications entity.
|
||||||
|
type NotificationsDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *NotificationsMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the NotificationsDelete builder.
|
||||||
|
func (_d *NotificationsDelete) Where(ps ...predicate.Notifications) *NotificationsDelete {
|
||||||
|
_d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (_d *NotificationsDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *NotificationsDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := _d.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_d *NotificationsDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(notifications.Table, sqlgraph.NewFieldSpec(notifications.FieldID, field.TypeInt64))
|
||||||
|
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
_d.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationsDeleteOne is the builder for deleting a single Notifications entity.
|
||||||
|
type NotificationsDeleteOne struct {
|
||||||
|
_d *NotificationsDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the NotificationsDelete builder.
|
||||||
|
func (_d *NotificationsDeleteOne) Where(ps ...predicate.Notifications) *NotificationsDeleteOne {
|
||||||
|
_d._d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (_d *NotificationsDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := _d._d.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{notifications.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *NotificationsDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _d.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,527 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/notifications"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/predicate"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NotificationsQuery is the builder for querying Notifications entities.
|
||||||
|
type NotificationsQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []notifications.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.Notifications
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the NotificationsQuery builder.
|
||||||
|
func (_q *NotificationsQuery) Where(ps ...predicate.Notifications) *NotificationsQuery {
|
||||||
|
_q.predicates = append(_q.predicates, ps...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (_q *NotificationsQuery) Limit(limit int) *NotificationsQuery {
|
||||||
|
_q.ctx.Limit = &limit
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (_q *NotificationsQuery) Offset(offset int) *NotificationsQuery {
|
||||||
|
_q.ctx.Offset = &offset
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (_q *NotificationsQuery) Unique(unique bool) *NotificationsQuery {
|
||||||
|
_q.ctx.Unique = &unique
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (_q *NotificationsQuery) Order(o ...notifications.OrderOption) *NotificationsQuery {
|
||||||
|
_q.order = append(_q.order, o...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first Notifications entity from the query.
|
||||||
|
// Returns a *NotFoundError when no Notifications was found.
|
||||||
|
func (_q *NotificationsQuery) First(ctx context.Context) (*Notifications, error) {
|
||||||
|
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{notifications.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (_q *NotificationsQuery) FirstX(ctx context.Context) *Notifications {
|
||||||
|
node, err := _q.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first Notifications ID from the query.
|
||||||
|
// Returns a *NotFoundError when no Notifications ID was found.
|
||||||
|
func (_q *NotificationsQuery) FirstID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{notifications.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (_q *NotificationsQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single Notifications entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one Notifications entity is found.
|
||||||
|
// Returns a *NotFoundError when no Notifications entities are found.
|
||||||
|
func (_q *NotificationsQuery) Only(ctx context.Context) (*Notifications, error) {
|
||||||
|
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{notifications.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{notifications.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (_q *NotificationsQuery) OnlyX(ctx context.Context) *Notifications {
|
||||||
|
node, err := _q.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only Notifications ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one Notifications ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (_q *NotificationsQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{notifications.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{notifications.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (_q *NotificationsQuery) OnlyIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of NotificationsSlice.
|
||||||
|
func (_q *NotificationsQuery) All(ctx context.Context) ([]*Notifications, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*Notifications, *NotificationsQuery]()
|
||||||
|
return withInterceptors[[]*Notifications](ctx, _q, qr, _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (_q *NotificationsQuery) AllX(ctx context.Context) []*Notifications {
|
||||||
|
nodes, err := _q.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of Notifications IDs.
|
||||||
|
func (_q *NotificationsQuery) IDs(ctx context.Context) (ids []int64, err error) {
|
||||||
|
if _q.ctx.Unique == nil && _q.path != nil {
|
||||||
|
_q.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||||
|
if err = _q.Select(notifications.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (_q *NotificationsQuery) IDsX(ctx context.Context) []int64 {
|
||||||
|
ids, err := _q.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (_q *NotificationsQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, _q, querierCount[*NotificationsQuery](), _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (_q *NotificationsQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := _q.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (_q *NotificationsQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||||
|
switch _, err := _q.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("models: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (_q *NotificationsQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := _q.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the NotificationsQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (_q *NotificationsQuery) Clone() *NotificationsQuery {
|
||||||
|
if _q == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &NotificationsQuery{
|
||||||
|
config: _q.config,
|
||||||
|
ctx: _q.ctx.Clone(),
|
||||||
|
order: append([]notifications.OrderOption{}, _q.order...),
|
||||||
|
inters: append([]Interceptor{}, _q.inters...),
|
||||||
|
predicates: append([]predicate.Notifications{}, _q.predicates...),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: _q.sql.Clone(),
|
||||||
|
path: _q.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// UserID int64 `json:"user_id,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Notifications.Query().
|
||||||
|
// GroupBy(notifications.FieldUserID).
|
||||||
|
// Aggregate(models.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *NotificationsQuery) GroupBy(field string, fields ...string) *NotificationsGroupBy {
|
||||||
|
_q.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &NotificationsGroupBy{build: _q}
|
||||||
|
grbuild.flds = &_q.ctx.Fields
|
||||||
|
grbuild.label = notifications.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// UserID int64 `json:"user_id,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Notifications.Query().
|
||||||
|
// Select(notifications.FieldUserID).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *NotificationsQuery) Select(fields ...string) *NotificationsSelect {
|
||||||
|
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||||
|
sbuild := &NotificationsSelect{NotificationsQuery: _q}
|
||||||
|
sbuild.label = notifications.Label
|
||||||
|
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a NotificationsSelect configured with the given aggregations.
|
||||||
|
func (_q *NotificationsQuery) Aggregate(fns ...AggregateFunc) *NotificationsSelect {
|
||||||
|
return _q.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *NotificationsQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range _q.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("models: uninitialized interceptor (forgotten import models/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, _q); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range _q.ctx.Fields {
|
||||||
|
if !notifications.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _q.path != nil {
|
||||||
|
prev, err := _q.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_q.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *NotificationsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Notifications, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*Notifications{}
|
||||||
|
_spec = _q.querySpec()
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*Notifications).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &Notifications{config: _q.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *NotificationsQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := _q.querySpec()
|
||||||
|
_spec.Node.Columns = _q.ctx.Fields
|
||||||
|
if len(_q.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *NotificationsQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(notifications.Table, notifications.Columns, sqlgraph.NewFieldSpec(notifications.FieldID, field.TypeInt64))
|
||||||
|
_spec.From = _q.sql
|
||||||
|
if unique := _q.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if _q.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, notifications.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != notifications.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := _q.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := _q.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := _q.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := _q.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *NotificationsQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(_q.driver.Dialect())
|
||||||
|
t1 := builder.Table(notifications.Table)
|
||||||
|
columns := _q.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = notifications.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if _q.sql != nil {
|
||||||
|
selector = _q.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range _q.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range _q.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := _q.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := _q.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationsGroupBy is the group-by builder for Notifications entities.
|
||||||
|
type NotificationsGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *NotificationsQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (_g *NotificationsGroupBy) Aggregate(fns ...AggregateFunc) *NotificationsGroupBy {
|
||||||
|
_g.fns = append(_g.fns, fns...)
|
||||||
|
return _g
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_g *NotificationsGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||||
|
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*NotificationsQuery, *NotificationsGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_g *NotificationsGroupBy) sqlScan(ctx context.Context, root *NotificationsQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(_g.fns))
|
||||||
|
for _, fn := range _g.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||||
|
for _, f := range *_g.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationsSelect is the builder for selecting fields of Notifications entities.
|
||||||
|
type NotificationsSelect struct {
|
||||||
|
*NotificationsQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (_s *NotificationsSelect) Aggregate(fns ...AggregateFunc) *NotificationsSelect {
|
||||||
|
_s.fns = append(_s.fns, fns...)
|
||||||
|
return _s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_s *NotificationsSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||||
|
if err := _s.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*NotificationsQuery, *NotificationsSelect](ctx, _s.NotificationsQuery, _s, _s.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_s *NotificationsSelect) sqlScan(ctx context.Context, root *NotificationsQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(_s.fns))
|
||||||
|
for _, fn := range _s.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*_s.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
@@ -0,0 +1,500 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/notifications"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/predicate"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NotificationsUpdate is the builder for updating Notifications entities.
|
||||||
|
type NotificationsUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *NotificationsMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the NotificationsUpdate builder.
|
||||||
|
func (_u *NotificationsUpdate) Where(ps ...predicate.Notifications) *NotificationsUpdate {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (_u *NotificationsUpdate) SetUserID(v int64) *NotificationsUpdate {
|
||||||
|
_u.mutation.ResetUserID()
|
||||||
|
_u.mutation.SetUserID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdate) SetNillableUserID(v *int64) *NotificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetUserID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddUserID adds value to the "user_id" field.
|
||||||
|
func (_u *NotificationsUpdate) AddUserID(v int64) *NotificationsUpdate {
|
||||||
|
_u.mutation.AddUserID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetType sets the "type" field.
|
||||||
|
func (_u *NotificationsUpdate) SetType(v string) *NotificationsUpdate {
|
||||||
|
_u.mutation.SetType(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableType sets the "type" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdate) SetNillableType(v *string) *NotificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetType(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTitle sets the "title" field.
|
||||||
|
func (_u *NotificationsUpdate) SetTitle(v string) *NotificationsUpdate {
|
||||||
|
_u.mutation.SetTitle(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdate) SetNillableTitle(v *string) *NotificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetTitle(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContent sets the "content" field.
|
||||||
|
func (_u *NotificationsUpdate) SetContent(v string) *NotificationsUpdate {
|
||||||
|
_u.mutation.SetContent(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableContent sets the "content" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdate) SetNillableContent(v *string) *NotificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetContent(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRead sets the "read" field.
|
||||||
|
func (_u *NotificationsUpdate) SetRead(v bool) *NotificationsUpdate {
|
||||||
|
_u.mutation.SetRead(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableRead sets the "read" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdate) SetNillableRead(v *bool) *NotificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetRead(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLink sets the "link" field.
|
||||||
|
func (_u *NotificationsUpdate) SetLink(v string) *NotificationsUpdate {
|
||||||
|
_u.mutation.SetLink(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableLink sets the "link" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdate) SetNillableLink(v *string) *NotificationsUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetLink(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLink clears the value of the "link" field.
|
||||||
|
func (_u *NotificationsUpdate) ClearLink() *NotificationsUpdate {
|
||||||
|
_u.mutation.ClearLink()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *NotificationsUpdate) SetUpdatedAt(v time.Time) *NotificationsUpdate {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the NotificationsMutation object of the builder.
|
||||||
|
func (_u *NotificationsUpdate) Mutation() *NotificationsMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (_u *NotificationsUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
_u.defaults()
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *NotificationsUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_u *NotificationsUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *NotificationsUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := _u.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_u *NotificationsUpdate) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := notifications.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *NotificationsUpdate) check() error {
|
||||||
|
if v, ok := _u.mutation.GetType(); ok {
|
||||||
|
if err := notifications.TypeValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "type", err: fmt.Errorf(`models: validator failed for field "Notifications.type": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.Title(); ok {
|
||||||
|
if err := notifications.TitleValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "title", err: fmt.Errorf(`models: validator failed for field "Notifications.title": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.Link(); ok {
|
||||||
|
if err := notifications.LinkValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "link", err: fmt.Errorf(`models: validator failed for field "Notifications.link": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *NotificationsUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(notifications.Table, notifications.Columns, sqlgraph.NewFieldSpec(notifications.FieldID, field.TypeInt64))
|
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UserID(); ok {
|
||||||
|
_spec.SetField(notifications.FieldUserID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedUserID(); ok {
|
||||||
|
_spec.AddField(notifications.FieldUserID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.GetType(); ok {
|
||||||
|
_spec.SetField(notifications.FieldType, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Title(); ok {
|
||||||
|
_spec.SetField(notifications.FieldTitle, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Content(); ok {
|
||||||
|
_spec.SetField(notifications.FieldContent, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Read(); ok {
|
||||||
|
_spec.SetField(notifications.FieldRead, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Link(); ok {
|
||||||
|
_spec.SetField(notifications.FieldLink, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.LinkCleared() {
|
||||||
|
_spec.ClearField(notifications.FieldLink, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(notifications.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{notifications.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationsUpdateOne is the builder for updating a single Notifications entity.
|
||||||
|
type NotificationsUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *NotificationsMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (_u *NotificationsUpdateOne) SetUserID(v int64) *NotificationsUpdateOne {
|
||||||
|
_u.mutation.ResetUserID()
|
||||||
|
_u.mutation.SetUserID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdateOne) SetNillableUserID(v *int64) *NotificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetUserID(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddUserID adds value to the "user_id" field.
|
||||||
|
func (_u *NotificationsUpdateOne) AddUserID(v int64) *NotificationsUpdateOne {
|
||||||
|
_u.mutation.AddUserID(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetType sets the "type" field.
|
||||||
|
func (_u *NotificationsUpdateOne) SetType(v string) *NotificationsUpdateOne {
|
||||||
|
_u.mutation.SetType(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableType sets the "type" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdateOne) SetNillableType(v *string) *NotificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetType(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTitle sets the "title" field.
|
||||||
|
func (_u *NotificationsUpdateOne) SetTitle(v string) *NotificationsUpdateOne {
|
||||||
|
_u.mutation.SetTitle(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdateOne) SetNillableTitle(v *string) *NotificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetTitle(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContent sets the "content" field.
|
||||||
|
func (_u *NotificationsUpdateOne) SetContent(v string) *NotificationsUpdateOne {
|
||||||
|
_u.mutation.SetContent(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableContent sets the "content" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdateOne) SetNillableContent(v *string) *NotificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetContent(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRead sets the "read" field.
|
||||||
|
func (_u *NotificationsUpdateOne) SetRead(v bool) *NotificationsUpdateOne {
|
||||||
|
_u.mutation.SetRead(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableRead sets the "read" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdateOne) SetNillableRead(v *bool) *NotificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetRead(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLink sets the "link" field.
|
||||||
|
func (_u *NotificationsUpdateOne) SetLink(v string) *NotificationsUpdateOne {
|
||||||
|
_u.mutation.SetLink(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableLink sets the "link" field if the given value is not nil.
|
||||||
|
func (_u *NotificationsUpdateOne) SetNillableLink(v *string) *NotificationsUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetLink(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLink clears the value of the "link" field.
|
||||||
|
func (_u *NotificationsUpdateOne) ClearLink() *NotificationsUpdateOne {
|
||||||
|
_u.mutation.ClearLink()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *NotificationsUpdateOne) SetUpdatedAt(v time.Time) *NotificationsUpdateOne {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the NotificationsMutation object of the builder.
|
||||||
|
func (_u *NotificationsUpdateOne) Mutation() *NotificationsMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the NotificationsUpdate builder.
|
||||||
|
func (_u *NotificationsUpdateOne) Where(ps ...predicate.Notifications) *NotificationsUpdateOne {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (_u *NotificationsUpdateOne) Select(field string, fields ...string) *NotificationsUpdateOne {
|
||||||
|
_u.fields = append([]string{field}, fields...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Notifications entity.
|
||||||
|
func (_u *NotificationsUpdateOne) Save(ctx context.Context) (*Notifications, error) {
|
||||||
|
_u.defaults()
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *NotificationsUpdateOne) SaveX(ctx context.Context) *Notifications {
|
||||||
|
node, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (_u *NotificationsUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *NotificationsUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _u.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_u *NotificationsUpdateOne) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := notifications.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *NotificationsUpdateOne) check() error {
|
||||||
|
if v, ok := _u.mutation.GetType(); ok {
|
||||||
|
if err := notifications.TypeValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "type", err: fmt.Errorf(`models: validator failed for field "Notifications.type": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.Title(); ok {
|
||||||
|
if err := notifications.TitleValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "title", err: fmt.Errorf(`models: validator failed for field "Notifications.title": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := _u.mutation.Link(); ok {
|
||||||
|
if err := notifications.LinkValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "link", err: fmt.Errorf(`models: validator failed for field "Notifications.link": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *NotificationsUpdateOne) sqlSave(ctx context.Context) (_node *Notifications, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(notifications.Table, notifications.Columns, sqlgraph.NewFieldSpec(notifications.FieldID, field.TypeInt64))
|
||||||
|
id, ok := _u.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Notifications.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := _u.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, notifications.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !notifications.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != notifications.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UserID(); ok {
|
||||||
|
_spec.SetField(notifications.FieldUserID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedUserID(); ok {
|
||||||
|
_spec.AddField(notifications.FieldUserID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.GetType(); ok {
|
||||||
|
_spec.SetField(notifications.FieldType, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Title(); ok {
|
||||||
|
_spec.SetField(notifications.FieldTitle, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Content(); ok {
|
||||||
|
_spec.SetField(notifications.FieldContent, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Read(); ok {
|
||||||
|
_spec.SetField(notifications.FieldRead, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Link(); ok {
|
||||||
|
_spec.SetField(notifications.FieldLink, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.LinkCleared() {
|
||||||
|
_spec.ClearField(notifications.FieldLink, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(notifications.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
_node = &Notifications{config: _u.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{notifications.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package predicate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Notifications is the predicate function for notifications builders.
|
||||||
|
type Notifications func(*sql.Selector)
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/notifications"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models/schema"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The init function reads all schema descriptors with runtime code
|
||||||
|
// (default values, validators, hooks and policies) and stitches it
|
||||||
|
// to their package variables.
|
||||||
|
func init() {
|
||||||
|
notificationsFields := schema.Notifications{}.Fields()
|
||||||
|
_ = notificationsFields
|
||||||
|
// notificationsDescType is the schema descriptor for type field.
|
||||||
|
notificationsDescType := notificationsFields[2].Descriptor()
|
||||||
|
// notifications.TypeValidator is a validator for the "type" field. It is called by the builders before save.
|
||||||
|
notifications.TypeValidator = notificationsDescType.Validators[0].(func(string) error)
|
||||||
|
// notificationsDescTitle is the schema descriptor for title field.
|
||||||
|
notificationsDescTitle := notificationsFields[3].Descriptor()
|
||||||
|
// notifications.TitleValidator is a validator for the "title" field. It is called by the builders before save.
|
||||||
|
notifications.TitleValidator = notificationsDescTitle.Validators[0].(func(string) error)
|
||||||
|
// notificationsDescRead is the schema descriptor for read field.
|
||||||
|
notificationsDescRead := notificationsFields[5].Descriptor()
|
||||||
|
// notifications.DefaultRead holds the default value on creation for the read field.
|
||||||
|
notifications.DefaultRead = notificationsDescRead.Default.(bool)
|
||||||
|
// notificationsDescLink is the schema descriptor for link field.
|
||||||
|
notificationsDescLink := notificationsFields[6].Descriptor()
|
||||||
|
// notifications.LinkValidator is a validator for the "link" field. It is called by the builders before save.
|
||||||
|
notifications.LinkValidator = notificationsDescLink.Validators[0].(func(string) error)
|
||||||
|
// notificationsDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
notificationsDescCreatedAt := notificationsFields[7].Descriptor()
|
||||||
|
// notifications.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
notifications.DefaultCreatedAt = notificationsDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// notificationsDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
notificationsDescUpdatedAt := notificationsFields[8].Descriptor()
|
||||||
|
// notifications.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
notifications.DefaultUpdatedAt = notificationsDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// notifications.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
notifications.UpdateDefaultUpdatedAt = notificationsDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package runtime
|
||||||
|
|
||||||
|
// The schema-stitching logic is generated in juwan-backend/app/notification/rpc/internal/models/runtime.go
|
||||||
|
|
||||||
|
const (
|
||||||
|
Version = "v0.14.5" // Version of ent codegen.
|
||||||
|
Sum = "h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4=" // Sum of ent codegen.
|
||||||
|
)
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"entgo.io/ent/schema/index"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Notifications struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Notifications) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.Int64("id").Unique().Immutable(),
|
||||||
|
field.Int64("user_id"),
|
||||||
|
field.String("type").MaxLen(20),
|
||||||
|
field.String("title").MaxLen(200),
|
||||||
|
field.String("content"),
|
||||||
|
field.Bool("read").Default(false),
|
||||||
|
field.String("link").MaxLen(500).Optional().Nillable(),
|
||||||
|
field.Time("created_at").Default(time.Now).Immutable(),
|
||||||
|
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Notifications) Indexes() []ent.Index {
|
||||||
|
return []ent.Index{
|
||||||
|
index.Fields("user_id", "created_at"),
|
||||||
|
index.Fields("user_id", "read", "created_at"),
|
||||||
|
index.Fields("user_id", "type", "created_at"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Notifications) Edges() []ent.Edge {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tx is a transactional client that is created by calling Client.Tx().
|
||||||
|
type Tx struct {
|
||||||
|
config
|
||||||
|
// Notifications is the client for interacting with the Notifications builders.
|
||||||
|
Notifications *NotificationsClient
|
||||||
|
|
||||||
|
// lazily loaded.
|
||||||
|
client *Client
|
||||||
|
clientOnce sync.Once
|
||||||
|
// ctx lives for the life of the transaction. It is
|
||||||
|
// the same context used by the underlying connection.
|
||||||
|
ctx context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Committer is the interface that wraps the Commit method.
|
||||||
|
Committer interface {
|
||||||
|
Commit(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The CommitFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Committer. If f is a function with the appropriate
|
||||||
|
// signature, CommitFunc(f) is a Committer that calls f.
|
||||||
|
CommitFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// CommitHook defines the "commit middleware". A function that gets a Committer
|
||||||
|
// and returns a Committer. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Committer) ent.Committer {
|
||||||
|
// return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Commit(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
CommitHook func(Committer) Committer
|
||||||
|
)
|
||||||
|
|
||||||
|
// Commit calls f(ctx, m).
|
||||||
|
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit commits the transaction.
|
||||||
|
func (tx *Tx) Commit() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Commit()
|
||||||
|
})
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
hooks := append([]CommitHook(nil), txDriver.onCommit...)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Commit(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnCommit adds a hook to call on commit.
|
||||||
|
func (tx *Tx) OnCommit(f CommitHook) {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
txDriver.onCommit = append(txDriver.onCommit, f)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Rollbacker is the interface that wraps the Rollback method.
|
||||||
|
Rollbacker interface {
|
||||||
|
Rollback(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The RollbackFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Rollbacker. If f is a function with the appropriate
|
||||||
|
// signature, RollbackFunc(f) is a Rollbacker that calls f.
|
||||||
|
RollbackFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
|
||||||
|
// and returns a Rollbacker. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Rollbacker) ent.Rollbacker {
|
||||||
|
// return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Rollback(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
RollbackHook func(Rollbacker) Rollbacker
|
||||||
|
)
|
||||||
|
|
||||||
|
// Rollback calls f(ctx, m).
|
||||||
|
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rollback rollbacks the transaction.
|
||||||
|
func (tx *Tx) Rollback() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Rollback()
|
||||||
|
})
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
hooks := append([]RollbackHook(nil), txDriver.onRollback...)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Rollback(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnRollback adds a hook to call on rollback.
|
||||||
|
func (tx *Tx) OnRollback(f RollbackHook) {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
txDriver.onRollback = append(txDriver.onRollback, f)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client returns a Client that binds to current transaction.
|
||||||
|
func (tx *Tx) Client() *Client {
|
||||||
|
tx.clientOnce.Do(func() {
|
||||||
|
tx.client = &Client{config: tx.config}
|
||||||
|
tx.client.init()
|
||||||
|
})
|
||||||
|
return tx.client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tx *Tx) init() {
|
||||||
|
tx.Notifications = NewNotificationsClient(tx.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
|
||||||
|
// The idea is to support transactions without adding any extra code to the builders.
|
||||||
|
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
|
||||||
|
// Commit and Rollback are nop for the internal builders and the user must call one
|
||||||
|
// of them in order to commit or rollback the transaction.
|
||||||
|
//
|
||||||
|
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||||
|
// applies a query, for example: Notifications.QueryXXX(), the query will be executed
|
||||||
|
// through the driver which created this transaction.
|
||||||
|
//
|
||||||
|
// Note that txDriver is not goroutine safe.
|
||||||
|
type txDriver struct {
|
||||||
|
// the driver we started the transaction from.
|
||||||
|
drv dialect.Driver
|
||||||
|
// tx is the underlying transaction.
|
||||||
|
tx dialect.Tx
|
||||||
|
// completion hooks.
|
||||||
|
mu sync.Mutex
|
||||||
|
onCommit []CommitHook
|
||||||
|
onRollback []RollbackHook
|
||||||
|
}
|
||||||
|
|
||||||
|
// newTx creates a new transactional driver.
|
||||||
|
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
|
||||||
|
tx, err := drv.Tx(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &txDriver{tx: tx, drv: drv}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
|
||||||
|
// from the internal builders. Should be called only by the internal builders.
|
||||||
|
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
|
||||||
|
|
||||||
|
// Dialect returns the dialect of the driver we started the transaction from.
|
||||||
|
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
|
||||||
|
|
||||||
|
// Close is a nop close.
|
||||||
|
func (*txDriver) Close() error { return nil }
|
||||||
|
|
||||||
|
// Commit is a nop commit for the internal builders.
|
||||||
|
// User must call `Tx.Commit` in order to commit the transaction.
|
||||||
|
func (*txDriver) Commit() error { return nil }
|
||||||
|
|
||||||
|
// Rollback is a nop rollback for the internal builders.
|
||||||
|
// User must call `Tx.Rollback` in order to rollback the transaction.
|
||||||
|
func (*txDriver) Rollback() error { return nil }
|
||||||
|
|
||||||
|
// Exec calls tx.Exec.
|
||||||
|
func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error {
|
||||||
|
return tx.tx.Exec(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query calls tx.Query.
|
||||||
|
func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error {
|
||||||
|
return tx.tx.Query(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ dialect.Driver = (*txDriver)(nil)
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.10.1
|
||||||
|
// Source: notification.proto
|
||||||
|
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/logic"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/notification/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type NotificationServiceServer struct {
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
pb.UnimplementedNotificationServiceServer
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNotificationServiceServer(svcCtx *svc.ServiceContext) *NotificationServiceServer {
|
||||||
|
return &NotificationServiceServer{
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *NotificationServiceServer) AddNotifications(ctx context.Context, in *pb.AddNotificationsReq) (*pb.AddNotificationsResp, error) {
|
||||||
|
l := logic.NewAddNotificationsLogic(ctx, s.svcCtx)
|
||||||
|
return l.AddNotifications(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *NotificationServiceServer) UpdateNotifications(ctx context.Context, in *pb.UpdateNotificationsReq) (*pb.UpdateNotificationsResp, error) {
|
||||||
|
l := logic.NewUpdateNotificationsLogic(ctx, s.svcCtx)
|
||||||
|
return l.UpdateNotifications(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *NotificationServiceServer) DelNotifications(ctx context.Context, in *pb.DelNotificationsReq) (*pb.DelNotificationsResp, error) {
|
||||||
|
l := logic.NewDelNotificationsLogic(ctx, s.svcCtx)
|
||||||
|
return l.DelNotifications(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *NotificationServiceServer) GetNotificationsById(ctx context.Context, in *pb.GetNotificationsByIdReq) (*pb.GetNotificationsByIdResp, error) {
|
||||||
|
l := logic.NewGetNotificationsByIdLogic(ctx, s.svcCtx)
|
||||||
|
return l.GetNotificationsById(in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *NotificationServiceServer) SearchNotifications(ctx context.Context, in *pb.SearchNotificationsReq) (*pb.SearchNotificationsResp, error) {
|
||||||
|
l := logic.NewSearchNotificationsLogic(ctx, s.svcCtx)
|
||||||
|
return l.SearchNotifications(in)
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
stdsql "database/sql"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/config"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/models"
|
||||||
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||||
|
"juwan-backend/common/redisx"
|
||||||
|
"juwan-backend/common/snowflakex"
|
||||||
|
"juwan-backend/pkg/adapter"
|
||||||
|
|
||||||
|
"ariga.io/entcache"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
|
||||||
|
_ "github.com/jackc/pgx/v5/stdlib"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServiceContext struct {
|
||||||
|
Config config.Config
|
||||||
|
Snowflake snowflake.SnowflakeServiceClient
|
||||||
|
NotificationModelRW *models.Client
|
||||||
|
NotificationModelRO *models.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
rawRW, err := stdsql.Open("pgx", c.DB.Master)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
rawRO, err := stdsql.Open("pgx", c.DB.Slaves)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
RWConn := sql.OpenDB(dialect.Postgres, rawRW)
|
||||||
|
ROConn := sql.OpenDB(dialect.Postgres, rawRO)
|
||||||
|
|
||||||
|
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
||||||
|
if redisCluster == nil || err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
RWDrv := entcache.NewDriver(RWConn, entcache.TTL(30*time.Second), entcache.Levels(adapter.NewRedisCache(redisCluster.Client)))
|
||||||
|
RODrv := entcache.NewDriver(ROConn, entcache.TTL(30*time.Second), entcache.Levels(adapter.NewRedisCache(redisCluster.Client)))
|
||||||
|
return &ServiceContext{
|
||||||
|
Config: c,
|
||||||
|
NotificationModelRW: models.NewClient(models.Driver(RWDrv)),
|
||||||
|
NotificationModelRO: models.NewClient(models.Driver(RODrv)),
|
||||||
|
Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
// goctl 1.10.1
|
||||||
|
// Source: notification.proto
|
||||||
|
|
||||||
|
package notificationservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
AddNotificationsReq = pb.AddNotificationsReq
|
||||||
|
AddNotificationsResp = pb.AddNotificationsResp
|
||||||
|
DelNotificationsReq = pb.DelNotificationsReq
|
||||||
|
DelNotificationsResp = pb.DelNotificationsResp
|
||||||
|
GetNotificationsByIdReq = pb.GetNotificationsByIdReq
|
||||||
|
GetNotificationsByIdResp = pb.GetNotificationsByIdResp
|
||||||
|
Notifications = pb.Notifications
|
||||||
|
SearchNotificationsReq = pb.SearchNotificationsReq
|
||||||
|
SearchNotificationsResp = pb.SearchNotificationsResp
|
||||||
|
UpdateNotificationsReq = pb.UpdateNotificationsReq
|
||||||
|
UpdateNotificationsResp = pb.UpdateNotificationsResp
|
||||||
|
|
||||||
|
NotificationService interface {
|
||||||
|
AddNotifications(ctx context.Context, in *AddNotificationsReq, opts ...grpc.CallOption) (*AddNotificationsResp, error)
|
||||||
|
UpdateNotifications(ctx context.Context, in *UpdateNotificationsReq, opts ...grpc.CallOption) (*UpdateNotificationsResp, error)
|
||||||
|
DelNotifications(ctx context.Context, in *DelNotificationsReq, opts ...grpc.CallOption) (*DelNotificationsResp, error)
|
||||||
|
GetNotificationsById(ctx context.Context, in *GetNotificationsByIdReq, opts ...grpc.CallOption) (*GetNotificationsByIdResp, error)
|
||||||
|
SearchNotifications(ctx context.Context, in *SearchNotificationsReq, opts ...grpc.CallOption) (*SearchNotificationsResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultNotificationService struct {
|
||||||
|
cli zrpc.Client
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewNotificationService(cli zrpc.Client) NotificationService {
|
||||||
|
return &defaultNotificationService{
|
||||||
|
cli: cli,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultNotificationService) AddNotifications(ctx context.Context, in *AddNotificationsReq, opts ...grpc.CallOption) (*AddNotificationsResp, error) {
|
||||||
|
client := pb.NewNotificationServiceClient(m.cli.Conn())
|
||||||
|
return client.AddNotifications(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultNotificationService) UpdateNotifications(ctx context.Context, in *UpdateNotificationsReq, opts ...grpc.CallOption) (*UpdateNotificationsResp, error) {
|
||||||
|
client := pb.NewNotificationServiceClient(m.cli.Conn())
|
||||||
|
return client.UpdateNotifications(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultNotificationService) DelNotifications(ctx context.Context, in *DelNotificationsReq, opts ...grpc.CallOption) (*DelNotificationsResp, error) {
|
||||||
|
client := pb.NewNotificationServiceClient(m.cli.Conn())
|
||||||
|
return client.DelNotifications(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultNotificationService) GetNotificationsById(ctx context.Context, in *GetNotificationsByIdReq, opts ...grpc.CallOption) (*GetNotificationsByIdResp, error) {
|
||||||
|
client := pb.NewNotificationServiceClient(m.cli.Conn())
|
||||||
|
return client.GetNotificationsById(ctx, in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultNotificationService) SearchNotifications(ctx context.Context, in *SearchNotificationsReq, opts ...grpc.CallOption) (*SearchNotificationsResp, error) {
|
||||||
|
client := pb.NewNotificationServiceClient(m.cli.Conn())
|
||||||
|
return client.SearchNotifications(ctx, in, opts...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"juwan-backend/app/notification/rpc/internal/config"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/server"
|
||||||
|
"juwan-backend/app/notification/rpc/internal/svc"
|
||||||
|
"juwan-backend/app/notification/rpc/pb"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
|
"github.com/zeromicro/go-zero/core/service"
|
||||||
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/reflection"
|
||||||
|
)
|
||||||
|
|
||||||
|
var configFile = flag.String("f", "etc/pb.yaml", "the config file")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var c config.Config
|
||||||
|
conf.MustLoad(*configFile, &c)
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|
||||||
|
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||||
|
pb.RegisterNotificationServiceServer(grpcServer, server.NewNotificationServiceServer(ctx))
|
||||||
|
|
||||||
|
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||||
|
reflection.Register(grpcServer)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
|
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
||||||
|
s.Start()
|
||||||
|
}
|
||||||
@@ -0,0 +1,816 @@
|
|||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// protoc-gen-go v1.36.11
|
||||||
|
// protoc v7.34.1
|
||||||
|
// source: notification.proto
|
||||||
|
|
||||||
|
package pb
|
||||||
|
|
||||||
|
import (
|
||||||
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
reflect "reflect"
|
||||||
|
sync "sync"
|
||||||
|
unsafe "unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Verify that this generated code is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||||
|
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||||
|
)
|
||||||
|
|
||||||
|
// --------------------------------notifications--------------------------------
|
||||||
|
type Notifications struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
UserId int64 `protobuf:"varint,2,opt,name=userId,proto3" json:"userId,omitempty"`
|
||||||
|
Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"`
|
||||||
|
Title string `protobuf:"bytes,4,opt,name=title,proto3" json:"title,omitempty"`
|
||||||
|
Content string `protobuf:"bytes,5,opt,name=content,proto3" json:"content,omitempty"`
|
||||||
|
Read bool `protobuf:"varint,6,opt,name=read,proto3" json:"read,omitempty"`
|
||||||
|
Link string `protobuf:"bytes,7,opt,name=link,proto3" json:"link,omitempty"`
|
||||||
|
CreatedAt int64 `protobuf:"varint,8,opt,name=createdAt,proto3" json:"createdAt,omitempty"`
|
||||||
|
UpdatedAt int64 `protobuf:"varint,9,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Notifications) Reset() {
|
||||||
|
*x = Notifications{}
|
||||||
|
mi := &file_notification_proto_msgTypes[0]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Notifications) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Notifications) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *Notifications) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_notification_proto_msgTypes[0]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use Notifications.ProtoReflect.Descriptor instead.
|
||||||
|
func (*Notifications) Descriptor() ([]byte, []int) {
|
||||||
|
return file_notification_proto_rawDescGZIP(), []int{0}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Notifications) GetId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Notifications) GetUserId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.UserId
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Notifications) GetType() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Type
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Notifications) GetTitle() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Title
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Notifications) GetContent() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Content
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Notifications) GetRead() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.Read
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Notifications) GetLink() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Link
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Notifications) GetCreatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.CreatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Notifications) GetUpdatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.UpdatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddNotificationsReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
UserId int64 `protobuf:"varint,1,opt,name=userId,proto3" json:"userId,omitempty"`
|
||||||
|
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
|
||||||
|
Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"`
|
||||||
|
Content string `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"`
|
||||||
|
Link *string `protobuf:"bytes,5,opt,name=link,proto3,oneof" json:"link,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddNotificationsReq) Reset() {
|
||||||
|
*x = AddNotificationsReq{}
|
||||||
|
mi := &file_notification_proto_msgTypes[1]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddNotificationsReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*AddNotificationsReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *AddNotificationsReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_notification_proto_msgTypes[1]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use AddNotificationsReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*AddNotificationsReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_notification_proto_rawDescGZIP(), []int{1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddNotificationsReq) GetUserId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.UserId
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddNotificationsReq) GetType() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Type
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddNotificationsReq) GetTitle() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Title
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddNotificationsReq) GetContent() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Content
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddNotificationsReq) GetLink() string {
|
||||||
|
if x != nil && x.Link != nil {
|
||||||
|
return *x.Link
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddNotificationsResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddNotificationsResp) Reset() {
|
||||||
|
*x = AddNotificationsResp{}
|
||||||
|
mi := &file_notification_proto_msgTypes[2]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddNotificationsResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*AddNotificationsResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *AddNotificationsResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_notification_proto_msgTypes[2]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use AddNotificationsResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*AddNotificationsResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_notification_proto_rawDescGZIP(), []int{2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *AddNotificationsResp) GetId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateNotificationsReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
Read *bool `protobuf:"varint,2,opt,name=read,proto3,oneof" json:"read,omitempty"`
|
||||||
|
Type *string `protobuf:"bytes,3,opt,name=type,proto3,oneof" json:"type,omitempty"`
|
||||||
|
Title *string `protobuf:"bytes,4,opt,name=title,proto3,oneof" json:"title,omitempty"`
|
||||||
|
Content *string `protobuf:"bytes,5,opt,name=content,proto3,oneof" json:"content,omitempty"`
|
||||||
|
Link *string `protobuf:"bytes,6,opt,name=link,proto3,oneof" json:"link,omitempty"`
|
||||||
|
UpdatedAt *int64 `protobuf:"varint,7,opt,name=updatedAt,proto3,oneof" json:"updatedAt,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsReq) Reset() {
|
||||||
|
*x = UpdateNotificationsReq{}
|
||||||
|
mi := &file_notification_proto_msgTypes[3]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*UpdateNotificationsReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_notification_proto_msgTypes[3]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use UpdateNotificationsReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*UpdateNotificationsReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_notification_proto_rawDescGZIP(), []int{3}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsReq) GetId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsReq) GetRead() bool {
|
||||||
|
if x != nil && x.Read != nil {
|
||||||
|
return *x.Read
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsReq) GetType() string {
|
||||||
|
if x != nil && x.Type != nil {
|
||||||
|
return *x.Type
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsReq) GetTitle() string {
|
||||||
|
if x != nil && x.Title != nil {
|
||||||
|
return *x.Title
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsReq) GetContent() string {
|
||||||
|
if x != nil && x.Content != nil {
|
||||||
|
return *x.Content
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsReq) GetLink() string {
|
||||||
|
if x != nil && x.Link != nil {
|
||||||
|
return *x.Link
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsReq) GetUpdatedAt() int64 {
|
||||||
|
if x != nil && x.UpdatedAt != nil {
|
||||||
|
return *x.UpdatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateNotificationsResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsResp) Reset() {
|
||||||
|
*x = UpdateNotificationsResp{}
|
||||||
|
mi := &file_notification_proto_msgTypes[4]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*UpdateNotificationsResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *UpdateNotificationsResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_notification_proto_msgTypes[4]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use UpdateNotificationsResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*UpdateNotificationsResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_notification_proto_rawDescGZIP(), []int{4}
|
||||||
|
}
|
||||||
|
|
||||||
|
type DelNotificationsReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DelNotificationsReq) Reset() {
|
||||||
|
*x = DelNotificationsReq{}
|
||||||
|
mi := &file_notification_proto_msgTypes[5]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DelNotificationsReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DelNotificationsReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *DelNotificationsReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_notification_proto_msgTypes[5]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use DelNotificationsReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*DelNotificationsReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_notification_proto_rawDescGZIP(), []int{5}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DelNotificationsReq) GetId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type DelNotificationsResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DelNotificationsResp) Reset() {
|
||||||
|
*x = DelNotificationsResp{}
|
||||||
|
mi := &file_notification_proto_msgTypes[6]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DelNotificationsResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DelNotificationsResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *DelNotificationsResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_notification_proto_msgTypes[6]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use DelNotificationsResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*DelNotificationsResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_notification_proto_rawDescGZIP(), []int{6}
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetNotificationsByIdReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetNotificationsByIdReq) Reset() {
|
||||||
|
*x = GetNotificationsByIdReq{}
|
||||||
|
mi := &file_notification_proto_msgTypes[7]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetNotificationsByIdReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*GetNotificationsByIdReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *GetNotificationsByIdReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_notification_proto_msgTypes[7]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use GetNotificationsByIdReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*GetNotificationsByIdReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_notification_proto_rawDescGZIP(), []int{7}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetNotificationsByIdReq) GetId() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetNotificationsByIdResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Notifications *Notifications `protobuf:"bytes,1,opt,name=notifications,proto3" json:"notifications,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetNotificationsByIdResp) Reset() {
|
||||||
|
*x = GetNotificationsByIdResp{}
|
||||||
|
mi := &file_notification_proto_msgTypes[8]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetNotificationsByIdResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*GetNotificationsByIdResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *GetNotificationsByIdResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_notification_proto_msgTypes[8]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use GetNotificationsByIdResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*GetNotificationsByIdResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_notification_proto_rawDescGZIP(), []int{8}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetNotificationsByIdResp) GetNotifications() *Notifications {
|
||||||
|
if x != nil {
|
||||||
|
return x.Notifications
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchNotificationsReq struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Offset int64 `protobuf:"varint,1,opt,name=offset,proto3" json:"offset,omitempty"`
|
||||||
|
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"`
|
||||||
|
Id *int64 `protobuf:"varint,3,opt,name=id,proto3,oneof" json:"id,omitempty"`
|
||||||
|
UserId *int64 `protobuf:"varint,4,opt,name=userId,proto3,oneof" json:"userId,omitempty"`
|
||||||
|
Type *string `protobuf:"bytes,5,opt,name=type,proto3,oneof" json:"type,omitempty"`
|
||||||
|
Read *bool `protobuf:"varint,6,opt,name=read,proto3,oneof" json:"read,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsReq) Reset() {
|
||||||
|
*x = SearchNotificationsReq{}
|
||||||
|
mi := &file_notification_proto_msgTypes[9]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsReq) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*SearchNotificationsReq) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsReq) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_notification_proto_msgTypes[9]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use SearchNotificationsReq.ProtoReflect.Descriptor instead.
|
||||||
|
func (*SearchNotificationsReq) Descriptor() ([]byte, []int) {
|
||||||
|
return file_notification_proto_rawDescGZIP(), []int{9}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsReq) GetOffset() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Offset
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsReq) GetLimit() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Limit
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsReq) GetId() int64 {
|
||||||
|
if x != nil && x.Id != nil {
|
||||||
|
return *x.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsReq) GetUserId() int64 {
|
||||||
|
if x != nil && x.UserId != nil {
|
||||||
|
return *x.UserId
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsReq) GetType() string {
|
||||||
|
if x != nil && x.Type != nil {
|
||||||
|
return *x.Type
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsReq) GetRead() bool {
|
||||||
|
if x != nil && x.Read != nil {
|
||||||
|
return *x.Read
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchNotificationsResp struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Notifications []*Notifications `protobuf:"bytes,1,rep,name=notifications,proto3" json:"notifications,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsResp) Reset() {
|
||||||
|
*x = SearchNotificationsResp{}
|
||||||
|
mi := &file_notification_proto_msgTypes[10]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsResp) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*SearchNotificationsResp) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsResp) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_notification_proto_msgTypes[10]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use SearchNotificationsResp.ProtoReflect.Descriptor instead.
|
||||||
|
func (*SearchNotificationsResp) Descriptor() ([]byte, []int) {
|
||||||
|
return file_notification_proto_rawDescGZIP(), []int{10}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SearchNotificationsResp) GetNotifications() []*Notifications {
|
||||||
|
if x != nil {
|
||||||
|
return x.Notifications
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var File_notification_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
|
const file_notification_proto_rawDesc = "" +
|
||||||
|
"\n" +
|
||||||
|
"\x12notification.proto\x12\x02pb\"\xdf\x01\n" +
|
||||||
|
"\rNotifications\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" +
|
||||||
|
"\x06userId\x18\x02 \x01(\x03R\x06userId\x12\x12\n" +
|
||||||
|
"\x04type\x18\x03 \x01(\tR\x04type\x12\x14\n" +
|
||||||
|
"\x05title\x18\x04 \x01(\tR\x05title\x12\x18\n" +
|
||||||
|
"\acontent\x18\x05 \x01(\tR\acontent\x12\x12\n" +
|
||||||
|
"\x04read\x18\x06 \x01(\bR\x04read\x12\x12\n" +
|
||||||
|
"\x04link\x18\a \x01(\tR\x04link\x12\x1c\n" +
|
||||||
|
"\tcreatedAt\x18\b \x01(\x03R\tcreatedAt\x12\x1c\n" +
|
||||||
|
"\tupdatedAt\x18\t \x01(\x03R\tupdatedAt\"\x93\x01\n" +
|
||||||
|
"\x13AddNotificationsReq\x12\x16\n" +
|
||||||
|
"\x06userId\x18\x01 \x01(\x03R\x06userId\x12\x12\n" +
|
||||||
|
"\x04type\x18\x02 \x01(\tR\x04type\x12\x14\n" +
|
||||||
|
"\x05title\x18\x03 \x01(\tR\x05title\x12\x18\n" +
|
||||||
|
"\acontent\x18\x04 \x01(\tR\acontent\x12\x17\n" +
|
||||||
|
"\x04link\x18\x05 \x01(\tH\x00R\x04link\x88\x01\x01B\a\n" +
|
||||||
|
"\x05_link\"&\n" +
|
||||||
|
"\x14AddNotificationsResp\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\x03R\x02id\"\x8f\x02\n" +
|
||||||
|
"\x16UpdateNotificationsReq\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x17\n" +
|
||||||
|
"\x04read\x18\x02 \x01(\bH\x00R\x04read\x88\x01\x01\x12\x17\n" +
|
||||||
|
"\x04type\x18\x03 \x01(\tH\x01R\x04type\x88\x01\x01\x12\x19\n" +
|
||||||
|
"\x05title\x18\x04 \x01(\tH\x02R\x05title\x88\x01\x01\x12\x1d\n" +
|
||||||
|
"\acontent\x18\x05 \x01(\tH\x03R\acontent\x88\x01\x01\x12\x17\n" +
|
||||||
|
"\x04link\x18\x06 \x01(\tH\x04R\x04link\x88\x01\x01\x12!\n" +
|
||||||
|
"\tupdatedAt\x18\a \x01(\x03H\x05R\tupdatedAt\x88\x01\x01B\a\n" +
|
||||||
|
"\x05_readB\a\n" +
|
||||||
|
"\x05_typeB\b\n" +
|
||||||
|
"\x06_titleB\n" +
|
||||||
|
"\n" +
|
||||||
|
"\b_contentB\a\n" +
|
||||||
|
"\x05_linkB\f\n" +
|
||||||
|
"\n" +
|
||||||
|
"_updatedAt\"\x19\n" +
|
||||||
|
"\x17UpdateNotificationsResp\"%\n" +
|
||||||
|
"\x13DelNotificationsReq\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\x03R\x02id\"\x16\n" +
|
||||||
|
"\x14DelNotificationsResp\")\n" +
|
||||||
|
"\x17GetNotificationsByIdReq\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\x03R\x02id\"S\n" +
|
||||||
|
"\x18GetNotificationsByIdResp\x127\n" +
|
||||||
|
"\rnotifications\x18\x01 \x01(\v2\x11.pb.NotificationsR\rnotifications\"\xce\x01\n" +
|
||||||
|
"\x16SearchNotificationsReq\x12\x16\n" +
|
||||||
|
"\x06offset\x18\x01 \x01(\x03R\x06offset\x12\x14\n" +
|
||||||
|
"\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x13\n" +
|
||||||
|
"\x02id\x18\x03 \x01(\x03H\x00R\x02id\x88\x01\x01\x12\x1b\n" +
|
||||||
|
"\x06userId\x18\x04 \x01(\x03H\x01R\x06userId\x88\x01\x01\x12\x17\n" +
|
||||||
|
"\x04type\x18\x05 \x01(\tH\x02R\x04type\x88\x01\x01\x12\x17\n" +
|
||||||
|
"\x04read\x18\x06 \x01(\bH\x03R\x04read\x88\x01\x01B\x05\n" +
|
||||||
|
"\x03_idB\t\n" +
|
||||||
|
"\a_userIdB\a\n" +
|
||||||
|
"\x05_typeB\a\n" +
|
||||||
|
"\x05_read\"R\n" +
|
||||||
|
"\x17SearchNotificationsResp\x127\n" +
|
||||||
|
"\rnotifications\x18\x01 \x03(\v2\x11.pb.NotificationsR\rnotifications2\x96\x03\n" +
|
||||||
|
"\x13notificationService\x12E\n" +
|
||||||
|
"\x10AddNotifications\x12\x17.pb.AddNotificationsReq\x1a\x18.pb.AddNotificationsResp\x12N\n" +
|
||||||
|
"\x13UpdateNotifications\x12\x1a.pb.UpdateNotificationsReq\x1a\x1b.pb.UpdateNotificationsResp\x12E\n" +
|
||||||
|
"\x10DelNotifications\x12\x17.pb.DelNotificationsReq\x1a\x18.pb.DelNotificationsResp\x12Q\n" +
|
||||||
|
"\x14GetNotificationsById\x12\x1b.pb.GetNotificationsByIdReq\x1a\x1c.pb.GetNotificationsByIdResp\x12N\n" +
|
||||||
|
"\x13SearchNotifications\x12\x1a.pb.SearchNotificationsReq\x1a\x1b.pb.SearchNotificationsRespB\x06Z\x04./pbb\x06proto3"
|
||||||
|
|
||||||
|
var (
|
||||||
|
file_notification_proto_rawDescOnce sync.Once
|
||||||
|
file_notification_proto_rawDescData []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
func file_notification_proto_rawDescGZIP() []byte {
|
||||||
|
file_notification_proto_rawDescOnce.Do(func() {
|
||||||
|
file_notification_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_notification_proto_rawDesc), len(file_notification_proto_rawDesc)))
|
||||||
|
})
|
||||||
|
return file_notification_proto_rawDescData
|
||||||
|
}
|
||||||
|
|
||||||
|
var file_notification_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
|
||||||
|
var file_notification_proto_goTypes = []any{
|
||||||
|
(*Notifications)(nil), // 0: pb.Notifications
|
||||||
|
(*AddNotificationsReq)(nil), // 1: pb.AddNotificationsReq
|
||||||
|
(*AddNotificationsResp)(nil), // 2: pb.AddNotificationsResp
|
||||||
|
(*UpdateNotificationsReq)(nil), // 3: pb.UpdateNotificationsReq
|
||||||
|
(*UpdateNotificationsResp)(nil), // 4: pb.UpdateNotificationsResp
|
||||||
|
(*DelNotificationsReq)(nil), // 5: pb.DelNotificationsReq
|
||||||
|
(*DelNotificationsResp)(nil), // 6: pb.DelNotificationsResp
|
||||||
|
(*GetNotificationsByIdReq)(nil), // 7: pb.GetNotificationsByIdReq
|
||||||
|
(*GetNotificationsByIdResp)(nil), // 8: pb.GetNotificationsByIdResp
|
||||||
|
(*SearchNotificationsReq)(nil), // 9: pb.SearchNotificationsReq
|
||||||
|
(*SearchNotificationsResp)(nil), // 10: pb.SearchNotificationsResp
|
||||||
|
}
|
||||||
|
var file_notification_proto_depIdxs = []int32{
|
||||||
|
0, // 0: pb.GetNotificationsByIdResp.notifications:type_name -> pb.Notifications
|
||||||
|
0, // 1: pb.SearchNotificationsResp.notifications:type_name -> pb.Notifications
|
||||||
|
1, // 2: pb.notificationService.AddNotifications:input_type -> pb.AddNotificationsReq
|
||||||
|
3, // 3: pb.notificationService.UpdateNotifications:input_type -> pb.UpdateNotificationsReq
|
||||||
|
5, // 4: pb.notificationService.DelNotifications:input_type -> pb.DelNotificationsReq
|
||||||
|
7, // 5: pb.notificationService.GetNotificationsById:input_type -> pb.GetNotificationsByIdReq
|
||||||
|
9, // 6: pb.notificationService.SearchNotifications:input_type -> pb.SearchNotificationsReq
|
||||||
|
2, // 7: pb.notificationService.AddNotifications:output_type -> pb.AddNotificationsResp
|
||||||
|
4, // 8: pb.notificationService.UpdateNotifications:output_type -> pb.UpdateNotificationsResp
|
||||||
|
6, // 9: pb.notificationService.DelNotifications:output_type -> pb.DelNotificationsResp
|
||||||
|
8, // 10: pb.notificationService.GetNotificationsById:output_type -> pb.GetNotificationsByIdResp
|
||||||
|
10, // 11: pb.notificationService.SearchNotifications:output_type -> pb.SearchNotificationsResp
|
||||||
|
7, // [7:12] is the sub-list for method output_type
|
||||||
|
2, // [2:7] is the sub-list for method input_type
|
||||||
|
2, // [2:2] is the sub-list for extension type_name
|
||||||
|
2, // [2:2] is the sub-list for extension extendee
|
||||||
|
0, // [0:2] is the sub-list for field type_name
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { file_notification_proto_init() }
|
||||||
|
func file_notification_proto_init() {
|
||||||
|
if File_notification_proto != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
file_notification_proto_msgTypes[1].OneofWrappers = []any{}
|
||||||
|
file_notification_proto_msgTypes[3].OneofWrappers = []any{}
|
||||||
|
file_notification_proto_msgTypes[9].OneofWrappers = []any{}
|
||||||
|
type x struct{}
|
||||||
|
out := protoimpl.TypeBuilder{
|
||||||
|
File: protoimpl.DescBuilder{
|
||||||
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
|
RawDescriptor: unsafe.Slice(unsafe.StringData(file_notification_proto_rawDesc), len(file_notification_proto_rawDesc)),
|
||||||
|
NumEnums: 0,
|
||||||
|
NumMessages: 11,
|
||||||
|
NumExtensions: 0,
|
||||||
|
NumServices: 1,
|
||||||
|
},
|
||||||
|
GoTypes: file_notification_proto_goTypes,
|
||||||
|
DependencyIndexes: file_notification_proto_depIdxs,
|
||||||
|
MessageInfos: file_notification_proto_msgTypes,
|
||||||
|
}.Build()
|
||||||
|
File_notification_proto = out.File
|
||||||
|
file_notification_proto_goTypes = nil
|
||||||
|
file_notification_proto_depIdxs = nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,273 @@
|
|||||||
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-grpc v1.6.1
|
||||||
|
// - protoc v7.34.1
|
||||||
|
// source: notification.proto
|
||||||
|
|
||||||
|
package pb
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
codes "google.golang.org/grpc/codes"
|
||||||
|
status "google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
// Requires gRPC-Go v1.64.0 or later.
|
||||||
|
const _ = grpc.SupportPackageIsVersion9
|
||||||
|
|
||||||
|
const (
|
||||||
|
NotificationService_AddNotifications_FullMethodName = "/pb.notificationService/AddNotifications"
|
||||||
|
NotificationService_UpdateNotifications_FullMethodName = "/pb.notificationService/UpdateNotifications"
|
||||||
|
NotificationService_DelNotifications_FullMethodName = "/pb.notificationService/DelNotifications"
|
||||||
|
NotificationService_GetNotificationsById_FullMethodName = "/pb.notificationService/GetNotificationsById"
|
||||||
|
NotificationService_SearchNotifications_FullMethodName = "/pb.notificationService/SearchNotifications"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NotificationServiceClient is the client API for NotificationService service.
|
||||||
|
//
|
||||||
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||||
|
type NotificationServiceClient interface {
|
||||||
|
AddNotifications(ctx context.Context, in *AddNotificationsReq, opts ...grpc.CallOption) (*AddNotificationsResp, error)
|
||||||
|
UpdateNotifications(ctx context.Context, in *UpdateNotificationsReq, opts ...grpc.CallOption) (*UpdateNotificationsResp, error)
|
||||||
|
DelNotifications(ctx context.Context, in *DelNotificationsReq, opts ...grpc.CallOption) (*DelNotificationsResp, error)
|
||||||
|
GetNotificationsById(ctx context.Context, in *GetNotificationsByIdReq, opts ...grpc.CallOption) (*GetNotificationsByIdResp, error)
|
||||||
|
SearchNotifications(ctx context.Context, in *SearchNotificationsReq, opts ...grpc.CallOption) (*SearchNotificationsResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type notificationServiceClient struct {
|
||||||
|
cc grpc.ClientConnInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNotificationServiceClient(cc grpc.ClientConnInterface) NotificationServiceClient {
|
||||||
|
return ¬ificationServiceClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *notificationServiceClient) AddNotifications(ctx context.Context, in *AddNotificationsReq, opts ...grpc.CallOption) (*AddNotificationsResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(AddNotificationsResp)
|
||||||
|
err := c.cc.Invoke(ctx, NotificationService_AddNotifications_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *notificationServiceClient) UpdateNotifications(ctx context.Context, in *UpdateNotificationsReq, opts ...grpc.CallOption) (*UpdateNotificationsResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(UpdateNotificationsResp)
|
||||||
|
err := c.cc.Invoke(ctx, NotificationService_UpdateNotifications_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *notificationServiceClient) DelNotifications(ctx context.Context, in *DelNotificationsReq, opts ...grpc.CallOption) (*DelNotificationsResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(DelNotificationsResp)
|
||||||
|
err := c.cc.Invoke(ctx, NotificationService_DelNotifications_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *notificationServiceClient) GetNotificationsById(ctx context.Context, in *GetNotificationsByIdReq, opts ...grpc.CallOption) (*GetNotificationsByIdResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(GetNotificationsByIdResp)
|
||||||
|
err := c.cc.Invoke(ctx, NotificationService_GetNotificationsById_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *notificationServiceClient) SearchNotifications(ctx context.Context, in *SearchNotificationsReq, opts ...grpc.CallOption) (*SearchNotificationsResp, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(SearchNotificationsResp)
|
||||||
|
err := c.cc.Invoke(ctx, NotificationService_SearchNotifications_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationServiceServer is the server API for NotificationService service.
|
||||||
|
// All implementations must embed UnimplementedNotificationServiceServer
|
||||||
|
// for forward compatibility.
|
||||||
|
type NotificationServiceServer interface {
|
||||||
|
AddNotifications(context.Context, *AddNotificationsReq) (*AddNotificationsResp, error)
|
||||||
|
UpdateNotifications(context.Context, *UpdateNotificationsReq) (*UpdateNotificationsResp, error)
|
||||||
|
DelNotifications(context.Context, *DelNotificationsReq) (*DelNotificationsResp, error)
|
||||||
|
GetNotificationsById(context.Context, *GetNotificationsByIdReq) (*GetNotificationsByIdResp, error)
|
||||||
|
SearchNotifications(context.Context, *SearchNotificationsReq) (*SearchNotificationsResp, error)
|
||||||
|
mustEmbedUnimplementedNotificationServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedNotificationServiceServer must be embedded to have
|
||||||
|
// forward compatible implementations.
|
||||||
|
//
|
||||||
|
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||||
|
// pointer dereference when methods are called.
|
||||||
|
type UnimplementedNotificationServiceServer struct{}
|
||||||
|
|
||||||
|
func (UnimplementedNotificationServiceServer) AddNotifications(context.Context, *AddNotificationsReq) (*AddNotificationsResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method AddNotifications not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedNotificationServiceServer) UpdateNotifications(context.Context, *UpdateNotificationsReq) (*UpdateNotificationsResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method UpdateNotifications not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedNotificationServiceServer) DelNotifications(context.Context, *DelNotificationsReq) (*DelNotificationsResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method DelNotifications not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedNotificationServiceServer) GetNotificationsById(context.Context, *GetNotificationsByIdReq) (*GetNotificationsByIdResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method GetNotificationsById not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedNotificationServiceServer) SearchNotifications(context.Context, *SearchNotificationsReq) (*SearchNotificationsResp, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method SearchNotifications not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedNotificationServiceServer) mustEmbedUnimplementedNotificationServiceServer() {}
|
||||||
|
func (UnimplementedNotificationServiceServer) testEmbeddedByValue() {}
|
||||||
|
|
||||||
|
// UnsafeNotificationServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||||
|
// Use of this interface is not recommended, as added methods to NotificationServiceServer will
|
||||||
|
// result in compilation errors.
|
||||||
|
type UnsafeNotificationServiceServer interface {
|
||||||
|
mustEmbedUnimplementedNotificationServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterNotificationServiceServer(s grpc.ServiceRegistrar, srv NotificationServiceServer) {
|
||||||
|
// If the following call panics, it indicates UnimplementedNotificationServiceServer was
|
||||||
|
// embedded by pointer and is nil. This will cause panics if an
|
||||||
|
// unimplemented method is ever invoked, so we test this at initialization
|
||||||
|
// time to prevent it from happening at runtime later due to I/O.
|
||||||
|
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||||
|
t.testEmbeddedByValue()
|
||||||
|
}
|
||||||
|
s.RegisterService(&NotificationService_ServiceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _NotificationService_AddNotifications_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(AddNotificationsReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(NotificationServiceServer).AddNotifications(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: NotificationService_AddNotifications_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(NotificationServiceServer).AddNotifications(ctx, req.(*AddNotificationsReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _NotificationService_UpdateNotifications_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(UpdateNotificationsReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(NotificationServiceServer).UpdateNotifications(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: NotificationService_UpdateNotifications_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(NotificationServiceServer).UpdateNotifications(ctx, req.(*UpdateNotificationsReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _NotificationService_DelNotifications_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(DelNotificationsReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(NotificationServiceServer).DelNotifications(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: NotificationService_DelNotifications_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(NotificationServiceServer).DelNotifications(ctx, req.(*DelNotificationsReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _NotificationService_GetNotificationsById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetNotificationsByIdReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(NotificationServiceServer).GetNotificationsById(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: NotificationService_GetNotificationsById_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(NotificationServiceServer).GetNotificationsById(ctx, req.(*GetNotificationsByIdReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _NotificationService_SearchNotifications_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SearchNotificationsReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(NotificationServiceServer).SearchNotifications(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: NotificationService_SearchNotifications_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(NotificationServiceServer).SearchNotifications(ctx, req.(*SearchNotificationsReq))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationService_ServiceDesc is the grpc.ServiceDesc for NotificationService service.
|
||||||
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
|
// and not to be introspected or modified (even as a copy)
|
||||||
|
var NotificationService_ServiceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "pb.notificationService",
|
||||||
|
HandlerType: (*NotificationServiceServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "AddNotifications",
|
||||||
|
Handler: _NotificationService_AddNotifications_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "UpdateNotifications",
|
||||||
|
Handler: _NotificationService_UpdateNotifications_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "DelNotifications",
|
||||||
|
Handler: _NotificationService_DelNotifications_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetNotificationsById",
|
||||||
|
Handler: _NotificationService_GetNotificationsById_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "SearchNotifications",
|
||||||
|
Handler: _NotificationService_SearchNotifications_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{},
|
||||||
|
Metadata: "notification.proto",
|
||||||
|
}
|
||||||
@@ -123,6 +123,8 @@ services:
|
|||||||
condition: service_started
|
condition: service_started
|
||||||
dispute-api:
|
dispute-api:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
|
notification-api:
|
||||||
|
condition: service_started
|
||||||
|
|
||||||
ratelimit:
|
ratelimit:
|
||||||
image: envoyproxy/ratelimit:05c08d03
|
image: envoyproxy/ratelimit:05c08d03
|
||||||
@@ -291,6 +293,19 @@ services:
|
|||||||
snowflake:
|
snowflake:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
|
|
||||||
|
notification-rpc:
|
||||||
|
image: juwan/notification-rpc:dev
|
||||||
|
container_name: juwan-notification-rpc
|
||||||
|
restart: unless-stopped
|
||||||
|
env_file: .env
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
redis:
|
||||||
|
condition: service_healthy
|
||||||
|
snowflake:
|
||||||
|
condition: service_started
|
||||||
|
|
||||||
# ==================== API 层 ====================
|
# ==================== API 层 ====================
|
||||||
users-api:
|
users-api:
|
||||||
image: juwan/users-api:dev
|
image: juwan/users-api:dev
|
||||||
@@ -427,6 +442,17 @@ services:
|
|||||||
order-rpc:
|
order-rpc:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
|
|
||||||
|
notification-api:
|
||||||
|
image: juwan/notification-api:dev
|
||||||
|
container_name: juwan-notification-api
|
||||||
|
restart: unless-stopped
|
||||||
|
env_file: .env
|
||||||
|
ports:
|
||||||
|
- "18812:8888"
|
||||||
|
depends_on:
|
||||||
|
notification-rpc:
|
||||||
|
condition: service_started
|
||||||
|
|
||||||
# ==================== MQ ====================
|
# ==================== MQ ====================
|
||||||
email-mq:
|
email-mq:
|
||||||
image: juwan/email-mq:dev
|
image: juwan/email-mq:dev
|
||||||
|
|||||||
@@ -371,6 +371,12 @@ static_resources:
|
|||||||
cluster: dispute_api_cluster
|
cluster: dispute_api_cluster
|
||||||
timeout: 30s
|
timeout: 30s
|
||||||
|
|
||||||
|
- match:
|
||||||
|
prefix: /api/v1/notifications
|
||||||
|
route:
|
||||||
|
cluster: notification_api_cluster
|
||||||
|
timeout: 30s
|
||||||
|
|
||||||
- match:
|
- match:
|
||||||
prefix: /
|
prefix: /
|
||||||
direct_response:
|
direct_response:
|
||||||
@@ -818,6 +824,20 @@ static_resources:
|
|||||||
address: dispute-api
|
address: dispute-api
|
||||||
port_value: 8888
|
port_value: 8888
|
||||||
|
|
||||||
|
- name: notification_api_cluster
|
||||||
|
connect_timeout: 2s
|
||||||
|
type: STRICT_DNS
|
||||||
|
lb_policy: ROUND_ROBIN
|
||||||
|
load_assignment:
|
||||||
|
cluster_name: notification_api_cluster
|
||||||
|
endpoints:
|
||||||
|
- lb_endpoints:
|
||||||
|
- endpoint:
|
||||||
|
address:
|
||||||
|
socket_address:
|
||||||
|
address: notification-api
|
||||||
|
port_value: 8888
|
||||||
|
|
||||||
- name: authz_adapter_cluster
|
- name: authz_adapter_cluster
|
||||||
connect_timeout: 0.5s
|
connect_timeout: 0.5s
|
||||||
type: STRICT_DNS
|
type: STRICT_DNS
|
||||||
|
|||||||
+31
-30
@@ -1,40 +1,41 @@
|
|||||||
syntax = "v1"
|
syntax = "v1"
|
||||||
|
|
||||||
import "common.api"
|
import "common.api"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
PathId {
|
PathId {
|
||||||
Id int64 `path:"id"`
|
Id int64 `path:"id"`
|
||||||
}
|
}
|
||||||
Notification {
|
Notification {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Read bool `json:"read"`
|
Read bool `json:"read"`
|
||||||
Link string `json:"link,optional"`
|
Link string `json:"link,optional"`
|
||||||
CreatedAt string `json:"createdAt"`
|
CreatedAt string `json:"createdAt"`
|
||||||
}
|
}
|
||||||
|
NotificationListResp {
|
||||||
NotificationListResp {
|
Items []Notification `json:"items"`
|
||||||
Items []Notification `json:"items"`
|
Meta PageMeta `json:"meta"`
|
||||||
Meta PageMeta `json:"meta"`
|
}
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@server(
|
@server (
|
||||||
prefix: api/v1
|
prefix: api/v1
|
||||||
group: notification
|
group: notification
|
||||||
)
|
)
|
||||||
service notifi-api {
|
service notifi-api {
|
||||||
@doc "获取通知列表"
|
@doc "获取通知列表"
|
||||||
@handler ListNotifications
|
@handler ListNotifications
|
||||||
get /notifications (PageReq) returns (NotificationListResp)
|
get /notifications (PageReq) returns (NotificationListResp)
|
||||||
|
|
||||||
@doc "标记已读"
|
@doc "标记已读"
|
||||||
@handler ReadNotification
|
@handler ReadNotification
|
||||||
put /notifications/:id/read (PathId) returns (EmptyResp)
|
put /notifications/:id/read (PathId) returns (EmptyResp)
|
||||||
|
|
||||||
|
@doc "全部已读"
|
||||||
|
@handler ReadAllNotifications
|
||||||
|
put /notifications/read-all (EmptyResp) returns (EmptyResp)
|
||||||
|
}
|
||||||
|
|
||||||
@doc "全部已读"
|
|
||||||
@handler ReadAllNotifications
|
|
||||||
put /notifications/read-all (EmptyResp) returns (EmptyResp)
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option go_package ="./pb";
|
||||||
|
|
||||||
|
package pb;
|
||||||
|
|
||||||
|
// ------------------------------------
|
||||||
|
// Messages
|
||||||
|
// ------------------------------------
|
||||||
|
|
||||||
|
//--------------------------------notifications--------------------------------
|
||||||
|
message Notifications {
|
||||||
|
int64 id = 1;
|
||||||
|
int64 userId = 2;
|
||||||
|
string type = 3;
|
||||||
|
string title = 4;
|
||||||
|
string content = 5;
|
||||||
|
bool read = 6;
|
||||||
|
string link = 7;
|
||||||
|
int64 createdAt = 8;
|
||||||
|
int64 updatedAt = 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
message AddNotificationsReq {
|
||||||
|
int64 userId = 1;
|
||||||
|
string type = 2;
|
||||||
|
string title = 3;
|
||||||
|
string content = 4;
|
||||||
|
optional string link = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message AddNotificationsResp {
|
||||||
|
int64 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateNotificationsReq {
|
||||||
|
int64 id = 1;
|
||||||
|
optional bool read = 2;
|
||||||
|
optional string type = 3;
|
||||||
|
optional string title = 4;
|
||||||
|
optional string content = 5;
|
||||||
|
optional string link = 6;
|
||||||
|
optional int64 updatedAt = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateNotificationsResp {
|
||||||
|
}
|
||||||
|
|
||||||
|
message DelNotificationsReq {
|
||||||
|
int64 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DelNotificationsResp {
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetNotificationsByIdReq {
|
||||||
|
int64 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetNotificationsByIdResp {
|
||||||
|
Notifications notifications = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SearchNotificationsReq {
|
||||||
|
int64 offset = 1;
|
||||||
|
int64 limit = 2;
|
||||||
|
optional int64 id = 3;
|
||||||
|
optional int64 userId = 4;
|
||||||
|
optional string type = 5;
|
||||||
|
optional bool read = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SearchNotificationsResp {
|
||||||
|
repeated Notifications notifications = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------
|
||||||
|
// Rpc Func
|
||||||
|
// ------------------------------------
|
||||||
|
|
||||||
|
service notificationService {
|
||||||
|
rpc AddNotifications(AddNotificationsReq) returns (AddNotificationsResp);
|
||||||
|
rpc UpdateNotifications(UpdateNotificationsReq) returns (UpdateNotificationsResp);
|
||||||
|
rpc DelNotifications(DelNotificationsReq) returns (DelNotificationsResp);
|
||||||
|
rpc GetNotificationsById(GetNotificationsByIdReq) returns (GetNotificationsByIdResp);
|
||||||
|
rpc SearchNotifications(SearchNotificationsReq) returns (SearchNotificationsResp);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
CREATE TABLE notifications
|
||||||
|
(
|
||||||
|
id BIGINT PRIMARY KEY,
|
||||||
|
user_id BIGINT NOT NULL,
|
||||||
|
type VARCHAR(20) NOT NULL,
|
||||||
|
title VARCHAR(200) NOT NULL,
|
||||||
|
content TEXT NOT NULL,
|
||||||
|
read BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
link VARCHAR(500),
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
|
|
||||||
|
CONSTRAINT chk_notification_type CHECK (type IN ('order', 'community', 'system'))
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_notifications_user_created ON notifications (user_id, created_at DESC);
|
||||||
|
CREATE INDEX idx_notifications_user_read_created ON notifications (user_id, read, created_at DESC);
|
||||||
|
CREATE INDEX idx_notifications_user_type_created ON notifications (user_id, type, created_at DESC);
|
||||||
|
|
||||||
|
CREATE TRIGGER trigger_notifications_updated_at
|
||||||
|
BEFORE UPDATE
|
||||||
|
ON notifications
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION update_updated_at_column();
|
||||||
Reference in New Issue
Block a user