feat: 添加评价微服务,支持密封互评与订单状态联动

This commit is contained in:
zetaloop
2026-04-24 10:43:15 +08:00
parent 3b56910100
commit 6edf15996c
53 changed files with 7891 additions and 39 deletions
+16
View File
@@ -0,0 +1,16 @@
Name: review-api
Host: 0.0.0.0
Port: 8888
Prometheus:
Host: 0.0.0.0
Port: 4001
Path: /metrics
# ===== DEV CONFIG =====
ReviewRpcConf:
Endpoints:
- review-rpc:8080
OrderRpcConf:
Endpoints:
- order-rpc:8080
+12
View File
@@ -0,0 +1,12 @@
package config
import (
"github.com/zeromicro/go-zero/rest"
"github.com/zeromicro/go-zero/zrpc"
)
type Config struct {
rest.RestConf
ReviewRpcConf zrpc.RpcClientConf
OrderRpcConf zrpc.RpcClientConf
}
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package review
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/review/api/internal/logic/review"
"juwan-backend/app/review/api/internal/svc"
"juwan-backend/app/review/api/internal/types"
)
// 获取订单评价
func GetOrderReviewsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetOrderReviewsReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := review.NewGetOrderReviewsLogic(r.Context(), svcCtx)
resp, err := l.GetOrderReviews(&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 review
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/review/api/internal/logic/review"
"juwan-backend/app/review/api/internal/svc"
"juwan-backend/app/review/api/internal/types"
)
// 获取公开评价列表
func ListReviewsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PageReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := review.NewListReviewsLogic(r.Context(), svcCtx)
resp, err := l.ListReviews(&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 review
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/review/api/internal/logic/review"
"juwan-backend/app/review/api/internal/svc"
"juwan-backend/app/review/api/internal/types"
)
// 获取用户收到的评价
func ListUserReviewsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListUserReviewsReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := review.NewListUserReviewsLogic(r.Context(), svcCtx)
resp, err := l.ListUserReviews(&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 review
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/review/api/internal/logic/review"
"juwan-backend/app/review/api/internal/svc"
"juwan-backend/app/review/api/internal/types"
)
// 提交评价
func SubmitReviewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SubmitReviewReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := review.NewSubmitReviewLogic(r.Context(), svcCtx)
resp, err := l.SubmitReview(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
+51
View File
@@ -0,0 +1,51 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.10.1
package handler
import (
"net/http"
review "juwan-backend/app/review/api/internal/handler/review"
"juwan-backend/app/review/api/internal/svc"
"github.com/zeromicro/go-zero/rest"
)
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
// 提交评价
Method: http.MethodPost,
Path: "/orders/:id/review",
Handler: review.SubmitReviewHandler(serverCtx),
},
{
// 获取订单评价
Method: http.MethodGet,
Path: "/orders/:id/reviews",
Handler: review.GetOrderReviewsHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
[]rest.Route{
{
// 获取公开评价列表
Method: http.MethodGet,
Path: "/reviews",
Handler: review.ListReviewsHandler(serverCtx),
},
{
// 获取用户收到的评价
Method: http.MethodGet,
Path: "/users/:id/reviews",
Handler: review.ListUserReviewsHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1"),
)
}
@@ -0,0 +1,54 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package review
import (
"context"
"juwan-backend/app/review/api/internal/svc"
"juwan-backend/app/review/api/internal/types"
reviewpb "juwan-backend/app/review/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetOrderReviewsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取订单评价
func NewGetOrderReviewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderReviewsLogic {
return &GetOrderReviewsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetOrderReviewsLogic) GetOrderReviews(req *types.GetOrderReviewsReq) (resp *types.ReviewListResp, err error) {
orderId := req.Id
result, err := l.svcCtx.ReviewRpc.SearchReviews(l.ctx, &reviewpb.SearchReviewsReq{
Offset: 0,
Limit: 10,
OrderId: &orderId,
})
if err != nil {
return nil, err
}
items := make([]types.Review, 0, len(result.GetReviews()))
for _, r := range result.GetReviews() {
items = append(items, toAPIReview(r))
}
return &types.ReviewListResp{
Items: items,
Meta: types.PageMeta{
Total: int64(len(items)),
Offset: 0,
Limit: 10,
},
}, nil
}
@@ -0,0 +1,28 @@
package review
import (
"time"
"juwan-backend/app/review/api/internal/types"
reviewpb "juwan-backend/app/review/rpc/pb"
)
func formatUnix(ts int64) string {
if ts <= 0 {
return ""
}
return time.Unix(ts, 0).UTC().Format(time.RFC3339)
}
func toAPIReview(r *reviewpb.Reviews) types.Review {
return types.Review{
Id: r.GetId(),
OrderId: r.GetOrderId(),
FromUserId: r.GetFromUserId(),
FromUserName: r.GetFromUserName(),
Rating: int(r.GetRating()),
Content: r.GetContent(),
Sealed: r.GetSealed(),
CreatedAt: formatUnix(r.GetCreatedAt()),
}
}
@@ -0,0 +1,54 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package review
import (
"context"
"juwan-backend/app/review/api/internal/svc"
"juwan-backend/app/review/api/internal/types"
reviewpb "juwan-backend/app/review/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type ListReviewsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取公开评价列表
func NewListReviewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListReviewsLogic {
return &ListReviewsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListReviewsLogic) ListReviews(req *types.PageReq) (resp *types.ReviewListResp, err error) {
sealed := false
result, err := l.svcCtx.ReviewRpc.SearchReviews(l.ctx, &reviewpb.SearchReviewsReq{
Offset: req.Offset,
Limit: req.Limit,
Sealed: &sealed,
})
if err != nil {
return nil, err
}
items := make([]types.Review, 0, len(result.GetReviews()))
for _, r := range result.GetReviews() {
items = append(items, toAPIReview(r))
}
return &types.ReviewListResp{
Items: items,
Meta: types.PageMeta{
Total: int64(len(items)),
Offset: req.Offset,
Limit: req.Limit,
},
}, nil
}
@@ -0,0 +1,56 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package review
import (
"context"
"juwan-backend/app/review/api/internal/svc"
"juwan-backend/app/review/api/internal/types"
reviewpb "juwan-backend/app/review/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type ListUserReviewsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取用户收到的评价
func NewListUserReviewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListUserReviewsLogic {
return &ListUserReviewsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListUserReviewsLogic) ListUserReviews(req *types.ListUserReviewsReq) (resp *types.ReviewListResp, err error) {
sealed := false
toUserId := req.Id
result, err := l.svcCtx.ReviewRpc.SearchReviews(l.ctx, &reviewpb.SearchReviewsReq{
Offset: req.Offset,
Limit: req.Limit,
ToUserId: &toUserId,
Sealed: &sealed,
})
if err != nil {
return nil, err
}
items := make([]types.Review, 0, len(result.GetReviews()))
for _, r := range result.GetReviews() {
items = append(items, toAPIReview(r))
}
return &types.ReviewListResp{
Items: items,
Meta: types.PageMeta{
Total: int64(len(items)),
Offset: req.Offset,
Limit: req.Limit,
},
}, nil
}
@@ -0,0 +1,104 @@
package review
import (
"context"
"errors"
"time"
"juwan-backend/app/order/rpc/orderservice"
"juwan-backend/app/review/api/internal/svc"
"juwan-backend/app/review/api/internal/types"
reviewpb "juwan-backend/app/review/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type SubmitReviewLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSubmitReviewLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubmitReviewLogic {
return &SubmitReviewLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SubmitReviewLogic) SubmitReview(req *types.SubmitReviewReq) (resp *types.EmptyResp, 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 order.GetStatus() != "pending_review" {
return nil, errors.New("order is not in pending_review status")
}
var fromUserId, toUserId int64
if uid == order.GetConsumerId() {
fromUserId = order.GetConsumerId()
toUserId = order.GetPlayerId()
} else if uid == order.GetPlayerId() {
fromUserId = order.GetPlayerId()
toUserId = order.GetConsumerId()
} else {
return nil, errors.New("not a participant of this order")
}
_, err = l.svcCtx.ReviewRpc.AddReviews(l.ctx, &reviewpb.AddReviewsReq{
OrderId: req.Id,
FromUserId: fromUserId,
ToUserId: toUserId,
Rating: int32(req.Rating),
Content: req.Content,
Sealed: true,
})
if err != nil {
return nil, err
}
existing, err := l.svcCtx.ReviewRpc.SearchReviews(l.ctx, &reviewpb.SearchReviewsReq{
Offset: 0,
Limit: 2,
OrderId: &req.Id,
})
if err != nil {
return nil, err
}
if len(existing.GetReviews()) >= 2 {
now := time.Now().Unix()
sealed := false
for _, r := range existing.GetReviews() {
_, _ = l.svcCtx.ReviewRpc.UpdateReviews(l.ctx, &reviewpb.UpdateReviewsReq{
Id: r.GetId(),
Sealed: &sealed,
UnsealedAt: &now,
})
}
completedStatus := "completed"
completedAt := now
updatedAt := now
_, _ = l.svcCtx.OrderRpc.UpdateOrders(l.ctx, &orderservice.UpdateOrdersReq{
Id: req.Id,
Status: &completedStatus,
CompletedAt: &completedAt,
UpdatedAt: &updatedAt,
})
}
return &types.EmptyResp{}, nil
}
@@ -0,0 +1,23 @@
package svc
import (
"juwan-backend/app/order/rpc/orderservice"
"juwan-backend/app/review/api/internal/config"
"juwan-backend/app/review/rpc/reviewservice"
"github.com/zeromicro/go-zero/zrpc"
)
type ServiceContext struct {
Config config.Config
ReviewRpc reviewservice.ReviewService
OrderRpc orderservice.OrderService
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
ReviewRpc: reviewservice.NewReviewService(zrpc.MustNewClient(c.ReviewRpcConf)),
OrderRpc: orderservice.NewOrderService(zrpc.MustNewClient(c.OrderRpcConf)),
}
}
+72
View File
@@ -0,0 +1,72 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.10.1
package types
type EmptyResp struct {
}
type GetOrderReviewsReq struct {
ReviewPathId
}
type ListUserReviewsReq struct {
ReviewPathId
PageReq
}
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 Review struct {
Id int64 `json:"id"`
OrderId int64 `json:"orderId"`
FromUserId int64 `json:"fromUserId"`
FromUserName string `json:"fromUserName"`
Rating int `json:"rating"`
Content string `json:"content"`
Sealed bool `json:"sealed"`
CreatedAt string `json:"createdAt"`
}
type ReviewListResp struct {
Items []Review `json:"items"`
Meta PageMeta `json:"meta"`
}
type ReviewPathId struct {
Id int64 `path:"id"`
}
type SimpleUser struct {
Id string `json:"id"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
}
type SubmitReviewReq struct {
ReviewPathId
Rating int `json:"rating"`
Content string `json:"content,optional"`
}
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"`
}
+34
View File
@@ -0,0 +1,34 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package main
import (
"flag"
"fmt"
"juwan-backend/app/review/api/internal/config"
"juwan-backend/app/review/api/internal/handler"
"juwan-backend/app/review/api/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/review-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()
}
+23
View File
@@ -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
+17
View File
@@ -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,64 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/review/rpc/internal/svc"
"juwan-backend/app/review/rpc/pb"
"juwan-backend/app/snowflake/rpc/snowflake"
"github.com/zeromicro/go-zero/core/logx"
)
type AddReviewsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddReviewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddReviewsLogic {
return &AddReviewsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *AddReviewsLogic) AddReviews(in *pb.AddReviewsReq) (*pb.AddReviewsResp, error) {
if in.GetOrderId() <= 0 {
return nil, errors.New("orderId is required")
}
if in.GetFromUserId() <= 0 {
return nil, errors.New("fromUserId is required")
}
if in.GetToUserId() <= 0 {
return nil, errors.New("toUserId is required")
}
if in.GetRating() < 1 || in.GetRating() > 5 {
return nil, errors.New("rating must be between 1 and 5")
}
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
if err != nil {
return nil, errors.New("create review id failed")
}
created, err := l.svcCtx.ReviewModelRW.Reviews.Create().
SetID(idResp.Id).
SetOrderID(in.GetOrderId()).
SetFromUserID(in.GetFromUserId()).
SetFromUserName(in.GetFromUserName()).
SetFromUserAvatar(in.GetFromUserAvatar()).
SetToUserID(in.GetToUserId()).
SetRating(int16(in.GetRating())).
SetContent(in.GetContent()).
SetSealed(in.GetSealed()).
Save(l.ctx)
if err != nil {
logx.Errorf("addReviews err: %v", err)
return nil, errors.New("add review failed")
}
return &pb.AddReviewsResp{Id: created.ID}, nil
}
@@ -0,0 +1,33 @@
package logic
import (
"context"
"juwan-backend/app/review/rpc/internal/svc"
"juwan-backend/app/review/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type DelReviewsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDelReviewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelReviewsLogic {
return &DelReviewsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DelReviewsLogic) DelReviews(in *pb.DelReviewsReq) (*pb.DelReviewsResp, error) {
err := l.svcCtx.ReviewModelRW.Reviews.DeleteOneID(in.GetId()).Exec(l.ctx)
if err != nil {
logx.Errorf("delReviews err: %v", err)
return nil, err
}
return &pb.DelReviewsResp{}, nil
}
@@ -0,0 +1,32 @@
package logic
import (
"context"
"juwan-backend/app/review/rpc/internal/svc"
"juwan-backend/app/review/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetReviewsByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetReviewsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetReviewsByIdLogic {
return &GetReviewsByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetReviewsByIdLogic) GetReviewsById(in *pb.GetReviewsByIdReq) (*pb.GetReviewsByIdResp, error) {
r, err := l.svcCtx.ReviewModelRO.Reviews.Get(l.ctx, in.GetId())
if err != nil {
return nil, err
}
return &pb.GetReviewsByIdResp{Reviews: entReviewToPb(r)}, nil
}
+25
View File
@@ -0,0 +1,25 @@
package logic
import (
"juwan-backend/app/review/rpc/internal/models"
"juwan-backend/app/review/rpc/pb"
)
func entReviewToPb(r *models.Reviews) *pb.Reviews {
out := &pb.Reviews{
Id: r.ID,
OrderId: r.OrderID,
FromUserId: r.FromUserID,
FromUserName: r.FromUserName,
FromUserAvatar: r.FromUserAvatar,
ToUserId: r.ToUserID,
Rating: int32(r.Rating),
Content: r.Content,
Sealed: r.Sealed,
CreatedAt: r.CreatedAt.Unix(),
}
if r.UnsealedAt != nil {
out.UnsealedAt = r.UnsealedAt.Unix()
}
return out
}
@@ -0,0 +1,76 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/review/rpc/internal/models/reviews"
"juwan-backend/app/review/rpc/internal/svc"
"juwan-backend/app/review/rpc/pb"
"entgo.io/ent/dialect/sql"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchReviewsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSearchReviewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchReviewsLogic {
return &SearchReviewsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SearchReviewsLogic) SearchReviews(in *pb.SearchReviewsReq) (*pb.SearchReviewsResp, 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.ReviewModelRO.Reviews.Query()
if in.Id != nil {
query = query.Where(reviews.IDEQ(in.GetId()))
}
if in.OrderId != nil {
query = query.Where(reviews.OrderIDEQ(in.GetOrderId()))
}
if in.FromUserId != nil {
query = query.Where(reviews.FromUserIDEQ(in.GetFromUserId()))
}
if in.ToUserId != nil {
query = query.Where(reviews.ToUserIDEQ(in.GetToUserId()))
}
if in.Sealed != nil {
query = query.Where(reviews.SealedEQ(in.GetSealed()))
}
list, err := query.
Order(reviews.ByCreatedAt(sql.OrderDesc()), reviews.ByID(sql.OrderDesc())).
Offset(int(offset)).
Limit(int(limit)).
All(l.ctx)
if err != nil {
logx.Errorf("searchReviews err: %v", err)
return nil, errors.New("search reviews failed")
}
out := make([]*pb.Reviews, len(list))
for i, r := range list {
out[i] = entReviewToPb(r)
}
return &pb.SearchReviewsResp{Reviews: out}, nil
}
@@ -0,0 +1,49 @@
package logic
import (
"context"
"time"
"juwan-backend/app/review/rpc/internal/svc"
"juwan-backend/app/review/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateReviewsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateReviewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateReviewsLogic {
return &UpdateReviewsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateReviewsLogic) UpdateReviews(in *pb.UpdateReviewsReq) (*pb.UpdateReviewsResp, error) {
updater := l.svcCtx.ReviewModelRW.Reviews.UpdateOneID(in.GetId())
if in.Sealed != nil {
updater = updater.SetSealed(in.GetSealed())
}
if in.UnsealedAt != nil {
updater = updater.SetUnsealedAt(time.Unix(in.GetUnsealedAt(), 0))
}
if in.Rating != nil {
updater = updater.SetRating(int16(in.GetRating()))
}
if in.Content != nil {
updater = updater.SetContent(in.GetContent())
}
_, err := updater.Save(l.ctx)
if err != nil {
logx.Errorf("updateReviews err: %v", err)
return nil, err
}
return &pb.UpdateReviewsResp{}, nil
}
+341
View File
@@ -0,0 +1,341 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"log"
"reflect"
"juwan-backend/app/review/rpc/internal/models/migrate"
"juwan-backend/app/review/rpc/internal/models/reviews"
"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
// Reviews is the client for interacting with the Reviews builders.
Reviews *ReviewsClient
}
// 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.Reviews = NewReviewsClient(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,
Reviews: NewReviewsClient(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,
Reviews: NewReviewsClient(cfg),
}, nil
}
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
// client.Debug().
// Reviews.
// 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.Reviews.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.Reviews.Intercept(interceptors...)
}
// Mutate implements the ent.Mutator interface.
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
switch m := m.(type) {
case *ReviewsMutation:
return c.Reviews.mutate(ctx, m)
default:
return nil, fmt.Errorf("models: unknown mutation type %T", m)
}
}
// ReviewsClient is a client for the Reviews schema.
type ReviewsClient struct {
config
}
// NewReviewsClient returns a client for the Reviews from the given config.
func NewReviewsClient(c config) *ReviewsClient {
return &ReviewsClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `reviews.Hooks(f(g(h())))`.
func (c *ReviewsClient) Use(hooks ...Hook) {
c.hooks.Reviews = append(c.hooks.Reviews, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `reviews.Intercept(f(g(h())))`.
func (c *ReviewsClient) Intercept(interceptors ...Interceptor) {
c.inters.Reviews = append(c.inters.Reviews, interceptors...)
}
// Create returns a builder for creating a Reviews entity.
func (c *ReviewsClient) Create() *ReviewsCreate {
mutation := newReviewsMutation(c.config, OpCreate)
return &ReviewsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Reviews entities.
func (c *ReviewsClient) CreateBulk(builders ...*ReviewsCreate) *ReviewsCreateBulk {
return &ReviewsCreateBulk{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 *ReviewsClient) MapCreateBulk(slice any, setFunc func(*ReviewsCreate, int)) *ReviewsCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &ReviewsCreateBulk{err: fmt.Errorf("calling to ReviewsClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*ReviewsCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &ReviewsCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Reviews.
func (c *ReviewsClient) Update() *ReviewsUpdate {
mutation := newReviewsMutation(c.config, OpUpdate)
return &ReviewsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *ReviewsClient) UpdateOne(_m *Reviews) *ReviewsUpdateOne {
mutation := newReviewsMutation(c.config, OpUpdateOne, withReviews(_m))
return &ReviewsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *ReviewsClient) UpdateOneID(id int64) *ReviewsUpdateOne {
mutation := newReviewsMutation(c.config, OpUpdateOne, withReviewsID(id))
return &ReviewsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Reviews.
func (c *ReviewsClient) Delete() *ReviewsDelete {
mutation := newReviewsMutation(c.config, OpDelete)
return &ReviewsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *ReviewsClient) DeleteOne(_m *Reviews) *ReviewsDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *ReviewsClient) DeleteOneID(id int64) *ReviewsDeleteOne {
builder := c.Delete().Where(reviews.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &ReviewsDeleteOne{builder}
}
// Query returns a query builder for Reviews.
func (c *ReviewsClient) Query() *ReviewsQuery {
return &ReviewsQuery{
config: c.config,
ctx: &QueryContext{Type: TypeReviews},
inters: c.Interceptors(),
}
}
// Get returns a Reviews entity by its id.
func (c *ReviewsClient) Get(ctx context.Context, id int64) (*Reviews, error) {
return c.Query().Where(reviews.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *ReviewsClient) GetX(ctx context.Context, id int64) *Reviews {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *ReviewsClient) Hooks() []Hook {
return c.hooks.Reviews
}
// Interceptors returns the client interceptors.
func (c *ReviewsClient) Interceptors() []Interceptor {
return c.inters.Reviews
}
func (c *ReviewsClient) mutate(ctx context.Context, m *ReviewsMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&ReviewsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&ReviewsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&ReviewsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&ReviewsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("models: unknown Reviews mutation op: %q", m.Op())
}
}
// hooks and interceptors per client, for fast access.
type (
hooks struct {
Reviews []ent.Hook
}
inters struct {
Reviews []ent.Interceptor
}
)
+608
View File
@@ -0,0 +1,608 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/review/rpc/internal/models/reviews"
"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{
reviews.Table: reviews.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/review/rpc/internal/models"
// required by schema hooks.
_ "juwan-backend/app/review/rpc/internal/models/runtime"
"juwan-backend/app/review/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
+198
View File
@@ -0,0 +1,198 @@
// Code generated by ent, DO NOT EDIT.
package hook
import (
"context"
"fmt"
"juwan-backend/app/review/rpc/internal/models"
)
// The ReviewsFunc type is an adapter to allow the use of ordinary
// function as Reviews mutator.
type ReviewsFunc func(context.Context, *models.ReviewsMutation) (models.Value, error)
// Mutate calls f(ctx, m).
func (f ReviewsFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
if mv, ok := m.(*models.ReviewsMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.ReviewsMutation", 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,60 @@
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"entgo.io/ent/dialect/sql/schema"
"entgo.io/ent/schema/field"
)
var (
// ReviewsColumns holds the columns for the "reviews" table.
ReviewsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "order_id", Type: field.TypeInt64},
{Name: "from_user_id", Type: field.TypeInt64},
{Name: "from_user_name", Type: field.TypeString, Size: 100},
{Name: "from_user_avatar", Type: field.TypeString, Nullable: true, Default: ""},
{Name: "to_user_id", Type: field.TypeInt64},
{Name: "rating", Type: field.TypeInt16},
{Name: "content", Type: field.TypeString, Nullable: true, Default: ""},
{Name: "sealed", Type: field.TypeBool, Default: true},
{Name: "created_at", Type: field.TypeTime},
{Name: "unsealed_at", Type: field.TypeTime, Nullable: true},
}
// ReviewsTable holds the schema information for the "reviews" table.
ReviewsTable = &schema.Table{
Name: "reviews",
Columns: ReviewsColumns,
PrimaryKey: []*schema.Column{ReviewsColumns[0]},
Indexes: []*schema.Index{
{
Name: "reviews_order_id_from_user_id",
Unique: true,
Columns: []*schema.Column{ReviewsColumns[1], ReviewsColumns[2]},
},
{
Name: "reviews_order_id",
Unique: false,
Columns: []*schema.Column{ReviewsColumns[1]},
},
{
Name: "reviews_to_user_id_created_at",
Unique: false,
Columns: []*schema.Column{ReviewsColumns[5], ReviewsColumns[9]},
},
{
Name: "reviews_from_user_id",
Unique: false,
Columns: []*schema.Column{ReviewsColumns[2]},
},
},
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
ReviewsTable,
}
)
func init() {
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,10 @@
// Code generated by ent, DO NOT EDIT.
package predicate
import (
"entgo.io/ent/dialect/sql"
)
// Reviews is the predicate function for reviews builders.
type Reviews func(*sql.Selector)
+210
View File
@@ -0,0 +1,210 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"fmt"
"juwan-backend/app/review/rpc/internal/models/reviews"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// Reviews is the model entity for the Reviews schema.
type Reviews 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"`
// FromUserID holds the value of the "from_user_id" field.
FromUserID int64 `json:"from_user_id,omitempty"`
// FromUserName holds the value of the "from_user_name" field.
FromUserName string `json:"from_user_name,omitempty"`
// FromUserAvatar holds the value of the "from_user_avatar" field.
FromUserAvatar string `json:"from_user_avatar,omitempty"`
// ToUserID holds the value of the "to_user_id" field.
ToUserID int64 `json:"to_user_id,omitempty"`
// Rating holds the value of the "rating" field.
Rating int16 `json:"rating,omitempty"`
// Content holds the value of the "content" field.
Content string `json:"content,omitempty"`
// Sealed holds the value of the "sealed" field.
Sealed bool `json:"sealed,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UnsealedAt holds the value of the "unsealed_at" field.
UnsealedAt *time.Time `json:"unsealed_at,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Reviews) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case reviews.FieldSealed:
values[i] = new(sql.NullBool)
case reviews.FieldID, reviews.FieldOrderID, reviews.FieldFromUserID, reviews.FieldToUserID, reviews.FieldRating:
values[i] = new(sql.NullInt64)
case reviews.FieldFromUserName, reviews.FieldFromUserAvatar, reviews.FieldContent:
values[i] = new(sql.NullString)
case reviews.FieldCreatedAt, reviews.FieldUnsealedAt:
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 Reviews fields.
func (_m *Reviews) 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 reviews.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 reviews.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 reviews.FieldFromUserID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field from_user_id", values[i])
} else if value.Valid {
_m.FromUserID = value.Int64
}
case reviews.FieldFromUserName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field from_user_name", values[i])
} else if value.Valid {
_m.FromUserName = value.String
}
case reviews.FieldFromUserAvatar:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field from_user_avatar", values[i])
} else if value.Valid {
_m.FromUserAvatar = value.String
}
case reviews.FieldToUserID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field to_user_id", values[i])
} else if value.Valid {
_m.ToUserID = value.Int64
}
case reviews.FieldRating:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field rating", values[i])
} else if value.Valid {
_m.Rating = int16(value.Int64)
}
case reviews.FieldContent:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field content", values[i])
} else if value.Valid {
_m.Content = value.String
}
case reviews.FieldSealed:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field sealed", values[i])
} else if value.Valid {
_m.Sealed = value.Bool
}
case reviews.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 reviews.FieldUnsealedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field unsealed_at", values[i])
} else if value.Valid {
_m.UnsealedAt = new(time.Time)
*_m.UnsealedAt = 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 Reviews.
// This includes values selected through modifiers, order, etc.
func (_m *Reviews) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// Update returns a builder for updating this Reviews.
// Note that you need to call Reviews.Unwrap() before calling this method if this Reviews
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Reviews) Update() *ReviewsUpdateOne {
return NewReviewsClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Reviews 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 *Reviews) Unwrap() *Reviews {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("models: Reviews is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Reviews) String() string {
var builder strings.Builder
builder.WriteString("Reviews(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("order_id=")
builder.WriteString(fmt.Sprintf("%v", _m.OrderID))
builder.WriteString(", ")
builder.WriteString("from_user_id=")
builder.WriteString(fmt.Sprintf("%v", _m.FromUserID))
builder.WriteString(", ")
builder.WriteString("from_user_name=")
builder.WriteString(_m.FromUserName)
builder.WriteString(", ")
builder.WriteString("from_user_avatar=")
builder.WriteString(_m.FromUserAvatar)
builder.WriteString(", ")
builder.WriteString("to_user_id=")
builder.WriteString(fmt.Sprintf("%v", _m.ToUserID))
builder.WriteString(", ")
builder.WriteString("rating=")
builder.WriteString(fmt.Sprintf("%v", _m.Rating))
builder.WriteString(", ")
builder.WriteString("content=")
builder.WriteString(_m.Content)
builder.WriteString(", ")
builder.WriteString("sealed=")
builder.WriteString(fmt.Sprintf("%v", _m.Sealed))
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := _m.UnsealedAt; v != nil {
builder.WriteString("unsealed_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteByte(')')
return builder.String()
}
// ReviewsSlice is a parsable slice of Reviews.
type ReviewsSlice []*Reviews
@@ -0,0 +1,134 @@
// Code generated by ent, DO NOT EDIT.
package reviews
import (
"time"
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the reviews type in the database.
Label = "reviews"
// 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"
// FieldFromUserID holds the string denoting the from_user_id field in the database.
FieldFromUserID = "from_user_id"
// FieldFromUserName holds the string denoting the from_user_name field in the database.
FieldFromUserName = "from_user_name"
// FieldFromUserAvatar holds the string denoting the from_user_avatar field in the database.
FieldFromUserAvatar = "from_user_avatar"
// FieldToUserID holds the string denoting the to_user_id field in the database.
FieldToUserID = "to_user_id"
// FieldRating holds the string denoting the rating field in the database.
FieldRating = "rating"
// FieldContent holds the string denoting the content field in the database.
FieldContent = "content"
// FieldSealed holds the string denoting the sealed field in the database.
FieldSealed = "sealed"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUnsealedAt holds the string denoting the unsealed_at field in the database.
FieldUnsealedAt = "unsealed_at"
// Table holds the table name of the reviews in the database.
Table = "reviews"
)
// Columns holds all SQL columns for reviews fields.
var Columns = []string{
FieldID,
FieldOrderID,
FieldFromUserID,
FieldFromUserName,
FieldFromUserAvatar,
FieldToUserID,
FieldRating,
FieldContent,
FieldSealed,
FieldCreatedAt,
FieldUnsealedAt,
}
// 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 (
// FromUserNameValidator is a validator for the "from_user_name" field. It is called by the builders before save.
FromUserNameValidator func(string) error
// DefaultFromUserAvatar holds the default value on creation for the "from_user_avatar" field.
DefaultFromUserAvatar string
// DefaultContent holds the default value on creation for the "content" field.
DefaultContent string
// DefaultSealed holds the default value on creation for the "sealed" field.
DefaultSealed bool
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
)
// OrderOption defines the ordering options for the Reviews 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()
}
// ByFromUserID orders the results by the from_user_id field.
func ByFromUserID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldFromUserID, opts...).ToFunc()
}
// ByFromUserName orders the results by the from_user_name field.
func ByFromUserName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldFromUserName, opts...).ToFunc()
}
// ByFromUserAvatar orders the results by the from_user_avatar field.
func ByFromUserAvatar(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldFromUserAvatar, opts...).ToFunc()
}
// ByToUserID orders the results by the to_user_id field.
func ByToUserID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldToUserID, opts...).ToFunc()
}
// ByRating orders the results by the rating field.
func ByRating(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldRating, opts...).ToFunc()
}
// ByContent orders the results by the content field.
func ByContent(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldContent, opts...).ToFunc()
}
// BySealed orders the results by the sealed field.
func BySealed(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSealed, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUnsealedAt orders the results by the unsealed_at field.
func ByUnsealedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUnsealedAt, opts...).ToFunc()
}
@@ -0,0 +1,595 @@
// Code generated by ent, DO NOT EDIT.
package reviews
import (
"juwan-backend/app/review/rpc/internal/models/predicate"
"time"
"entgo.io/ent/dialect/sql"
)
// ID filters vertices based on their ID field.
func ID(id int64) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int64) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int64) predicate.Reviews {
return predicate.Reviews(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int64) predicate.Reviews {
return predicate.Reviews(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int64) predicate.Reviews {
return predicate.Reviews(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int64) predicate.Reviews {
return predicate.Reviews(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int64) predicate.Reviews {
return predicate.Reviews(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int64) predicate.Reviews {
return predicate.Reviews(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int64) predicate.Reviews {
return predicate.Reviews(sql.FieldLTE(FieldID, id))
}
// OrderID applies equality check predicate on the "order_id" field. It's identical to OrderIDEQ.
func OrderID(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldOrderID, v))
}
// FromUserID applies equality check predicate on the "from_user_id" field. It's identical to FromUserIDEQ.
func FromUserID(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldFromUserID, v))
}
// FromUserName applies equality check predicate on the "from_user_name" field. It's identical to FromUserNameEQ.
func FromUserName(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldFromUserName, v))
}
// FromUserAvatar applies equality check predicate on the "from_user_avatar" field. It's identical to FromUserAvatarEQ.
func FromUserAvatar(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldFromUserAvatar, v))
}
// ToUserID applies equality check predicate on the "to_user_id" field. It's identical to ToUserIDEQ.
func ToUserID(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldToUserID, v))
}
// Rating applies equality check predicate on the "rating" field. It's identical to RatingEQ.
func Rating(v int16) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldRating, v))
}
// Content applies equality check predicate on the "content" field. It's identical to ContentEQ.
func Content(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldContent, v))
}
// Sealed applies equality check predicate on the "sealed" field. It's identical to SealedEQ.
func Sealed(v bool) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldSealed, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldCreatedAt, v))
}
// UnsealedAt applies equality check predicate on the "unsealed_at" field. It's identical to UnsealedAtEQ.
func UnsealedAt(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldUnsealedAt, v))
}
// OrderIDEQ applies the EQ predicate on the "order_id" field.
func OrderIDEQ(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldOrderID, v))
}
// OrderIDNEQ applies the NEQ predicate on the "order_id" field.
func OrderIDNEQ(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldNEQ(FieldOrderID, v))
}
// OrderIDIn applies the In predicate on the "order_id" field.
func OrderIDIn(vs ...int64) predicate.Reviews {
return predicate.Reviews(sql.FieldIn(FieldOrderID, vs...))
}
// OrderIDNotIn applies the NotIn predicate on the "order_id" field.
func OrderIDNotIn(vs ...int64) predicate.Reviews {
return predicate.Reviews(sql.FieldNotIn(FieldOrderID, vs...))
}
// OrderIDGT applies the GT predicate on the "order_id" field.
func OrderIDGT(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldGT(FieldOrderID, v))
}
// OrderIDGTE applies the GTE predicate on the "order_id" field.
func OrderIDGTE(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldGTE(FieldOrderID, v))
}
// OrderIDLT applies the LT predicate on the "order_id" field.
func OrderIDLT(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldLT(FieldOrderID, v))
}
// OrderIDLTE applies the LTE predicate on the "order_id" field.
func OrderIDLTE(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldLTE(FieldOrderID, v))
}
// FromUserIDEQ applies the EQ predicate on the "from_user_id" field.
func FromUserIDEQ(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldFromUserID, v))
}
// FromUserIDNEQ applies the NEQ predicate on the "from_user_id" field.
func FromUserIDNEQ(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldNEQ(FieldFromUserID, v))
}
// FromUserIDIn applies the In predicate on the "from_user_id" field.
func FromUserIDIn(vs ...int64) predicate.Reviews {
return predicate.Reviews(sql.FieldIn(FieldFromUserID, vs...))
}
// FromUserIDNotIn applies the NotIn predicate on the "from_user_id" field.
func FromUserIDNotIn(vs ...int64) predicate.Reviews {
return predicate.Reviews(sql.FieldNotIn(FieldFromUserID, vs...))
}
// FromUserIDGT applies the GT predicate on the "from_user_id" field.
func FromUserIDGT(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldGT(FieldFromUserID, v))
}
// FromUserIDGTE applies the GTE predicate on the "from_user_id" field.
func FromUserIDGTE(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldGTE(FieldFromUserID, v))
}
// FromUserIDLT applies the LT predicate on the "from_user_id" field.
func FromUserIDLT(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldLT(FieldFromUserID, v))
}
// FromUserIDLTE applies the LTE predicate on the "from_user_id" field.
func FromUserIDLTE(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldLTE(FieldFromUserID, v))
}
// FromUserNameEQ applies the EQ predicate on the "from_user_name" field.
func FromUserNameEQ(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldFromUserName, v))
}
// FromUserNameNEQ applies the NEQ predicate on the "from_user_name" field.
func FromUserNameNEQ(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldNEQ(FieldFromUserName, v))
}
// FromUserNameIn applies the In predicate on the "from_user_name" field.
func FromUserNameIn(vs ...string) predicate.Reviews {
return predicate.Reviews(sql.FieldIn(FieldFromUserName, vs...))
}
// FromUserNameNotIn applies the NotIn predicate on the "from_user_name" field.
func FromUserNameNotIn(vs ...string) predicate.Reviews {
return predicate.Reviews(sql.FieldNotIn(FieldFromUserName, vs...))
}
// FromUserNameGT applies the GT predicate on the "from_user_name" field.
func FromUserNameGT(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldGT(FieldFromUserName, v))
}
// FromUserNameGTE applies the GTE predicate on the "from_user_name" field.
func FromUserNameGTE(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldGTE(FieldFromUserName, v))
}
// FromUserNameLT applies the LT predicate on the "from_user_name" field.
func FromUserNameLT(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldLT(FieldFromUserName, v))
}
// FromUserNameLTE applies the LTE predicate on the "from_user_name" field.
func FromUserNameLTE(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldLTE(FieldFromUserName, v))
}
// FromUserNameContains applies the Contains predicate on the "from_user_name" field.
func FromUserNameContains(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldContains(FieldFromUserName, v))
}
// FromUserNameHasPrefix applies the HasPrefix predicate on the "from_user_name" field.
func FromUserNameHasPrefix(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldHasPrefix(FieldFromUserName, v))
}
// FromUserNameHasSuffix applies the HasSuffix predicate on the "from_user_name" field.
func FromUserNameHasSuffix(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldHasSuffix(FieldFromUserName, v))
}
// FromUserNameEqualFold applies the EqualFold predicate on the "from_user_name" field.
func FromUserNameEqualFold(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldEqualFold(FieldFromUserName, v))
}
// FromUserNameContainsFold applies the ContainsFold predicate on the "from_user_name" field.
func FromUserNameContainsFold(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldContainsFold(FieldFromUserName, v))
}
// FromUserAvatarEQ applies the EQ predicate on the "from_user_avatar" field.
func FromUserAvatarEQ(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldFromUserAvatar, v))
}
// FromUserAvatarNEQ applies the NEQ predicate on the "from_user_avatar" field.
func FromUserAvatarNEQ(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldNEQ(FieldFromUserAvatar, v))
}
// FromUserAvatarIn applies the In predicate on the "from_user_avatar" field.
func FromUserAvatarIn(vs ...string) predicate.Reviews {
return predicate.Reviews(sql.FieldIn(FieldFromUserAvatar, vs...))
}
// FromUserAvatarNotIn applies the NotIn predicate on the "from_user_avatar" field.
func FromUserAvatarNotIn(vs ...string) predicate.Reviews {
return predicate.Reviews(sql.FieldNotIn(FieldFromUserAvatar, vs...))
}
// FromUserAvatarGT applies the GT predicate on the "from_user_avatar" field.
func FromUserAvatarGT(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldGT(FieldFromUserAvatar, v))
}
// FromUserAvatarGTE applies the GTE predicate on the "from_user_avatar" field.
func FromUserAvatarGTE(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldGTE(FieldFromUserAvatar, v))
}
// FromUserAvatarLT applies the LT predicate on the "from_user_avatar" field.
func FromUserAvatarLT(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldLT(FieldFromUserAvatar, v))
}
// FromUserAvatarLTE applies the LTE predicate on the "from_user_avatar" field.
func FromUserAvatarLTE(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldLTE(FieldFromUserAvatar, v))
}
// FromUserAvatarContains applies the Contains predicate on the "from_user_avatar" field.
func FromUserAvatarContains(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldContains(FieldFromUserAvatar, v))
}
// FromUserAvatarHasPrefix applies the HasPrefix predicate on the "from_user_avatar" field.
func FromUserAvatarHasPrefix(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldHasPrefix(FieldFromUserAvatar, v))
}
// FromUserAvatarHasSuffix applies the HasSuffix predicate on the "from_user_avatar" field.
func FromUserAvatarHasSuffix(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldHasSuffix(FieldFromUserAvatar, v))
}
// FromUserAvatarIsNil applies the IsNil predicate on the "from_user_avatar" field.
func FromUserAvatarIsNil() predicate.Reviews {
return predicate.Reviews(sql.FieldIsNull(FieldFromUserAvatar))
}
// FromUserAvatarNotNil applies the NotNil predicate on the "from_user_avatar" field.
func FromUserAvatarNotNil() predicate.Reviews {
return predicate.Reviews(sql.FieldNotNull(FieldFromUserAvatar))
}
// FromUserAvatarEqualFold applies the EqualFold predicate on the "from_user_avatar" field.
func FromUserAvatarEqualFold(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldEqualFold(FieldFromUserAvatar, v))
}
// FromUserAvatarContainsFold applies the ContainsFold predicate on the "from_user_avatar" field.
func FromUserAvatarContainsFold(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldContainsFold(FieldFromUserAvatar, v))
}
// ToUserIDEQ applies the EQ predicate on the "to_user_id" field.
func ToUserIDEQ(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldToUserID, v))
}
// ToUserIDNEQ applies the NEQ predicate on the "to_user_id" field.
func ToUserIDNEQ(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldNEQ(FieldToUserID, v))
}
// ToUserIDIn applies the In predicate on the "to_user_id" field.
func ToUserIDIn(vs ...int64) predicate.Reviews {
return predicate.Reviews(sql.FieldIn(FieldToUserID, vs...))
}
// ToUserIDNotIn applies the NotIn predicate on the "to_user_id" field.
func ToUserIDNotIn(vs ...int64) predicate.Reviews {
return predicate.Reviews(sql.FieldNotIn(FieldToUserID, vs...))
}
// ToUserIDGT applies the GT predicate on the "to_user_id" field.
func ToUserIDGT(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldGT(FieldToUserID, v))
}
// ToUserIDGTE applies the GTE predicate on the "to_user_id" field.
func ToUserIDGTE(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldGTE(FieldToUserID, v))
}
// ToUserIDLT applies the LT predicate on the "to_user_id" field.
func ToUserIDLT(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldLT(FieldToUserID, v))
}
// ToUserIDLTE applies the LTE predicate on the "to_user_id" field.
func ToUserIDLTE(v int64) predicate.Reviews {
return predicate.Reviews(sql.FieldLTE(FieldToUserID, v))
}
// RatingEQ applies the EQ predicate on the "rating" field.
func RatingEQ(v int16) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldRating, v))
}
// RatingNEQ applies the NEQ predicate on the "rating" field.
func RatingNEQ(v int16) predicate.Reviews {
return predicate.Reviews(sql.FieldNEQ(FieldRating, v))
}
// RatingIn applies the In predicate on the "rating" field.
func RatingIn(vs ...int16) predicate.Reviews {
return predicate.Reviews(sql.FieldIn(FieldRating, vs...))
}
// RatingNotIn applies the NotIn predicate on the "rating" field.
func RatingNotIn(vs ...int16) predicate.Reviews {
return predicate.Reviews(sql.FieldNotIn(FieldRating, vs...))
}
// RatingGT applies the GT predicate on the "rating" field.
func RatingGT(v int16) predicate.Reviews {
return predicate.Reviews(sql.FieldGT(FieldRating, v))
}
// RatingGTE applies the GTE predicate on the "rating" field.
func RatingGTE(v int16) predicate.Reviews {
return predicate.Reviews(sql.FieldGTE(FieldRating, v))
}
// RatingLT applies the LT predicate on the "rating" field.
func RatingLT(v int16) predicate.Reviews {
return predicate.Reviews(sql.FieldLT(FieldRating, v))
}
// RatingLTE applies the LTE predicate on the "rating" field.
func RatingLTE(v int16) predicate.Reviews {
return predicate.Reviews(sql.FieldLTE(FieldRating, v))
}
// ContentEQ applies the EQ predicate on the "content" field.
func ContentEQ(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldContent, v))
}
// ContentNEQ applies the NEQ predicate on the "content" field.
func ContentNEQ(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldNEQ(FieldContent, v))
}
// ContentIn applies the In predicate on the "content" field.
func ContentIn(vs ...string) predicate.Reviews {
return predicate.Reviews(sql.FieldIn(FieldContent, vs...))
}
// ContentNotIn applies the NotIn predicate on the "content" field.
func ContentNotIn(vs ...string) predicate.Reviews {
return predicate.Reviews(sql.FieldNotIn(FieldContent, vs...))
}
// ContentGT applies the GT predicate on the "content" field.
func ContentGT(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldGT(FieldContent, v))
}
// ContentGTE applies the GTE predicate on the "content" field.
func ContentGTE(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldGTE(FieldContent, v))
}
// ContentLT applies the LT predicate on the "content" field.
func ContentLT(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldLT(FieldContent, v))
}
// ContentLTE applies the LTE predicate on the "content" field.
func ContentLTE(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldLTE(FieldContent, v))
}
// ContentContains applies the Contains predicate on the "content" field.
func ContentContains(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldContains(FieldContent, v))
}
// ContentHasPrefix applies the HasPrefix predicate on the "content" field.
func ContentHasPrefix(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldHasPrefix(FieldContent, v))
}
// ContentHasSuffix applies the HasSuffix predicate on the "content" field.
func ContentHasSuffix(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldHasSuffix(FieldContent, v))
}
// ContentIsNil applies the IsNil predicate on the "content" field.
func ContentIsNil() predicate.Reviews {
return predicate.Reviews(sql.FieldIsNull(FieldContent))
}
// ContentNotNil applies the NotNil predicate on the "content" field.
func ContentNotNil() predicate.Reviews {
return predicate.Reviews(sql.FieldNotNull(FieldContent))
}
// ContentEqualFold applies the EqualFold predicate on the "content" field.
func ContentEqualFold(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldEqualFold(FieldContent, v))
}
// ContentContainsFold applies the ContainsFold predicate on the "content" field.
func ContentContainsFold(v string) predicate.Reviews {
return predicate.Reviews(sql.FieldContainsFold(FieldContent, v))
}
// SealedEQ applies the EQ predicate on the "sealed" field.
func SealedEQ(v bool) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldSealed, v))
}
// SealedNEQ applies the NEQ predicate on the "sealed" field.
func SealedNEQ(v bool) predicate.Reviews {
return predicate.Reviews(sql.FieldNEQ(FieldSealed, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldLTE(FieldCreatedAt, v))
}
// UnsealedAtEQ applies the EQ predicate on the "unsealed_at" field.
func UnsealedAtEQ(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldEQ(FieldUnsealedAt, v))
}
// UnsealedAtNEQ applies the NEQ predicate on the "unsealed_at" field.
func UnsealedAtNEQ(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldNEQ(FieldUnsealedAt, v))
}
// UnsealedAtIn applies the In predicate on the "unsealed_at" field.
func UnsealedAtIn(vs ...time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldIn(FieldUnsealedAt, vs...))
}
// UnsealedAtNotIn applies the NotIn predicate on the "unsealed_at" field.
func UnsealedAtNotIn(vs ...time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldNotIn(FieldUnsealedAt, vs...))
}
// UnsealedAtGT applies the GT predicate on the "unsealed_at" field.
func UnsealedAtGT(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldGT(FieldUnsealedAt, v))
}
// UnsealedAtGTE applies the GTE predicate on the "unsealed_at" field.
func UnsealedAtGTE(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldGTE(FieldUnsealedAt, v))
}
// UnsealedAtLT applies the LT predicate on the "unsealed_at" field.
func UnsealedAtLT(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldLT(FieldUnsealedAt, v))
}
// UnsealedAtLTE applies the LTE predicate on the "unsealed_at" field.
func UnsealedAtLTE(v time.Time) predicate.Reviews {
return predicate.Reviews(sql.FieldLTE(FieldUnsealedAt, v))
}
// UnsealedAtIsNil applies the IsNil predicate on the "unsealed_at" field.
func UnsealedAtIsNil() predicate.Reviews {
return predicate.Reviews(sql.FieldIsNull(FieldUnsealedAt))
}
// UnsealedAtNotNil applies the NotNil predicate on the "unsealed_at" field.
func UnsealedAtNotNil() predicate.Reviews {
return predicate.Reviews(sql.FieldNotNull(FieldUnsealedAt))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Reviews) predicate.Reviews {
return predicate.Reviews(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.Reviews) predicate.Reviews {
return predicate.Reviews(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.Reviews) predicate.Reviews {
return predicate.Reviews(sql.NotPredicates(p))
}
@@ -0,0 +1,371 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/review/rpc/internal/models/reviews"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ReviewsCreate is the builder for creating a Reviews entity.
type ReviewsCreate struct {
config
mutation *ReviewsMutation
hooks []Hook
}
// SetOrderID sets the "order_id" field.
func (_c *ReviewsCreate) SetOrderID(v int64) *ReviewsCreate {
_c.mutation.SetOrderID(v)
return _c
}
// SetFromUserID sets the "from_user_id" field.
func (_c *ReviewsCreate) SetFromUserID(v int64) *ReviewsCreate {
_c.mutation.SetFromUserID(v)
return _c
}
// SetFromUserName sets the "from_user_name" field.
func (_c *ReviewsCreate) SetFromUserName(v string) *ReviewsCreate {
_c.mutation.SetFromUserName(v)
return _c
}
// SetFromUserAvatar sets the "from_user_avatar" field.
func (_c *ReviewsCreate) SetFromUserAvatar(v string) *ReviewsCreate {
_c.mutation.SetFromUserAvatar(v)
return _c
}
// SetNillableFromUserAvatar sets the "from_user_avatar" field if the given value is not nil.
func (_c *ReviewsCreate) SetNillableFromUserAvatar(v *string) *ReviewsCreate {
if v != nil {
_c.SetFromUserAvatar(*v)
}
return _c
}
// SetToUserID sets the "to_user_id" field.
func (_c *ReviewsCreate) SetToUserID(v int64) *ReviewsCreate {
_c.mutation.SetToUserID(v)
return _c
}
// SetRating sets the "rating" field.
func (_c *ReviewsCreate) SetRating(v int16) *ReviewsCreate {
_c.mutation.SetRating(v)
return _c
}
// SetContent sets the "content" field.
func (_c *ReviewsCreate) SetContent(v string) *ReviewsCreate {
_c.mutation.SetContent(v)
return _c
}
// SetNillableContent sets the "content" field if the given value is not nil.
func (_c *ReviewsCreate) SetNillableContent(v *string) *ReviewsCreate {
if v != nil {
_c.SetContent(*v)
}
return _c
}
// SetSealed sets the "sealed" field.
func (_c *ReviewsCreate) SetSealed(v bool) *ReviewsCreate {
_c.mutation.SetSealed(v)
return _c
}
// SetNillableSealed sets the "sealed" field if the given value is not nil.
func (_c *ReviewsCreate) SetNillableSealed(v *bool) *ReviewsCreate {
if v != nil {
_c.SetSealed(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *ReviewsCreate) SetCreatedAt(v time.Time) *ReviewsCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *ReviewsCreate) SetNillableCreatedAt(v *time.Time) *ReviewsCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUnsealedAt sets the "unsealed_at" field.
func (_c *ReviewsCreate) SetUnsealedAt(v time.Time) *ReviewsCreate {
_c.mutation.SetUnsealedAt(v)
return _c
}
// SetNillableUnsealedAt sets the "unsealed_at" field if the given value is not nil.
func (_c *ReviewsCreate) SetNillableUnsealedAt(v *time.Time) *ReviewsCreate {
if v != nil {
_c.SetUnsealedAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *ReviewsCreate) SetID(v int64) *ReviewsCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the ReviewsMutation object of the builder.
func (_c *ReviewsCreate) Mutation() *ReviewsMutation {
return _c.mutation
}
// Save creates the Reviews in the database.
func (_c *ReviewsCreate) Save(ctx context.Context) (*Reviews, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *ReviewsCreate) SaveX(ctx context.Context) *Reviews {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ReviewsCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ReviewsCreate) 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 *ReviewsCreate) defaults() {
if _, ok := _c.mutation.FromUserAvatar(); !ok {
v := reviews.DefaultFromUserAvatar
_c.mutation.SetFromUserAvatar(v)
}
if _, ok := _c.mutation.Content(); !ok {
v := reviews.DefaultContent
_c.mutation.SetContent(v)
}
if _, ok := _c.mutation.Sealed(); !ok {
v := reviews.DefaultSealed
_c.mutation.SetSealed(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := reviews.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *ReviewsCreate) check() error {
if _, ok := _c.mutation.OrderID(); !ok {
return &ValidationError{Name: "order_id", err: errors.New(`models: missing required field "Reviews.order_id"`)}
}
if _, ok := _c.mutation.FromUserID(); !ok {
return &ValidationError{Name: "from_user_id", err: errors.New(`models: missing required field "Reviews.from_user_id"`)}
}
if _, ok := _c.mutation.FromUserName(); !ok {
return &ValidationError{Name: "from_user_name", err: errors.New(`models: missing required field "Reviews.from_user_name"`)}
}
if v, ok := _c.mutation.FromUserName(); ok {
if err := reviews.FromUserNameValidator(v); err != nil {
return &ValidationError{Name: "from_user_name", err: fmt.Errorf(`models: validator failed for field "Reviews.from_user_name": %w`, err)}
}
}
if _, ok := _c.mutation.ToUserID(); !ok {
return &ValidationError{Name: "to_user_id", err: errors.New(`models: missing required field "Reviews.to_user_id"`)}
}
if _, ok := _c.mutation.Rating(); !ok {
return &ValidationError{Name: "rating", err: errors.New(`models: missing required field "Reviews.rating"`)}
}
if _, ok := _c.mutation.Sealed(); !ok {
return &ValidationError{Name: "sealed", err: errors.New(`models: missing required field "Reviews.sealed"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "Reviews.created_at"`)}
}
return nil
}
func (_c *ReviewsCreate) sqlSave(ctx context.Context) (*Reviews, 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 *ReviewsCreate) createSpec() (*Reviews, *sqlgraph.CreateSpec) {
var (
_node = &Reviews{config: _c.config}
_spec = sqlgraph.NewCreateSpec(reviews.Table, sqlgraph.NewFieldSpec(reviews.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(reviews.FieldOrderID, field.TypeInt64, value)
_node.OrderID = value
}
if value, ok := _c.mutation.FromUserID(); ok {
_spec.SetField(reviews.FieldFromUserID, field.TypeInt64, value)
_node.FromUserID = value
}
if value, ok := _c.mutation.FromUserName(); ok {
_spec.SetField(reviews.FieldFromUserName, field.TypeString, value)
_node.FromUserName = value
}
if value, ok := _c.mutation.FromUserAvatar(); ok {
_spec.SetField(reviews.FieldFromUserAvatar, field.TypeString, value)
_node.FromUserAvatar = value
}
if value, ok := _c.mutation.ToUserID(); ok {
_spec.SetField(reviews.FieldToUserID, field.TypeInt64, value)
_node.ToUserID = value
}
if value, ok := _c.mutation.Rating(); ok {
_spec.SetField(reviews.FieldRating, field.TypeInt16, value)
_node.Rating = value
}
if value, ok := _c.mutation.Content(); ok {
_spec.SetField(reviews.FieldContent, field.TypeString, value)
_node.Content = value
}
if value, ok := _c.mutation.Sealed(); ok {
_spec.SetField(reviews.FieldSealed, field.TypeBool, value)
_node.Sealed = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(reviews.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UnsealedAt(); ok {
_spec.SetField(reviews.FieldUnsealedAt, field.TypeTime, value)
_node.UnsealedAt = &value
}
return _node, _spec
}
// ReviewsCreateBulk is the builder for creating many Reviews entities in bulk.
type ReviewsCreateBulk struct {
config
err error
builders []*ReviewsCreate
}
// Save creates the Reviews entities in the database.
func (_c *ReviewsCreateBulk) Save(ctx context.Context) ([]*Reviews, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*Reviews, 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.(*ReviewsMutation)
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 *ReviewsCreateBulk) SaveX(ctx context.Context) []*Reviews {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ReviewsCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ReviewsCreateBulk) 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/review/rpc/internal/models/predicate"
"juwan-backend/app/review/rpc/internal/models/reviews"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ReviewsDelete is the builder for deleting a Reviews entity.
type ReviewsDelete struct {
config
hooks []Hook
mutation *ReviewsMutation
}
// Where appends a list predicates to the ReviewsDelete builder.
func (_d *ReviewsDelete) Where(ps ...predicate.Reviews) *ReviewsDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *ReviewsDelete) 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 *ReviewsDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *ReviewsDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(reviews.Table, sqlgraph.NewFieldSpec(reviews.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
}
// ReviewsDeleteOne is the builder for deleting a single Reviews entity.
type ReviewsDeleteOne struct {
_d *ReviewsDelete
}
// Where appends a list predicates to the ReviewsDelete builder.
func (_d *ReviewsDeleteOne) Where(ps ...predicate.Reviews) *ReviewsDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *ReviewsDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{reviews.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ReviewsDeleteOne) 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/review/rpc/internal/models/predicate"
"juwan-backend/app/review/rpc/internal/models/reviews"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ReviewsQuery is the builder for querying Reviews entities.
type ReviewsQuery struct {
config
ctx *QueryContext
order []reviews.OrderOption
inters []Interceptor
predicates []predicate.Reviews
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the ReviewsQuery builder.
func (_q *ReviewsQuery) Where(ps ...predicate.Reviews) *ReviewsQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *ReviewsQuery) Limit(limit int) *ReviewsQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *ReviewsQuery) Offset(offset int) *ReviewsQuery {
_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 *ReviewsQuery) Unique(unique bool) *ReviewsQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *ReviewsQuery) Order(o ...reviews.OrderOption) *ReviewsQuery {
_q.order = append(_q.order, o...)
return _q
}
// First returns the first Reviews entity from the query.
// Returns a *NotFoundError when no Reviews was found.
func (_q *ReviewsQuery) First(ctx context.Context) (*Reviews, 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{reviews.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *ReviewsQuery) FirstX(ctx context.Context) *Reviews {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first Reviews ID from the query.
// Returns a *NotFoundError when no Reviews ID was found.
func (_q *ReviewsQuery) 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{reviews.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *ReviewsQuery) FirstIDX(ctx context.Context) int64 {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single Reviews entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one Reviews entity is found.
// Returns a *NotFoundError when no Reviews entities are found.
func (_q *ReviewsQuery) Only(ctx context.Context) (*Reviews, 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{reviews.Label}
default:
return nil, &NotSingularError{reviews.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *ReviewsQuery) OnlyX(ctx context.Context) *Reviews {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only Reviews ID in the query.
// Returns a *NotSingularError when more than one Reviews ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *ReviewsQuery) 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{reviews.Label}
default:
err = &NotSingularError{reviews.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *ReviewsQuery) 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 ReviewsSlice.
func (_q *ReviewsQuery) All(ctx context.Context) ([]*Reviews, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*Reviews, *ReviewsQuery]()
return withInterceptors[[]*Reviews](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *ReviewsQuery) AllX(ctx context.Context) []*Reviews {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of Reviews IDs.
func (_q *ReviewsQuery) 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(reviews.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *ReviewsQuery) 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 *ReviewsQuery) 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[*ReviewsQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *ReviewsQuery) 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 *ReviewsQuery) 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 *ReviewsQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the ReviewsQuery 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 *ReviewsQuery) Clone() *ReviewsQuery {
if _q == nil {
return nil
}
return &ReviewsQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]reviews.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.Reviews{}, _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.Reviews.Query().
// GroupBy(reviews.FieldOrderID).
// Aggregate(models.Count()).
// Scan(ctx, &v)
func (_q *ReviewsQuery) GroupBy(field string, fields ...string) *ReviewsGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &ReviewsGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = reviews.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.Reviews.Query().
// Select(reviews.FieldOrderID).
// Scan(ctx, &v)
func (_q *ReviewsQuery) Select(fields ...string) *ReviewsSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &ReviewsSelect{ReviewsQuery: _q}
sbuild.label = reviews.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a ReviewsSelect configured with the given aggregations.
func (_q *ReviewsQuery) Aggregate(fns ...AggregateFunc) *ReviewsSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *ReviewsQuery) 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 !reviews.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 *ReviewsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Reviews, error) {
var (
nodes = []*Reviews{}
_spec = _q.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*Reviews).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &Reviews{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 *ReviewsQuery) 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 *ReviewsQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(reviews.Table, reviews.Columns, sqlgraph.NewFieldSpec(reviews.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, reviews.FieldID)
for i := range fields {
if fields[i] != reviews.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 *ReviewsQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(reviews.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = reviews.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
}
// ReviewsGroupBy is the group-by builder for Reviews entities.
type ReviewsGroupBy struct {
selector
build *ReviewsQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *ReviewsGroupBy) Aggregate(fns ...AggregateFunc) *ReviewsGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *ReviewsGroupBy) 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[*ReviewsQuery, *ReviewsGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *ReviewsGroupBy) sqlScan(ctx context.Context, root *ReviewsQuery, 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)
}
// ReviewsSelect is the builder for selecting fields of Reviews entities.
type ReviewsSelect struct {
*ReviewsQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *ReviewsSelect) Aggregate(fns ...AggregateFunc) *ReviewsSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *ReviewsSelect) 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[*ReviewsQuery, *ReviewsSelect](ctx, _s.ReviewsQuery, _s, _s.inters, v)
}
func (_s *ReviewsSelect) sqlScan(ctx context.Context, root *ReviewsQuery, 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,642 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/review/rpc/internal/models/predicate"
"juwan-backend/app/review/rpc/internal/models/reviews"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ReviewsUpdate is the builder for updating Reviews entities.
type ReviewsUpdate struct {
config
hooks []Hook
mutation *ReviewsMutation
}
// Where appends a list predicates to the ReviewsUpdate builder.
func (_u *ReviewsUpdate) Where(ps ...predicate.Reviews) *ReviewsUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetOrderID sets the "order_id" field.
func (_u *ReviewsUpdate) SetOrderID(v int64) *ReviewsUpdate {
_u.mutation.ResetOrderID()
_u.mutation.SetOrderID(v)
return _u
}
// SetNillableOrderID sets the "order_id" field if the given value is not nil.
func (_u *ReviewsUpdate) SetNillableOrderID(v *int64) *ReviewsUpdate {
if v != nil {
_u.SetOrderID(*v)
}
return _u
}
// AddOrderID adds value to the "order_id" field.
func (_u *ReviewsUpdate) AddOrderID(v int64) *ReviewsUpdate {
_u.mutation.AddOrderID(v)
return _u
}
// SetFromUserID sets the "from_user_id" field.
func (_u *ReviewsUpdate) SetFromUserID(v int64) *ReviewsUpdate {
_u.mutation.ResetFromUserID()
_u.mutation.SetFromUserID(v)
return _u
}
// SetNillableFromUserID sets the "from_user_id" field if the given value is not nil.
func (_u *ReviewsUpdate) SetNillableFromUserID(v *int64) *ReviewsUpdate {
if v != nil {
_u.SetFromUserID(*v)
}
return _u
}
// AddFromUserID adds value to the "from_user_id" field.
func (_u *ReviewsUpdate) AddFromUserID(v int64) *ReviewsUpdate {
_u.mutation.AddFromUserID(v)
return _u
}
// SetFromUserName sets the "from_user_name" field.
func (_u *ReviewsUpdate) SetFromUserName(v string) *ReviewsUpdate {
_u.mutation.SetFromUserName(v)
return _u
}
// SetNillableFromUserName sets the "from_user_name" field if the given value is not nil.
func (_u *ReviewsUpdate) SetNillableFromUserName(v *string) *ReviewsUpdate {
if v != nil {
_u.SetFromUserName(*v)
}
return _u
}
// SetFromUserAvatar sets the "from_user_avatar" field.
func (_u *ReviewsUpdate) SetFromUserAvatar(v string) *ReviewsUpdate {
_u.mutation.SetFromUserAvatar(v)
return _u
}
// SetNillableFromUserAvatar sets the "from_user_avatar" field if the given value is not nil.
func (_u *ReviewsUpdate) SetNillableFromUserAvatar(v *string) *ReviewsUpdate {
if v != nil {
_u.SetFromUserAvatar(*v)
}
return _u
}
// ClearFromUserAvatar clears the value of the "from_user_avatar" field.
func (_u *ReviewsUpdate) ClearFromUserAvatar() *ReviewsUpdate {
_u.mutation.ClearFromUserAvatar()
return _u
}
// SetToUserID sets the "to_user_id" field.
func (_u *ReviewsUpdate) SetToUserID(v int64) *ReviewsUpdate {
_u.mutation.ResetToUserID()
_u.mutation.SetToUserID(v)
return _u
}
// SetNillableToUserID sets the "to_user_id" field if the given value is not nil.
func (_u *ReviewsUpdate) SetNillableToUserID(v *int64) *ReviewsUpdate {
if v != nil {
_u.SetToUserID(*v)
}
return _u
}
// AddToUserID adds value to the "to_user_id" field.
func (_u *ReviewsUpdate) AddToUserID(v int64) *ReviewsUpdate {
_u.mutation.AddToUserID(v)
return _u
}
// SetRating sets the "rating" field.
func (_u *ReviewsUpdate) SetRating(v int16) *ReviewsUpdate {
_u.mutation.ResetRating()
_u.mutation.SetRating(v)
return _u
}
// SetNillableRating sets the "rating" field if the given value is not nil.
func (_u *ReviewsUpdate) SetNillableRating(v *int16) *ReviewsUpdate {
if v != nil {
_u.SetRating(*v)
}
return _u
}
// AddRating adds value to the "rating" field.
func (_u *ReviewsUpdate) AddRating(v int16) *ReviewsUpdate {
_u.mutation.AddRating(v)
return _u
}
// SetContent sets the "content" field.
func (_u *ReviewsUpdate) SetContent(v string) *ReviewsUpdate {
_u.mutation.SetContent(v)
return _u
}
// SetNillableContent sets the "content" field if the given value is not nil.
func (_u *ReviewsUpdate) SetNillableContent(v *string) *ReviewsUpdate {
if v != nil {
_u.SetContent(*v)
}
return _u
}
// ClearContent clears the value of the "content" field.
func (_u *ReviewsUpdate) ClearContent() *ReviewsUpdate {
_u.mutation.ClearContent()
return _u
}
// SetSealed sets the "sealed" field.
func (_u *ReviewsUpdate) SetSealed(v bool) *ReviewsUpdate {
_u.mutation.SetSealed(v)
return _u
}
// SetNillableSealed sets the "sealed" field if the given value is not nil.
func (_u *ReviewsUpdate) SetNillableSealed(v *bool) *ReviewsUpdate {
if v != nil {
_u.SetSealed(*v)
}
return _u
}
// SetUnsealedAt sets the "unsealed_at" field.
func (_u *ReviewsUpdate) SetUnsealedAt(v time.Time) *ReviewsUpdate {
_u.mutation.SetUnsealedAt(v)
return _u
}
// SetNillableUnsealedAt sets the "unsealed_at" field if the given value is not nil.
func (_u *ReviewsUpdate) SetNillableUnsealedAt(v *time.Time) *ReviewsUpdate {
if v != nil {
_u.SetUnsealedAt(*v)
}
return _u
}
// ClearUnsealedAt clears the value of the "unsealed_at" field.
func (_u *ReviewsUpdate) ClearUnsealedAt() *ReviewsUpdate {
_u.mutation.ClearUnsealedAt()
return _u
}
// Mutation returns the ReviewsMutation object of the builder.
func (_u *ReviewsUpdate) Mutation() *ReviewsMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ReviewsUpdate) 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 *ReviewsUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ReviewsUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ReviewsUpdate) 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 *ReviewsUpdate) check() error {
if v, ok := _u.mutation.FromUserName(); ok {
if err := reviews.FromUserNameValidator(v); err != nil {
return &ValidationError{Name: "from_user_name", err: fmt.Errorf(`models: validator failed for field "Reviews.from_user_name": %w`, err)}
}
}
return nil
}
func (_u *ReviewsUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(reviews.Table, reviews.Columns, sqlgraph.NewFieldSpec(reviews.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(reviews.FieldOrderID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedOrderID(); ok {
_spec.AddField(reviews.FieldOrderID, field.TypeInt64, value)
}
if value, ok := _u.mutation.FromUserID(); ok {
_spec.SetField(reviews.FieldFromUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedFromUserID(); ok {
_spec.AddField(reviews.FieldFromUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.FromUserName(); ok {
_spec.SetField(reviews.FieldFromUserName, field.TypeString, value)
}
if value, ok := _u.mutation.FromUserAvatar(); ok {
_spec.SetField(reviews.FieldFromUserAvatar, field.TypeString, value)
}
if _u.mutation.FromUserAvatarCleared() {
_spec.ClearField(reviews.FieldFromUserAvatar, field.TypeString)
}
if value, ok := _u.mutation.ToUserID(); ok {
_spec.SetField(reviews.FieldToUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedToUserID(); ok {
_spec.AddField(reviews.FieldToUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.Rating(); ok {
_spec.SetField(reviews.FieldRating, field.TypeInt16, value)
}
if value, ok := _u.mutation.AddedRating(); ok {
_spec.AddField(reviews.FieldRating, field.TypeInt16, value)
}
if value, ok := _u.mutation.Content(); ok {
_spec.SetField(reviews.FieldContent, field.TypeString, value)
}
if _u.mutation.ContentCleared() {
_spec.ClearField(reviews.FieldContent, field.TypeString)
}
if value, ok := _u.mutation.Sealed(); ok {
_spec.SetField(reviews.FieldSealed, field.TypeBool, value)
}
if value, ok := _u.mutation.UnsealedAt(); ok {
_spec.SetField(reviews.FieldUnsealedAt, field.TypeTime, value)
}
if _u.mutation.UnsealedAtCleared() {
_spec.ClearField(reviews.FieldUnsealedAt, field.TypeTime)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{reviews.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ReviewsUpdateOne is the builder for updating a single Reviews entity.
type ReviewsUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ReviewsMutation
}
// SetOrderID sets the "order_id" field.
func (_u *ReviewsUpdateOne) SetOrderID(v int64) *ReviewsUpdateOne {
_u.mutation.ResetOrderID()
_u.mutation.SetOrderID(v)
return _u
}
// SetNillableOrderID sets the "order_id" field if the given value is not nil.
func (_u *ReviewsUpdateOne) SetNillableOrderID(v *int64) *ReviewsUpdateOne {
if v != nil {
_u.SetOrderID(*v)
}
return _u
}
// AddOrderID adds value to the "order_id" field.
func (_u *ReviewsUpdateOne) AddOrderID(v int64) *ReviewsUpdateOne {
_u.mutation.AddOrderID(v)
return _u
}
// SetFromUserID sets the "from_user_id" field.
func (_u *ReviewsUpdateOne) SetFromUserID(v int64) *ReviewsUpdateOne {
_u.mutation.ResetFromUserID()
_u.mutation.SetFromUserID(v)
return _u
}
// SetNillableFromUserID sets the "from_user_id" field if the given value is not nil.
func (_u *ReviewsUpdateOne) SetNillableFromUserID(v *int64) *ReviewsUpdateOne {
if v != nil {
_u.SetFromUserID(*v)
}
return _u
}
// AddFromUserID adds value to the "from_user_id" field.
func (_u *ReviewsUpdateOne) AddFromUserID(v int64) *ReviewsUpdateOne {
_u.mutation.AddFromUserID(v)
return _u
}
// SetFromUserName sets the "from_user_name" field.
func (_u *ReviewsUpdateOne) SetFromUserName(v string) *ReviewsUpdateOne {
_u.mutation.SetFromUserName(v)
return _u
}
// SetNillableFromUserName sets the "from_user_name" field if the given value is not nil.
func (_u *ReviewsUpdateOne) SetNillableFromUserName(v *string) *ReviewsUpdateOne {
if v != nil {
_u.SetFromUserName(*v)
}
return _u
}
// SetFromUserAvatar sets the "from_user_avatar" field.
func (_u *ReviewsUpdateOne) SetFromUserAvatar(v string) *ReviewsUpdateOne {
_u.mutation.SetFromUserAvatar(v)
return _u
}
// SetNillableFromUserAvatar sets the "from_user_avatar" field if the given value is not nil.
func (_u *ReviewsUpdateOne) SetNillableFromUserAvatar(v *string) *ReviewsUpdateOne {
if v != nil {
_u.SetFromUserAvatar(*v)
}
return _u
}
// ClearFromUserAvatar clears the value of the "from_user_avatar" field.
func (_u *ReviewsUpdateOne) ClearFromUserAvatar() *ReviewsUpdateOne {
_u.mutation.ClearFromUserAvatar()
return _u
}
// SetToUserID sets the "to_user_id" field.
func (_u *ReviewsUpdateOne) SetToUserID(v int64) *ReviewsUpdateOne {
_u.mutation.ResetToUserID()
_u.mutation.SetToUserID(v)
return _u
}
// SetNillableToUserID sets the "to_user_id" field if the given value is not nil.
func (_u *ReviewsUpdateOne) SetNillableToUserID(v *int64) *ReviewsUpdateOne {
if v != nil {
_u.SetToUserID(*v)
}
return _u
}
// AddToUserID adds value to the "to_user_id" field.
func (_u *ReviewsUpdateOne) AddToUserID(v int64) *ReviewsUpdateOne {
_u.mutation.AddToUserID(v)
return _u
}
// SetRating sets the "rating" field.
func (_u *ReviewsUpdateOne) SetRating(v int16) *ReviewsUpdateOne {
_u.mutation.ResetRating()
_u.mutation.SetRating(v)
return _u
}
// SetNillableRating sets the "rating" field if the given value is not nil.
func (_u *ReviewsUpdateOne) SetNillableRating(v *int16) *ReviewsUpdateOne {
if v != nil {
_u.SetRating(*v)
}
return _u
}
// AddRating adds value to the "rating" field.
func (_u *ReviewsUpdateOne) AddRating(v int16) *ReviewsUpdateOne {
_u.mutation.AddRating(v)
return _u
}
// SetContent sets the "content" field.
func (_u *ReviewsUpdateOne) SetContent(v string) *ReviewsUpdateOne {
_u.mutation.SetContent(v)
return _u
}
// SetNillableContent sets the "content" field if the given value is not nil.
func (_u *ReviewsUpdateOne) SetNillableContent(v *string) *ReviewsUpdateOne {
if v != nil {
_u.SetContent(*v)
}
return _u
}
// ClearContent clears the value of the "content" field.
func (_u *ReviewsUpdateOne) ClearContent() *ReviewsUpdateOne {
_u.mutation.ClearContent()
return _u
}
// SetSealed sets the "sealed" field.
func (_u *ReviewsUpdateOne) SetSealed(v bool) *ReviewsUpdateOne {
_u.mutation.SetSealed(v)
return _u
}
// SetNillableSealed sets the "sealed" field if the given value is not nil.
func (_u *ReviewsUpdateOne) SetNillableSealed(v *bool) *ReviewsUpdateOne {
if v != nil {
_u.SetSealed(*v)
}
return _u
}
// SetUnsealedAt sets the "unsealed_at" field.
func (_u *ReviewsUpdateOne) SetUnsealedAt(v time.Time) *ReviewsUpdateOne {
_u.mutation.SetUnsealedAt(v)
return _u
}
// SetNillableUnsealedAt sets the "unsealed_at" field if the given value is not nil.
func (_u *ReviewsUpdateOne) SetNillableUnsealedAt(v *time.Time) *ReviewsUpdateOne {
if v != nil {
_u.SetUnsealedAt(*v)
}
return _u
}
// ClearUnsealedAt clears the value of the "unsealed_at" field.
func (_u *ReviewsUpdateOne) ClearUnsealedAt() *ReviewsUpdateOne {
_u.mutation.ClearUnsealedAt()
return _u
}
// Mutation returns the ReviewsMutation object of the builder.
func (_u *ReviewsUpdateOne) Mutation() *ReviewsMutation {
return _u.mutation
}
// Where appends a list predicates to the ReviewsUpdate builder.
func (_u *ReviewsUpdateOne) Where(ps ...predicate.Reviews) *ReviewsUpdateOne {
_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 *ReviewsUpdateOne) Select(field string, fields ...string) *ReviewsUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Reviews entity.
func (_u *ReviewsUpdateOne) Save(ctx context.Context) (*Reviews, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ReviewsUpdateOne) SaveX(ctx context.Context) *Reviews {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ReviewsUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ReviewsUpdateOne) 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 *ReviewsUpdateOne) check() error {
if v, ok := _u.mutation.FromUserName(); ok {
if err := reviews.FromUserNameValidator(v); err != nil {
return &ValidationError{Name: "from_user_name", err: fmt.Errorf(`models: validator failed for field "Reviews.from_user_name": %w`, err)}
}
}
return nil
}
func (_u *ReviewsUpdateOne) sqlSave(ctx context.Context) (_node *Reviews, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(reviews.Table, reviews.Columns, sqlgraph.NewFieldSpec(reviews.FieldID, field.TypeInt64))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Reviews.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, reviews.FieldID)
for _, f := range fields {
if !reviews.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
}
if f != reviews.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(reviews.FieldOrderID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedOrderID(); ok {
_spec.AddField(reviews.FieldOrderID, field.TypeInt64, value)
}
if value, ok := _u.mutation.FromUserID(); ok {
_spec.SetField(reviews.FieldFromUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedFromUserID(); ok {
_spec.AddField(reviews.FieldFromUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.FromUserName(); ok {
_spec.SetField(reviews.FieldFromUserName, field.TypeString, value)
}
if value, ok := _u.mutation.FromUserAvatar(); ok {
_spec.SetField(reviews.FieldFromUserAvatar, field.TypeString, value)
}
if _u.mutation.FromUserAvatarCleared() {
_spec.ClearField(reviews.FieldFromUserAvatar, field.TypeString)
}
if value, ok := _u.mutation.ToUserID(); ok {
_spec.SetField(reviews.FieldToUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedToUserID(); ok {
_spec.AddField(reviews.FieldToUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.Rating(); ok {
_spec.SetField(reviews.FieldRating, field.TypeInt16, value)
}
if value, ok := _u.mutation.AddedRating(); ok {
_spec.AddField(reviews.FieldRating, field.TypeInt16, value)
}
if value, ok := _u.mutation.Content(); ok {
_spec.SetField(reviews.FieldContent, field.TypeString, value)
}
if _u.mutation.ContentCleared() {
_spec.ClearField(reviews.FieldContent, field.TypeString)
}
if value, ok := _u.mutation.Sealed(); ok {
_spec.SetField(reviews.FieldSealed, field.TypeBool, value)
}
if value, ok := _u.mutation.UnsealedAt(); ok {
_spec.SetField(reviews.FieldUnsealedAt, field.TypeTime, value)
}
if _u.mutation.UnsealedAtCleared() {
_spec.ClearField(reviews.FieldUnsealedAt, field.TypeTime)
}
_node = &Reviews{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{reviews.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
+37
View File
@@ -0,0 +1,37 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"juwan-backend/app/review/rpc/internal/models/reviews"
"juwan-backend/app/review/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() {
reviewsFields := schema.Reviews{}.Fields()
_ = reviewsFields
// reviewsDescFromUserName is the schema descriptor for from_user_name field.
reviewsDescFromUserName := reviewsFields[3].Descriptor()
// reviews.FromUserNameValidator is a validator for the "from_user_name" field. It is called by the builders before save.
reviews.FromUserNameValidator = reviewsDescFromUserName.Validators[0].(func(string) error)
// reviewsDescFromUserAvatar is the schema descriptor for from_user_avatar field.
reviewsDescFromUserAvatar := reviewsFields[4].Descriptor()
// reviews.DefaultFromUserAvatar holds the default value on creation for the from_user_avatar field.
reviews.DefaultFromUserAvatar = reviewsDescFromUserAvatar.Default.(string)
// reviewsDescContent is the schema descriptor for content field.
reviewsDescContent := reviewsFields[7].Descriptor()
// reviews.DefaultContent holds the default value on creation for the content field.
reviews.DefaultContent = reviewsDescContent.Default.(string)
// reviewsDescSealed is the schema descriptor for sealed field.
reviewsDescSealed := reviewsFields[8].Descriptor()
// reviews.DefaultSealed holds the default value on creation for the sealed field.
reviews.DefaultSealed = reviewsDescSealed.Default.(bool)
// reviewsDescCreatedAt is the schema descriptor for created_at field.
reviewsDescCreatedAt := reviewsFields[9].Descriptor()
// reviews.DefaultCreatedAt holds the default value on creation for the created_at field.
reviews.DefaultCreatedAt = reviewsDescCreatedAt.Default.(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/review/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,42 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
type Reviews struct {
ent.Schema
}
func (Reviews) Fields() []ent.Field {
return []ent.Field{
field.Int64("id").Unique().Immutable(),
field.Int64("order_id"),
field.Int64("from_user_id"),
field.String("from_user_name").MaxLen(100),
field.String("from_user_avatar").Optional().Default(""),
field.Int64("to_user_id"),
field.Int16("rating"),
field.String("content").Optional().Default(""),
field.Bool("sealed").Default(true),
field.Time("created_at").Default(time.Now).Immutable(),
field.Time("unsealed_at").Optional().Nillable(),
}
}
func (Reviews) Indexes() []ent.Index {
return []ent.Index{
index.Fields("order_id", "from_user_id").Unique(),
index.Fields("order_id"),
index.Fields("to_user_id", "created_at"),
index.Fields("from_user_id"),
}
}
func (Reviews) Edges() []ent.Edge {
return nil
}
+210
View File
@@ -0,0 +1,210 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"sync"
"entgo.io/ent/dialect"
)
// Tx is a transactional client that is created by calling Client.Tx().
type Tx struct {
config
// Reviews is the client for interacting with the Reviews builders.
Reviews *ReviewsClient
// 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.Reviews = NewReviewsClient(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: Reviews.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,50 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.10.1
// Source: review.proto
package server
import (
"context"
"juwan-backend/app/review/rpc/internal/logic"
"juwan-backend/app/review/rpc/internal/svc"
"juwan-backend/app/review/rpc/pb"
)
type ReviewServiceServer struct {
svcCtx *svc.ServiceContext
pb.UnimplementedReviewServiceServer
}
func NewReviewServiceServer(svcCtx *svc.ServiceContext) *ReviewServiceServer {
return &ReviewServiceServer{
svcCtx: svcCtx,
}
}
// -----------------------reviews-----------------------
func (s *ReviewServiceServer) AddReviews(ctx context.Context, in *pb.AddReviewsReq) (*pb.AddReviewsResp, error) {
l := logic.NewAddReviewsLogic(ctx, s.svcCtx)
return l.AddReviews(in)
}
func (s *ReviewServiceServer) UpdateReviews(ctx context.Context, in *pb.UpdateReviewsReq) (*pb.UpdateReviewsResp, error) {
l := logic.NewUpdateReviewsLogic(ctx, s.svcCtx)
return l.UpdateReviews(in)
}
func (s *ReviewServiceServer) DelReviews(ctx context.Context, in *pb.DelReviewsReq) (*pb.DelReviewsResp, error) {
l := logic.NewDelReviewsLogic(ctx, s.svcCtx)
return l.DelReviews(in)
}
func (s *ReviewServiceServer) GetReviewsById(ctx context.Context, in *pb.GetReviewsByIdReq) (*pb.GetReviewsByIdResp, error) {
l := logic.NewGetReviewsByIdLogic(ctx, s.svcCtx)
return l.GetReviewsById(in)
}
func (s *ReviewServiceServer) SearchReviews(ctx context.Context, in *pb.SearchReviewsReq) (*pb.SearchReviewsResp, error) {
l := logic.NewSearchReviewsLogic(ctx, s.svcCtx)
return l.SearchReviews(in)
}
@@ -0,0 +1,52 @@
package svc
import (
stdsql "database/sql"
"juwan-backend/app/review/rpc/internal/config"
"juwan-backend/app/review/rpc/internal/models"
"juwan-backend/app/snowflake/rpc/snowflake"
"juwan-backend/common/redisx"
"juwan-backend/common/snowflakex"
"juwan-backend/pkg/adapter"
"time"
"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
ReviewModelRW *models.Client
ReviewModelRO *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,
ReviewModelRW: models.NewClient(models.Driver(RWDrv)),
ReviewModelRO: models.NewClient(models.Driver(RODrv)),
Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf),
}
}
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"flag"
"fmt"
"juwan-backend/app/review/rpc/internal/config"
"juwan-backend/app/review/rpc/internal/server"
"juwan-backend/app/review/rpc/internal/svc"
"juwan-backend/app/review/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.RegisterReviewServiceServer(grpcServer, server.NewReviewServiceServer(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()
}
+936
View File
@@ -0,0 +1,936 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.11
// protoc v7.34.1
// source: review.proto
package pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// --------------------------------reviews--------------------------------
type Reviews struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
OrderId int64 `protobuf:"varint,2,opt,name=orderId,proto3" json:"orderId,omitempty"` //orderId
FromUserId int64 `protobuf:"varint,3,opt,name=fromUserId,proto3" json:"fromUserId,omitempty"` //fromUserId
FromUserName string `protobuf:"bytes,4,opt,name=fromUserName,proto3" json:"fromUserName,omitempty"` //fromUserName
FromUserAvatar string `protobuf:"bytes,5,opt,name=fromUserAvatar,proto3" json:"fromUserAvatar,omitempty"` //fromUserAvatar
ToUserId int64 `protobuf:"varint,6,opt,name=toUserId,proto3" json:"toUserId,omitempty"` //toUserId
Rating int32 `protobuf:"varint,7,opt,name=rating,proto3" json:"rating,omitempty"` //rating
Content string `protobuf:"bytes,8,opt,name=content,proto3" json:"content,omitempty"` //content
Sealed bool `protobuf:"varint,9,opt,name=sealed,proto3" json:"sealed,omitempty"` //sealed
CreatedAt int64 `protobuf:"varint,10,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
UnsealedAt int64 `protobuf:"varint,11,opt,name=unsealedAt,proto3" json:"unsealedAt,omitempty"` //unsealedAt
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Reviews) Reset() {
*x = Reviews{}
mi := &file_review_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Reviews) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Reviews) ProtoMessage() {}
func (x *Reviews) ProtoReflect() protoreflect.Message {
mi := &file_review_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Reviews.ProtoReflect.Descriptor instead.
func (*Reviews) Descriptor() ([]byte, []int) {
return file_review_proto_rawDescGZIP(), []int{0}
}
func (x *Reviews) GetId() int64 {
if x != nil {
return x.Id
}
return 0
}
func (x *Reviews) GetOrderId() int64 {
if x != nil {
return x.OrderId
}
return 0
}
func (x *Reviews) GetFromUserId() int64 {
if x != nil {
return x.FromUserId
}
return 0
}
func (x *Reviews) GetFromUserName() string {
if x != nil {
return x.FromUserName
}
return ""
}
func (x *Reviews) GetFromUserAvatar() string {
if x != nil {
return x.FromUserAvatar
}
return ""
}
func (x *Reviews) GetToUserId() int64 {
if x != nil {
return x.ToUserId
}
return 0
}
func (x *Reviews) GetRating() int32 {
if x != nil {
return x.Rating
}
return 0
}
func (x *Reviews) GetContent() string {
if x != nil {
return x.Content
}
return ""
}
func (x *Reviews) GetSealed() bool {
if x != nil {
return x.Sealed
}
return false
}
func (x *Reviews) GetCreatedAt() int64 {
if x != nil {
return x.CreatedAt
}
return 0
}
func (x *Reviews) GetUnsealedAt() int64 {
if x != nil {
return x.UnsealedAt
}
return 0
}
type AddReviewsReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
OrderId int64 `protobuf:"varint,1,opt,name=orderId,proto3" json:"orderId,omitempty"` //orderId
FromUserId int64 `protobuf:"varint,2,opt,name=fromUserId,proto3" json:"fromUserId,omitempty"` //fromUserId
FromUserName string `protobuf:"bytes,3,opt,name=fromUserName,proto3" json:"fromUserName,omitempty"` //fromUserName
FromUserAvatar string `protobuf:"bytes,4,opt,name=fromUserAvatar,proto3" json:"fromUserAvatar,omitempty"` //fromUserAvatar
ToUserId int64 `protobuf:"varint,5,opt,name=toUserId,proto3" json:"toUserId,omitempty"` //toUserId
Rating int32 `protobuf:"varint,6,opt,name=rating,proto3" json:"rating,omitempty"` //rating
Content string `protobuf:"bytes,7,opt,name=content,proto3" json:"content,omitempty"` //content
Sealed bool `protobuf:"varint,8,opt,name=sealed,proto3" json:"sealed,omitempty"` //sealed
CreatedAt int64 `protobuf:"varint,9,opt,name=createdAt,proto3" json:"createdAt,omitempty"` //createdAt
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AddReviewsReq) Reset() {
*x = AddReviewsReq{}
mi := &file_review_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AddReviewsReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AddReviewsReq) ProtoMessage() {}
func (x *AddReviewsReq) ProtoReflect() protoreflect.Message {
mi := &file_review_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AddReviewsReq.ProtoReflect.Descriptor instead.
func (*AddReviewsReq) Descriptor() ([]byte, []int) {
return file_review_proto_rawDescGZIP(), []int{1}
}
func (x *AddReviewsReq) GetOrderId() int64 {
if x != nil {
return x.OrderId
}
return 0
}
func (x *AddReviewsReq) GetFromUserId() int64 {
if x != nil {
return x.FromUserId
}
return 0
}
func (x *AddReviewsReq) GetFromUserName() string {
if x != nil {
return x.FromUserName
}
return ""
}
func (x *AddReviewsReq) GetFromUserAvatar() string {
if x != nil {
return x.FromUserAvatar
}
return ""
}
func (x *AddReviewsReq) GetToUserId() int64 {
if x != nil {
return x.ToUserId
}
return 0
}
func (x *AddReviewsReq) GetRating() int32 {
if x != nil {
return x.Rating
}
return 0
}
func (x *AddReviewsReq) GetContent() string {
if x != nil {
return x.Content
}
return ""
}
func (x *AddReviewsReq) GetSealed() bool {
if x != nil {
return x.Sealed
}
return false
}
func (x *AddReviewsReq) GetCreatedAt() int64 {
if x != nil {
return x.CreatedAt
}
return 0
}
type AddReviewsResp struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AddReviewsResp) Reset() {
*x = AddReviewsResp{}
mi := &file_review_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AddReviewsResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AddReviewsResp) ProtoMessage() {}
func (x *AddReviewsResp) ProtoReflect() protoreflect.Message {
mi := &file_review_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AddReviewsResp.ProtoReflect.Descriptor instead.
func (*AddReviewsResp) Descriptor() ([]byte, []int) {
return file_review_proto_rawDescGZIP(), []int{2}
}
func (x *AddReviewsResp) GetId() int64 {
if x != nil {
return x.Id
}
return 0
}
type UpdateReviewsReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
OrderId *int64 `protobuf:"varint,2,opt,name=orderId,proto3,oneof" json:"orderId,omitempty"` //orderId
FromUserId *int64 `protobuf:"varint,3,opt,name=fromUserId,proto3,oneof" json:"fromUserId,omitempty"` //fromUserId
FromUserName *string `protobuf:"bytes,4,opt,name=fromUserName,proto3,oneof" json:"fromUserName,omitempty"` //fromUserName
FromUserAvatar *string `protobuf:"bytes,5,opt,name=fromUserAvatar,proto3,oneof" json:"fromUserAvatar,omitempty"` //fromUserAvatar
ToUserId *int64 `protobuf:"varint,6,opt,name=toUserId,proto3,oneof" json:"toUserId,omitempty"` //toUserId
Rating *int32 `protobuf:"varint,7,opt,name=rating,proto3,oneof" json:"rating,omitempty"` //rating
Content *string `protobuf:"bytes,8,opt,name=content,proto3,oneof" json:"content,omitempty"` //content
Sealed *bool `protobuf:"varint,9,opt,name=sealed,proto3,oneof" json:"sealed,omitempty"` //sealed
CreatedAt *int64 `protobuf:"varint,10,opt,name=createdAt,proto3,oneof" json:"createdAt,omitempty"` //createdAt
UnsealedAt *int64 `protobuf:"varint,11,opt,name=unsealedAt,proto3,oneof" json:"unsealedAt,omitempty"` //unsealedAt
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *UpdateReviewsReq) Reset() {
*x = UpdateReviewsReq{}
mi := &file_review_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *UpdateReviewsReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpdateReviewsReq) ProtoMessage() {}
func (x *UpdateReviewsReq) ProtoReflect() protoreflect.Message {
mi := &file_review_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UpdateReviewsReq.ProtoReflect.Descriptor instead.
func (*UpdateReviewsReq) Descriptor() ([]byte, []int) {
return file_review_proto_rawDescGZIP(), []int{3}
}
func (x *UpdateReviewsReq) GetId() int64 {
if x != nil {
return x.Id
}
return 0
}
func (x *UpdateReviewsReq) GetOrderId() int64 {
if x != nil && x.OrderId != nil {
return *x.OrderId
}
return 0
}
func (x *UpdateReviewsReq) GetFromUserId() int64 {
if x != nil && x.FromUserId != nil {
return *x.FromUserId
}
return 0
}
func (x *UpdateReviewsReq) GetFromUserName() string {
if x != nil && x.FromUserName != nil {
return *x.FromUserName
}
return ""
}
func (x *UpdateReviewsReq) GetFromUserAvatar() string {
if x != nil && x.FromUserAvatar != nil {
return *x.FromUserAvatar
}
return ""
}
func (x *UpdateReviewsReq) GetToUserId() int64 {
if x != nil && x.ToUserId != nil {
return *x.ToUserId
}
return 0
}
func (x *UpdateReviewsReq) GetRating() int32 {
if x != nil && x.Rating != nil {
return *x.Rating
}
return 0
}
func (x *UpdateReviewsReq) GetContent() string {
if x != nil && x.Content != nil {
return *x.Content
}
return ""
}
func (x *UpdateReviewsReq) GetSealed() bool {
if x != nil && x.Sealed != nil {
return *x.Sealed
}
return false
}
func (x *UpdateReviewsReq) GetCreatedAt() int64 {
if x != nil && x.CreatedAt != nil {
return *x.CreatedAt
}
return 0
}
func (x *UpdateReviewsReq) GetUnsealedAt() int64 {
if x != nil && x.UnsealedAt != nil {
return *x.UnsealedAt
}
return 0
}
type UpdateReviewsResp struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *UpdateReviewsResp) Reset() {
*x = UpdateReviewsResp{}
mi := &file_review_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *UpdateReviewsResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpdateReviewsResp) ProtoMessage() {}
func (x *UpdateReviewsResp) ProtoReflect() protoreflect.Message {
mi := &file_review_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UpdateReviewsResp.ProtoReflect.Descriptor instead.
func (*UpdateReviewsResp) Descriptor() ([]byte, []int) {
return file_review_proto_rawDescGZIP(), []int{4}
}
type DelReviewsReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *DelReviewsReq) Reset() {
*x = DelReviewsReq{}
mi := &file_review_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *DelReviewsReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DelReviewsReq) ProtoMessage() {}
func (x *DelReviewsReq) ProtoReflect() protoreflect.Message {
mi := &file_review_proto_msgTypes[5]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DelReviewsReq.ProtoReflect.Descriptor instead.
func (*DelReviewsReq) Descriptor() ([]byte, []int) {
return file_review_proto_rawDescGZIP(), []int{5}
}
func (x *DelReviewsReq) GetId() int64 {
if x != nil {
return x.Id
}
return 0
}
type DelReviewsResp struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *DelReviewsResp) Reset() {
*x = DelReviewsResp{}
mi := &file_review_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *DelReviewsResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DelReviewsResp) ProtoMessage() {}
func (x *DelReviewsResp) ProtoReflect() protoreflect.Message {
mi := &file_review_proto_msgTypes[6]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DelReviewsResp.ProtoReflect.Descriptor instead.
func (*DelReviewsResp) Descriptor() ([]byte, []int) {
return file_review_proto_rawDescGZIP(), []int{6}
}
type GetReviewsByIdReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetReviewsByIdReq) Reset() {
*x = GetReviewsByIdReq{}
mi := &file_review_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetReviewsByIdReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetReviewsByIdReq) ProtoMessage() {}
func (x *GetReviewsByIdReq) ProtoReflect() protoreflect.Message {
mi := &file_review_proto_msgTypes[7]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetReviewsByIdReq.ProtoReflect.Descriptor instead.
func (*GetReviewsByIdReq) Descriptor() ([]byte, []int) {
return file_review_proto_rawDescGZIP(), []int{7}
}
func (x *GetReviewsByIdReq) GetId() int64 {
if x != nil {
return x.Id
}
return 0
}
type GetReviewsByIdResp struct {
state protoimpl.MessageState `protogen:"open.v1"`
Reviews *Reviews `protobuf:"bytes,1,opt,name=reviews,proto3" json:"reviews,omitempty"` //reviews
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetReviewsByIdResp) Reset() {
*x = GetReviewsByIdResp{}
mi := &file_review_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetReviewsByIdResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetReviewsByIdResp) ProtoMessage() {}
func (x *GetReviewsByIdResp) ProtoReflect() protoreflect.Message {
mi := &file_review_proto_msgTypes[8]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetReviewsByIdResp.ProtoReflect.Descriptor instead.
func (*GetReviewsByIdResp) Descriptor() ([]byte, []int) {
return file_review_proto_rawDescGZIP(), []int{8}
}
func (x *GetReviewsByIdResp) GetReviews() *Reviews {
if x != nil {
return x.Reviews
}
return nil
}
type SearchReviewsReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Offset int64 `protobuf:"varint,1,opt,name=offset,proto3" json:"offset,omitempty"` //offset
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` //limit
Id *int64 `protobuf:"varint,3,opt,name=id,proto3,oneof" json:"id,omitempty"` //id
OrderId *int64 `protobuf:"varint,4,opt,name=orderId,proto3,oneof" json:"orderId,omitempty"` //orderId
FromUserId *int64 `protobuf:"varint,5,opt,name=fromUserId,proto3,oneof" json:"fromUserId,omitempty"` //fromUserId
ToUserId *int64 `protobuf:"varint,6,opt,name=toUserId,proto3,oneof" json:"toUserId,omitempty"` //toUserId
Sealed *bool `protobuf:"varint,7,opt,name=sealed,proto3,oneof" json:"sealed,omitempty"` //sealed
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *SearchReviewsReq) Reset() {
*x = SearchReviewsReq{}
mi := &file_review_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SearchReviewsReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SearchReviewsReq) ProtoMessage() {}
func (x *SearchReviewsReq) ProtoReflect() protoreflect.Message {
mi := &file_review_proto_msgTypes[9]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SearchReviewsReq.ProtoReflect.Descriptor instead.
func (*SearchReviewsReq) Descriptor() ([]byte, []int) {
return file_review_proto_rawDescGZIP(), []int{9}
}
func (x *SearchReviewsReq) GetOffset() int64 {
if x != nil {
return x.Offset
}
return 0
}
func (x *SearchReviewsReq) GetLimit() int64 {
if x != nil {
return x.Limit
}
return 0
}
func (x *SearchReviewsReq) GetId() int64 {
if x != nil && x.Id != nil {
return *x.Id
}
return 0
}
func (x *SearchReviewsReq) GetOrderId() int64 {
if x != nil && x.OrderId != nil {
return *x.OrderId
}
return 0
}
func (x *SearchReviewsReq) GetFromUserId() int64 {
if x != nil && x.FromUserId != nil {
return *x.FromUserId
}
return 0
}
func (x *SearchReviewsReq) GetToUserId() int64 {
if x != nil && x.ToUserId != nil {
return *x.ToUserId
}
return 0
}
func (x *SearchReviewsReq) GetSealed() bool {
if x != nil && x.Sealed != nil {
return *x.Sealed
}
return false
}
type SearchReviewsResp struct {
state protoimpl.MessageState `protogen:"open.v1"`
Reviews []*Reviews `protobuf:"bytes,1,rep,name=reviews,proto3" json:"reviews,omitempty"` //reviews
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *SearchReviewsResp) Reset() {
*x = SearchReviewsResp{}
mi := &file_review_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SearchReviewsResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SearchReviewsResp) ProtoMessage() {}
func (x *SearchReviewsResp) ProtoReflect() protoreflect.Message {
mi := &file_review_proto_msgTypes[10]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SearchReviewsResp.ProtoReflect.Descriptor instead.
func (*SearchReviewsResp) Descriptor() ([]byte, []int) {
return file_review_proto_rawDescGZIP(), []int{10}
}
func (x *SearchReviewsResp) GetReviews() []*Reviews {
if x != nil {
return x.Reviews
}
return nil
}
var File_review_proto protoreflect.FileDescriptor
const file_review_proto_rawDesc = "" +
"\n" +
"\freview.proto\x12\x02pb\"\xc3\x02\n" +
"\aReviews\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x18\n" +
"\aorderId\x18\x02 \x01(\x03R\aorderId\x12\x1e\n" +
"\n" +
"fromUserId\x18\x03 \x01(\x03R\n" +
"fromUserId\x12\"\n" +
"\ffromUserName\x18\x04 \x01(\tR\ffromUserName\x12&\n" +
"\x0efromUserAvatar\x18\x05 \x01(\tR\x0efromUserAvatar\x12\x1a\n" +
"\btoUserId\x18\x06 \x01(\x03R\btoUserId\x12\x16\n" +
"\x06rating\x18\a \x01(\x05R\x06rating\x12\x18\n" +
"\acontent\x18\b \x01(\tR\acontent\x12\x16\n" +
"\x06sealed\x18\t \x01(\bR\x06sealed\x12\x1c\n" +
"\tcreatedAt\x18\n" +
" \x01(\x03R\tcreatedAt\x12\x1e\n" +
"\n" +
"unsealedAt\x18\v \x01(\x03R\n" +
"unsealedAt\"\x99\x02\n" +
"\rAddReviewsReq\x12\x18\n" +
"\aorderId\x18\x01 \x01(\x03R\aorderId\x12\x1e\n" +
"\n" +
"fromUserId\x18\x02 \x01(\x03R\n" +
"fromUserId\x12\"\n" +
"\ffromUserName\x18\x03 \x01(\tR\ffromUserName\x12&\n" +
"\x0efromUserAvatar\x18\x04 \x01(\tR\x0efromUserAvatar\x12\x1a\n" +
"\btoUserId\x18\x05 \x01(\x03R\btoUserId\x12\x16\n" +
"\x06rating\x18\x06 \x01(\x05R\x06rating\x12\x18\n" +
"\acontent\x18\a \x01(\tR\acontent\x12\x16\n" +
"\x06sealed\x18\b \x01(\bR\x06sealed\x12\x1c\n" +
"\tcreatedAt\x18\t \x01(\x03R\tcreatedAt\" \n" +
"\x0eAddReviewsResp\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\"\x89\x04\n" +
"\x10UpdateReviewsReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x1d\n" +
"\aorderId\x18\x02 \x01(\x03H\x00R\aorderId\x88\x01\x01\x12#\n" +
"\n" +
"fromUserId\x18\x03 \x01(\x03H\x01R\n" +
"fromUserId\x88\x01\x01\x12'\n" +
"\ffromUserName\x18\x04 \x01(\tH\x02R\ffromUserName\x88\x01\x01\x12+\n" +
"\x0efromUserAvatar\x18\x05 \x01(\tH\x03R\x0efromUserAvatar\x88\x01\x01\x12\x1f\n" +
"\btoUserId\x18\x06 \x01(\x03H\x04R\btoUserId\x88\x01\x01\x12\x1b\n" +
"\x06rating\x18\a \x01(\x05H\x05R\x06rating\x88\x01\x01\x12\x1d\n" +
"\acontent\x18\b \x01(\tH\x06R\acontent\x88\x01\x01\x12\x1b\n" +
"\x06sealed\x18\t \x01(\bH\aR\x06sealed\x88\x01\x01\x12!\n" +
"\tcreatedAt\x18\n" +
" \x01(\x03H\bR\tcreatedAt\x88\x01\x01\x12#\n" +
"\n" +
"unsealedAt\x18\v \x01(\x03H\tR\n" +
"unsealedAt\x88\x01\x01B\n" +
"\n" +
"\b_orderIdB\r\n" +
"\v_fromUserIdB\x0f\n" +
"\r_fromUserNameB\x11\n" +
"\x0f_fromUserAvatarB\v\n" +
"\t_toUserIdB\t\n" +
"\a_ratingB\n" +
"\n" +
"\b_contentB\t\n" +
"\a_sealedB\f\n" +
"\n" +
"_createdAtB\r\n" +
"\v_unsealedAt\"\x13\n" +
"\x11UpdateReviewsResp\"\x1f\n" +
"\rDelReviewsReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\"\x10\n" +
"\x0eDelReviewsResp\"#\n" +
"\x11GetReviewsByIdReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\";\n" +
"\x12GetReviewsByIdResp\x12%\n" +
"\areviews\x18\x01 \x01(\v2\v.pb.ReviewsR\areviews\"\x91\x02\n" +
"\x10SearchReviewsReq\x12\x16\n" +
"\x06offset\x18\x01 \x01(\x03R\x06offset\x12\x14\n" +
"\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x13\n" +
"\x02id\x18\x03 \x01(\x03H\x00R\x02id\x88\x01\x01\x12\x1d\n" +
"\aorderId\x18\x04 \x01(\x03H\x01R\aorderId\x88\x01\x01\x12#\n" +
"\n" +
"fromUserId\x18\x05 \x01(\x03H\x02R\n" +
"fromUserId\x88\x01\x01\x12\x1f\n" +
"\btoUserId\x18\x06 \x01(\x03H\x03R\btoUserId\x88\x01\x01\x12\x1b\n" +
"\x06sealed\x18\a \x01(\bH\x04R\x06sealed\x88\x01\x01B\x05\n" +
"\x03_idB\n" +
"\n" +
"\b_orderIdB\r\n" +
"\v_fromUserIdB\v\n" +
"\t_toUserIdB\t\n" +
"\a_sealed\":\n" +
"\x11SearchReviewsResp\x12%\n" +
"\areviews\x18\x01 \x03(\v2\v.pb.ReviewsR\areviews2\xb6\x02\n" +
"\rreviewService\x123\n" +
"\n" +
"AddReviews\x12\x11.pb.AddReviewsReq\x1a\x12.pb.AddReviewsResp\x12<\n" +
"\rUpdateReviews\x12\x14.pb.UpdateReviewsReq\x1a\x15.pb.UpdateReviewsResp\x123\n" +
"\n" +
"DelReviews\x12\x11.pb.DelReviewsReq\x1a\x12.pb.DelReviewsResp\x12?\n" +
"\x0eGetReviewsById\x12\x15.pb.GetReviewsByIdReq\x1a\x16.pb.GetReviewsByIdResp\x12<\n" +
"\rSearchReviews\x12\x14.pb.SearchReviewsReq\x1a\x15.pb.SearchReviewsRespB\x06Z\x04./pbb\x06proto3"
var (
file_review_proto_rawDescOnce sync.Once
file_review_proto_rawDescData []byte
)
func file_review_proto_rawDescGZIP() []byte {
file_review_proto_rawDescOnce.Do(func() {
file_review_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_review_proto_rawDesc), len(file_review_proto_rawDesc)))
})
return file_review_proto_rawDescData
}
var file_review_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
var file_review_proto_goTypes = []any{
(*Reviews)(nil), // 0: pb.Reviews
(*AddReviewsReq)(nil), // 1: pb.AddReviewsReq
(*AddReviewsResp)(nil), // 2: pb.AddReviewsResp
(*UpdateReviewsReq)(nil), // 3: pb.UpdateReviewsReq
(*UpdateReviewsResp)(nil), // 4: pb.UpdateReviewsResp
(*DelReviewsReq)(nil), // 5: pb.DelReviewsReq
(*DelReviewsResp)(nil), // 6: pb.DelReviewsResp
(*GetReviewsByIdReq)(nil), // 7: pb.GetReviewsByIdReq
(*GetReviewsByIdResp)(nil), // 8: pb.GetReviewsByIdResp
(*SearchReviewsReq)(nil), // 9: pb.SearchReviewsReq
(*SearchReviewsResp)(nil), // 10: pb.SearchReviewsResp
}
var file_review_proto_depIdxs = []int32{
0, // 0: pb.GetReviewsByIdResp.reviews:type_name -> pb.Reviews
0, // 1: pb.SearchReviewsResp.reviews:type_name -> pb.Reviews
1, // 2: pb.reviewService.AddReviews:input_type -> pb.AddReviewsReq
3, // 3: pb.reviewService.UpdateReviews:input_type -> pb.UpdateReviewsReq
5, // 4: pb.reviewService.DelReviews:input_type -> pb.DelReviewsReq
7, // 5: pb.reviewService.GetReviewsById:input_type -> pb.GetReviewsByIdReq
9, // 6: pb.reviewService.SearchReviews:input_type -> pb.SearchReviewsReq
2, // 7: pb.reviewService.AddReviews:output_type -> pb.AddReviewsResp
4, // 8: pb.reviewService.UpdateReviews:output_type -> pb.UpdateReviewsResp
6, // 9: pb.reviewService.DelReviews:output_type -> pb.DelReviewsResp
8, // 10: pb.reviewService.GetReviewsById:output_type -> pb.GetReviewsByIdResp
10, // 11: pb.reviewService.SearchReviews:output_type -> pb.SearchReviewsResp
7, // [7:12] is the sub-list for method output_type
2, // [2:7] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
func init() { file_review_proto_init() }
func file_review_proto_init() {
if File_review_proto != nil {
return
}
file_review_proto_msgTypes[3].OneofWrappers = []any{}
file_review_proto_msgTypes[9].OneofWrappers = []any{}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_review_proto_rawDesc), len(file_review_proto_rawDesc)),
NumEnums: 0,
NumMessages: 11,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_review_proto_goTypes,
DependencyIndexes: file_review_proto_depIdxs,
MessageInfos: file_review_proto_msgTypes,
}.Build()
File_review_proto = out.File
file_review_proto_goTypes = nil
file_review_proto_depIdxs = nil
}
+275
View File
@@ -0,0 +1,275 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.6.1
// - protoc v7.34.1
// source: review.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 (
ReviewService_AddReviews_FullMethodName = "/pb.reviewService/AddReviews"
ReviewService_UpdateReviews_FullMethodName = "/pb.reviewService/UpdateReviews"
ReviewService_DelReviews_FullMethodName = "/pb.reviewService/DelReviews"
ReviewService_GetReviewsById_FullMethodName = "/pb.reviewService/GetReviewsById"
ReviewService_SearchReviews_FullMethodName = "/pb.reviewService/SearchReviews"
)
// ReviewServiceClient is the client API for ReviewService 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 ReviewServiceClient interface {
// -----------------------reviews-----------------------
AddReviews(ctx context.Context, in *AddReviewsReq, opts ...grpc.CallOption) (*AddReviewsResp, error)
UpdateReviews(ctx context.Context, in *UpdateReviewsReq, opts ...grpc.CallOption) (*UpdateReviewsResp, error)
DelReviews(ctx context.Context, in *DelReviewsReq, opts ...grpc.CallOption) (*DelReviewsResp, error)
GetReviewsById(ctx context.Context, in *GetReviewsByIdReq, opts ...grpc.CallOption) (*GetReviewsByIdResp, error)
SearchReviews(ctx context.Context, in *SearchReviewsReq, opts ...grpc.CallOption) (*SearchReviewsResp, error)
}
type reviewServiceClient struct {
cc grpc.ClientConnInterface
}
func NewReviewServiceClient(cc grpc.ClientConnInterface) ReviewServiceClient {
return &reviewServiceClient{cc}
}
func (c *reviewServiceClient) AddReviews(ctx context.Context, in *AddReviewsReq, opts ...grpc.CallOption) (*AddReviewsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(AddReviewsResp)
err := c.cc.Invoke(ctx, ReviewService_AddReviews_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *reviewServiceClient) UpdateReviews(ctx context.Context, in *UpdateReviewsReq, opts ...grpc.CallOption) (*UpdateReviewsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UpdateReviewsResp)
err := c.cc.Invoke(ctx, ReviewService_UpdateReviews_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *reviewServiceClient) DelReviews(ctx context.Context, in *DelReviewsReq, opts ...grpc.CallOption) (*DelReviewsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(DelReviewsResp)
err := c.cc.Invoke(ctx, ReviewService_DelReviews_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *reviewServiceClient) GetReviewsById(ctx context.Context, in *GetReviewsByIdReq, opts ...grpc.CallOption) (*GetReviewsByIdResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetReviewsByIdResp)
err := c.cc.Invoke(ctx, ReviewService_GetReviewsById_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *reviewServiceClient) SearchReviews(ctx context.Context, in *SearchReviewsReq, opts ...grpc.CallOption) (*SearchReviewsResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(SearchReviewsResp)
err := c.cc.Invoke(ctx, ReviewService_SearchReviews_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// ReviewServiceServer is the server API for ReviewService service.
// All implementations must embed UnimplementedReviewServiceServer
// for forward compatibility.
type ReviewServiceServer interface {
// -----------------------reviews-----------------------
AddReviews(context.Context, *AddReviewsReq) (*AddReviewsResp, error)
UpdateReviews(context.Context, *UpdateReviewsReq) (*UpdateReviewsResp, error)
DelReviews(context.Context, *DelReviewsReq) (*DelReviewsResp, error)
GetReviewsById(context.Context, *GetReviewsByIdReq) (*GetReviewsByIdResp, error)
SearchReviews(context.Context, *SearchReviewsReq) (*SearchReviewsResp, error)
mustEmbedUnimplementedReviewServiceServer()
}
// UnimplementedReviewServiceServer 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 UnimplementedReviewServiceServer struct{}
func (UnimplementedReviewServiceServer) AddReviews(context.Context, *AddReviewsReq) (*AddReviewsResp, error) {
return nil, status.Error(codes.Unimplemented, "method AddReviews not implemented")
}
func (UnimplementedReviewServiceServer) UpdateReviews(context.Context, *UpdateReviewsReq) (*UpdateReviewsResp, error) {
return nil, status.Error(codes.Unimplemented, "method UpdateReviews not implemented")
}
func (UnimplementedReviewServiceServer) DelReviews(context.Context, *DelReviewsReq) (*DelReviewsResp, error) {
return nil, status.Error(codes.Unimplemented, "method DelReviews not implemented")
}
func (UnimplementedReviewServiceServer) GetReviewsById(context.Context, *GetReviewsByIdReq) (*GetReviewsByIdResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetReviewsById not implemented")
}
func (UnimplementedReviewServiceServer) SearchReviews(context.Context, *SearchReviewsReq) (*SearchReviewsResp, error) {
return nil, status.Error(codes.Unimplemented, "method SearchReviews not implemented")
}
func (UnimplementedReviewServiceServer) mustEmbedUnimplementedReviewServiceServer() {}
func (UnimplementedReviewServiceServer) testEmbeddedByValue() {}
// UnsafeReviewServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to ReviewServiceServer will
// result in compilation errors.
type UnsafeReviewServiceServer interface {
mustEmbedUnimplementedReviewServiceServer()
}
func RegisterReviewServiceServer(s grpc.ServiceRegistrar, srv ReviewServiceServer) {
// If the following call panics, it indicates UnimplementedReviewServiceServer 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(&ReviewService_ServiceDesc, srv)
}
func _ReviewService_AddReviews_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AddReviewsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ReviewServiceServer).AddReviews(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ReviewService_AddReviews_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ReviewServiceServer).AddReviews(ctx, req.(*AddReviewsReq))
}
return interceptor(ctx, in, info, handler)
}
func _ReviewService_UpdateReviews_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateReviewsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ReviewServiceServer).UpdateReviews(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ReviewService_UpdateReviews_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ReviewServiceServer).UpdateReviews(ctx, req.(*UpdateReviewsReq))
}
return interceptor(ctx, in, info, handler)
}
func _ReviewService_DelReviews_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DelReviewsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ReviewServiceServer).DelReviews(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ReviewService_DelReviews_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ReviewServiceServer).DelReviews(ctx, req.(*DelReviewsReq))
}
return interceptor(ctx, in, info, handler)
}
func _ReviewService_GetReviewsById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetReviewsByIdReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ReviewServiceServer).GetReviewsById(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ReviewService_GetReviewsById_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ReviewServiceServer).GetReviewsById(ctx, req.(*GetReviewsByIdReq))
}
return interceptor(ctx, in, info, handler)
}
func _ReviewService_SearchReviews_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SearchReviewsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ReviewServiceServer).SearchReviews(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ReviewService_SearchReviews_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ReviewServiceServer).SearchReviews(ctx, req.(*SearchReviewsReq))
}
return interceptor(ctx, in, info, handler)
}
// ReviewService_ServiceDesc is the grpc.ServiceDesc for ReviewService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var ReviewService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "pb.reviewService",
HandlerType: (*ReviewServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "AddReviews",
Handler: _ReviewService_AddReviews_Handler,
},
{
MethodName: "UpdateReviews",
Handler: _ReviewService_UpdateReviews_Handler,
},
{
MethodName: "DelReviews",
Handler: _ReviewService_DelReviews_Handler,
},
{
MethodName: "GetReviewsById",
Handler: _ReviewService_GetReviewsById_Handler,
},
{
MethodName: "SearchReviews",
Handler: _ReviewService_SearchReviews_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "review.proto",
}
@@ -0,0 +1,73 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.10.1
// Source: review.proto
package reviewservice
import (
"context"
"juwan-backend/app/review/rpc/pb"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
AddReviewsReq = pb.AddReviewsReq
AddReviewsResp = pb.AddReviewsResp
DelReviewsReq = pb.DelReviewsReq
DelReviewsResp = pb.DelReviewsResp
GetReviewsByIdReq = pb.GetReviewsByIdReq
GetReviewsByIdResp = pb.GetReviewsByIdResp
Reviews = pb.Reviews
SearchReviewsReq = pb.SearchReviewsReq
SearchReviewsResp = pb.SearchReviewsResp
UpdateReviewsReq = pb.UpdateReviewsReq
UpdateReviewsResp = pb.UpdateReviewsResp
ReviewService interface {
// -----------------------reviews-----------------------
AddReviews(ctx context.Context, in *AddReviewsReq, opts ...grpc.CallOption) (*AddReviewsResp, error)
UpdateReviews(ctx context.Context, in *UpdateReviewsReq, opts ...grpc.CallOption) (*UpdateReviewsResp, error)
DelReviews(ctx context.Context, in *DelReviewsReq, opts ...grpc.CallOption) (*DelReviewsResp, error)
GetReviewsById(ctx context.Context, in *GetReviewsByIdReq, opts ...grpc.CallOption) (*GetReviewsByIdResp, error)
SearchReviews(ctx context.Context, in *SearchReviewsReq, opts ...grpc.CallOption) (*SearchReviewsResp, error)
}
defaultReviewService struct {
cli zrpc.Client
}
)
func NewReviewService(cli zrpc.Client) ReviewService {
return &defaultReviewService{
cli: cli,
}
}
// -----------------------reviews-----------------------
func (m *defaultReviewService) AddReviews(ctx context.Context, in *AddReviewsReq, opts ...grpc.CallOption) (*AddReviewsResp, error) {
client := pb.NewReviewServiceClient(m.cli.Conn())
return client.AddReviews(ctx, in, opts...)
}
func (m *defaultReviewService) UpdateReviews(ctx context.Context, in *UpdateReviewsReq, opts ...grpc.CallOption) (*UpdateReviewsResp, error) {
client := pb.NewReviewServiceClient(m.cli.Conn())
return client.UpdateReviews(ctx, in, opts...)
}
func (m *defaultReviewService) DelReviews(ctx context.Context, in *DelReviewsReq, opts ...grpc.CallOption) (*DelReviewsResp, error) {
client := pb.NewReviewServiceClient(m.cli.Conn())
return client.DelReviews(ctx, in, opts...)
}
func (m *defaultReviewService) GetReviewsById(ctx context.Context, in *GetReviewsByIdReq, opts ...grpc.CallOption) (*GetReviewsByIdResp, error) {
client := pb.NewReviewServiceClient(m.cli.Conn())
return client.GetReviewsById(ctx, in, opts...)
}
func (m *defaultReviewService) SearchReviews(ctx context.Context, in *SearchReviewsReq, opts ...grpc.CallOption) (*SearchReviewsResp, error) {
client := pb.NewReviewServiceClient(m.cli.Conn())
return client.SearchReviews(ctx, in, opts...)
}
+28
View File
@@ -119,6 +119,8 @@ services:
condition: service_started condition: service_started
email-api: email-api:
condition: service_started condition: service_started
review-api:
condition: service_started
ratelimit: ratelimit:
image: envoyproxy/ratelimit:05c08d03 image: envoyproxy/ratelimit:05c08d03
@@ -261,6 +263,19 @@ services:
restart: unless-stopped restart: unless-stopped
env_file: .env env_file: .env
review-rpc:
image: juwan/review-rpc:dev
container_name: juwan-review-rpc
restart: unless-stopped
env_file: .env
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
snowflake:
condition: service_started
# ==================== API 层 ==================== # ==================== API 层 ====================
users-api: users-api:
image: juwan/users-api:dev image: juwan/users-api:dev
@@ -371,6 +386,19 @@ services:
kafka: kafka:
condition: service_healthy condition: service_healthy
review-api:
image: juwan/review-api:dev
container_name: juwan-review-api
restart: unless-stopped
env_file: .env
ports:
- "18810:8888"
depends_on:
review-rpc:
condition: service_started
order-rpc:
condition: service_started
# ==================== MQ ==================== # ==================== MQ ====================
email-mq: email-mq:
image: juwan/email-mq:dev image: juwan/email-mq:dev
+62
View File
@@ -321,6 +321,42 @@ static_resources:
cluster: objectstory_api_cluster cluster: objectstory_api_cluster
timeout: 30s timeout: 30s
- match:
prefix: /api/v1/reviews
headers:
- name: ":method"
exact_match: GET
route:
cluster: review_api_cluster
timeout: 30s
typed_per_filter_config:
envoy.filters.http.ext_authz:
"@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute
disabled: true
- match:
safe_regex:
google_re2: {}
regex: "^/api/v1/users/[0-9]+/reviews$"
headers:
- name: ":method"
exact_match: GET
route:
cluster: review_api_cluster
timeout: 30s
typed_per_filter_config:
envoy.filters.http.ext_authz:
"@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute
disabled: true
- match:
safe_regex:
google_re2: {}
regex: "^/api/v1/orders/[0-9]+/review.*"
route:
cluster: review_api_cluster
timeout: 30s
- match: - match:
prefix: / prefix: /
direct_response: direct_response:
@@ -565,6 +601,18 @@ static_resources:
headers: headers:
- name: ":method" - name: ":method"
exact_match: GET exact_match: GET
- match:
prefix: /api/v1/reviews
headers:
- name: ":method"
exact_match: GET
- match:
safe_regex:
google_re2: {}
regex: "^/api/v1/users/[0-9]+/reviews$"
headers:
- name: ":method"
exact_match: GET
- match: - match:
prefix: /api/v1 prefix: /api/v1
requires: requires:
@@ -728,6 +776,20 @@ static_resources:
address: objectstory-api address: objectstory-api
port_value: 8888 port_value: 8888
- name: review_api_cluster
connect_timeout: 2s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: review_api_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: review-api
port_value: 8888
- name: authz_adapter_cluster - name: authz_adapter_cluster
connect_timeout: 0.5s connect_timeout: 0.5s
type: STRICT_DNS type: STRICT_DNS
+15 -4
View File
@@ -1,7 +1,11 @@
syntax = "v1" syntax = "v1"
import "common.api" import "common.api"
type ( type (
ReviewPathId {
Id int64 `path:"id"`
}
Review { Review {
Id int64 `json:"id"` Id int64 `json:"id"`
OrderId int64 `json:"orderId"` OrderId int64 `json:"orderId"`
@@ -12,16 +16,22 @@ type (
Sealed bool `json:"sealed"` Sealed bool `json:"sealed"`
CreatedAt string `json:"createdAt"` CreatedAt string `json:"createdAt"`
} }
ReviewListResp { ReviewListResp {
Items []Review `json:"items"` Items []Review `json:"items"`
Meta PageMeta `json:"meta"` Meta PageMeta `json:"meta"`
} }
SubmitReviewReq { SubmitReviewReq {
ReviewPathId
Rating int `json:"rating"` Rating int `json:"rating"`
Content string `json:"content,optional"` Content string `json:"content,optional"`
} }
GetOrderReviewsReq {
ReviewPathId
}
ListUserReviewsReq {
ReviewPathId
PageReq
}
) )
@server ( @server (
@@ -35,7 +45,7 @@ service review-api {
@doc "获取订单评价" @doc "获取订单评价"
@handler GetOrderReviews @handler GetOrderReviews
get /orders/:id/reviews (EmptyResp) returns ([]Review) get /orders/:id/reviews (GetOrderReviewsReq) returns (ReviewListResp)
} }
@server ( @server (
@@ -49,5 +59,6 @@ service review-api {
@doc "获取用户收到的评价" @doc "获取用户收到的评价"
@handler ListUserReviews @handler ListUserReviews
get /users/:id/reviews (PageReq) returns (ReviewListResp) get /users/:id/reviews (ListUserReviewsReq) returns (ReviewListResp)
} }
+99
View File
@@ -0,0 +1,99 @@
syntax = "proto3";
option go_package ="./pb";
package pb;
// ------------------------------------
// Messages
// ------------------------------------
//--------------------------------reviews--------------------------------
message Reviews {
int64 id = 1; //id
int64 orderId = 2; //orderId
int64 fromUserId = 3; //fromUserId
string fromUserName = 4; //fromUserName
string fromUserAvatar = 5; //fromUserAvatar
int64 toUserId = 6; //toUserId
int32 rating = 7; //rating
string content = 8; //content
bool sealed = 9; //sealed
int64 createdAt = 10; //createdAt
int64 unsealedAt = 11; //unsealedAt
}
message AddReviewsReq {
int64 orderId = 1; //orderId
int64 fromUserId = 2; //fromUserId
string fromUserName = 3; //fromUserName
string fromUserAvatar = 4; //fromUserAvatar
int64 toUserId = 5; //toUserId
int32 rating = 6; //rating
string content = 7; //content
bool sealed = 8; //sealed
int64 createdAt = 9; //createdAt
}
message AddReviewsResp {
int64 id = 1; //id
}
message UpdateReviewsReq {
int64 id = 1; //id
optional int64 orderId = 2; //orderId
optional int64 fromUserId = 3; //fromUserId
optional string fromUserName = 4; //fromUserName
optional string fromUserAvatar = 5; //fromUserAvatar
optional int64 toUserId = 6; //toUserId
optional int32 rating = 7; //rating
optional string content = 8; //content
optional bool sealed = 9; //sealed
optional int64 createdAt = 10; //createdAt
optional int64 unsealedAt = 11; //unsealedAt
}
message UpdateReviewsResp {
}
message DelReviewsReq {
int64 id = 1; //id
}
message DelReviewsResp {
}
message GetReviewsByIdReq {
int64 id = 1; //id
}
message GetReviewsByIdResp {
Reviews reviews = 1; //reviews
}
message SearchReviewsReq {
int64 offset = 1; //offset
int64 limit = 2; //limit
optional int64 id = 3; //id
optional int64 orderId = 4; //orderId
optional int64 fromUserId = 5; //fromUserId
optional int64 toUserId = 6; //toUserId
optional bool sealed = 7; //sealed
}
message SearchReviewsResp {
repeated Reviews reviews = 1; //reviews
}
// ------------------------------------
// Rpc Func
// ------------------------------------
service reviewService {
//-----------------------reviews-----------------------
rpc AddReviews(AddReviewsReq) returns (AddReviewsResp);
rpc UpdateReviews(UpdateReviewsReq) returns (UpdateReviewsResp);
rpc DelReviews(DelReviewsReq) returns (DelReviewsResp);
rpc GetReviewsById(GetReviewsByIdReq) returns (GetReviewsByIdResp);
rpc SearchReviews(SearchReviewsReq) returns (SearchReviewsResp);
}