feat: 添加争议微服务,支持订单争议流程
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"juwan-backend/app/dispute/api/internal/config"
|
||||
"juwan-backend/app/dispute/api/internal/handler"
|
||||
"juwan-backend/app/dispute/api/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/dispute-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,16 @@
|
||||
Name: dispute-api
|
||||
Host: 0.0.0.0
|
||||
Port: 8888
|
||||
|
||||
Prometheus:
|
||||
Host: 0.0.0.0
|
||||
Port: 4001
|
||||
Path: /metrics
|
||||
|
||||
# ===== DEV CONFIG =====
|
||||
DisputeRpcConf:
|
||||
Endpoints:
|
||||
- dispute-rpc:8080
|
||||
OrderRpcConf:
|
||||
Endpoints:
|
||||
- order-rpc:8080
|
||||
@@ -0,0 +1,12 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
DisputeRpcConf zrpc.RpcClientConf
|
||||
OrderRpcConf zrpc.RpcClientConf
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package dispute
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/dispute/api/internal/logic/dispute"
|
||||
"juwan-backend/app/dispute/api/internal/svc"
|
||||
"juwan-backend/app/dispute/api/internal/types"
|
||||
)
|
||||
|
||||
// 申诉
|
||||
func AppealDisputeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AppealReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := dispute.NewAppealDisputeLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AppealDispute(&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 dispute
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/dispute/api/internal/logic/dispute"
|
||||
"juwan-backend/app/dispute/api/internal/svc"
|
||||
"juwan-backend/app/dispute/api/internal/types"
|
||||
)
|
||||
|
||||
// 发起争议
|
||||
func CreateDisputeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateDisputeReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := dispute.NewCreateDisputeLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateDispute(&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 dispute
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/dispute/api/internal/logic/dispute"
|
||||
"juwan-backend/app/dispute/api/internal/svc"
|
||||
"juwan-backend/app/dispute/api/internal/types"
|
||||
)
|
||||
|
||||
// 获取订单争议
|
||||
func GetOrderDisputeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DisputePathId
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := dispute.NewGetOrderDisputeLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetOrderDispute(&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 dispute
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/dispute/api/internal/logic/dispute"
|
||||
"juwan-backend/app/dispute/api/internal/svc"
|
||||
"juwan-backend/app/dispute/api/internal/types"
|
||||
)
|
||||
|
||||
// 获取争议列表
|
||||
func ListDisputesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DisputeListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := dispute.NewListDisputesLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ListDisputes(&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 dispute
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/dispute/api/internal/logic/dispute"
|
||||
"juwan-backend/app/dispute/api/internal/svc"
|
||||
"juwan-backend/app/dispute/api/internal/types"
|
||||
)
|
||||
|
||||
// 回应争议
|
||||
func RespondDisputeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DisputeResponseReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := dispute.NewRespondDisputeLogic(r.Context(), svcCtx)
|
||||
resp, err := l.RespondDispute(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
dispute "juwan-backend/app/dispute/api/internal/handler/dispute"
|
||||
"juwan-backend/app/dispute/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: "/disputes",
|
||||
Handler: dispute.ListDisputesHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 申诉
|
||||
Method: http.MethodPost,
|
||||
Path: "/disputes/:id/appeal",
|
||||
Handler: dispute.AppealDisputeHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 回应争议
|
||||
Method: http.MethodPost,
|
||||
Path: "/disputes/:id/response",
|
||||
Handler: dispute.RespondDisputeHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 获取订单争议
|
||||
Method: http.MethodGet,
|
||||
Path: "/orders/:id/dispute",
|
||||
Handler: dispute.GetOrderDisputeHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 发起争议
|
||||
Method: http.MethodPost,
|
||||
Path: "/orders/:id/dispute",
|
||||
Handler: dispute.CreateDisputeHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/v1"),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package dispute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/dispute/api/internal/svc"
|
||||
"juwan-backend/app/dispute/api/internal/types"
|
||||
"juwan-backend/app/dispute/rpc/disputeservice"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AppealDisputeLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 申诉
|
||||
func NewAppealDisputeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppealDisputeLogic {
|
||||
return &AppealDisputeLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AppealDisputeLogic) AppealDispute(req *types.AppealReq) (resp *types.EmptyResp, err error) {
|
||||
uid, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if req.Reason == "" {
|
||||
return nil, errors.New("reason is required")
|
||||
}
|
||||
|
||||
disputeResp, err := l.svcCtx.DisputeRpc.GetDisputesById(l.ctx, &disputeservice.GetDisputesByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
d := disputeResp.GetDisputes()
|
||||
if d == nil {
|
||||
return nil, errors.New("dispute not found")
|
||||
}
|
||||
if uid != d.GetInitiatorId() && uid != d.GetRespondentId() {
|
||||
return nil, errors.New("not a participant of this dispute")
|
||||
}
|
||||
if d.GetStatus() != "resolved" {
|
||||
return nil, errors.New("dispute status does not allow appeal")
|
||||
}
|
||||
|
||||
status := "appealed"
|
||||
now := time.Now().Unix()
|
||||
_, err = l.svcCtx.DisputeRpc.UpdateDisputes(l.ctx, &disputeservice.UpdateDisputesReq{
|
||||
Id: req.Id,
|
||||
Status: &status,
|
||||
AppealReason: &req.Reason,
|
||||
AppealedAt: &now,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.DisputeRpc.AddDisputeTimeline(l.ctx, &disputeservice.AddDisputeTimelineReq{
|
||||
DisputeId: req.Id,
|
||||
EventType: "appealed",
|
||||
ActorId: uid,
|
||||
ActorName: actorName(uid),
|
||||
Details: detailsJSON(map[string]any{"reason": req.Reason}),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.EmptyResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package dispute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/dispute/api/internal/svc"
|
||||
"juwan-backend/app/dispute/api/internal/types"
|
||||
"juwan-backend/app/dispute/rpc/disputeservice"
|
||||
"juwan-backend/app/order/rpc/orderservice"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateDisputeLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 发起争议
|
||||
func NewCreateDisputeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateDisputeLogic {
|
||||
return &CreateDisputeLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateDisputeLogic) CreateDispute(req *types.CreateDisputeReq) (resp *types.EmptyResp, err error) {
|
||||
uid, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if req.Reason == "" {
|
||||
return nil, errors.New("reason is required")
|
||||
}
|
||||
|
||||
orderResp, err := l.svcCtx.OrderRpc.GetOrdersById(l.ctx, &orderservice.GetOrdersByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
order := orderResp.GetOrders()
|
||||
if order == nil {
|
||||
return nil, errors.New("order not found")
|
||||
}
|
||||
if order.GetStatus() != "in_progress" && order.GetStatus() != "pending_close" {
|
||||
return nil, errors.New("order status does not allow disputes")
|
||||
}
|
||||
|
||||
var respondentID int64
|
||||
if uid == order.GetConsumerId() {
|
||||
respondentID = order.GetPlayerId()
|
||||
} else if uid == order.GetPlayerId() {
|
||||
respondentID = order.GetConsumerId()
|
||||
} else {
|
||||
return nil, errors.New("not a participant of this order")
|
||||
}
|
||||
|
||||
existing, err := l.svcCtx.DisputeRpc.SearchDisputes(l.ctx, &disputeservice.SearchDisputesReq{
|
||||
Offset: 0,
|
||||
Limit: 1,
|
||||
OrderId: &req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(existing.GetDisputes()) > 0 {
|
||||
return nil, errors.New("dispute already exists")
|
||||
}
|
||||
|
||||
created, err := l.svcCtx.DisputeRpc.AddDisputes(l.ctx, &disputeservice.AddDisputesReq{
|
||||
OrderId: req.Id,
|
||||
InitiatorId: uid,
|
||||
InitiatorName: actorName(uid),
|
||||
RespondentId: respondentID,
|
||||
Reason: req.Reason,
|
||||
Evidence: req.Evidence,
|
||||
Status: "open",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.DisputeRpc.AddDisputeTimeline(l.ctx, &disputeservice.AddDisputeTimelineReq{
|
||||
DisputeId: created.GetId(),
|
||||
EventType: "created",
|
||||
ActorId: uid,
|
||||
ActorName: actorName(uid),
|
||||
Details: detailsJSON(map[string]any{"reason": req.Reason, "evidence": req.Evidence}),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
status := "disputed"
|
||||
oldStatus := order.GetStatus()
|
||||
metadata := detailsJSON(map[string]any{"disputeId": created.GetId()})
|
||||
_, err = l.svcCtx.OrderRpc.UpdateOrders(l.ctx, &orderservice.UpdateOrdersReq{
|
||||
Id: req.Id,
|
||||
Status: &status,
|
||||
UpdatedAt: &now,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = l.svcCtx.OrderRpc.AddOrderStateLogs(l.ctx, &orderservice.AddOrderStateLogsReq{
|
||||
OrderId: req.Id,
|
||||
FromStatus: &oldStatus,
|
||||
ToStatus: status,
|
||||
Action: "open_dispute",
|
||||
ActorId: uid,
|
||||
ActorRole: "user",
|
||||
Metadata: &metadata,
|
||||
CreatedAt: &now,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.EmptyResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package dispute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/dispute/api/internal/svc"
|
||||
"juwan-backend/app/dispute/api/internal/types"
|
||||
"juwan-backend/app/dispute/rpc/disputeservice"
|
||||
"juwan-backend/app/order/rpc/orderservice"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetOrderDisputeLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 获取订单争议
|
||||
func NewGetOrderDisputeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderDisputeLogic {
|
||||
return &GetOrderDisputeLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetOrderDisputeLogic) GetOrderDispute(req *types.DisputePathId) (resp *types.Dispute, err error) {
|
||||
uid, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
orderResp, err := l.svcCtx.OrderRpc.GetOrdersById(l.ctx, &orderservice.GetOrdersByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
order := orderResp.GetOrders()
|
||||
if order == nil {
|
||||
return nil, errors.New("order not found")
|
||||
}
|
||||
if uid != order.GetConsumerId() && uid != order.GetPlayerId() {
|
||||
return nil, errors.New("not a participant of this order")
|
||||
}
|
||||
|
||||
out, err := l.svcCtx.DisputeRpc.SearchDisputes(l.ctx, &disputeservice.SearchDisputesReq{
|
||||
Offset: 0,
|
||||
Limit: 1,
|
||||
OrderId: &req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(out.GetDisputes()) == 0 {
|
||||
return nil, errors.New("dispute not found")
|
||||
}
|
||||
dispute := toAPIDispute(out.GetDisputes()[0])
|
||||
|
||||
return &dispute, nil
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package dispute
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/dispute/api/internal/types"
|
||||
"juwan-backend/app/dispute/rpc/disputeservice"
|
||||
)
|
||||
|
||||
func formatUnix(ts int64) string {
|
||||
if ts <= 0 {
|
||||
return ""
|
||||
}
|
||||
return time.Unix(ts, 0).UTC().Format(time.RFC3339)
|
||||
}
|
||||
|
||||
func toAPIDispute(d *disputeservice.Disputes) types.Dispute {
|
||||
return types.Dispute{
|
||||
Id: d.GetId(),
|
||||
OrderId: d.GetOrderId(),
|
||||
InitiatorId: d.GetInitiatorId(),
|
||||
InitiatorName: d.GetInitiatorName(),
|
||||
RespondentId: d.GetRespondentId(),
|
||||
Reason: d.GetReason(),
|
||||
Evidence: d.GetEvidence(),
|
||||
Status: d.GetStatus(),
|
||||
Result: d.GetResult(),
|
||||
RespondentReason: d.GetRespondentReason(),
|
||||
RespondentEvidence: d.GetRespondentEvidence(),
|
||||
AppealReason: d.GetAppealReason(),
|
||||
AppealedAt: formatUnix(d.GetAppealedAt()),
|
||||
ResolvedBy: d.GetResolvedBy(),
|
||||
ResolvedAt: formatUnix(d.GetResolvedAt()),
|
||||
CreatedAt: formatUnix(d.GetCreatedAt()),
|
||||
UpdatedAt: formatUnix(d.GetUpdatedAt()),
|
||||
}
|
||||
}
|
||||
|
||||
func mergeDisputes(groups ...[]*disputeservice.Disputes) []*disputeservice.Disputes {
|
||||
seen := make(map[int64]struct{})
|
||||
items := make([]*disputeservice.Disputes, 0)
|
||||
for _, group := range groups {
|
||||
for _, item := range group {
|
||||
if item == nil {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[item.GetId()]; ok {
|
||||
continue
|
||||
}
|
||||
seen[item.GetId()] = struct{}{}
|
||||
items = append(items, item)
|
||||
}
|
||||
}
|
||||
sort.Slice(items, func(i, j int) bool {
|
||||
if items[i].GetCreatedAt() == items[j].GetCreatedAt() {
|
||||
return items[i].GetId() > items[j].GetId()
|
||||
}
|
||||
return items[i].GetCreatedAt() > items[j].GetCreatedAt()
|
||||
})
|
||||
return items
|
||||
}
|
||||
|
||||
func paginateDisputes(items []*disputeservice.Disputes, offset int64, limit int64) []*disputeservice.Disputes {
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
start := int(offset)
|
||||
if start >= len(items) {
|
||||
return []*disputeservice.Disputes{}
|
||||
}
|
||||
end := start + int(limit)
|
||||
if end > len(items) {
|
||||
end = len(items)
|
||||
}
|
||||
return items[start:end]
|
||||
}
|
||||
|
||||
func actorName(uid int64) string {
|
||||
return strconv.FormatInt(uid, 10)
|
||||
}
|
||||
|
||||
func detailsJSON(values map[string]any) string {
|
||||
if len(values) == 0 {
|
||||
return "{}"
|
||||
}
|
||||
b, err := json.Marshal(values)
|
||||
if err != nil {
|
||||
return "{}"
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package dispute
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/dispute/api/internal/svc"
|
||||
"juwan-backend/app/dispute/api/internal/types"
|
||||
"juwan-backend/app/dispute/rpc/disputeservice"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ListDisputesLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 获取争议列表
|
||||
func NewListDisputesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDisputesLogic {
|
||||
return &ListDisputesLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListDisputesLogic) ListDisputes(req *types.DisputeListReq) (resp *types.DisputeListResp, err error) {
|
||||
uid, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
limit := req.Limit
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
var status *string
|
||||
if req.Status != "" {
|
||||
status = &req.Status
|
||||
}
|
||||
|
||||
initiated, err := l.svcCtx.DisputeRpc.SearchDisputes(l.ctx, &disputeservice.SearchDisputesReq{
|
||||
Offset: 0,
|
||||
Limit: 100,
|
||||
InitiatorId: &uid,
|
||||
Status: status,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
responded, err := l.svcCtx.DisputeRpc.SearchDisputes(l.ctx, &disputeservice.SearchDisputesReq{
|
||||
Offset: 0,
|
||||
Limit: 100,
|
||||
RespondentId: &uid,
|
||||
Status: status,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := mergeDisputes(initiated.GetDisputes(), responded.GetDisputes())
|
||||
page := paginateDisputes(items, req.Offset, limit)
|
||||
out := make([]types.Dispute, 0, len(page))
|
||||
for _, item := range page {
|
||||
out = append(out, toAPIDispute(item))
|
||||
}
|
||||
|
||||
return &types.DisputeListResp{
|
||||
Items: out,
|
||||
Meta: types.PageMeta{
|
||||
Total: int64(len(items)),
|
||||
Offset: req.Offset,
|
||||
Limit: limit,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package dispute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/dispute/api/internal/svc"
|
||||
"juwan-backend/app/dispute/api/internal/types"
|
||||
"juwan-backend/app/dispute/rpc/disputeservice"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type RespondDisputeLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 回应争议
|
||||
func NewRespondDisputeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RespondDisputeLogic {
|
||||
return &RespondDisputeLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RespondDisputeLogic) RespondDispute(req *types.DisputeResponseReq) (resp *types.EmptyResp, err error) {
|
||||
uid, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if req.Reason == "" {
|
||||
return nil, errors.New("reason is required")
|
||||
}
|
||||
|
||||
disputeResp, err := l.svcCtx.DisputeRpc.GetDisputesById(l.ctx, &disputeservice.GetDisputesByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
d := disputeResp.GetDisputes()
|
||||
if d == nil {
|
||||
return nil, errors.New("dispute not found")
|
||||
}
|
||||
if uid != d.GetRespondentId() {
|
||||
return nil, errors.New("not the respondent of this dispute")
|
||||
}
|
||||
if d.GetStatus() != "open" {
|
||||
return nil, errors.New("dispute status does not allow response")
|
||||
}
|
||||
|
||||
status := "reviewing"
|
||||
_, err = l.svcCtx.DisputeRpc.UpdateDisputes(l.ctx, &disputeservice.UpdateDisputesReq{
|
||||
Id: req.Id,
|
||||
Status: &status,
|
||||
RespondentReason: &req.Reason,
|
||||
RespondentEvidence: req.Evidence,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.DisputeRpc.AddDisputeTimeline(l.ctx, &disputeservice.AddDisputeTimelineReq{
|
||||
DisputeId: req.Id,
|
||||
EventType: "response",
|
||||
ActorId: uid,
|
||||
ActorName: actorName(uid),
|
||||
Details: detailsJSON(map[string]any{"reason": req.Reason, "evidence": req.Evidence}),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.EmptyResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"juwan-backend/app/dispute/api/internal/config"
|
||||
"juwan-backend/app/dispute/rpc/disputeservice"
|
||||
"juwan-backend/app/order/rpc/orderservice"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DisputeRpc disputeservice.DisputeService
|
||||
OrderRpc orderservice.OrderService
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DisputeRpc: disputeservice.NewDisputeService(zrpc.MustNewClient(c.DisputeRpcConf)),
|
||||
OrderRpc: orderservice.NewOrderService(zrpc.MustNewClient(c.OrderRpcConf)),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
|
||||
package types
|
||||
|
||||
type AppealReq struct {
|
||||
DisputePathId
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
type CreateDisputeReq struct {
|
||||
DisputePathId
|
||||
Reason string `json:"reason"`
|
||||
Evidence []string `json:"evidence"`
|
||||
}
|
||||
|
||||
type Dispute struct {
|
||||
Id int64 `json:"id"`
|
||||
OrderId int64 `json:"orderId"`
|
||||
InitiatorId int64 `json:"initiatorId"`
|
||||
InitiatorName string `json:"initiatorName"`
|
||||
RespondentId int64 `json:"respondentId"`
|
||||
Reason string `json:"reason"`
|
||||
Evidence []string `json:"evidence"`
|
||||
Status string `json:"status"`
|
||||
Result string `json:"result,optional"`
|
||||
RespondentReason string `json:"respondentReason,optional"`
|
||||
RespondentEvidence []string `json:"respondentEvidence"`
|
||||
AppealReason string `json:"appealReason,optional"`
|
||||
AppealedAt string `json:"appealedAt,optional"`
|
||||
ResolvedBy int64 `json:"resolvedBy,optional"`
|
||||
ResolvedAt string `json:"resolvedAt,optional"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type DisputeListReq struct {
|
||||
PageReq
|
||||
Status string `form:"status,optional"`
|
||||
}
|
||||
|
||||
type DisputeListResp struct {
|
||||
Items []Dispute `json:"items"`
|
||||
Meta PageMeta `json:"meta"`
|
||||
}
|
||||
|
||||
type DisputePathId struct {
|
||||
Id int64 `path:"id"`
|
||||
}
|
||||
|
||||
type DisputeResponseReq struct {
|
||||
DisputePathId
|
||||
Reason string `json:"reason"`
|
||||
Evidence []string `json:"evidence"`
|
||||
}
|
||||
|
||||
type EmptyResp struct {
|
||||
}
|
||||
|
||||
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 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,92 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
// Source: dispute.proto
|
||||
|
||||
package disputeservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
AddDisputeTimelineReq = pb.AddDisputeTimelineReq
|
||||
AddDisputeTimelineResp = pb.AddDisputeTimelineResp
|
||||
AddDisputesReq = pb.AddDisputesReq
|
||||
AddDisputesResp = pb.AddDisputesResp
|
||||
DelDisputesReq = pb.DelDisputesReq
|
||||
DelDisputesResp = pb.DelDisputesResp
|
||||
DisputeTimeline = pb.DisputeTimeline
|
||||
Disputes = pb.Disputes
|
||||
GetDisputesByIdReq = pb.GetDisputesByIdReq
|
||||
GetDisputesByIdResp = pb.GetDisputesByIdResp
|
||||
SearchDisputeTimelineReq = pb.SearchDisputeTimelineReq
|
||||
SearchDisputeTimelineResp = pb.SearchDisputeTimelineResp
|
||||
SearchDisputesReq = pb.SearchDisputesReq
|
||||
SearchDisputesResp = pb.SearchDisputesResp
|
||||
UpdateDisputesReq = pb.UpdateDisputesReq
|
||||
UpdateDisputesResp = pb.UpdateDisputesResp
|
||||
|
||||
DisputeService interface {
|
||||
// -----------------------disputes-----------------------
|
||||
AddDisputes(ctx context.Context, in *AddDisputesReq, opts ...grpc.CallOption) (*AddDisputesResp, error)
|
||||
UpdateDisputes(ctx context.Context, in *UpdateDisputesReq, opts ...grpc.CallOption) (*UpdateDisputesResp, error)
|
||||
DelDisputes(ctx context.Context, in *DelDisputesReq, opts ...grpc.CallOption) (*DelDisputesResp, error)
|
||||
GetDisputesById(ctx context.Context, in *GetDisputesByIdReq, opts ...grpc.CallOption) (*GetDisputesByIdResp, error)
|
||||
SearchDisputes(ctx context.Context, in *SearchDisputesReq, opts ...grpc.CallOption) (*SearchDisputesResp, error)
|
||||
// -----------------------disputeTimeline-----------------------
|
||||
AddDisputeTimeline(ctx context.Context, in *AddDisputeTimelineReq, opts ...grpc.CallOption) (*AddDisputeTimelineResp, error)
|
||||
SearchDisputeTimeline(ctx context.Context, in *SearchDisputeTimelineReq, opts ...grpc.CallOption) (*SearchDisputeTimelineResp, error)
|
||||
}
|
||||
|
||||
defaultDisputeService struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewDisputeService(cli zrpc.Client) DisputeService {
|
||||
return &defaultDisputeService{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------disputes-----------------------
|
||||
func (m *defaultDisputeService) AddDisputes(ctx context.Context, in *AddDisputesReq, opts ...grpc.CallOption) (*AddDisputesResp, error) {
|
||||
client := pb.NewDisputeServiceClient(m.cli.Conn())
|
||||
return client.AddDisputes(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultDisputeService) UpdateDisputes(ctx context.Context, in *UpdateDisputesReq, opts ...grpc.CallOption) (*UpdateDisputesResp, error) {
|
||||
client := pb.NewDisputeServiceClient(m.cli.Conn())
|
||||
return client.UpdateDisputes(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultDisputeService) DelDisputes(ctx context.Context, in *DelDisputesReq, opts ...grpc.CallOption) (*DelDisputesResp, error) {
|
||||
client := pb.NewDisputeServiceClient(m.cli.Conn())
|
||||
return client.DelDisputes(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultDisputeService) GetDisputesById(ctx context.Context, in *GetDisputesByIdReq, opts ...grpc.CallOption) (*GetDisputesByIdResp, error) {
|
||||
client := pb.NewDisputeServiceClient(m.cli.Conn())
|
||||
return client.GetDisputesById(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultDisputeService) SearchDisputes(ctx context.Context, in *SearchDisputesReq, opts ...grpc.CallOption) (*SearchDisputesResp, error) {
|
||||
client := pb.NewDisputeServiceClient(m.cli.Conn())
|
||||
return client.SearchDisputes(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// -----------------------disputeTimeline-----------------------
|
||||
func (m *defaultDisputeService) AddDisputeTimeline(ctx context.Context, in *AddDisputeTimelineReq, opts ...grpc.CallOption) (*AddDisputeTimelineResp, error) {
|
||||
client := pb.NewDisputeServiceClient(m.cli.Conn())
|
||||
return client.AddDisputeTimeline(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultDisputeService) SearchDisputeTimeline(ctx context.Context, in *SearchDisputeTimelineReq, opts ...grpc.CallOption) (*SearchDisputeTimelineResp, error) {
|
||||
client := pb.NewDisputeServiceClient(m.cli.Conn())
|
||||
return client.SearchDisputeTimeline(ctx, in, opts...)
|
||||
}
|
||||
@@ -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,60 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/svc"
|
||||
"juwan-backend/app/dispute/rpc/pb"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddDisputeTimelineLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddDisputeTimelineLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddDisputeTimelineLogic {
|
||||
return &AddDisputeTimelineLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------disputeTimeline-----------------------
|
||||
func (l *AddDisputeTimelineLogic) AddDisputeTimeline(in *pb.AddDisputeTimelineReq) (*pb.AddDisputeTimelineResp, error) {
|
||||
if in.GetDisputeId() <= 0 {
|
||||
return nil, errors.New("disputeId is required")
|
||||
}
|
||||
if in.GetEventType() == "" {
|
||||
return nil, errors.New("eventType is required")
|
||||
}
|
||||
|
||||
details, err := parseJSONMap(in.GetDetails())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||
if err != nil {
|
||||
return nil, errors.New("create dispute timeline id failed")
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.DisputeModelRW.DisputeTimeline.Create().
|
||||
SetID(idResp.Id).
|
||||
SetDisputeID(in.GetDisputeId()).
|
||||
SetEventType(in.GetEventType()).
|
||||
SetActorID(in.GetActorId()).
|
||||
SetActorName(in.GetActorName()).
|
||||
SetDetails(details).
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("addDisputeTimeline err: %v", err)
|
||||
return nil, errors.New("add dispute timeline failed")
|
||||
}
|
||||
|
||||
return &pb.AddDisputeTimelineResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/svc"
|
||||
"juwan-backend/app/dispute/rpc/pb"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddDisputesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddDisputesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddDisputesLogic {
|
||||
return &AddDisputesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------disputes-----------------------
|
||||
func (l *AddDisputesLogic) AddDisputes(in *pb.AddDisputesReq) (*pb.AddDisputesResp, error) {
|
||||
if in.GetOrderId() <= 0 {
|
||||
return nil, errors.New("orderId is required")
|
||||
}
|
||||
if in.GetInitiatorId() <= 0 {
|
||||
return nil, errors.New("initiatorId is required")
|
||||
}
|
||||
if in.GetRespondentId() <= 0 {
|
||||
return nil, errors.New("respondentId is required")
|
||||
}
|
||||
if in.GetReason() == "" {
|
||||
return nil, errors.New("reason is required")
|
||||
}
|
||||
|
||||
status := in.GetStatus()
|
||||
if status == "" {
|
||||
status = "open"
|
||||
}
|
||||
|
||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||
if err != nil {
|
||||
return nil, errors.New("create dispute id failed")
|
||||
}
|
||||
|
||||
created, err := l.svcCtx.DisputeModelRW.Disputes.Create().
|
||||
SetID(idResp.Id).
|
||||
SetOrderID(in.GetOrderId()).
|
||||
SetInitiatorID(in.GetInitiatorId()).
|
||||
SetInitiatorName(in.GetInitiatorName()).
|
||||
SetRespondentID(in.GetRespondentId()).
|
||||
SetReason(in.GetReason()).
|
||||
SetEvidence(toTextArray(in.GetEvidence())).
|
||||
SetStatus(status).
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("addDisputes err: %v", err)
|
||||
return nil, errors.New("add dispute failed")
|
||||
}
|
||||
|
||||
return &pb.AddDisputesResp{Id: created.ID}, nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/svc"
|
||||
"juwan-backend/app/dispute/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelDisputesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelDisputesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelDisputesLogic {
|
||||
return &DelDisputesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelDisputesLogic) DelDisputes(in *pb.DelDisputesReq) (*pb.DelDisputesResp, error) {
|
||||
err := l.svcCtx.DisputeModelRW.Disputes.DeleteOneID(in.GetId()).Exec(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("delDisputes err: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.DelDisputesResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/svc"
|
||||
"juwan-backend/app/dispute/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetDisputesByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetDisputesByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDisputesByIdLogic {
|
||||
return &GetDisputesByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetDisputesByIdLogic) GetDisputesById(in *pb.GetDisputesByIdReq) (*pb.GetDisputesByIdResp, error) {
|
||||
d, err := l.svcCtx.DisputeModelRO.Disputes.Get(l.ctx, in.GetId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.GetDisputesByIdResp{Disputes: entDisputeToPb(d)}, nil
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/models"
|
||||
"juwan-backend/app/dispute/rpc/pb"
|
||||
"juwan-backend/pkg/types"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
func toTextArray(s []string) types.TextArray {
|
||||
if len(s) == 0 {
|
||||
return types.TextArray{Valid: true}
|
||||
}
|
||||
return types.TextArray{
|
||||
Elements: s,
|
||||
Dims: []pgtype.ArrayDimension{{Length: int32(len(s)), LowerBound: 1}},
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
|
||||
func parseJSONMap(v string) (map[string]any, error) {
|
||||
if v == "" {
|
||||
return map[string]any{}, nil
|
||||
}
|
||||
var result map[string]any
|
||||
if err := json.Unmarshal([]byte(v), &result); err != nil {
|
||||
return nil, errors.New("invalid json value")
|
||||
}
|
||||
if result == nil {
|
||||
return map[string]any{}, nil
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func entDisputeToPb(d *models.Disputes) *pb.Disputes {
|
||||
out := &pb.Disputes{
|
||||
Id: d.ID,
|
||||
OrderId: d.OrderID,
|
||||
InitiatorId: d.InitiatorID,
|
||||
InitiatorName: d.InitiatorName,
|
||||
RespondentId: d.RespondentID,
|
||||
Reason: d.Reason,
|
||||
Evidence: d.Evidence.Elements,
|
||||
Status: d.Status,
|
||||
RespondentEvidence: d.RespondentEvidence.Elements,
|
||||
CreatedAt: d.CreatedAt.Unix(),
|
||||
UpdatedAt: d.UpdatedAt.Unix(),
|
||||
}
|
||||
if d.Result != nil {
|
||||
out.Result = *d.Result
|
||||
}
|
||||
if d.RespondentReason != nil {
|
||||
out.RespondentReason = *d.RespondentReason
|
||||
}
|
||||
if d.AppealReason != nil {
|
||||
out.AppealReason = *d.AppealReason
|
||||
}
|
||||
if d.AppealedAt != nil {
|
||||
out.AppealedAt = d.AppealedAt.Unix()
|
||||
}
|
||||
if d.ResolvedBy != nil {
|
||||
out.ResolvedBy = *d.ResolvedBy
|
||||
}
|
||||
if d.ResolvedAt != nil {
|
||||
out.ResolvedAt = d.ResolvedAt.Unix()
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func entDisputeTimelineToPb(t *models.DisputeTimeline) *pb.DisputeTimeline {
|
||||
details := "{}"
|
||||
if t.Details != nil {
|
||||
if b, err := json.Marshal(t.Details); err == nil {
|
||||
details = string(b)
|
||||
}
|
||||
}
|
||||
return &pb.DisputeTimeline{
|
||||
Id: t.ID,
|
||||
DisputeId: t.DisputeID,
|
||||
EventType: t.EventType,
|
||||
ActorId: t.ActorID,
|
||||
ActorName: t.ActorName,
|
||||
Details: details,
|
||||
CreatedAt: t.CreatedAt.Unix(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputetimeline"
|
||||
"juwan-backend/app/dispute/rpc/internal/svc"
|
||||
"juwan-backend/app/dispute/rpc/pb"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchDisputeTimelineLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchDisputeTimelineLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchDisputeTimelineLogic {
|
||||
return &SearchDisputeTimelineLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchDisputeTimelineLogic) SearchDisputeTimeline(in *pb.SearchDisputeTimelineReq) (*pb.SearchDisputeTimelineResp, 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.DisputeModelRO.DisputeTimeline.Query()
|
||||
if in.DisputeId != nil {
|
||||
query = query.Where(disputetimeline.DisputeIDEQ(in.GetDisputeId()))
|
||||
}
|
||||
|
||||
list, err := query.
|
||||
Order(disputetimeline.ByCreatedAt(sql.OrderAsc()), disputetimeline.ByID(sql.OrderAsc())).
|
||||
Offset(int(offset)).
|
||||
Limit(int(limit)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("searchDisputeTimeline err: %v", err)
|
||||
return nil, errors.New("search dispute timeline failed")
|
||||
}
|
||||
|
||||
out := make([]*pb.DisputeTimeline, len(list))
|
||||
for i, item := range list {
|
||||
out[i] = entDisputeTimelineToPb(item)
|
||||
}
|
||||
|
||||
return &pb.SearchDisputeTimelineResp{Timeline: out}, nil
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputes"
|
||||
"juwan-backend/app/dispute/rpc/internal/svc"
|
||||
"juwan-backend/app/dispute/rpc/pb"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchDisputesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchDisputesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchDisputesLogic {
|
||||
return &SearchDisputesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchDisputesLogic) SearchDisputes(in *pb.SearchDisputesReq) (*pb.SearchDisputesResp, 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.DisputeModelRO.Disputes.Query()
|
||||
if in.Id != nil {
|
||||
query = query.Where(disputes.IDEQ(in.GetId()))
|
||||
}
|
||||
if in.OrderId != nil {
|
||||
query = query.Where(disputes.OrderIDEQ(in.GetOrderId()))
|
||||
}
|
||||
if in.InitiatorId != nil {
|
||||
query = query.Where(disputes.InitiatorIDEQ(in.GetInitiatorId()))
|
||||
}
|
||||
if in.RespondentId != nil {
|
||||
query = query.Where(disputes.RespondentIDEQ(in.GetRespondentId()))
|
||||
}
|
||||
if in.Status != nil {
|
||||
query = query.Where(disputes.StatusEQ(in.GetStatus()))
|
||||
}
|
||||
|
||||
list, err := query.
|
||||
Order(disputes.ByCreatedAt(sql.OrderDesc()), disputes.ByID(sql.OrderDesc())).
|
||||
Offset(int(offset)).
|
||||
Limit(int(limit)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("searchDisputes err: %v", err)
|
||||
return nil, errors.New("search disputes failed")
|
||||
}
|
||||
|
||||
out := make([]*pb.Disputes, len(list))
|
||||
for i, d := range list {
|
||||
out[i] = entDisputeToPb(d)
|
||||
}
|
||||
|
||||
return &pb.SearchDisputesResp{Disputes: out}, nil
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/svc"
|
||||
"juwan-backend/app/dispute/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateDisputesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateDisputesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateDisputesLogic {
|
||||
return &UpdateDisputesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateDisputesLogic) UpdateDisputes(in *pb.UpdateDisputesReq) (*pb.UpdateDisputesResp, error) {
|
||||
updater := l.svcCtx.DisputeModelRW.Disputes.UpdateOneID(in.GetId())
|
||||
|
||||
if in.Status != nil {
|
||||
updater = updater.SetStatus(in.GetStatus())
|
||||
}
|
||||
if in.Result != nil {
|
||||
updater = updater.SetResult(in.GetResult())
|
||||
}
|
||||
if in.RespondentReason != nil {
|
||||
updater = updater.SetRespondentReason(in.GetRespondentReason())
|
||||
}
|
||||
if len(in.GetRespondentEvidence()) > 0 {
|
||||
updater = updater.SetRespondentEvidence(toTextArray(in.GetRespondentEvidence()))
|
||||
}
|
||||
if in.AppealReason != nil {
|
||||
updater = updater.SetAppealReason(in.GetAppealReason())
|
||||
}
|
||||
if in.AppealedAt != nil {
|
||||
updater = updater.SetAppealedAt(time.Unix(in.GetAppealedAt(), 0))
|
||||
}
|
||||
if in.ResolvedBy != nil {
|
||||
updater = updater.SetResolvedBy(in.GetResolvedBy())
|
||||
}
|
||||
if in.ResolvedAt != nil {
|
||||
updater = updater.SetResolvedAt(time.Unix(in.GetResolvedAt(), 0))
|
||||
}
|
||||
|
||||
_, err := updater.Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("updateDisputes err: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.UpdateDisputesResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,484 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/models/migrate"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputes"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputetimeline"
|
||||
|
||||
"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
|
||||
// DisputeTimeline is the client for interacting with the DisputeTimeline builders.
|
||||
DisputeTimeline *DisputeTimelineClient
|
||||
// Disputes is the client for interacting with the Disputes builders.
|
||||
Disputes *DisputesClient
|
||||
}
|
||||
|
||||
// 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.DisputeTimeline = NewDisputeTimelineClient(c.config)
|
||||
c.Disputes = NewDisputesClient(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,
|
||||
DisputeTimeline: NewDisputeTimelineClient(cfg),
|
||||
Disputes: NewDisputesClient(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,
|
||||
DisputeTimeline: NewDisputeTimelineClient(cfg),
|
||||
Disputes: NewDisputesClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// DisputeTimeline.
|
||||
// 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.DisputeTimeline.Use(hooks...)
|
||||
c.Disputes.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.DisputeTimeline.Intercept(interceptors...)
|
||||
c.Disputes.Intercept(interceptors...)
|
||||
}
|
||||
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *DisputeTimelineMutation:
|
||||
return c.DisputeTimeline.mutate(ctx, m)
|
||||
case *DisputesMutation:
|
||||
return c.Disputes.mutate(ctx, m)
|
||||
default:
|
||||
return nil, fmt.Errorf("models: unknown mutation type %T", m)
|
||||
}
|
||||
}
|
||||
|
||||
// DisputeTimelineClient is a client for the DisputeTimeline schema.
|
||||
type DisputeTimelineClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewDisputeTimelineClient returns a client for the DisputeTimeline from the given config.
|
||||
func NewDisputeTimelineClient(c config) *DisputeTimelineClient {
|
||||
return &DisputeTimelineClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `disputetimeline.Hooks(f(g(h())))`.
|
||||
func (c *DisputeTimelineClient) Use(hooks ...Hook) {
|
||||
c.hooks.DisputeTimeline = append(c.hooks.DisputeTimeline, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `disputetimeline.Intercept(f(g(h())))`.
|
||||
func (c *DisputeTimelineClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.DisputeTimeline = append(c.inters.DisputeTimeline, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a DisputeTimeline entity.
|
||||
func (c *DisputeTimelineClient) Create() *DisputeTimelineCreate {
|
||||
mutation := newDisputeTimelineMutation(c.config, OpCreate)
|
||||
return &DisputeTimelineCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of DisputeTimeline entities.
|
||||
func (c *DisputeTimelineClient) CreateBulk(builders ...*DisputeTimelineCreate) *DisputeTimelineCreateBulk {
|
||||
return &DisputeTimelineCreateBulk{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 *DisputeTimelineClient) MapCreateBulk(slice any, setFunc func(*DisputeTimelineCreate, int)) *DisputeTimelineCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &DisputeTimelineCreateBulk{err: fmt.Errorf("calling to DisputeTimelineClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*DisputeTimelineCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &DisputeTimelineCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for DisputeTimeline.
|
||||
func (c *DisputeTimelineClient) Update() *DisputeTimelineUpdate {
|
||||
mutation := newDisputeTimelineMutation(c.config, OpUpdate)
|
||||
return &DisputeTimelineUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *DisputeTimelineClient) UpdateOne(_m *DisputeTimeline) *DisputeTimelineUpdateOne {
|
||||
mutation := newDisputeTimelineMutation(c.config, OpUpdateOne, withDisputeTimeline(_m))
|
||||
return &DisputeTimelineUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *DisputeTimelineClient) UpdateOneID(id int64) *DisputeTimelineUpdateOne {
|
||||
mutation := newDisputeTimelineMutation(c.config, OpUpdateOne, withDisputeTimelineID(id))
|
||||
return &DisputeTimelineUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for DisputeTimeline.
|
||||
func (c *DisputeTimelineClient) Delete() *DisputeTimelineDelete {
|
||||
mutation := newDisputeTimelineMutation(c.config, OpDelete)
|
||||
return &DisputeTimelineDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *DisputeTimelineClient) DeleteOne(_m *DisputeTimeline) *DisputeTimelineDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *DisputeTimelineClient) DeleteOneID(id int64) *DisputeTimelineDeleteOne {
|
||||
builder := c.Delete().Where(disputetimeline.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &DisputeTimelineDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for DisputeTimeline.
|
||||
func (c *DisputeTimelineClient) Query() *DisputeTimelineQuery {
|
||||
return &DisputeTimelineQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeDisputeTimeline},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a DisputeTimeline entity by its id.
|
||||
func (c *DisputeTimelineClient) Get(ctx context.Context, id int64) (*DisputeTimeline, error) {
|
||||
return c.Query().Where(disputetimeline.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *DisputeTimelineClient) GetX(ctx context.Context, id int64) *DisputeTimeline {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *DisputeTimelineClient) Hooks() []Hook {
|
||||
return c.hooks.DisputeTimeline
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *DisputeTimelineClient) Interceptors() []Interceptor {
|
||||
return c.inters.DisputeTimeline
|
||||
}
|
||||
|
||||
func (c *DisputeTimelineClient) mutate(ctx context.Context, m *DisputeTimelineMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&DisputeTimelineCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&DisputeTimelineUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&DisputeTimelineUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&DisputeTimelineDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("models: unknown DisputeTimeline mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// DisputesClient is a client for the Disputes schema.
|
||||
type DisputesClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewDisputesClient returns a client for the Disputes from the given config.
|
||||
func NewDisputesClient(c config) *DisputesClient {
|
||||
return &DisputesClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `disputes.Hooks(f(g(h())))`.
|
||||
func (c *DisputesClient) Use(hooks ...Hook) {
|
||||
c.hooks.Disputes = append(c.hooks.Disputes, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `disputes.Intercept(f(g(h())))`.
|
||||
func (c *DisputesClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Disputes = append(c.inters.Disputes, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Disputes entity.
|
||||
func (c *DisputesClient) Create() *DisputesCreate {
|
||||
mutation := newDisputesMutation(c.config, OpCreate)
|
||||
return &DisputesCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Disputes entities.
|
||||
func (c *DisputesClient) CreateBulk(builders ...*DisputesCreate) *DisputesCreateBulk {
|
||||
return &DisputesCreateBulk{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 *DisputesClient) MapCreateBulk(slice any, setFunc func(*DisputesCreate, int)) *DisputesCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &DisputesCreateBulk{err: fmt.Errorf("calling to DisputesClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*DisputesCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &DisputesCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Disputes.
|
||||
func (c *DisputesClient) Update() *DisputesUpdate {
|
||||
mutation := newDisputesMutation(c.config, OpUpdate)
|
||||
return &DisputesUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *DisputesClient) UpdateOne(_m *Disputes) *DisputesUpdateOne {
|
||||
mutation := newDisputesMutation(c.config, OpUpdateOne, withDisputes(_m))
|
||||
return &DisputesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *DisputesClient) UpdateOneID(id int64) *DisputesUpdateOne {
|
||||
mutation := newDisputesMutation(c.config, OpUpdateOne, withDisputesID(id))
|
||||
return &DisputesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Disputes.
|
||||
func (c *DisputesClient) Delete() *DisputesDelete {
|
||||
mutation := newDisputesMutation(c.config, OpDelete)
|
||||
return &DisputesDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *DisputesClient) DeleteOne(_m *Disputes) *DisputesDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *DisputesClient) DeleteOneID(id int64) *DisputesDeleteOne {
|
||||
builder := c.Delete().Where(disputes.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &DisputesDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Disputes.
|
||||
func (c *DisputesClient) Query() *DisputesQuery {
|
||||
return &DisputesQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeDisputes},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Disputes entity by its id.
|
||||
func (c *DisputesClient) Get(ctx context.Context, id int64) (*Disputes, error) {
|
||||
return c.Query().Where(disputes.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *DisputesClient) GetX(ctx context.Context, id int64) *Disputes {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *DisputesClient) Hooks() []Hook {
|
||||
return c.hooks.Disputes
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *DisputesClient) Interceptors() []Interceptor {
|
||||
return c.inters.Disputes
|
||||
}
|
||||
|
||||
func (c *DisputesClient) mutate(ctx context.Context, m *DisputesMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&DisputesCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&DisputesUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&DisputesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&DisputesDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("models: unknown Disputes mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
DisputeTimeline, Disputes []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
DisputeTimeline, Disputes []ent.Interceptor
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,292 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputes"
|
||||
"juwan-backend/pkg/types"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Disputes is the model entity for the Disputes schema.
|
||||
type Disputes struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int64 `json:"id,omitempty"`
|
||||
// OrderID holds the value of the "order_id" field.
|
||||
OrderID int64 `json:"order_id,omitempty"`
|
||||
// InitiatorID holds the value of the "initiator_id" field.
|
||||
InitiatorID int64 `json:"initiator_id,omitempty"`
|
||||
// InitiatorName holds the value of the "initiator_name" field.
|
||||
InitiatorName string `json:"initiator_name,omitempty"`
|
||||
// RespondentID holds the value of the "respondent_id" field.
|
||||
RespondentID int64 `json:"respondent_id,omitempty"`
|
||||
// Reason holds the value of the "reason" field.
|
||||
Reason string `json:"reason,omitempty"`
|
||||
// Evidence holds the value of the "evidence" field.
|
||||
Evidence types.TextArray `json:"evidence,omitempty"`
|
||||
// Status holds the value of the "status" field.
|
||||
Status string `json:"status,omitempty"`
|
||||
// Result holds the value of the "result" field.
|
||||
Result *string `json:"result,omitempty"`
|
||||
// RespondentReason holds the value of the "respondent_reason" field.
|
||||
RespondentReason *string `json:"respondent_reason,omitempty"`
|
||||
// RespondentEvidence holds the value of the "respondent_evidence" field.
|
||||
RespondentEvidence types.TextArray `json:"respondent_evidence,omitempty"`
|
||||
// AppealReason holds the value of the "appeal_reason" field.
|
||||
AppealReason *string `json:"appeal_reason,omitempty"`
|
||||
// AppealedAt holds the value of the "appealed_at" field.
|
||||
AppealedAt *time.Time `json:"appealed_at,omitempty"`
|
||||
// ResolvedBy holds the value of the "resolved_by" field.
|
||||
ResolvedBy *int64 `json:"resolved_by,omitempty"`
|
||||
// ResolvedAt holds the value of the "resolved_at" field.
|
||||
ResolvedAt *time.Time `json:"resolved_at,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 (*Disputes) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case disputes.FieldID, disputes.FieldOrderID, disputes.FieldInitiatorID, disputes.FieldRespondentID, disputes.FieldResolvedBy:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case disputes.FieldInitiatorName, disputes.FieldReason, disputes.FieldStatus, disputes.FieldResult, disputes.FieldRespondentReason, disputes.FieldAppealReason:
|
||||
values[i] = new(sql.NullString)
|
||||
case disputes.FieldAppealedAt, disputes.FieldResolvedAt, disputes.FieldCreatedAt, disputes.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case disputes.FieldEvidence, disputes.FieldRespondentEvidence:
|
||||
values[i] = new(types.TextArray)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Disputes fields.
|
||||
func (_m *Disputes) 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 disputes.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 disputes.FieldOrderID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field order_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.OrderID = value.Int64
|
||||
}
|
||||
case disputes.FieldInitiatorID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field initiator_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.InitiatorID = value.Int64
|
||||
}
|
||||
case disputes.FieldInitiatorName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field initiator_name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.InitiatorName = value.String
|
||||
}
|
||||
case disputes.FieldRespondentID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field respondent_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.RespondentID = value.Int64
|
||||
}
|
||||
case disputes.FieldReason:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field reason", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Reason = value.String
|
||||
}
|
||||
case disputes.FieldEvidence:
|
||||
if value, ok := values[i].(*types.TextArray); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field evidence", values[i])
|
||||
} else if value != nil {
|
||||
_m.Evidence = *value
|
||||
}
|
||||
case disputes.FieldStatus:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Status = value.String
|
||||
}
|
||||
case disputes.FieldResult:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field result", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Result = new(string)
|
||||
*_m.Result = value.String
|
||||
}
|
||||
case disputes.FieldRespondentReason:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field respondent_reason", values[i])
|
||||
} else if value.Valid {
|
||||
_m.RespondentReason = new(string)
|
||||
*_m.RespondentReason = value.String
|
||||
}
|
||||
case disputes.FieldRespondentEvidence:
|
||||
if value, ok := values[i].(*types.TextArray); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field respondent_evidence", values[i])
|
||||
} else if value != nil {
|
||||
_m.RespondentEvidence = *value
|
||||
}
|
||||
case disputes.FieldAppealReason:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field appeal_reason", values[i])
|
||||
} else if value.Valid {
|
||||
_m.AppealReason = new(string)
|
||||
*_m.AppealReason = value.String
|
||||
}
|
||||
case disputes.FieldAppealedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field appealed_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.AppealedAt = new(time.Time)
|
||||
*_m.AppealedAt = value.Time
|
||||
}
|
||||
case disputes.FieldResolvedBy:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field resolved_by", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ResolvedBy = new(int64)
|
||||
*_m.ResolvedBy = value.Int64
|
||||
}
|
||||
case disputes.FieldResolvedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field resolved_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ResolvedAt = new(time.Time)
|
||||
*_m.ResolvedAt = value.Time
|
||||
}
|
||||
case disputes.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 disputes.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 Disputes.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Disputes) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Disputes.
|
||||
// Note that you need to call Disputes.Unwrap() before calling this method if this Disputes
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Disputes) Update() *DisputesUpdateOne {
|
||||
return NewDisputesClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Disputes 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 *Disputes) Unwrap() *Disputes {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("models: Disputes is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Disputes) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Disputes(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("order_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.OrderID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("initiator_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.InitiatorID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("initiator_name=")
|
||||
builder.WriteString(_m.InitiatorName)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("respondent_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.RespondentID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("reason=")
|
||||
builder.WriteString(_m.Reason)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("evidence=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Evidence))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("status=")
|
||||
builder.WriteString(_m.Status)
|
||||
builder.WriteString(", ")
|
||||
if v := _m.Result; v != nil {
|
||||
builder.WriteString("result=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := _m.RespondentReason; v != nil {
|
||||
builder.WriteString("respondent_reason=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("respondent_evidence=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.RespondentEvidence))
|
||||
builder.WriteString(", ")
|
||||
if v := _m.AppealReason; v != nil {
|
||||
builder.WriteString("appeal_reason=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := _m.AppealedAt; v != nil {
|
||||
builder.WriteString("appealed_at=")
|
||||
builder.WriteString(v.Format(time.ANSIC))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := _m.ResolvedBy; v != nil {
|
||||
builder.WriteString("resolved_by=")
|
||||
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := _m.ResolvedAt; v != nil {
|
||||
builder.WriteString("resolved_at=")
|
||||
builder.WriteString(v.Format(time.ANSIC))
|
||||
}
|
||||
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()
|
||||
}
|
||||
|
||||
// DisputesSlice is a parsable slice of Disputes.
|
||||
type DisputesSlice []*Disputes
|
||||
@@ -0,0 +1,186 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package disputes
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the disputes type in the database.
|
||||
Label = "disputes"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldOrderID holds the string denoting the order_id field in the database.
|
||||
FieldOrderID = "order_id"
|
||||
// FieldInitiatorID holds the string denoting the initiator_id field in the database.
|
||||
FieldInitiatorID = "initiator_id"
|
||||
// FieldInitiatorName holds the string denoting the initiator_name field in the database.
|
||||
FieldInitiatorName = "initiator_name"
|
||||
// FieldRespondentID holds the string denoting the respondent_id field in the database.
|
||||
FieldRespondentID = "respondent_id"
|
||||
// FieldReason holds the string denoting the reason field in the database.
|
||||
FieldReason = "reason"
|
||||
// FieldEvidence holds the string denoting the evidence field in the database.
|
||||
FieldEvidence = "evidence"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
FieldStatus = "status"
|
||||
// FieldResult holds the string denoting the result field in the database.
|
||||
FieldResult = "result"
|
||||
// FieldRespondentReason holds the string denoting the respondent_reason field in the database.
|
||||
FieldRespondentReason = "respondent_reason"
|
||||
// FieldRespondentEvidence holds the string denoting the respondent_evidence field in the database.
|
||||
FieldRespondentEvidence = "respondent_evidence"
|
||||
// FieldAppealReason holds the string denoting the appeal_reason field in the database.
|
||||
FieldAppealReason = "appeal_reason"
|
||||
// FieldAppealedAt holds the string denoting the appealed_at field in the database.
|
||||
FieldAppealedAt = "appealed_at"
|
||||
// FieldResolvedBy holds the string denoting the resolved_by field in the database.
|
||||
FieldResolvedBy = "resolved_by"
|
||||
// FieldResolvedAt holds the string denoting the resolved_at field in the database.
|
||||
FieldResolvedAt = "resolved_at"
|
||||
// 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 disputes in the database.
|
||||
Table = "disputes"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for disputes fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldOrderID,
|
||||
FieldInitiatorID,
|
||||
FieldInitiatorName,
|
||||
FieldRespondentID,
|
||||
FieldReason,
|
||||
FieldEvidence,
|
||||
FieldStatus,
|
||||
FieldResult,
|
||||
FieldRespondentReason,
|
||||
FieldRespondentEvidence,
|
||||
FieldAppealReason,
|
||||
FieldAppealedAt,
|
||||
FieldResolvedBy,
|
||||
FieldResolvedAt,
|
||||
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 (
|
||||
// InitiatorNameValidator is a validator for the "initiator_name" field. It is called by the builders before save.
|
||||
InitiatorNameValidator func(string) error
|
||||
// DefaultStatus holds the default value on creation for the "status" field.
|
||||
DefaultStatus string
|
||||
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||
StatusValidator func(string) error
|
||||
// ResultValidator is a validator for the "result" field. It is called by the builders before save.
|
||||
ResultValidator 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 Disputes 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()
|
||||
}
|
||||
|
||||
// ByOrderID orders the results by the order_id field.
|
||||
func ByOrderID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOrderID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByInitiatorID orders the results by the initiator_id field.
|
||||
func ByInitiatorID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldInitiatorID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByInitiatorName orders the results by the initiator_name field.
|
||||
func ByInitiatorName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldInitiatorName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByRespondentID orders the results by the respondent_id field.
|
||||
func ByRespondentID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldRespondentID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByReason orders the results by the reason field.
|
||||
func ByReason(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldReason, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByEvidence orders the results by the evidence field.
|
||||
func ByEvidence(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldEvidence, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByStatus orders the results by the status field.
|
||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByResult orders the results by the result field.
|
||||
func ByResult(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldResult, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByRespondentReason orders the results by the respondent_reason field.
|
||||
func ByRespondentReason(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldRespondentReason, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByRespondentEvidence orders the results by the respondent_evidence field.
|
||||
func ByRespondentEvidence(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldRespondentEvidence, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAppealReason orders the results by the appeal_reason field.
|
||||
func ByAppealReason(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAppealReason, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAppealedAt orders the results by the appealed_at field.
|
||||
func ByAppealedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAppealedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByResolvedBy orders the results by the resolved_by field.
|
||||
func ByResolvedBy(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldResolvedBy, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByResolvedAt orders the results by the resolved_at field.
|
||||
func ByResolvedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldResolvedAt, 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()
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,489 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputes"
|
||||
"juwan-backend/pkg/types"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// DisputesCreate is the builder for creating a Disputes entity.
|
||||
type DisputesCreate struct {
|
||||
config
|
||||
mutation *DisputesMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetOrderID sets the "order_id" field.
|
||||
func (_c *DisputesCreate) SetOrderID(v int64) *DisputesCreate {
|
||||
_c.mutation.SetOrderID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInitiatorID sets the "initiator_id" field.
|
||||
func (_c *DisputesCreate) SetInitiatorID(v int64) *DisputesCreate {
|
||||
_c.mutation.SetInitiatorID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInitiatorName sets the "initiator_name" field.
|
||||
func (_c *DisputesCreate) SetInitiatorName(v string) *DisputesCreate {
|
||||
_c.mutation.SetInitiatorName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetRespondentID sets the "respondent_id" field.
|
||||
func (_c *DisputesCreate) SetRespondentID(v int64) *DisputesCreate {
|
||||
_c.mutation.SetRespondentID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (_c *DisputesCreate) SetReason(v string) *DisputesCreate {
|
||||
_c.mutation.SetReason(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetEvidence sets the "evidence" field.
|
||||
func (_c *DisputesCreate) SetEvidence(v types.TextArray) *DisputesCreate {
|
||||
_c.mutation.SetEvidence(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableEvidence sets the "evidence" field if the given value is not nil.
|
||||
func (_c *DisputesCreate) SetNillableEvidence(v *types.TextArray) *DisputesCreate {
|
||||
if v != nil {
|
||||
_c.SetEvidence(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_c *DisputesCreate) SetStatus(v string) *DisputesCreate {
|
||||
_c.mutation.SetStatus(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_c *DisputesCreate) SetNillableStatus(v *string) *DisputesCreate {
|
||||
if v != nil {
|
||||
_c.SetStatus(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetResult sets the "result" field.
|
||||
func (_c *DisputesCreate) SetResult(v string) *DisputesCreate {
|
||||
_c.mutation.SetResult(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableResult sets the "result" field if the given value is not nil.
|
||||
func (_c *DisputesCreate) SetNillableResult(v *string) *DisputesCreate {
|
||||
if v != nil {
|
||||
_c.SetResult(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetRespondentReason sets the "respondent_reason" field.
|
||||
func (_c *DisputesCreate) SetRespondentReason(v string) *DisputesCreate {
|
||||
_c.mutation.SetRespondentReason(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableRespondentReason sets the "respondent_reason" field if the given value is not nil.
|
||||
func (_c *DisputesCreate) SetNillableRespondentReason(v *string) *DisputesCreate {
|
||||
if v != nil {
|
||||
_c.SetRespondentReason(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetRespondentEvidence sets the "respondent_evidence" field.
|
||||
func (_c *DisputesCreate) SetRespondentEvidence(v types.TextArray) *DisputesCreate {
|
||||
_c.mutation.SetRespondentEvidence(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableRespondentEvidence sets the "respondent_evidence" field if the given value is not nil.
|
||||
func (_c *DisputesCreate) SetNillableRespondentEvidence(v *types.TextArray) *DisputesCreate {
|
||||
if v != nil {
|
||||
_c.SetRespondentEvidence(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAppealReason sets the "appeal_reason" field.
|
||||
func (_c *DisputesCreate) SetAppealReason(v string) *DisputesCreate {
|
||||
_c.mutation.SetAppealReason(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableAppealReason sets the "appeal_reason" field if the given value is not nil.
|
||||
func (_c *DisputesCreate) SetNillableAppealReason(v *string) *DisputesCreate {
|
||||
if v != nil {
|
||||
_c.SetAppealReason(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAppealedAt sets the "appealed_at" field.
|
||||
func (_c *DisputesCreate) SetAppealedAt(v time.Time) *DisputesCreate {
|
||||
_c.mutation.SetAppealedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableAppealedAt sets the "appealed_at" field if the given value is not nil.
|
||||
func (_c *DisputesCreate) SetNillableAppealedAt(v *time.Time) *DisputesCreate {
|
||||
if v != nil {
|
||||
_c.SetAppealedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetResolvedBy sets the "resolved_by" field.
|
||||
func (_c *DisputesCreate) SetResolvedBy(v int64) *DisputesCreate {
|
||||
_c.mutation.SetResolvedBy(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableResolvedBy sets the "resolved_by" field if the given value is not nil.
|
||||
func (_c *DisputesCreate) SetNillableResolvedBy(v *int64) *DisputesCreate {
|
||||
if v != nil {
|
||||
_c.SetResolvedBy(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetResolvedAt sets the "resolved_at" field.
|
||||
func (_c *DisputesCreate) SetResolvedAt(v time.Time) *DisputesCreate {
|
||||
_c.mutation.SetResolvedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil.
|
||||
func (_c *DisputesCreate) SetNillableResolvedAt(v *time.Time) *DisputesCreate {
|
||||
if v != nil {
|
||||
_c.SetResolvedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *DisputesCreate) SetCreatedAt(v time.Time) *DisputesCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *DisputesCreate) SetNillableCreatedAt(v *time.Time) *DisputesCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_c *DisputesCreate) SetUpdatedAt(v time.Time) *DisputesCreate {
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_c *DisputesCreate) SetNillableUpdatedAt(v *time.Time) *DisputesCreate {
|
||||
if v != nil {
|
||||
_c.SetUpdatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *DisputesCreate) SetID(v int64) *DisputesCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the DisputesMutation object of the builder.
|
||||
func (_c *DisputesCreate) Mutation() *DisputesMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Disputes in the database.
|
||||
func (_c *DisputesCreate) Save(ctx context.Context) (*Disputes, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *DisputesCreate) SaveX(ctx context.Context) *Disputes {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *DisputesCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *DisputesCreate) 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 *DisputesCreate) defaults() {
|
||||
if _, ok := _c.mutation.Status(); !ok {
|
||||
v := disputes.DefaultStatus
|
||||
_c.mutation.SetStatus(v)
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := disputes.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
v := disputes.DefaultUpdatedAt()
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *DisputesCreate) check() error {
|
||||
if _, ok := _c.mutation.OrderID(); !ok {
|
||||
return &ValidationError{Name: "order_id", err: errors.New(`models: missing required field "Disputes.order_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.InitiatorID(); !ok {
|
||||
return &ValidationError{Name: "initiator_id", err: errors.New(`models: missing required field "Disputes.initiator_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.InitiatorName(); !ok {
|
||||
return &ValidationError{Name: "initiator_name", err: errors.New(`models: missing required field "Disputes.initiator_name"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.InitiatorName(); ok {
|
||||
if err := disputes.InitiatorNameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "initiator_name", err: fmt.Errorf(`models: validator failed for field "Disputes.initiator_name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.RespondentID(); !ok {
|
||||
return &ValidationError{Name: "respondent_id", err: errors.New(`models: missing required field "Disputes.respondent_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Reason(); !ok {
|
||||
return &ValidationError{Name: "reason", err: errors.New(`models: missing required field "Disputes.reason"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Status(); !ok {
|
||||
return &ValidationError{Name: "status", err: errors.New(`models: missing required field "Disputes.status"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Status(); ok {
|
||||
if err := disputes.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "Disputes.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _c.mutation.Result(); ok {
|
||||
if err := disputes.ResultValidator(v); err != nil {
|
||||
return &ValidationError{Name: "result", err: fmt.Errorf(`models: validator failed for field "Disputes.result": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "Disputes.created_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`models: missing required field "Disputes.updated_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *DisputesCreate) sqlSave(ctx context.Context) (*Disputes, 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 *DisputesCreate) createSpec() (*Disputes, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Disputes{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(disputes.Table, sqlgraph.NewFieldSpec(disputes.FieldID, field.TypeInt64))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := _c.mutation.OrderID(); ok {
|
||||
_spec.SetField(disputes.FieldOrderID, field.TypeInt64, value)
|
||||
_node.OrderID = value
|
||||
}
|
||||
if value, ok := _c.mutation.InitiatorID(); ok {
|
||||
_spec.SetField(disputes.FieldInitiatorID, field.TypeInt64, value)
|
||||
_node.InitiatorID = value
|
||||
}
|
||||
if value, ok := _c.mutation.InitiatorName(); ok {
|
||||
_spec.SetField(disputes.FieldInitiatorName, field.TypeString, value)
|
||||
_node.InitiatorName = value
|
||||
}
|
||||
if value, ok := _c.mutation.RespondentID(); ok {
|
||||
_spec.SetField(disputes.FieldRespondentID, field.TypeInt64, value)
|
||||
_node.RespondentID = value
|
||||
}
|
||||
if value, ok := _c.mutation.Reason(); ok {
|
||||
_spec.SetField(disputes.FieldReason, field.TypeString, value)
|
||||
_node.Reason = value
|
||||
}
|
||||
if value, ok := _c.mutation.Evidence(); ok {
|
||||
_spec.SetField(disputes.FieldEvidence, field.TypeOther, value)
|
||||
_node.Evidence = value
|
||||
}
|
||||
if value, ok := _c.mutation.Status(); ok {
|
||||
_spec.SetField(disputes.FieldStatus, field.TypeString, value)
|
||||
_node.Status = value
|
||||
}
|
||||
if value, ok := _c.mutation.Result(); ok {
|
||||
_spec.SetField(disputes.FieldResult, field.TypeString, value)
|
||||
_node.Result = &value
|
||||
}
|
||||
if value, ok := _c.mutation.RespondentReason(); ok {
|
||||
_spec.SetField(disputes.FieldRespondentReason, field.TypeString, value)
|
||||
_node.RespondentReason = &value
|
||||
}
|
||||
if value, ok := _c.mutation.RespondentEvidence(); ok {
|
||||
_spec.SetField(disputes.FieldRespondentEvidence, field.TypeOther, value)
|
||||
_node.RespondentEvidence = value
|
||||
}
|
||||
if value, ok := _c.mutation.AppealReason(); ok {
|
||||
_spec.SetField(disputes.FieldAppealReason, field.TypeString, value)
|
||||
_node.AppealReason = &value
|
||||
}
|
||||
if value, ok := _c.mutation.AppealedAt(); ok {
|
||||
_spec.SetField(disputes.FieldAppealedAt, field.TypeTime, value)
|
||||
_node.AppealedAt = &value
|
||||
}
|
||||
if value, ok := _c.mutation.ResolvedBy(); ok {
|
||||
_spec.SetField(disputes.FieldResolvedBy, field.TypeInt64, value)
|
||||
_node.ResolvedBy = &value
|
||||
}
|
||||
if value, ok := _c.mutation.ResolvedAt(); ok {
|
||||
_spec.SetField(disputes.FieldResolvedAt, field.TypeTime, value)
|
||||
_node.ResolvedAt = &value
|
||||
}
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(disputes.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(disputes.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// DisputesCreateBulk is the builder for creating many Disputes entities in bulk.
|
||||
type DisputesCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*DisputesCreate
|
||||
}
|
||||
|
||||
// Save creates the Disputes entities in the database.
|
||||
func (_c *DisputesCreateBulk) Save(ctx context.Context) ([]*Disputes, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Disputes, 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.(*DisputesMutation)
|
||||
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 *DisputesCreateBulk) SaveX(ctx context.Context) []*Disputes {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *DisputesCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *DisputesCreateBulk) 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/dispute/rpc/internal/models/disputes"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// DisputesDelete is the builder for deleting a Disputes entity.
|
||||
type DisputesDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *DisputesMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the DisputesDelete builder.
|
||||
func (_d *DisputesDelete) Where(ps ...predicate.Disputes) *DisputesDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *DisputesDelete) 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 *DisputesDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *DisputesDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(disputes.Table, sqlgraph.NewFieldSpec(disputes.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
|
||||
}
|
||||
|
||||
// DisputesDeleteOne is the builder for deleting a single Disputes entity.
|
||||
type DisputesDeleteOne struct {
|
||||
_d *DisputesDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the DisputesDelete builder.
|
||||
func (_d *DisputesDeleteOne) Where(ps ...predicate.Disputes) *DisputesDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *DisputesDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{disputes.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *DisputesDeleteOne) 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/dispute/rpc/internal/models/disputes"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/predicate"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// DisputesQuery is the builder for querying Disputes entities.
|
||||
type DisputesQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []disputes.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Disputes
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the DisputesQuery builder.
|
||||
func (_q *DisputesQuery) Where(ps ...predicate.Disputes) *DisputesQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *DisputesQuery) Limit(limit int) *DisputesQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *DisputesQuery) Offset(offset int) *DisputesQuery {
|
||||
_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 *DisputesQuery) Unique(unique bool) *DisputesQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *DisputesQuery) Order(o ...disputes.OrderOption) *DisputesQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first Disputes entity from the query.
|
||||
// Returns a *NotFoundError when no Disputes was found.
|
||||
func (_q *DisputesQuery) First(ctx context.Context) (*Disputes, 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{disputes.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *DisputesQuery) FirstX(ctx context.Context) *Disputes {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Disputes ID from the query.
|
||||
// Returns a *NotFoundError when no Disputes ID was found.
|
||||
func (_q *DisputesQuery) 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{disputes.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *DisputesQuery) FirstIDX(ctx context.Context) int64 {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Disputes entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Disputes entity is found.
|
||||
// Returns a *NotFoundError when no Disputes entities are found.
|
||||
func (_q *DisputesQuery) Only(ctx context.Context) (*Disputes, 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{disputes.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{disputes.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *DisputesQuery) OnlyX(ctx context.Context) *Disputes {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Disputes ID in the query.
|
||||
// Returns a *NotSingularError when more than one Disputes ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *DisputesQuery) 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{disputes.Label}
|
||||
default:
|
||||
err = &NotSingularError{disputes.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *DisputesQuery) 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 DisputesSlice.
|
||||
func (_q *DisputesQuery) All(ctx context.Context) ([]*Disputes, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Disputes, *DisputesQuery]()
|
||||
return withInterceptors[[]*Disputes](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *DisputesQuery) AllX(ctx context.Context) []*Disputes {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Disputes IDs.
|
||||
func (_q *DisputesQuery) 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(disputes.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *DisputesQuery) 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 *DisputesQuery) 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[*DisputesQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *DisputesQuery) 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 *DisputesQuery) 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 *DisputesQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the DisputesQuery 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 *DisputesQuery) Clone() *DisputesQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &DisputesQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]disputes.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Disputes{}, _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 {
|
||||
// OrderID int64 `json:"order_id,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Disputes.Query().
|
||||
// GroupBy(disputes.FieldOrderID).
|
||||
// Aggregate(models.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *DisputesQuery) GroupBy(field string, fields ...string) *DisputesGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &DisputesGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = disputes.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 {
|
||||
// OrderID int64 `json:"order_id,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Disputes.Query().
|
||||
// Select(disputes.FieldOrderID).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *DisputesQuery) Select(fields ...string) *DisputesSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &DisputesSelect{DisputesQuery: _q}
|
||||
sbuild.label = disputes.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a DisputesSelect configured with the given aggregations.
|
||||
func (_q *DisputesQuery) Aggregate(fns ...AggregateFunc) *DisputesSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *DisputesQuery) 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 !disputes.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 *DisputesQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Disputes, error) {
|
||||
var (
|
||||
nodes = []*Disputes{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Disputes).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Disputes{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 *DisputesQuery) 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 *DisputesQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(disputes.Table, disputes.Columns, sqlgraph.NewFieldSpec(disputes.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, disputes.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != disputes.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 *DisputesQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(disputes.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = disputes.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
|
||||
}
|
||||
|
||||
// DisputesGroupBy is the group-by builder for Disputes entities.
|
||||
type DisputesGroupBy struct {
|
||||
selector
|
||||
build *DisputesQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *DisputesGroupBy) Aggregate(fns ...AggregateFunc) *DisputesGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *DisputesGroupBy) 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[*DisputesQuery, *DisputesGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *DisputesGroupBy) sqlScan(ctx context.Context, root *DisputesQuery, 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)
|
||||
}
|
||||
|
||||
// DisputesSelect is the builder for selecting fields of Disputes entities.
|
||||
type DisputesSelect struct {
|
||||
*DisputesQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *DisputesSelect) Aggregate(fns ...AggregateFunc) *DisputesSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *DisputesSelect) 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[*DisputesQuery, *DisputesSelect](ctx, _s.DisputesQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *DisputesSelect) sqlScan(ctx context.Context, root *DisputesQuery, 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,959 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputes"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/predicate"
|
||||
"juwan-backend/pkg/types"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// DisputesUpdate is the builder for updating Disputes entities.
|
||||
type DisputesUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *DisputesMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the DisputesUpdate builder.
|
||||
func (_u *DisputesUpdate) Where(ps ...predicate.Disputes) *DisputesUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOrderID sets the "order_id" field.
|
||||
func (_u *DisputesUpdate) SetOrderID(v int64) *DisputesUpdate {
|
||||
_u.mutation.ResetOrderID()
|
||||
_u.mutation.SetOrderID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOrderID sets the "order_id" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableOrderID(v *int64) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetOrderID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddOrderID adds value to the "order_id" field.
|
||||
func (_u *DisputesUpdate) AddOrderID(v int64) *DisputesUpdate {
|
||||
_u.mutation.AddOrderID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInitiatorID sets the "initiator_id" field.
|
||||
func (_u *DisputesUpdate) SetInitiatorID(v int64) *DisputesUpdate {
|
||||
_u.mutation.ResetInitiatorID()
|
||||
_u.mutation.SetInitiatorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInitiatorID sets the "initiator_id" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableInitiatorID(v *int64) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetInitiatorID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddInitiatorID adds value to the "initiator_id" field.
|
||||
func (_u *DisputesUpdate) AddInitiatorID(v int64) *DisputesUpdate {
|
||||
_u.mutation.AddInitiatorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInitiatorName sets the "initiator_name" field.
|
||||
func (_u *DisputesUpdate) SetInitiatorName(v string) *DisputesUpdate {
|
||||
_u.mutation.SetInitiatorName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInitiatorName sets the "initiator_name" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableInitiatorName(v *string) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetInitiatorName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetRespondentID sets the "respondent_id" field.
|
||||
func (_u *DisputesUpdate) SetRespondentID(v int64) *DisputesUpdate {
|
||||
_u.mutation.ResetRespondentID()
|
||||
_u.mutation.SetRespondentID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableRespondentID sets the "respondent_id" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableRespondentID(v *int64) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetRespondentID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddRespondentID adds value to the "respondent_id" field.
|
||||
func (_u *DisputesUpdate) AddRespondentID(v int64) *DisputesUpdate {
|
||||
_u.mutation.AddRespondentID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (_u *DisputesUpdate) SetReason(v string) *DisputesUpdate {
|
||||
_u.mutation.SetReason(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableReason sets the "reason" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableReason(v *string) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetReason(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetEvidence sets the "evidence" field.
|
||||
func (_u *DisputesUpdate) SetEvidence(v types.TextArray) *DisputesUpdate {
|
||||
_u.mutation.SetEvidence(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableEvidence sets the "evidence" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableEvidence(v *types.TextArray) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetEvidence(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearEvidence clears the value of the "evidence" field.
|
||||
func (_u *DisputesUpdate) ClearEvidence() *DisputesUpdate {
|
||||
_u.mutation.ClearEvidence()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *DisputesUpdate) SetStatus(v string) *DisputesUpdate {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableStatus(v *string) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetResult sets the "result" field.
|
||||
func (_u *DisputesUpdate) SetResult(v string) *DisputesUpdate {
|
||||
_u.mutation.SetResult(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableResult sets the "result" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableResult(v *string) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetResult(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearResult clears the value of the "result" field.
|
||||
func (_u *DisputesUpdate) ClearResult() *DisputesUpdate {
|
||||
_u.mutation.ClearResult()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetRespondentReason sets the "respondent_reason" field.
|
||||
func (_u *DisputesUpdate) SetRespondentReason(v string) *DisputesUpdate {
|
||||
_u.mutation.SetRespondentReason(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableRespondentReason sets the "respondent_reason" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableRespondentReason(v *string) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetRespondentReason(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearRespondentReason clears the value of the "respondent_reason" field.
|
||||
func (_u *DisputesUpdate) ClearRespondentReason() *DisputesUpdate {
|
||||
_u.mutation.ClearRespondentReason()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetRespondentEvidence sets the "respondent_evidence" field.
|
||||
func (_u *DisputesUpdate) SetRespondentEvidence(v types.TextArray) *DisputesUpdate {
|
||||
_u.mutation.SetRespondentEvidence(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableRespondentEvidence sets the "respondent_evidence" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableRespondentEvidence(v *types.TextArray) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetRespondentEvidence(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearRespondentEvidence clears the value of the "respondent_evidence" field.
|
||||
func (_u *DisputesUpdate) ClearRespondentEvidence() *DisputesUpdate {
|
||||
_u.mutation.ClearRespondentEvidence()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAppealReason sets the "appeal_reason" field.
|
||||
func (_u *DisputesUpdate) SetAppealReason(v string) *DisputesUpdate {
|
||||
_u.mutation.SetAppealReason(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAppealReason sets the "appeal_reason" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableAppealReason(v *string) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetAppealReason(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearAppealReason clears the value of the "appeal_reason" field.
|
||||
func (_u *DisputesUpdate) ClearAppealReason() *DisputesUpdate {
|
||||
_u.mutation.ClearAppealReason()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAppealedAt sets the "appealed_at" field.
|
||||
func (_u *DisputesUpdate) SetAppealedAt(v time.Time) *DisputesUpdate {
|
||||
_u.mutation.SetAppealedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAppealedAt sets the "appealed_at" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableAppealedAt(v *time.Time) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetAppealedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearAppealedAt clears the value of the "appealed_at" field.
|
||||
func (_u *DisputesUpdate) ClearAppealedAt() *DisputesUpdate {
|
||||
_u.mutation.ClearAppealedAt()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetResolvedBy sets the "resolved_by" field.
|
||||
func (_u *DisputesUpdate) SetResolvedBy(v int64) *DisputesUpdate {
|
||||
_u.mutation.ResetResolvedBy()
|
||||
_u.mutation.SetResolvedBy(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableResolvedBy sets the "resolved_by" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableResolvedBy(v *int64) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetResolvedBy(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddResolvedBy adds value to the "resolved_by" field.
|
||||
func (_u *DisputesUpdate) AddResolvedBy(v int64) *DisputesUpdate {
|
||||
_u.mutation.AddResolvedBy(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearResolvedBy clears the value of the "resolved_by" field.
|
||||
func (_u *DisputesUpdate) ClearResolvedBy() *DisputesUpdate {
|
||||
_u.mutation.ClearResolvedBy()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetResolvedAt sets the "resolved_at" field.
|
||||
func (_u *DisputesUpdate) SetResolvedAt(v time.Time) *DisputesUpdate {
|
||||
_u.mutation.SetResolvedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil.
|
||||
func (_u *DisputesUpdate) SetNillableResolvedAt(v *time.Time) *DisputesUpdate {
|
||||
if v != nil {
|
||||
_u.SetResolvedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearResolvedAt clears the value of the "resolved_at" field.
|
||||
func (_u *DisputesUpdate) ClearResolvedAt() *DisputesUpdate {
|
||||
_u.mutation.ClearResolvedAt()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *DisputesUpdate) SetUpdatedAt(v time.Time) *DisputesUpdate {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the DisputesMutation object of the builder.
|
||||
func (_u *DisputesUpdate) Mutation() *DisputesMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *DisputesUpdate) 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 *DisputesUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *DisputesUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *DisputesUpdate) 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 *DisputesUpdate) defaults() {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
v := disputes.UpdateDefaultUpdatedAt()
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *DisputesUpdate) check() error {
|
||||
if v, ok := _u.mutation.InitiatorName(); ok {
|
||||
if err := disputes.InitiatorNameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "initiator_name", err: fmt.Errorf(`models: validator failed for field "Disputes.initiator_name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Status(); ok {
|
||||
if err := disputes.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "Disputes.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Result(); ok {
|
||||
if err := disputes.ResultValidator(v); err != nil {
|
||||
return &ValidationError{Name: "result", err: fmt.Errorf(`models: validator failed for field "Disputes.result": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *DisputesUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(disputes.Table, disputes.Columns, sqlgraph.NewFieldSpec(disputes.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.OrderID(); ok {
|
||||
_spec.SetField(disputes.FieldOrderID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedOrderID(); ok {
|
||||
_spec.AddField(disputes.FieldOrderID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.InitiatorID(); ok {
|
||||
_spec.SetField(disputes.FieldInitiatorID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedInitiatorID(); ok {
|
||||
_spec.AddField(disputes.FieldInitiatorID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.InitiatorName(); ok {
|
||||
_spec.SetField(disputes.FieldInitiatorName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.RespondentID(); ok {
|
||||
_spec.SetField(disputes.FieldRespondentID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedRespondentID(); ok {
|
||||
_spec.AddField(disputes.FieldRespondentID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Reason(); ok {
|
||||
_spec.SetField(disputes.FieldReason, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Evidence(); ok {
|
||||
_spec.SetField(disputes.FieldEvidence, field.TypeOther, value)
|
||||
}
|
||||
if _u.mutation.EvidenceCleared() {
|
||||
_spec.ClearField(disputes.FieldEvidence, field.TypeOther)
|
||||
}
|
||||
if value, ok := _u.mutation.Status(); ok {
|
||||
_spec.SetField(disputes.FieldStatus, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Result(); ok {
|
||||
_spec.SetField(disputes.FieldResult, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.ResultCleared() {
|
||||
_spec.ClearField(disputes.FieldResult, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.RespondentReason(); ok {
|
||||
_spec.SetField(disputes.FieldRespondentReason, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.RespondentReasonCleared() {
|
||||
_spec.ClearField(disputes.FieldRespondentReason, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.RespondentEvidence(); ok {
|
||||
_spec.SetField(disputes.FieldRespondentEvidence, field.TypeOther, value)
|
||||
}
|
||||
if _u.mutation.RespondentEvidenceCleared() {
|
||||
_spec.ClearField(disputes.FieldRespondentEvidence, field.TypeOther)
|
||||
}
|
||||
if value, ok := _u.mutation.AppealReason(); ok {
|
||||
_spec.SetField(disputes.FieldAppealReason, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.AppealReasonCleared() {
|
||||
_spec.ClearField(disputes.FieldAppealReason, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.AppealedAt(); ok {
|
||||
_spec.SetField(disputes.FieldAppealedAt, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.AppealedAtCleared() {
|
||||
_spec.ClearField(disputes.FieldAppealedAt, field.TypeTime)
|
||||
}
|
||||
if value, ok := _u.mutation.ResolvedBy(); ok {
|
||||
_spec.SetField(disputes.FieldResolvedBy, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedResolvedBy(); ok {
|
||||
_spec.AddField(disputes.FieldResolvedBy, field.TypeInt64, value)
|
||||
}
|
||||
if _u.mutation.ResolvedByCleared() {
|
||||
_spec.ClearField(disputes.FieldResolvedBy, field.TypeInt64)
|
||||
}
|
||||
if value, ok := _u.mutation.ResolvedAt(); ok {
|
||||
_spec.SetField(disputes.FieldResolvedAt, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.ResolvedAtCleared() {
|
||||
_spec.ClearField(disputes.FieldResolvedAt, field.TypeTime)
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(disputes.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{disputes.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// DisputesUpdateOne is the builder for updating a single Disputes entity.
|
||||
type DisputesUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *DisputesMutation
|
||||
}
|
||||
|
||||
// SetOrderID sets the "order_id" field.
|
||||
func (_u *DisputesUpdateOne) SetOrderID(v int64) *DisputesUpdateOne {
|
||||
_u.mutation.ResetOrderID()
|
||||
_u.mutation.SetOrderID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOrderID sets the "order_id" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableOrderID(v *int64) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetOrderID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddOrderID adds value to the "order_id" field.
|
||||
func (_u *DisputesUpdateOne) AddOrderID(v int64) *DisputesUpdateOne {
|
||||
_u.mutation.AddOrderID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInitiatorID sets the "initiator_id" field.
|
||||
func (_u *DisputesUpdateOne) SetInitiatorID(v int64) *DisputesUpdateOne {
|
||||
_u.mutation.ResetInitiatorID()
|
||||
_u.mutation.SetInitiatorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInitiatorID sets the "initiator_id" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableInitiatorID(v *int64) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetInitiatorID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddInitiatorID adds value to the "initiator_id" field.
|
||||
func (_u *DisputesUpdateOne) AddInitiatorID(v int64) *DisputesUpdateOne {
|
||||
_u.mutation.AddInitiatorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInitiatorName sets the "initiator_name" field.
|
||||
func (_u *DisputesUpdateOne) SetInitiatorName(v string) *DisputesUpdateOne {
|
||||
_u.mutation.SetInitiatorName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInitiatorName sets the "initiator_name" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableInitiatorName(v *string) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetInitiatorName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetRespondentID sets the "respondent_id" field.
|
||||
func (_u *DisputesUpdateOne) SetRespondentID(v int64) *DisputesUpdateOne {
|
||||
_u.mutation.ResetRespondentID()
|
||||
_u.mutation.SetRespondentID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableRespondentID sets the "respondent_id" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableRespondentID(v *int64) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetRespondentID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddRespondentID adds value to the "respondent_id" field.
|
||||
func (_u *DisputesUpdateOne) AddRespondentID(v int64) *DisputesUpdateOne {
|
||||
_u.mutation.AddRespondentID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (_u *DisputesUpdateOne) SetReason(v string) *DisputesUpdateOne {
|
||||
_u.mutation.SetReason(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableReason sets the "reason" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableReason(v *string) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetReason(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetEvidence sets the "evidence" field.
|
||||
func (_u *DisputesUpdateOne) SetEvidence(v types.TextArray) *DisputesUpdateOne {
|
||||
_u.mutation.SetEvidence(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableEvidence sets the "evidence" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableEvidence(v *types.TextArray) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetEvidence(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearEvidence clears the value of the "evidence" field.
|
||||
func (_u *DisputesUpdateOne) ClearEvidence() *DisputesUpdateOne {
|
||||
_u.mutation.ClearEvidence()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *DisputesUpdateOne) SetStatus(v string) *DisputesUpdateOne {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableStatus(v *string) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetResult sets the "result" field.
|
||||
func (_u *DisputesUpdateOne) SetResult(v string) *DisputesUpdateOne {
|
||||
_u.mutation.SetResult(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableResult sets the "result" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableResult(v *string) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetResult(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearResult clears the value of the "result" field.
|
||||
func (_u *DisputesUpdateOne) ClearResult() *DisputesUpdateOne {
|
||||
_u.mutation.ClearResult()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetRespondentReason sets the "respondent_reason" field.
|
||||
func (_u *DisputesUpdateOne) SetRespondentReason(v string) *DisputesUpdateOne {
|
||||
_u.mutation.SetRespondentReason(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableRespondentReason sets the "respondent_reason" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableRespondentReason(v *string) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetRespondentReason(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearRespondentReason clears the value of the "respondent_reason" field.
|
||||
func (_u *DisputesUpdateOne) ClearRespondentReason() *DisputesUpdateOne {
|
||||
_u.mutation.ClearRespondentReason()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetRespondentEvidence sets the "respondent_evidence" field.
|
||||
func (_u *DisputesUpdateOne) SetRespondentEvidence(v types.TextArray) *DisputesUpdateOne {
|
||||
_u.mutation.SetRespondentEvidence(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableRespondentEvidence sets the "respondent_evidence" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableRespondentEvidence(v *types.TextArray) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetRespondentEvidence(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearRespondentEvidence clears the value of the "respondent_evidence" field.
|
||||
func (_u *DisputesUpdateOne) ClearRespondentEvidence() *DisputesUpdateOne {
|
||||
_u.mutation.ClearRespondentEvidence()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAppealReason sets the "appeal_reason" field.
|
||||
func (_u *DisputesUpdateOne) SetAppealReason(v string) *DisputesUpdateOne {
|
||||
_u.mutation.SetAppealReason(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAppealReason sets the "appeal_reason" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableAppealReason(v *string) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetAppealReason(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearAppealReason clears the value of the "appeal_reason" field.
|
||||
func (_u *DisputesUpdateOne) ClearAppealReason() *DisputesUpdateOne {
|
||||
_u.mutation.ClearAppealReason()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAppealedAt sets the "appealed_at" field.
|
||||
func (_u *DisputesUpdateOne) SetAppealedAt(v time.Time) *DisputesUpdateOne {
|
||||
_u.mutation.SetAppealedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAppealedAt sets the "appealed_at" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableAppealedAt(v *time.Time) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetAppealedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearAppealedAt clears the value of the "appealed_at" field.
|
||||
func (_u *DisputesUpdateOne) ClearAppealedAt() *DisputesUpdateOne {
|
||||
_u.mutation.ClearAppealedAt()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetResolvedBy sets the "resolved_by" field.
|
||||
func (_u *DisputesUpdateOne) SetResolvedBy(v int64) *DisputesUpdateOne {
|
||||
_u.mutation.ResetResolvedBy()
|
||||
_u.mutation.SetResolvedBy(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableResolvedBy sets the "resolved_by" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableResolvedBy(v *int64) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetResolvedBy(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddResolvedBy adds value to the "resolved_by" field.
|
||||
func (_u *DisputesUpdateOne) AddResolvedBy(v int64) *DisputesUpdateOne {
|
||||
_u.mutation.AddResolvedBy(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearResolvedBy clears the value of the "resolved_by" field.
|
||||
func (_u *DisputesUpdateOne) ClearResolvedBy() *DisputesUpdateOne {
|
||||
_u.mutation.ClearResolvedBy()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetResolvedAt sets the "resolved_at" field.
|
||||
func (_u *DisputesUpdateOne) SetResolvedAt(v time.Time) *DisputesUpdateOne {
|
||||
_u.mutation.SetResolvedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil.
|
||||
func (_u *DisputesUpdateOne) SetNillableResolvedAt(v *time.Time) *DisputesUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetResolvedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearResolvedAt clears the value of the "resolved_at" field.
|
||||
func (_u *DisputesUpdateOne) ClearResolvedAt() *DisputesUpdateOne {
|
||||
_u.mutation.ClearResolvedAt()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *DisputesUpdateOne) SetUpdatedAt(v time.Time) *DisputesUpdateOne {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the DisputesMutation object of the builder.
|
||||
func (_u *DisputesUpdateOne) Mutation() *DisputesMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the DisputesUpdate builder.
|
||||
func (_u *DisputesUpdateOne) Where(ps ...predicate.Disputes) *DisputesUpdateOne {
|
||||
_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 *DisputesUpdateOne) Select(field string, fields ...string) *DisputesUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Disputes entity.
|
||||
func (_u *DisputesUpdateOne) Save(ctx context.Context) (*Disputes, error) {
|
||||
_u.defaults()
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *DisputesUpdateOne) SaveX(ctx context.Context) *Disputes {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *DisputesUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *DisputesUpdateOne) 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 *DisputesUpdateOne) defaults() {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
v := disputes.UpdateDefaultUpdatedAt()
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *DisputesUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.InitiatorName(); ok {
|
||||
if err := disputes.InitiatorNameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "initiator_name", err: fmt.Errorf(`models: validator failed for field "Disputes.initiator_name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Status(); ok {
|
||||
if err := disputes.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "Disputes.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Result(); ok {
|
||||
if err := disputes.ResultValidator(v); err != nil {
|
||||
return &ValidationError{Name: "result", err: fmt.Errorf(`models: validator failed for field "Disputes.result": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *DisputesUpdateOne) sqlSave(ctx context.Context) (_node *Disputes, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(disputes.Table, disputes.Columns, sqlgraph.NewFieldSpec(disputes.FieldID, field.TypeInt64))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Disputes.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, disputes.FieldID)
|
||||
for _, f := range fields {
|
||||
if !disputes.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
||||
}
|
||||
if f != disputes.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.OrderID(); ok {
|
||||
_spec.SetField(disputes.FieldOrderID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedOrderID(); ok {
|
||||
_spec.AddField(disputes.FieldOrderID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.InitiatorID(); ok {
|
||||
_spec.SetField(disputes.FieldInitiatorID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedInitiatorID(); ok {
|
||||
_spec.AddField(disputes.FieldInitiatorID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.InitiatorName(); ok {
|
||||
_spec.SetField(disputes.FieldInitiatorName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.RespondentID(); ok {
|
||||
_spec.SetField(disputes.FieldRespondentID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedRespondentID(); ok {
|
||||
_spec.AddField(disputes.FieldRespondentID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Reason(); ok {
|
||||
_spec.SetField(disputes.FieldReason, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Evidence(); ok {
|
||||
_spec.SetField(disputes.FieldEvidence, field.TypeOther, value)
|
||||
}
|
||||
if _u.mutation.EvidenceCleared() {
|
||||
_spec.ClearField(disputes.FieldEvidence, field.TypeOther)
|
||||
}
|
||||
if value, ok := _u.mutation.Status(); ok {
|
||||
_spec.SetField(disputes.FieldStatus, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Result(); ok {
|
||||
_spec.SetField(disputes.FieldResult, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.ResultCleared() {
|
||||
_spec.ClearField(disputes.FieldResult, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.RespondentReason(); ok {
|
||||
_spec.SetField(disputes.FieldRespondentReason, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.RespondentReasonCleared() {
|
||||
_spec.ClearField(disputes.FieldRespondentReason, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.RespondentEvidence(); ok {
|
||||
_spec.SetField(disputes.FieldRespondentEvidence, field.TypeOther, value)
|
||||
}
|
||||
if _u.mutation.RespondentEvidenceCleared() {
|
||||
_spec.ClearField(disputes.FieldRespondentEvidence, field.TypeOther)
|
||||
}
|
||||
if value, ok := _u.mutation.AppealReason(); ok {
|
||||
_spec.SetField(disputes.FieldAppealReason, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.AppealReasonCleared() {
|
||||
_spec.ClearField(disputes.FieldAppealReason, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.AppealedAt(); ok {
|
||||
_spec.SetField(disputes.FieldAppealedAt, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.AppealedAtCleared() {
|
||||
_spec.ClearField(disputes.FieldAppealedAt, field.TypeTime)
|
||||
}
|
||||
if value, ok := _u.mutation.ResolvedBy(); ok {
|
||||
_spec.SetField(disputes.FieldResolvedBy, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedResolvedBy(); ok {
|
||||
_spec.AddField(disputes.FieldResolvedBy, field.TypeInt64, value)
|
||||
}
|
||||
if _u.mutation.ResolvedByCleared() {
|
||||
_spec.ClearField(disputes.FieldResolvedBy, field.TypeInt64)
|
||||
}
|
||||
if value, ok := _u.mutation.ResolvedAt(); ok {
|
||||
_spec.SetField(disputes.FieldResolvedAt, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.ResolvedAtCleared() {
|
||||
_spec.ClearField(disputes.FieldResolvedAt, field.TypeTime)
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(disputes.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
_node = &Disputes{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{disputes.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,166 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputetimeline"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// DisputeTimeline is the model entity for the DisputeTimeline schema.
|
||||
type DisputeTimeline struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int64 `json:"id,omitempty"`
|
||||
// DisputeID holds the value of the "dispute_id" field.
|
||||
DisputeID int64 `json:"dispute_id,omitempty"`
|
||||
// EventType holds the value of the "event_type" field.
|
||||
EventType string `json:"event_type,omitempty"`
|
||||
// ActorID holds the value of the "actor_id" field.
|
||||
ActorID int64 `json:"actor_id,omitempty"`
|
||||
// ActorName holds the value of the "actor_name" field.
|
||||
ActorName string `json:"actor_name,omitempty"`
|
||||
// Details holds the value of the "details" field.
|
||||
Details map[string]interface{} `json:"details,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*DisputeTimeline) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case disputetimeline.FieldDetails:
|
||||
values[i] = new([]byte)
|
||||
case disputetimeline.FieldID, disputetimeline.FieldDisputeID, disputetimeline.FieldActorID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case disputetimeline.FieldEventType, disputetimeline.FieldActorName:
|
||||
values[i] = new(sql.NullString)
|
||||
case disputetimeline.FieldCreatedAt:
|
||||
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 DisputeTimeline fields.
|
||||
func (_m *DisputeTimeline) 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 disputetimeline.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 disputetimeline.FieldDisputeID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field dispute_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.DisputeID = value.Int64
|
||||
}
|
||||
case disputetimeline.FieldEventType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field event_type", values[i])
|
||||
} else if value.Valid {
|
||||
_m.EventType = value.String
|
||||
}
|
||||
case disputetimeline.FieldActorID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field actor_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ActorID = value.Int64
|
||||
}
|
||||
case disputetimeline.FieldActorName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field actor_name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ActorName = value.String
|
||||
}
|
||||
case disputetimeline.FieldDetails:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field details", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &_m.Details); err != nil {
|
||||
return fmt.Errorf("unmarshal field details: %w", err)
|
||||
}
|
||||
}
|
||||
case disputetimeline.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
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the DisputeTimeline.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *DisputeTimeline) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this DisputeTimeline.
|
||||
// Note that you need to call DisputeTimeline.Unwrap() before calling this method if this DisputeTimeline
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *DisputeTimeline) Update() *DisputeTimelineUpdateOne {
|
||||
return NewDisputeTimelineClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the DisputeTimeline 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 *DisputeTimeline) Unwrap() *DisputeTimeline {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("models: DisputeTimeline is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *DisputeTimeline) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("DisputeTimeline(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("dispute_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.DisputeID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("event_type=")
|
||||
builder.WriteString(_m.EventType)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("actor_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.ActorID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("actor_name=")
|
||||
builder.WriteString(_m.ActorName)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("details=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Details))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// DisputeTimelines is a parsable slice of DisputeTimeline.
|
||||
type DisputeTimelines []*DisputeTimeline
|
||||
@@ -0,0 +1,93 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package disputetimeline
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the disputetimeline type in the database.
|
||||
Label = "dispute_timeline"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldDisputeID holds the string denoting the dispute_id field in the database.
|
||||
FieldDisputeID = "dispute_id"
|
||||
// FieldEventType holds the string denoting the event_type field in the database.
|
||||
FieldEventType = "event_type"
|
||||
// FieldActorID holds the string denoting the actor_id field in the database.
|
||||
FieldActorID = "actor_id"
|
||||
// FieldActorName holds the string denoting the actor_name field in the database.
|
||||
FieldActorName = "actor_name"
|
||||
// FieldDetails holds the string denoting the details field in the database.
|
||||
FieldDetails = "details"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// Table holds the table name of the disputetimeline in the database.
|
||||
Table = "dispute_timelines"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for disputetimeline fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldDisputeID,
|
||||
FieldEventType,
|
||||
FieldActorID,
|
||||
FieldActorName,
|
||||
FieldDetails,
|
||||
FieldCreatedAt,
|
||||
}
|
||||
|
||||
// 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 (
|
||||
// EventTypeValidator is a validator for the "event_type" field. It is called by the builders before save.
|
||||
EventTypeValidator func(string) error
|
||||
// ActorNameValidator is a validator for the "actor_name" field. It is called by the builders before save.
|
||||
ActorNameValidator func(string) error
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the DisputeTimeline 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()
|
||||
}
|
||||
|
||||
// ByDisputeID orders the results by the dispute_id field.
|
||||
func ByDisputeID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDisputeID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByEventType orders the results by the event_type field.
|
||||
func ByEventType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldEventType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByActorID orders the results by the actor_id field.
|
||||
func ByActorID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldActorID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByActorName orders the results by the actor_name field.
|
||||
func ByActorName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldActorName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
@@ -0,0 +1,375 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package disputetimeline
|
||||
|
||||
import (
|
||||
"juwan-backend/app/dispute/rpc/internal/models/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// DisputeID applies equality check predicate on the "dispute_id" field. It's identical to DisputeIDEQ.
|
||||
func DisputeID(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldDisputeID, v))
|
||||
}
|
||||
|
||||
// EventType applies equality check predicate on the "event_type" field. It's identical to EventTypeEQ.
|
||||
func EventType(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldEventType, v))
|
||||
}
|
||||
|
||||
// ActorID applies equality check predicate on the "actor_id" field. It's identical to ActorIDEQ.
|
||||
func ActorID(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorName applies equality check predicate on the "actor_name" field. It's identical to ActorNameEQ.
|
||||
func ActorName(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldActorName, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// DisputeIDEQ applies the EQ predicate on the "dispute_id" field.
|
||||
func DisputeIDEQ(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldDisputeID, v))
|
||||
}
|
||||
|
||||
// DisputeIDNEQ applies the NEQ predicate on the "dispute_id" field.
|
||||
func DisputeIDNEQ(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNEQ(FieldDisputeID, v))
|
||||
}
|
||||
|
||||
// DisputeIDIn applies the In predicate on the "dispute_id" field.
|
||||
func DisputeIDIn(vs ...int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldIn(FieldDisputeID, vs...))
|
||||
}
|
||||
|
||||
// DisputeIDNotIn applies the NotIn predicate on the "dispute_id" field.
|
||||
func DisputeIDNotIn(vs ...int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNotIn(FieldDisputeID, vs...))
|
||||
}
|
||||
|
||||
// DisputeIDGT applies the GT predicate on the "dispute_id" field.
|
||||
func DisputeIDGT(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGT(FieldDisputeID, v))
|
||||
}
|
||||
|
||||
// DisputeIDGTE applies the GTE predicate on the "dispute_id" field.
|
||||
func DisputeIDGTE(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGTE(FieldDisputeID, v))
|
||||
}
|
||||
|
||||
// DisputeIDLT applies the LT predicate on the "dispute_id" field.
|
||||
func DisputeIDLT(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLT(FieldDisputeID, v))
|
||||
}
|
||||
|
||||
// DisputeIDLTE applies the LTE predicate on the "dispute_id" field.
|
||||
func DisputeIDLTE(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLTE(FieldDisputeID, v))
|
||||
}
|
||||
|
||||
// EventTypeEQ applies the EQ predicate on the "event_type" field.
|
||||
func EventTypeEQ(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldEventType, v))
|
||||
}
|
||||
|
||||
// EventTypeNEQ applies the NEQ predicate on the "event_type" field.
|
||||
func EventTypeNEQ(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNEQ(FieldEventType, v))
|
||||
}
|
||||
|
||||
// EventTypeIn applies the In predicate on the "event_type" field.
|
||||
func EventTypeIn(vs ...string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldIn(FieldEventType, vs...))
|
||||
}
|
||||
|
||||
// EventTypeNotIn applies the NotIn predicate on the "event_type" field.
|
||||
func EventTypeNotIn(vs ...string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNotIn(FieldEventType, vs...))
|
||||
}
|
||||
|
||||
// EventTypeGT applies the GT predicate on the "event_type" field.
|
||||
func EventTypeGT(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGT(FieldEventType, v))
|
||||
}
|
||||
|
||||
// EventTypeGTE applies the GTE predicate on the "event_type" field.
|
||||
func EventTypeGTE(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGTE(FieldEventType, v))
|
||||
}
|
||||
|
||||
// EventTypeLT applies the LT predicate on the "event_type" field.
|
||||
func EventTypeLT(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLT(FieldEventType, v))
|
||||
}
|
||||
|
||||
// EventTypeLTE applies the LTE predicate on the "event_type" field.
|
||||
func EventTypeLTE(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLTE(FieldEventType, v))
|
||||
}
|
||||
|
||||
// EventTypeContains applies the Contains predicate on the "event_type" field.
|
||||
func EventTypeContains(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldContains(FieldEventType, v))
|
||||
}
|
||||
|
||||
// EventTypeHasPrefix applies the HasPrefix predicate on the "event_type" field.
|
||||
func EventTypeHasPrefix(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldHasPrefix(FieldEventType, v))
|
||||
}
|
||||
|
||||
// EventTypeHasSuffix applies the HasSuffix predicate on the "event_type" field.
|
||||
func EventTypeHasSuffix(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldHasSuffix(FieldEventType, v))
|
||||
}
|
||||
|
||||
// EventTypeEqualFold applies the EqualFold predicate on the "event_type" field.
|
||||
func EventTypeEqualFold(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEqualFold(FieldEventType, v))
|
||||
}
|
||||
|
||||
// EventTypeContainsFold applies the ContainsFold predicate on the "event_type" field.
|
||||
func EventTypeContainsFold(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldContainsFold(FieldEventType, v))
|
||||
}
|
||||
|
||||
// ActorIDEQ applies the EQ predicate on the "actor_id" field.
|
||||
func ActorIDEQ(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorIDNEQ applies the NEQ predicate on the "actor_id" field.
|
||||
func ActorIDNEQ(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNEQ(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorIDIn applies the In predicate on the "actor_id" field.
|
||||
func ActorIDIn(vs ...int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldIn(FieldActorID, vs...))
|
||||
}
|
||||
|
||||
// ActorIDNotIn applies the NotIn predicate on the "actor_id" field.
|
||||
func ActorIDNotIn(vs ...int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNotIn(FieldActorID, vs...))
|
||||
}
|
||||
|
||||
// ActorIDGT applies the GT predicate on the "actor_id" field.
|
||||
func ActorIDGT(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGT(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorIDGTE applies the GTE predicate on the "actor_id" field.
|
||||
func ActorIDGTE(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGTE(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorIDLT applies the LT predicate on the "actor_id" field.
|
||||
func ActorIDLT(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLT(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorIDLTE applies the LTE predicate on the "actor_id" field.
|
||||
func ActorIDLTE(v int64) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLTE(FieldActorID, v))
|
||||
}
|
||||
|
||||
// ActorIDIsNil applies the IsNil predicate on the "actor_id" field.
|
||||
func ActorIDIsNil() predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldIsNull(FieldActorID))
|
||||
}
|
||||
|
||||
// ActorIDNotNil applies the NotNil predicate on the "actor_id" field.
|
||||
func ActorIDNotNil() predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNotNull(FieldActorID))
|
||||
}
|
||||
|
||||
// ActorNameEQ applies the EQ predicate on the "actor_name" field.
|
||||
func ActorNameEQ(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldActorName, v))
|
||||
}
|
||||
|
||||
// ActorNameNEQ applies the NEQ predicate on the "actor_name" field.
|
||||
func ActorNameNEQ(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNEQ(FieldActorName, v))
|
||||
}
|
||||
|
||||
// ActorNameIn applies the In predicate on the "actor_name" field.
|
||||
func ActorNameIn(vs ...string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldIn(FieldActorName, vs...))
|
||||
}
|
||||
|
||||
// ActorNameNotIn applies the NotIn predicate on the "actor_name" field.
|
||||
func ActorNameNotIn(vs ...string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNotIn(FieldActorName, vs...))
|
||||
}
|
||||
|
||||
// ActorNameGT applies the GT predicate on the "actor_name" field.
|
||||
func ActorNameGT(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGT(FieldActorName, v))
|
||||
}
|
||||
|
||||
// ActorNameGTE applies the GTE predicate on the "actor_name" field.
|
||||
func ActorNameGTE(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGTE(FieldActorName, v))
|
||||
}
|
||||
|
||||
// ActorNameLT applies the LT predicate on the "actor_name" field.
|
||||
func ActorNameLT(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLT(FieldActorName, v))
|
||||
}
|
||||
|
||||
// ActorNameLTE applies the LTE predicate on the "actor_name" field.
|
||||
func ActorNameLTE(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLTE(FieldActorName, v))
|
||||
}
|
||||
|
||||
// ActorNameContains applies the Contains predicate on the "actor_name" field.
|
||||
func ActorNameContains(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldContains(FieldActorName, v))
|
||||
}
|
||||
|
||||
// ActorNameHasPrefix applies the HasPrefix predicate on the "actor_name" field.
|
||||
func ActorNameHasPrefix(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldHasPrefix(FieldActorName, v))
|
||||
}
|
||||
|
||||
// ActorNameHasSuffix applies the HasSuffix predicate on the "actor_name" field.
|
||||
func ActorNameHasSuffix(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldHasSuffix(FieldActorName, v))
|
||||
}
|
||||
|
||||
// ActorNameIsNil applies the IsNil predicate on the "actor_name" field.
|
||||
func ActorNameIsNil() predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldIsNull(FieldActorName))
|
||||
}
|
||||
|
||||
// ActorNameNotNil applies the NotNil predicate on the "actor_name" field.
|
||||
func ActorNameNotNil() predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNotNull(FieldActorName))
|
||||
}
|
||||
|
||||
// ActorNameEqualFold applies the EqualFold predicate on the "actor_name" field.
|
||||
func ActorNameEqualFold(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEqualFold(FieldActorName, v))
|
||||
}
|
||||
|
||||
// ActorNameContainsFold applies the ContainsFold predicate on the "actor_name" field.
|
||||
func ActorNameContainsFold(v string) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldContainsFold(FieldActorName, v))
|
||||
}
|
||||
|
||||
// DetailsIsNil applies the IsNil predicate on the "details" field.
|
||||
func DetailsIsNil() predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldIsNull(FieldDetails))
|
||||
}
|
||||
|
||||
// DetailsNotNil applies the NotNil predicate on the "details" field.
|
||||
func DetailsNotNil() predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNotNull(FieldDetails))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.DisputeTimeline) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.DisputeTimeline) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.DisputeTimeline) predicate.DisputeTimeline {
|
||||
return predicate.DisputeTimeline(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputetimeline"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// DisputeTimelineCreate is the builder for creating a DisputeTimeline entity.
|
||||
type DisputeTimelineCreate struct {
|
||||
config
|
||||
mutation *DisputeTimelineMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetDisputeID sets the "dispute_id" field.
|
||||
func (_c *DisputeTimelineCreate) SetDisputeID(v int64) *DisputeTimelineCreate {
|
||||
_c.mutation.SetDisputeID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetEventType sets the "event_type" field.
|
||||
func (_c *DisputeTimelineCreate) SetEventType(v string) *DisputeTimelineCreate {
|
||||
_c.mutation.SetEventType(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetActorID sets the "actor_id" field.
|
||||
func (_c *DisputeTimelineCreate) SetActorID(v int64) *DisputeTimelineCreate {
|
||||
_c.mutation.SetActorID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableActorID sets the "actor_id" field if the given value is not nil.
|
||||
func (_c *DisputeTimelineCreate) SetNillableActorID(v *int64) *DisputeTimelineCreate {
|
||||
if v != nil {
|
||||
_c.SetActorID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetActorName sets the "actor_name" field.
|
||||
func (_c *DisputeTimelineCreate) SetActorName(v string) *DisputeTimelineCreate {
|
||||
_c.mutation.SetActorName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableActorName sets the "actor_name" field if the given value is not nil.
|
||||
func (_c *DisputeTimelineCreate) SetNillableActorName(v *string) *DisputeTimelineCreate {
|
||||
if v != nil {
|
||||
_c.SetActorName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetDetails sets the "details" field.
|
||||
func (_c *DisputeTimelineCreate) SetDetails(v map[string]interface{}) *DisputeTimelineCreate {
|
||||
_c.mutation.SetDetails(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *DisputeTimelineCreate) SetCreatedAt(v time.Time) *DisputeTimelineCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *DisputeTimelineCreate) SetNillableCreatedAt(v *time.Time) *DisputeTimelineCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *DisputeTimelineCreate) SetID(v int64) *DisputeTimelineCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the DisputeTimelineMutation object of the builder.
|
||||
func (_c *DisputeTimelineCreate) Mutation() *DisputeTimelineMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the DisputeTimeline in the database.
|
||||
func (_c *DisputeTimelineCreate) Save(ctx context.Context) (*DisputeTimeline, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *DisputeTimelineCreate) SaveX(ctx context.Context) *DisputeTimeline {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *DisputeTimelineCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *DisputeTimelineCreate) 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 *DisputeTimelineCreate) defaults() {
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := disputetimeline.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *DisputeTimelineCreate) check() error {
|
||||
if _, ok := _c.mutation.DisputeID(); !ok {
|
||||
return &ValidationError{Name: "dispute_id", err: errors.New(`models: missing required field "DisputeTimeline.dispute_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.EventType(); !ok {
|
||||
return &ValidationError{Name: "event_type", err: errors.New(`models: missing required field "DisputeTimeline.event_type"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.EventType(); ok {
|
||||
if err := disputetimeline.EventTypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "event_type", err: fmt.Errorf(`models: validator failed for field "DisputeTimeline.event_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _c.mutation.ActorName(); ok {
|
||||
if err := disputetimeline.ActorNameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "actor_name", err: fmt.Errorf(`models: validator failed for field "DisputeTimeline.actor_name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "DisputeTimeline.created_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *DisputeTimelineCreate) sqlSave(ctx context.Context) (*DisputeTimeline, 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 *DisputeTimelineCreate) createSpec() (*DisputeTimeline, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &DisputeTimeline{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(disputetimeline.Table, sqlgraph.NewFieldSpec(disputetimeline.FieldID, field.TypeInt64))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := _c.mutation.DisputeID(); ok {
|
||||
_spec.SetField(disputetimeline.FieldDisputeID, field.TypeInt64, value)
|
||||
_node.DisputeID = value
|
||||
}
|
||||
if value, ok := _c.mutation.EventType(); ok {
|
||||
_spec.SetField(disputetimeline.FieldEventType, field.TypeString, value)
|
||||
_node.EventType = value
|
||||
}
|
||||
if value, ok := _c.mutation.ActorID(); ok {
|
||||
_spec.SetField(disputetimeline.FieldActorID, field.TypeInt64, value)
|
||||
_node.ActorID = value
|
||||
}
|
||||
if value, ok := _c.mutation.ActorName(); ok {
|
||||
_spec.SetField(disputetimeline.FieldActorName, field.TypeString, value)
|
||||
_node.ActorName = value
|
||||
}
|
||||
if value, ok := _c.mutation.Details(); ok {
|
||||
_spec.SetField(disputetimeline.FieldDetails, field.TypeJSON, value)
|
||||
_node.Details = value
|
||||
}
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(disputetimeline.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// DisputeTimelineCreateBulk is the builder for creating many DisputeTimeline entities in bulk.
|
||||
type DisputeTimelineCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*DisputeTimelineCreate
|
||||
}
|
||||
|
||||
// Save creates the DisputeTimeline entities in the database.
|
||||
func (_c *DisputeTimelineCreateBulk) Save(ctx context.Context) ([]*DisputeTimeline, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*DisputeTimeline, 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.(*DisputeTimelineMutation)
|
||||
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 *DisputeTimelineCreateBulk) SaveX(ctx context.Context) []*DisputeTimeline {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *DisputeTimelineCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *DisputeTimelineCreateBulk) 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/dispute/rpc/internal/models/disputetimeline"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// DisputeTimelineDelete is the builder for deleting a DisputeTimeline entity.
|
||||
type DisputeTimelineDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *DisputeTimelineMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the DisputeTimelineDelete builder.
|
||||
func (_d *DisputeTimelineDelete) Where(ps ...predicate.DisputeTimeline) *DisputeTimelineDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *DisputeTimelineDelete) 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 *DisputeTimelineDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *DisputeTimelineDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(disputetimeline.Table, sqlgraph.NewFieldSpec(disputetimeline.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
|
||||
}
|
||||
|
||||
// DisputeTimelineDeleteOne is the builder for deleting a single DisputeTimeline entity.
|
||||
type DisputeTimelineDeleteOne struct {
|
||||
_d *DisputeTimelineDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the DisputeTimelineDelete builder.
|
||||
func (_d *DisputeTimelineDeleteOne) Where(ps ...predicate.DisputeTimeline) *DisputeTimelineDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *DisputeTimelineDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{disputetimeline.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *DisputeTimelineDeleteOne) 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/dispute/rpc/internal/models/disputetimeline"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/predicate"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// DisputeTimelineQuery is the builder for querying DisputeTimeline entities.
|
||||
type DisputeTimelineQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []disputetimeline.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.DisputeTimeline
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the DisputeTimelineQuery builder.
|
||||
func (_q *DisputeTimelineQuery) Where(ps ...predicate.DisputeTimeline) *DisputeTimelineQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *DisputeTimelineQuery) Limit(limit int) *DisputeTimelineQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *DisputeTimelineQuery) Offset(offset int) *DisputeTimelineQuery {
|
||||
_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 *DisputeTimelineQuery) Unique(unique bool) *DisputeTimelineQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *DisputeTimelineQuery) Order(o ...disputetimeline.OrderOption) *DisputeTimelineQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first DisputeTimeline entity from the query.
|
||||
// Returns a *NotFoundError when no DisputeTimeline was found.
|
||||
func (_q *DisputeTimelineQuery) First(ctx context.Context) (*DisputeTimeline, 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{disputetimeline.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *DisputeTimelineQuery) FirstX(ctx context.Context) *DisputeTimeline {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first DisputeTimeline ID from the query.
|
||||
// Returns a *NotFoundError when no DisputeTimeline ID was found.
|
||||
func (_q *DisputeTimelineQuery) 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{disputetimeline.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *DisputeTimelineQuery) FirstIDX(ctx context.Context) int64 {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single DisputeTimeline entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one DisputeTimeline entity is found.
|
||||
// Returns a *NotFoundError when no DisputeTimeline entities are found.
|
||||
func (_q *DisputeTimelineQuery) Only(ctx context.Context) (*DisputeTimeline, 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{disputetimeline.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{disputetimeline.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *DisputeTimelineQuery) OnlyX(ctx context.Context) *DisputeTimeline {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only DisputeTimeline ID in the query.
|
||||
// Returns a *NotSingularError when more than one DisputeTimeline ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *DisputeTimelineQuery) 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{disputetimeline.Label}
|
||||
default:
|
||||
err = &NotSingularError{disputetimeline.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *DisputeTimelineQuery) 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 DisputeTimelines.
|
||||
func (_q *DisputeTimelineQuery) All(ctx context.Context) ([]*DisputeTimeline, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*DisputeTimeline, *DisputeTimelineQuery]()
|
||||
return withInterceptors[[]*DisputeTimeline](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *DisputeTimelineQuery) AllX(ctx context.Context) []*DisputeTimeline {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of DisputeTimeline IDs.
|
||||
func (_q *DisputeTimelineQuery) 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(disputetimeline.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *DisputeTimelineQuery) 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 *DisputeTimelineQuery) 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[*DisputeTimelineQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *DisputeTimelineQuery) 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 *DisputeTimelineQuery) 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 *DisputeTimelineQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the DisputeTimelineQuery 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 *DisputeTimelineQuery) Clone() *DisputeTimelineQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &DisputeTimelineQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]disputetimeline.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.DisputeTimeline{}, _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 {
|
||||
// DisputeID int64 `json:"dispute_id,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.DisputeTimeline.Query().
|
||||
// GroupBy(disputetimeline.FieldDisputeID).
|
||||
// Aggregate(models.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *DisputeTimelineQuery) GroupBy(field string, fields ...string) *DisputeTimelineGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &DisputeTimelineGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = disputetimeline.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 {
|
||||
// DisputeID int64 `json:"dispute_id,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.DisputeTimeline.Query().
|
||||
// Select(disputetimeline.FieldDisputeID).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *DisputeTimelineQuery) Select(fields ...string) *DisputeTimelineSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &DisputeTimelineSelect{DisputeTimelineQuery: _q}
|
||||
sbuild.label = disputetimeline.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a DisputeTimelineSelect configured with the given aggregations.
|
||||
func (_q *DisputeTimelineQuery) Aggregate(fns ...AggregateFunc) *DisputeTimelineSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *DisputeTimelineQuery) 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 !disputetimeline.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 *DisputeTimelineQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*DisputeTimeline, error) {
|
||||
var (
|
||||
nodes = []*DisputeTimeline{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*DisputeTimeline).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &DisputeTimeline{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 *DisputeTimelineQuery) 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 *DisputeTimelineQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(disputetimeline.Table, disputetimeline.Columns, sqlgraph.NewFieldSpec(disputetimeline.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, disputetimeline.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != disputetimeline.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 *DisputeTimelineQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(disputetimeline.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = disputetimeline.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
|
||||
}
|
||||
|
||||
// DisputeTimelineGroupBy is the group-by builder for DisputeTimeline entities.
|
||||
type DisputeTimelineGroupBy struct {
|
||||
selector
|
||||
build *DisputeTimelineQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *DisputeTimelineGroupBy) Aggregate(fns ...AggregateFunc) *DisputeTimelineGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *DisputeTimelineGroupBy) 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[*DisputeTimelineQuery, *DisputeTimelineGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *DisputeTimelineGroupBy) sqlScan(ctx context.Context, root *DisputeTimelineQuery, 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)
|
||||
}
|
||||
|
||||
// DisputeTimelineSelect is the builder for selecting fields of DisputeTimeline entities.
|
||||
type DisputeTimelineSelect struct {
|
||||
*DisputeTimelineQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *DisputeTimelineSelect) Aggregate(fns ...AggregateFunc) *DisputeTimelineSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *DisputeTimelineSelect) 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[*DisputeTimelineQuery, *DisputeTimelineSelect](ctx, _s.DisputeTimelineQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *DisputeTimelineSelect) sqlScan(ctx context.Context, root *DisputeTimelineQuery, 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,459 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputetimeline"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// DisputeTimelineUpdate is the builder for updating DisputeTimeline entities.
|
||||
type DisputeTimelineUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *DisputeTimelineMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the DisputeTimelineUpdate builder.
|
||||
func (_u *DisputeTimelineUpdate) Where(ps ...predicate.DisputeTimeline) *DisputeTimelineUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDisputeID sets the "dispute_id" field.
|
||||
func (_u *DisputeTimelineUpdate) SetDisputeID(v int64) *DisputeTimelineUpdate {
|
||||
_u.mutation.ResetDisputeID()
|
||||
_u.mutation.SetDisputeID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDisputeID sets the "dispute_id" field if the given value is not nil.
|
||||
func (_u *DisputeTimelineUpdate) SetNillableDisputeID(v *int64) *DisputeTimelineUpdate {
|
||||
if v != nil {
|
||||
_u.SetDisputeID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddDisputeID adds value to the "dispute_id" field.
|
||||
func (_u *DisputeTimelineUpdate) AddDisputeID(v int64) *DisputeTimelineUpdate {
|
||||
_u.mutation.AddDisputeID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetEventType sets the "event_type" field.
|
||||
func (_u *DisputeTimelineUpdate) SetEventType(v string) *DisputeTimelineUpdate {
|
||||
_u.mutation.SetEventType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableEventType sets the "event_type" field if the given value is not nil.
|
||||
func (_u *DisputeTimelineUpdate) SetNillableEventType(v *string) *DisputeTimelineUpdate {
|
||||
if v != nil {
|
||||
_u.SetEventType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetActorID sets the "actor_id" field.
|
||||
func (_u *DisputeTimelineUpdate) SetActorID(v int64) *DisputeTimelineUpdate {
|
||||
_u.mutation.ResetActorID()
|
||||
_u.mutation.SetActorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableActorID sets the "actor_id" field if the given value is not nil.
|
||||
func (_u *DisputeTimelineUpdate) SetNillableActorID(v *int64) *DisputeTimelineUpdate {
|
||||
if v != nil {
|
||||
_u.SetActorID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddActorID adds value to the "actor_id" field.
|
||||
func (_u *DisputeTimelineUpdate) AddActorID(v int64) *DisputeTimelineUpdate {
|
||||
_u.mutation.AddActorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearActorID clears the value of the "actor_id" field.
|
||||
func (_u *DisputeTimelineUpdate) ClearActorID() *DisputeTimelineUpdate {
|
||||
_u.mutation.ClearActorID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetActorName sets the "actor_name" field.
|
||||
func (_u *DisputeTimelineUpdate) SetActorName(v string) *DisputeTimelineUpdate {
|
||||
_u.mutation.SetActorName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableActorName sets the "actor_name" field if the given value is not nil.
|
||||
func (_u *DisputeTimelineUpdate) SetNillableActorName(v *string) *DisputeTimelineUpdate {
|
||||
if v != nil {
|
||||
_u.SetActorName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearActorName clears the value of the "actor_name" field.
|
||||
func (_u *DisputeTimelineUpdate) ClearActorName() *DisputeTimelineUpdate {
|
||||
_u.mutation.ClearActorName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDetails sets the "details" field.
|
||||
func (_u *DisputeTimelineUpdate) SetDetails(v map[string]interface{}) *DisputeTimelineUpdate {
|
||||
_u.mutation.SetDetails(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearDetails clears the value of the "details" field.
|
||||
func (_u *DisputeTimelineUpdate) ClearDetails() *DisputeTimelineUpdate {
|
||||
_u.mutation.ClearDetails()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the DisputeTimelineMutation object of the builder.
|
||||
func (_u *DisputeTimelineUpdate) Mutation() *DisputeTimelineMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *DisputeTimelineUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *DisputeTimelineUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *DisputeTimelineUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *DisputeTimelineUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *DisputeTimelineUpdate) check() error {
|
||||
if v, ok := _u.mutation.EventType(); ok {
|
||||
if err := disputetimeline.EventTypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "event_type", err: fmt.Errorf(`models: validator failed for field "DisputeTimeline.event_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.ActorName(); ok {
|
||||
if err := disputetimeline.ActorNameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "actor_name", err: fmt.Errorf(`models: validator failed for field "DisputeTimeline.actor_name": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *DisputeTimelineUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(disputetimeline.Table, disputetimeline.Columns, sqlgraph.NewFieldSpec(disputetimeline.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.DisputeID(); ok {
|
||||
_spec.SetField(disputetimeline.FieldDisputeID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedDisputeID(); ok {
|
||||
_spec.AddField(disputetimeline.FieldDisputeID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.EventType(); ok {
|
||||
_spec.SetField(disputetimeline.FieldEventType, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ActorID(); ok {
|
||||
_spec.SetField(disputetimeline.FieldActorID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedActorID(); ok {
|
||||
_spec.AddField(disputetimeline.FieldActorID, field.TypeInt64, value)
|
||||
}
|
||||
if _u.mutation.ActorIDCleared() {
|
||||
_spec.ClearField(disputetimeline.FieldActorID, field.TypeInt64)
|
||||
}
|
||||
if value, ok := _u.mutation.ActorName(); ok {
|
||||
_spec.SetField(disputetimeline.FieldActorName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.ActorNameCleared() {
|
||||
_spec.ClearField(disputetimeline.FieldActorName, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Details(); ok {
|
||||
_spec.SetField(disputetimeline.FieldDetails, field.TypeJSON, value)
|
||||
}
|
||||
if _u.mutation.DetailsCleared() {
|
||||
_spec.ClearField(disputetimeline.FieldDetails, field.TypeJSON)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{disputetimeline.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// DisputeTimelineUpdateOne is the builder for updating a single DisputeTimeline entity.
|
||||
type DisputeTimelineUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *DisputeTimelineMutation
|
||||
}
|
||||
|
||||
// SetDisputeID sets the "dispute_id" field.
|
||||
func (_u *DisputeTimelineUpdateOne) SetDisputeID(v int64) *DisputeTimelineUpdateOne {
|
||||
_u.mutation.ResetDisputeID()
|
||||
_u.mutation.SetDisputeID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDisputeID sets the "dispute_id" field if the given value is not nil.
|
||||
func (_u *DisputeTimelineUpdateOne) SetNillableDisputeID(v *int64) *DisputeTimelineUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetDisputeID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddDisputeID adds value to the "dispute_id" field.
|
||||
func (_u *DisputeTimelineUpdateOne) AddDisputeID(v int64) *DisputeTimelineUpdateOne {
|
||||
_u.mutation.AddDisputeID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetEventType sets the "event_type" field.
|
||||
func (_u *DisputeTimelineUpdateOne) SetEventType(v string) *DisputeTimelineUpdateOne {
|
||||
_u.mutation.SetEventType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableEventType sets the "event_type" field if the given value is not nil.
|
||||
func (_u *DisputeTimelineUpdateOne) SetNillableEventType(v *string) *DisputeTimelineUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetEventType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetActorID sets the "actor_id" field.
|
||||
func (_u *DisputeTimelineUpdateOne) SetActorID(v int64) *DisputeTimelineUpdateOne {
|
||||
_u.mutation.ResetActorID()
|
||||
_u.mutation.SetActorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableActorID sets the "actor_id" field if the given value is not nil.
|
||||
func (_u *DisputeTimelineUpdateOne) SetNillableActorID(v *int64) *DisputeTimelineUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetActorID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddActorID adds value to the "actor_id" field.
|
||||
func (_u *DisputeTimelineUpdateOne) AddActorID(v int64) *DisputeTimelineUpdateOne {
|
||||
_u.mutation.AddActorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearActorID clears the value of the "actor_id" field.
|
||||
func (_u *DisputeTimelineUpdateOne) ClearActorID() *DisputeTimelineUpdateOne {
|
||||
_u.mutation.ClearActorID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetActorName sets the "actor_name" field.
|
||||
func (_u *DisputeTimelineUpdateOne) SetActorName(v string) *DisputeTimelineUpdateOne {
|
||||
_u.mutation.SetActorName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableActorName sets the "actor_name" field if the given value is not nil.
|
||||
func (_u *DisputeTimelineUpdateOne) SetNillableActorName(v *string) *DisputeTimelineUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetActorName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearActorName clears the value of the "actor_name" field.
|
||||
func (_u *DisputeTimelineUpdateOne) ClearActorName() *DisputeTimelineUpdateOne {
|
||||
_u.mutation.ClearActorName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDetails sets the "details" field.
|
||||
func (_u *DisputeTimelineUpdateOne) SetDetails(v map[string]interface{}) *DisputeTimelineUpdateOne {
|
||||
_u.mutation.SetDetails(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearDetails clears the value of the "details" field.
|
||||
func (_u *DisputeTimelineUpdateOne) ClearDetails() *DisputeTimelineUpdateOne {
|
||||
_u.mutation.ClearDetails()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the DisputeTimelineMutation object of the builder.
|
||||
func (_u *DisputeTimelineUpdateOne) Mutation() *DisputeTimelineMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the DisputeTimelineUpdate builder.
|
||||
func (_u *DisputeTimelineUpdateOne) Where(ps ...predicate.DisputeTimeline) *DisputeTimelineUpdateOne {
|
||||
_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 *DisputeTimelineUpdateOne) Select(field string, fields ...string) *DisputeTimelineUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated DisputeTimeline entity.
|
||||
func (_u *DisputeTimelineUpdateOne) Save(ctx context.Context) (*DisputeTimeline, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *DisputeTimelineUpdateOne) SaveX(ctx context.Context) *DisputeTimeline {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *DisputeTimelineUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *DisputeTimelineUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *DisputeTimelineUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.EventType(); ok {
|
||||
if err := disputetimeline.EventTypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "event_type", err: fmt.Errorf(`models: validator failed for field "DisputeTimeline.event_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.ActorName(); ok {
|
||||
if err := disputetimeline.ActorNameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "actor_name", err: fmt.Errorf(`models: validator failed for field "DisputeTimeline.actor_name": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *DisputeTimelineUpdateOne) sqlSave(ctx context.Context) (_node *DisputeTimeline, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(disputetimeline.Table, disputetimeline.Columns, sqlgraph.NewFieldSpec(disputetimeline.FieldID, field.TypeInt64))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "DisputeTimeline.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, disputetimeline.FieldID)
|
||||
for _, f := range fields {
|
||||
if !disputetimeline.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
|
||||
}
|
||||
if f != disputetimeline.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.DisputeID(); ok {
|
||||
_spec.SetField(disputetimeline.FieldDisputeID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedDisputeID(); ok {
|
||||
_spec.AddField(disputetimeline.FieldDisputeID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.EventType(); ok {
|
||||
_spec.SetField(disputetimeline.FieldEventType, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ActorID(); ok {
|
||||
_spec.SetField(disputetimeline.FieldActorID, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedActorID(); ok {
|
||||
_spec.AddField(disputetimeline.FieldActorID, field.TypeInt64, value)
|
||||
}
|
||||
if _u.mutation.ActorIDCleared() {
|
||||
_spec.ClearField(disputetimeline.FieldActorID, field.TypeInt64)
|
||||
}
|
||||
if value, ok := _u.mutation.ActorName(); ok {
|
||||
_spec.SetField(disputetimeline.FieldActorName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.ActorNameCleared() {
|
||||
_spec.ClearField(disputetimeline.FieldActorName, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Details(); ok {
|
||||
_spec.SetField(disputetimeline.FieldDetails, field.TypeJSON, value)
|
||||
}
|
||||
if _u.mutation.DetailsCleared() {
|
||||
_spec.ClearField(disputetimeline.FieldDetails, field.TypeJSON)
|
||||
}
|
||||
_node = &DisputeTimeline{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{disputetimeline.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,610 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputes"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputetimeline"
|
||||
"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{
|
||||
disputetimeline.Table: disputetimeline.ValidColumn,
|
||||
disputes.Table: disputes.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/dispute/rpc/internal/models"
|
||||
// required by schema hooks.
|
||||
_ "juwan-backend/app/dispute/rpc/internal/models/runtime"
|
||||
|
||||
"juwan-backend/app/dispute/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,210 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package hook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"juwan-backend/app/dispute/rpc/internal/models"
|
||||
)
|
||||
|
||||
// The DisputeTimelineFunc type is an adapter to allow the use of ordinary
|
||||
// function as DisputeTimeline mutator.
|
||||
type DisputeTimelineFunc func(context.Context, *models.DisputeTimelineMutation) (models.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f DisputeTimelineFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||
if mv, ok := m.(*models.DisputeTimelineMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.DisputeTimelineMutation", m)
|
||||
}
|
||||
|
||||
// The DisputesFunc type is an adapter to allow the use of ordinary
|
||||
// function as Disputes mutator.
|
||||
type DisputesFunc func(context.Context, *models.DisputesMutation) (models.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f DisputesFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
|
||||
if mv, ok := m.(*models.DisputesMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.DisputesMutation", 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,95 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
var (
|
||||
// DisputeTimelinesColumns holds the columns for the "dispute_timelines" table.
|
||||
DisputeTimelinesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "dispute_id", Type: field.TypeInt64},
|
||||
{Name: "event_type", Type: field.TypeString, Size: 30},
|
||||
{Name: "actor_id", Type: field.TypeInt64, Nullable: true},
|
||||
{Name: "actor_name", Type: field.TypeString, Nullable: true, Size: 100},
|
||||
{Name: "details", Type: field.TypeJSON, Nullable: true, SchemaType: map[string]string{"postgres": "jsonb"}},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
}
|
||||
// DisputeTimelinesTable holds the schema information for the "dispute_timelines" table.
|
||||
DisputeTimelinesTable = &schema.Table{
|
||||
Name: "dispute_timelines",
|
||||
Columns: DisputeTimelinesColumns,
|
||||
PrimaryKey: []*schema.Column{DisputeTimelinesColumns[0]},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "disputetimeline_dispute_id_created_at",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{DisputeTimelinesColumns[1], DisputeTimelinesColumns[6]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// DisputesColumns holds the columns for the "disputes" table.
|
||||
DisputesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "order_id", Type: field.TypeInt64, Unique: true},
|
||||
{Name: "initiator_id", Type: field.TypeInt64},
|
||||
{Name: "initiator_name", Type: field.TypeString, Size: 100},
|
||||
{Name: "respondent_id", Type: field.TypeInt64},
|
||||
{Name: "reason", Type: field.TypeString},
|
||||
{Name: "evidence", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "text[]"}},
|
||||
{Name: "status", Type: field.TypeString, Size: 20, Default: "open"},
|
||||
{Name: "result", Type: field.TypeString, Nullable: true, Size: 30},
|
||||
{Name: "respondent_reason", Type: field.TypeString, Nullable: true},
|
||||
{Name: "respondent_evidence", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "text[]"}},
|
||||
{Name: "appeal_reason", Type: field.TypeString, Nullable: true},
|
||||
{Name: "appealed_at", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "resolved_by", Type: field.TypeInt64, Nullable: true},
|
||||
{Name: "resolved_at", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
}
|
||||
// DisputesTable holds the schema information for the "disputes" table.
|
||||
DisputesTable = &schema.Table{
|
||||
Name: "disputes",
|
||||
Columns: DisputesColumns,
|
||||
PrimaryKey: []*schema.Column{DisputesColumns[0]},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "disputes_order_id",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{DisputesColumns[1]},
|
||||
},
|
||||
{
|
||||
Name: "disputes_status_created_at",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{DisputesColumns[7], DisputesColumns[15]},
|
||||
},
|
||||
{
|
||||
Name: "disputes_initiator_id",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{DisputesColumns[2]},
|
||||
},
|
||||
{
|
||||
Name: "disputes_initiator_id_status_created_at",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{DisputesColumns[2], DisputesColumns[7], DisputesColumns[15]},
|
||||
},
|
||||
{
|
||||
Name: "disputes_respondent_id_status_created_at",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{DisputesColumns[4], DisputesColumns[7], DisputesColumns[15]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
DisputeTimelinesTable,
|
||||
DisputesTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package predicate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// DisputeTimeline is the predicate function for disputetimeline builders.
|
||||
type DisputeTimeline func(*sql.Selector)
|
||||
|
||||
// Disputes is the predicate function for disputes builders.
|
||||
type Disputes func(*sql.Selector)
|
||||
@@ -0,0 +1,56 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputes"
|
||||
"juwan-backend/app/dispute/rpc/internal/models/disputetimeline"
|
||||
"juwan-backend/app/dispute/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() {
|
||||
disputetimelineFields := schema.DisputeTimeline{}.Fields()
|
||||
_ = disputetimelineFields
|
||||
// disputetimelineDescEventType is the schema descriptor for event_type field.
|
||||
disputetimelineDescEventType := disputetimelineFields[2].Descriptor()
|
||||
// disputetimeline.EventTypeValidator is a validator for the "event_type" field. It is called by the builders before save.
|
||||
disputetimeline.EventTypeValidator = disputetimelineDescEventType.Validators[0].(func(string) error)
|
||||
// disputetimelineDescActorName is the schema descriptor for actor_name field.
|
||||
disputetimelineDescActorName := disputetimelineFields[4].Descriptor()
|
||||
// disputetimeline.ActorNameValidator is a validator for the "actor_name" field. It is called by the builders before save.
|
||||
disputetimeline.ActorNameValidator = disputetimelineDescActorName.Validators[0].(func(string) error)
|
||||
// disputetimelineDescCreatedAt is the schema descriptor for created_at field.
|
||||
disputetimelineDescCreatedAt := disputetimelineFields[6].Descriptor()
|
||||
// disputetimeline.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
disputetimeline.DefaultCreatedAt = disputetimelineDescCreatedAt.Default.(func() time.Time)
|
||||
disputesFields := schema.Disputes{}.Fields()
|
||||
_ = disputesFields
|
||||
// disputesDescInitiatorName is the schema descriptor for initiator_name field.
|
||||
disputesDescInitiatorName := disputesFields[3].Descriptor()
|
||||
// disputes.InitiatorNameValidator is a validator for the "initiator_name" field. It is called by the builders before save.
|
||||
disputes.InitiatorNameValidator = disputesDescInitiatorName.Validators[0].(func(string) error)
|
||||
// disputesDescStatus is the schema descriptor for status field.
|
||||
disputesDescStatus := disputesFields[7].Descriptor()
|
||||
// disputes.DefaultStatus holds the default value on creation for the status field.
|
||||
disputes.DefaultStatus = disputesDescStatus.Default.(string)
|
||||
// disputes.StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||
disputes.StatusValidator = disputesDescStatus.Validators[0].(func(string) error)
|
||||
// disputesDescResult is the schema descriptor for result field.
|
||||
disputesDescResult := disputesFields[8].Descriptor()
|
||||
// disputes.ResultValidator is a validator for the "result" field. It is called by the builders before save.
|
||||
disputes.ResultValidator = disputesDescResult.Validators[0].(func(string) error)
|
||||
// disputesDescCreatedAt is the schema descriptor for created_at field.
|
||||
disputesDescCreatedAt := disputesFields[15].Descriptor()
|
||||
// disputes.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
disputes.DefaultCreatedAt = disputesDescCreatedAt.Default.(func() time.Time)
|
||||
// disputesDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
disputesDescUpdatedAt := disputesFields[16].Descriptor()
|
||||
// disputes.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
disputes.DefaultUpdatedAt = disputesDescUpdatedAt.Default.(func() time.Time)
|
||||
// disputes.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
disputes.UpdateDefaultUpdatedAt = disputesDescUpdatedAt.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/dispute/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,38 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
type DisputeTimeline struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (DisputeTimeline) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("id").Unique().Immutable(),
|
||||
field.Int64("dispute_id"),
|
||||
field.String("event_type").MaxLen(30),
|
||||
field.Int64("actor_id").Optional(),
|
||||
field.String("actor_name").MaxLen(100).Optional(),
|
||||
field.JSON("details", map[string]any{}).
|
||||
SchemaType(map[string]string{dialect.Postgres: "jsonb"}).
|
||||
Optional(),
|
||||
field.Time("created_at").Default(time.Now).Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (DisputeTimeline) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("dispute_id", "created_at"),
|
||||
}
|
||||
}
|
||||
|
||||
func (DisputeTimeline) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"juwan-backend/pkg/types"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
type Disputes struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Disputes) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("id").Unique().Immutable(),
|
||||
field.Int64("order_id").Unique(),
|
||||
field.Int64("initiator_id"),
|
||||
field.String("initiator_name").MaxLen(100),
|
||||
field.Int64("respondent_id"),
|
||||
field.String("reason"),
|
||||
field.Other("evidence", types.TextArray{}).
|
||||
SchemaType(map[string]string{dialect.Postgres: "text[]"}).
|
||||
Optional(),
|
||||
field.String("status").MaxLen(20).Default("open"),
|
||||
field.String("result").MaxLen(30).Optional().Nillable(),
|
||||
field.String("respondent_reason").Optional().Nillable(),
|
||||
field.Other("respondent_evidence", types.TextArray{}).
|
||||
SchemaType(map[string]string{dialect.Postgres: "text[]"}).
|
||||
Optional(),
|
||||
field.String("appeal_reason").Optional().Nillable(),
|
||||
field.Time("appealed_at").Optional().Nillable(),
|
||||
field.Int64("resolved_by").Optional().Nillable(),
|
||||
field.Time("resolved_at").Optional().Nillable(),
|
||||
field.Time("created_at").Default(time.Now).Immutable(),
|
||||
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
||||
}
|
||||
}
|
||||
|
||||
func (Disputes) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("order_id"),
|
||||
index.Fields("status", "created_at"),
|
||||
index.Fields("initiator_id"),
|
||||
index.Fields("initiator_id", "status", "created_at"),
|
||||
index.Fields("respondent_id", "status", "created_at"),
|
||||
}
|
||||
}
|
||||
|
||||
func (Disputes) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
// 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
|
||||
// DisputeTimeline is the client for interacting with the DisputeTimeline builders.
|
||||
DisputeTimeline *DisputeTimelineClient
|
||||
// Disputes is the client for interacting with the Disputes builders.
|
||||
Disputes *DisputesClient
|
||||
|
||||
// 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.DisputeTimeline = NewDisputeTimelineClient(tx.config)
|
||||
tx.Disputes = NewDisputesClient(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: DisputeTimeline.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,61 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
// Source: dispute.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/logic"
|
||||
"juwan-backend/app/dispute/rpc/internal/svc"
|
||||
"juwan-backend/app/dispute/rpc/pb"
|
||||
)
|
||||
|
||||
type DisputeServiceServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
pb.UnimplementedDisputeServiceServer
|
||||
}
|
||||
|
||||
func NewDisputeServiceServer(svcCtx *svc.ServiceContext) *DisputeServiceServer {
|
||||
return &DisputeServiceServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------disputes-----------------------
|
||||
func (s *DisputeServiceServer) AddDisputes(ctx context.Context, in *pb.AddDisputesReq) (*pb.AddDisputesResp, error) {
|
||||
l := logic.NewAddDisputesLogic(ctx, s.svcCtx)
|
||||
return l.AddDisputes(in)
|
||||
}
|
||||
|
||||
func (s *DisputeServiceServer) UpdateDisputes(ctx context.Context, in *pb.UpdateDisputesReq) (*pb.UpdateDisputesResp, error) {
|
||||
l := logic.NewUpdateDisputesLogic(ctx, s.svcCtx)
|
||||
return l.UpdateDisputes(in)
|
||||
}
|
||||
|
||||
func (s *DisputeServiceServer) DelDisputes(ctx context.Context, in *pb.DelDisputesReq) (*pb.DelDisputesResp, error) {
|
||||
l := logic.NewDelDisputesLogic(ctx, s.svcCtx)
|
||||
return l.DelDisputes(in)
|
||||
}
|
||||
|
||||
func (s *DisputeServiceServer) GetDisputesById(ctx context.Context, in *pb.GetDisputesByIdReq) (*pb.GetDisputesByIdResp, error) {
|
||||
l := logic.NewGetDisputesByIdLogic(ctx, s.svcCtx)
|
||||
return l.GetDisputesById(in)
|
||||
}
|
||||
|
||||
func (s *DisputeServiceServer) SearchDisputes(ctx context.Context, in *pb.SearchDisputesReq) (*pb.SearchDisputesResp, error) {
|
||||
l := logic.NewSearchDisputesLogic(ctx, s.svcCtx)
|
||||
return l.SearchDisputes(in)
|
||||
}
|
||||
|
||||
// -----------------------disputeTimeline-----------------------
|
||||
func (s *DisputeServiceServer) AddDisputeTimeline(ctx context.Context, in *pb.AddDisputeTimelineReq) (*pb.AddDisputeTimelineResp, error) {
|
||||
l := logic.NewAddDisputeTimelineLogic(ctx, s.svcCtx)
|
||||
return l.AddDisputeTimeline(in)
|
||||
}
|
||||
|
||||
func (s *DisputeServiceServer) SearchDisputeTimeline(ctx context.Context, in *pb.SearchDisputeTimelineReq) (*pb.SearchDisputeTimelineResp, error) {
|
||||
l := logic.NewSearchDisputeTimelineLogic(ctx, s.svcCtx)
|
||||
return l.SearchDisputeTimeline(in)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
stdsql "database/sql"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/config"
|
||||
"juwan-backend/app/dispute/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
|
||||
DisputeModelRW *models.Client
|
||||
DisputeModelRO *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,
|
||||
DisputeModelRW: models.NewClient(models.Driver(RWDrv)),
|
||||
DisputeModelRO: models.NewClient(models.Driver(RODrv)),
|
||||
Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"juwan-backend/app/dispute/rpc/internal/config"
|
||||
"juwan-backend/app/dispute/rpc/internal/server"
|
||||
"juwan-backend/app/dispute/rpc/internal/svc"
|
||||
"juwan-backend/app/dispute/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.RegisterDisputeServiceServer(grpcServer, server.NewDisputeServiceServer(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()
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,353 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.6.1
|
||||
// - protoc v7.34.1
|
||||
// source: dispute.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 (
|
||||
DisputeService_AddDisputes_FullMethodName = "/pb.disputeService/AddDisputes"
|
||||
DisputeService_UpdateDisputes_FullMethodName = "/pb.disputeService/UpdateDisputes"
|
||||
DisputeService_DelDisputes_FullMethodName = "/pb.disputeService/DelDisputes"
|
||||
DisputeService_GetDisputesById_FullMethodName = "/pb.disputeService/GetDisputesById"
|
||||
DisputeService_SearchDisputes_FullMethodName = "/pb.disputeService/SearchDisputes"
|
||||
DisputeService_AddDisputeTimeline_FullMethodName = "/pb.disputeService/AddDisputeTimeline"
|
||||
DisputeService_SearchDisputeTimeline_FullMethodName = "/pb.disputeService/SearchDisputeTimeline"
|
||||
)
|
||||
|
||||
// DisputeServiceClient is the client API for DisputeService 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 DisputeServiceClient interface {
|
||||
// -----------------------disputes-----------------------
|
||||
AddDisputes(ctx context.Context, in *AddDisputesReq, opts ...grpc.CallOption) (*AddDisputesResp, error)
|
||||
UpdateDisputes(ctx context.Context, in *UpdateDisputesReq, opts ...grpc.CallOption) (*UpdateDisputesResp, error)
|
||||
DelDisputes(ctx context.Context, in *DelDisputesReq, opts ...grpc.CallOption) (*DelDisputesResp, error)
|
||||
GetDisputesById(ctx context.Context, in *GetDisputesByIdReq, opts ...grpc.CallOption) (*GetDisputesByIdResp, error)
|
||||
SearchDisputes(ctx context.Context, in *SearchDisputesReq, opts ...grpc.CallOption) (*SearchDisputesResp, error)
|
||||
// -----------------------disputeTimeline-----------------------
|
||||
AddDisputeTimeline(ctx context.Context, in *AddDisputeTimelineReq, opts ...grpc.CallOption) (*AddDisputeTimelineResp, error)
|
||||
SearchDisputeTimeline(ctx context.Context, in *SearchDisputeTimelineReq, opts ...grpc.CallOption) (*SearchDisputeTimelineResp, error)
|
||||
}
|
||||
|
||||
type disputeServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewDisputeServiceClient(cc grpc.ClientConnInterface) DisputeServiceClient {
|
||||
return &disputeServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *disputeServiceClient) AddDisputes(ctx context.Context, in *AddDisputesReq, opts ...grpc.CallOption) (*AddDisputesResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(AddDisputesResp)
|
||||
err := c.cc.Invoke(ctx, DisputeService_AddDisputes_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *disputeServiceClient) UpdateDisputes(ctx context.Context, in *UpdateDisputesReq, opts ...grpc.CallOption) (*UpdateDisputesResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(UpdateDisputesResp)
|
||||
err := c.cc.Invoke(ctx, DisputeService_UpdateDisputes_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *disputeServiceClient) DelDisputes(ctx context.Context, in *DelDisputesReq, opts ...grpc.CallOption) (*DelDisputesResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(DelDisputesResp)
|
||||
err := c.cc.Invoke(ctx, DisputeService_DelDisputes_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *disputeServiceClient) GetDisputesById(ctx context.Context, in *GetDisputesByIdReq, opts ...grpc.CallOption) (*GetDisputesByIdResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetDisputesByIdResp)
|
||||
err := c.cc.Invoke(ctx, DisputeService_GetDisputesById_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *disputeServiceClient) SearchDisputes(ctx context.Context, in *SearchDisputesReq, opts ...grpc.CallOption) (*SearchDisputesResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(SearchDisputesResp)
|
||||
err := c.cc.Invoke(ctx, DisputeService_SearchDisputes_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *disputeServiceClient) AddDisputeTimeline(ctx context.Context, in *AddDisputeTimelineReq, opts ...grpc.CallOption) (*AddDisputeTimelineResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(AddDisputeTimelineResp)
|
||||
err := c.cc.Invoke(ctx, DisputeService_AddDisputeTimeline_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *disputeServiceClient) SearchDisputeTimeline(ctx context.Context, in *SearchDisputeTimelineReq, opts ...grpc.CallOption) (*SearchDisputeTimelineResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(SearchDisputeTimelineResp)
|
||||
err := c.cc.Invoke(ctx, DisputeService_SearchDisputeTimeline_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// DisputeServiceServer is the server API for DisputeService service.
|
||||
// All implementations must embed UnimplementedDisputeServiceServer
|
||||
// for forward compatibility.
|
||||
type DisputeServiceServer interface {
|
||||
// -----------------------disputes-----------------------
|
||||
AddDisputes(context.Context, *AddDisputesReq) (*AddDisputesResp, error)
|
||||
UpdateDisputes(context.Context, *UpdateDisputesReq) (*UpdateDisputesResp, error)
|
||||
DelDisputes(context.Context, *DelDisputesReq) (*DelDisputesResp, error)
|
||||
GetDisputesById(context.Context, *GetDisputesByIdReq) (*GetDisputesByIdResp, error)
|
||||
SearchDisputes(context.Context, *SearchDisputesReq) (*SearchDisputesResp, error)
|
||||
// -----------------------disputeTimeline-----------------------
|
||||
AddDisputeTimeline(context.Context, *AddDisputeTimelineReq) (*AddDisputeTimelineResp, error)
|
||||
SearchDisputeTimeline(context.Context, *SearchDisputeTimelineReq) (*SearchDisputeTimelineResp, error)
|
||||
mustEmbedUnimplementedDisputeServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedDisputeServiceServer 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 UnimplementedDisputeServiceServer struct{}
|
||||
|
||||
func (UnimplementedDisputeServiceServer) AddDisputes(context.Context, *AddDisputesReq) (*AddDisputesResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method AddDisputes not implemented")
|
||||
}
|
||||
func (UnimplementedDisputeServiceServer) UpdateDisputes(context.Context, *UpdateDisputesReq) (*UpdateDisputesResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method UpdateDisputes not implemented")
|
||||
}
|
||||
func (UnimplementedDisputeServiceServer) DelDisputes(context.Context, *DelDisputesReq) (*DelDisputesResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method DelDisputes not implemented")
|
||||
}
|
||||
func (UnimplementedDisputeServiceServer) GetDisputesById(context.Context, *GetDisputesByIdReq) (*GetDisputesByIdResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetDisputesById not implemented")
|
||||
}
|
||||
func (UnimplementedDisputeServiceServer) SearchDisputes(context.Context, *SearchDisputesReq) (*SearchDisputesResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method SearchDisputes not implemented")
|
||||
}
|
||||
func (UnimplementedDisputeServiceServer) AddDisputeTimeline(context.Context, *AddDisputeTimelineReq) (*AddDisputeTimelineResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method AddDisputeTimeline not implemented")
|
||||
}
|
||||
func (UnimplementedDisputeServiceServer) SearchDisputeTimeline(context.Context, *SearchDisputeTimelineReq) (*SearchDisputeTimelineResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method SearchDisputeTimeline not implemented")
|
||||
}
|
||||
func (UnimplementedDisputeServiceServer) mustEmbedUnimplementedDisputeServiceServer() {}
|
||||
func (UnimplementedDisputeServiceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeDisputeServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to DisputeServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeDisputeServiceServer interface {
|
||||
mustEmbedUnimplementedDisputeServiceServer()
|
||||
}
|
||||
|
||||
func RegisterDisputeServiceServer(s grpc.ServiceRegistrar, srv DisputeServiceServer) {
|
||||
// If the following call panics, it indicates UnimplementedDisputeServiceServer 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(&DisputeService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _DisputeService_AddDisputes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddDisputesReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DisputeServiceServer).AddDisputes(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: DisputeService_AddDisputes_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DisputeServiceServer).AddDisputes(ctx, req.(*AddDisputesReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _DisputeService_UpdateDisputes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateDisputesReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DisputeServiceServer).UpdateDisputes(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: DisputeService_UpdateDisputes_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DisputeServiceServer).UpdateDisputes(ctx, req.(*UpdateDisputesReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _DisputeService_DelDisputes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DelDisputesReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DisputeServiceServer).DelDisputes(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: DisputeService_DelDisputes_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DisputeServiceServer).DelDisputes(ctx, req.(*DelDisputesReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _DisputeService_GetDisputesById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetDisputesByIdReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DisputeServiceServer).GetDisputesById(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: DisputeService_GetDisputesById_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DisputeServiceServer).GetDisputesById(ctx, req.(*GetDisputesByIdReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _DisputeService_SearchDisputes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SearchDisputesReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DisputeServiceServer).SearchDisputes(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: DisputeService_SearchDisputes_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DisputeServiceServer).SearchDisputes(ctx, req.(*SearchDisputesReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _DisputeService_AddDisputeTimeline_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddDisputeTimelineReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DisputeServiceServer).AddDisputeTimeline(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: DisputeService_AddDisputeTimeline_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DisputeServiceServer).AddDisputeTimeline(ctx, req.(*AddDisputeTimelineReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _DisputeService_SearchDisputeTimeline_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SearchDisputeTimelineReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DisputeServiceServer).SearchDisputeTimeline(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: DisputeService_SearchDisputeTimeline_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DisputeServiceServer).SearchDisputeTimeline(ctx, req.(*SearchDisputeTimelineReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// DisputeService_ServiceDesc is the grpc.ServiceDesc for DisputeService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var DisputeService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "pb.disputeService",
|
||||
HandlerType: (*DisputeServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "AddDisputes",
|
||||
Handler: _DisputeService_AddDisputes_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UpdateDisputes",
|
||||
Handler: _DisputeService_UpdateDisputes_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DelDisputes",
|
||||
Handler: _DisputeService_DelDisputes_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetDisputesById",
|
||||
Handler: _DisputeService_GetDisputesById_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "SearchDisputes",
|
||||
Handler: _DisputeService_SearchDisputes_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "AddDisputeTimeline",
|
||||
Handler: _DisputeService_AddDisputeTimeline_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "SearchDisputeTimeline",
|
||||
Handler: _DisputeService_SearchDisputeTimeline_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "dispute.proto",
|
||||
}
|
||||
Reference in New Issue
Block a user