init: init refactor
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
Name: file-api
|
||||
Host: 0.0.0.0
|
||||
Port: 9002
|
||||
|
||||
Auth:
|
||||
AccessSecret: 9149f2eb-d517-4a50-a03a-231dbcf0d872
|
||||
AccessExpire: 7200
|
||||
|
||||
# file-rpc 服务配置
|
||||
FileRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 192.168.100.127:2379
|
||||
Key: file.rpc
|
||||
|
||||
# MinIO
|
||||
Minio:
|
||||
Endpoint: 129.28.103.17:3407
|
||||
AccessKeyId: qP5QXP3g6Axw1hkwX21Y
|
||||
AccessKeySecret: sddT6J3S6yDn9m1wfth0pzelPg9KWmbHjMAUF5S9
|
||||
BucketName: sundynix-plant
|
||||
BucketUrl: https://res.sundynix.cn/sundynix-plant
|
||||
UseSsl: false
|
||||
@@ -0,0 +1,60 @@
|
||||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "文件服务API"
|
||||
desc: "文件上传、删除、查询等HTTP接口"
|
||||
author: "sundynix"
|
||||
version: "v1.0.0"
|
||||
)
|
||||
|
||||
type (
|
||||
// 文件信息
|
||||
FileInfo {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
Tag string `json:"tag"`
|
||||
Key string `json:"key"`
|
||||
Suffix string `json:"suffix"`
|
||||
Md5 string `json:"md5"`
|
||||
}
|
||||
// 批量ID请求
|
||||
IdsReq {
|
||||
Ids []string `json:"ids"`
|
||||
}
|
||||
// 文件列表查询
|
||||
FileListReq {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
}
|
||||
// 文件ID请求
|
||||
FileIdReq {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
)
|
||||
|
||||
// ========== 需要鉴权的接口 ==========
|
||||
@server (
|
||||
prefix: /api/file
|
||||
group: file
|
||||
jwt: Auth
|
||||
)
|
||||
service file-api {
|
||||
@doc "上传文件"
|
||||
@handler UploadFile
|
||||
post /upload returns (FileInfo)
|
||||
|
||||
@doc "删除文件"
|
||||
@handler DeleteFile
|
||||
delete /delete (IdsReq)
|
||||
|
||||
@doc "文件列表"
|
||||
@handler GetFileList
|
||||
post /list (FileListReq)
|
||||
|
||||
@doc "获取文件信息"
|
||||
@handler GetFileById
|
||||
get /:id (FileIdReq) returns (FileInfo)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"sundynix-micro-go/app/file/api/internal/config"
|
||||
"sundynix-micro-go/app/file/api/internal/handler"
|
||||
"sundynix-micro-go/app/file/api/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/file-api.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rest.MustNewServer(c.RestConf)
|
||||
defer server.Stop()
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
Auth struct {
|
||||
AccessSecret string
|
||||
AccessExpire int64
|
||||
}
|
||||
FileRpc zrpc.RpcClientConf
|
||||
Minio struct {
|
||||
Endpoint string
|
||||
AccessKeyId string
|
||||
AccessKeySecret string
|
||||
BucketName string
|
||||
BucketUrl string
|
||||
UseSsl bool
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package file
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/file/api/internal/logic/file"
|
||||
"sundynix-micro-go/app/file/api/internal/svc"
|
||||
"sundynix-micro-go/app/file/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除文件
|
||||
func DeleteFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := file.NewDeleteFileLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteFile(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package file
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/file/api/internal/logic/file"
|
||||
"sundynix-micro-go/app/file/api/internal/svc"
|
||||
"sundynix-micro-go/app/file/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 获取文件信息
|
||||
func GetFileByIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.FileIdReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := file.NewGetFileByIdLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetFileById(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package file
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/file/api/internal/logic/file"
|
||||
"sundynix-micro-go/app/file/api/internal/svc"
|
||||
"sundynix-micro-go/app/file/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 文件列表
|
||||
func GetFileListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.FileListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := file.NewGetFileListLogic(r.Context(), svcCtx)
|
||||
err := l.GetFileList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package file
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"sundynix-micro-go/app/file/api/internal/logic/file"
|
||||
"sundynix-micro-go/app/file/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 上传文件
|
||||
func UploadFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := file.NewUploadFileLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UploadFile()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
file "sundynix-micro-go/app/file/api/internal/handler/file"
|
||||
"sundynix-micro-go/app/file/api/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 获取文件信息
|
||||
Method: http.MethodGet,
|
||||
Path: "/:id",
|
||||
Handler: file.GetFileByIdHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除文件
|
||||
Method: http.MethodDelete,
|
||||
Path: "/delete",
|
||||
Handler: file.DeleteFileHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 文件列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/list",
|
||||
Handler: file.GetFileListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 上传文件
|
||||
Method: http.MethodPost,
|
||||
Path: "/upload",
|
||||
Handler: file.UploadFileHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/file"),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package file
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/file/api/internal/svc"
|
||||
"sundynix-micro-go/app/file/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteFileLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 删除文件
|
||||
func NewDeleteFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteFileLogic {
|
||||
return &DeleteFileLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteFileLogic) DeleteFile(req *types.IdsReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package file
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/file/api/internal/svc"
|
||||
"sundynix-micro-go/app/file/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetFileByIdLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 获取文件信息
|
||||
func NewGetFileByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileByIdLogic {
|
||||
return &GetFileByIdLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetFileByIdLogic) GetFileById(req *types.FileIdReq) (resp *types.FileInfo, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package file
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/file/api/internal/svc"
|
||||
"sundynix-micro-go/app/file/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetFileListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 文件列表
|
||||
func NewGetFileListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileListLogic {
|
||||
return &GetFileListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetFileListLogic) GetFileList(req *types.FileListReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package file
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/file/api/internal/svc"
|
||||
"sundynix-micro-go/app/file/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UploadFileLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 上传文件
|
||||
func NewUploadFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadFileLogic {
|
||||
return &UploadFileLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UploadFileLogic) UploadFile() (resp *types.FileInfo, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package svc
|
||||
|
||||
import (
|
||||
"sundynix-micro-go/app/file/api/internal/config"
|
||||
"sundynix-micro-go/app/file/rpc/fileservice"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
FileRpc fileservice.FileService
|
||||
MinioClient *minio.Client
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
// 初始化MinIO客户端(上传需要在API层操作)
|
||||
minioClient, err := minio.New(c.Minio.Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(c.Minio.AccessKeyId, c.Minio.AccessKeySecret, ""),
|
||||
Secure: c.Minio.UseSsl,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("初始化MinIO客户端失败: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
FileRpc: fileservice.NewFileService(zrpc.MustNewClient(c.FileRpc)),
|
||||
MinioClient: minioClient,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
|
||||
package types
|
||||
|
||||
type FileIdReq struct {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
type FileInfo struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
Tag string `json:"tag"`
|
||||
Key string `json:"key"`
|
||||
Suffix string `json:"suffix"`
|
||||
Md5 string `json:"md5"`
|
||||
}
|
||||
|
||||
type FileListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
}
|
||||
|
||||
type IdsReq struct {
|
||||
Ids []string `json:"ids"`
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"sundynix-micro-go/common/model"
|
||||
)
|
||||
|
||||
// SundynixOss OSS文件表
|
||||
type SundynixOss struct {
|
||||
model.BaseModel
|
||||
Name string `json:"name" gorm:"column:name;comment:文件名"`
|
||||
Url string `json:"url" gorm:"column:url;comment:文件地址"`
|
||||
Tag string `json:"tag" gorm:"column:tag;comment:文件标签"`
|
||||
Key string `json:"key" gorm:"column:key;comment:文件key"`
|
||||
Suffix string `json:"suffix" gorm:"column:suffix;comment:文件后缀"`
|
||||
MD5 string `json:"md5" gorm:"column:md5;comment:文件md5"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (SundynixOss) TableName() string {
|
||||
return "sundynix_oss"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
Name: file.rpc
|
||||
ListenOn: 0.0.0.0:9102
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 192.168.100.127:2379
|
||||
Key: file.rpc
|
||||
|
||||
# MySQL
|
||||
DB:
|
||||
DataSource: root:root@tcp(192.168.100.127:3307)/sundynix_micro_go?charset=utf8mb4&parseTime=True&loc=Local
|
||||
|
||||
# MinIO
|
||||
Minio:
|
||||
Endpoint: 129.28.103.17:3407
|
||||
AccessKeyId: qP5QXP3g6Axw1hkwX21Y
|
||||
AccessKeySecret: sddT6J3S6yDn9m1wfth0pzelPg9KWmbHjMAUF5S9
|
||||
BucketName: sundynix-plant
|
||||
BucketUrl: https://res.sundynix.cn/sundynix-plant
|
||||
UseSsl: false
|
||||
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/config"
|
||||
"sundynix-micro-go/app/file/rpc/internal/server"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
|
||||
"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/file.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) {
|
||||
file.RegisterFileServiceServer(grpcServer, server.NewFileServiceServer(ctx))
|
||||
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
}
|
||||
})
|
||||
defer s.Stop()
|
||||
|
||||
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
||||
s.Start()
|
||||
}
|
||||
@@ -0,0 +1,439 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc v7.34.1
|
||||
// source: pb/file.proto
|
||||
|
||||
package file
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
type CommonResp struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
|
||||
Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *CommonResp) Reset() {
|
||||
*x = CommonResp{}
|
||||
mi := &file_pb_file_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *CommonResp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CommonResp) ProtoMessage() {}
|
||||
|
||||
func (x *CommonResp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_pb_file_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 CommonResp.ProtoReflect.Descriptor instead.
|
||||
func (*CommonResp) Descriptor() ([]byte, []int) {
|
||||
return file_pb_file_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *CommonResp) GetCode() int64 {
|
||||
if x != nil {
|
||||
return x.Code
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *CommonResp) GetMsg() string {
|
||||
if x != nil {
|
||||
return x.Msg
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type FileInfo struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"`
|
||||
Tag string `protobuf:"bytes,4,opt,name=tag,proto3" json:"tag,omitempty"`
|
||||
Key string `protobuf:"bytes,5,opt,name=key,proto3" json:"key,omitempty"`
|
||||
Suffix string `protobuf:"bytes,6,opt,name=suffix,proto3" json:"suffix,omitempty"`
|
||||
Md5 string `protobuf:"bytes,7,opt,name=md5,proto3" json:"md5,omitempty"`
|
||||
CreatedAt int64 `protobuf:"varint,8,opt,name=createdAt,proto3" json:"createdAt,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *FileInfo) Reset() {
|
||||
*x = FileInfo{}
|
||||
mi := &file_pb_file_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *FileInfo) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*FileInfo) ProtoMessage() {}
|
||||
|
||||
func (x *FileInfo) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_pb_file_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 FileInfo.ProtoReflect.Descriptor instead.
|
||||
func (*FileInfo) Descriptor() ([]byte, []int) {
|
||||
return file_pb_file_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *FileInfo) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *FileInfo) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *FileInfo) GetUrl() string {
|
||||
if x != nil {
|
||||
return x.Url
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *FileInfo) GetTag() string {
|
||||
if x != nil {
|
||||
return x.Tag
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *FileInfo) GetKey() string {
|
||||
if x != nil {
|
||||
return x.Key
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *FileInfo) GetSuffix() string {
|
||||
if x != nil {
|
||||
return x.Suffix
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *FileInfo) GetMd5() string {
|
||||
if x != nil {
|
||||
return x.Md5
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *FileInfo) GetCreatedAt() int64 {
|
||||
if x != nil {
|
||||
return x.CreatedAt
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type GetFileByIdReq struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *GetFileByIdReq) Reset() {
|
||||
*x = GetFileByIdReq{}
|
||||
mi := &file_pb_file_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *GetFileByIdReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetFileByIdReq) ProtoMessage() {}
|
||||
|
||||
func (x *GetFileByIdReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_pb_file_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 GetFileByIdReq.ProtoReflect.Descriptor instead.
|
||||
func (*GetFileByIdReq) Descriptor() ([]byte, []int) {
|
||||
return file_pb_file_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *GetFileByIdReq) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type GetFileByIdResp struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
File *FileInfo `protobuf:"bytes,1,opt,name=file,proto3" json:"file,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *GetFileByIdResp) Reset() {
|
||||
*x = GetFileByIdResp{}
|
||||
mi := &file_pb_file_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *GetFileByIdResp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetFileByIdResp) ProtoMessage() {}
|
||||
|
||||
func (x *GetFileByIdResp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_pb_file_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 GetFileByIdResp.ProtoReflect.Descriptor instead.
|
||||
func (*GetFileByIdResp) Descriptor() ([]byte, []int) {
|
||||
return file_pb_file_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *GetFileByIdResp) GetFile() *FileInfo {
|
||||
if x != nil {
|
||||
return x.File
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type GetFilesByIdsReq struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Ids []string `protobuf:"bytes,1,rep,name=ids,proto3" json:"ids,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *GetFilesByIdsReq) Reset() {
|
||||
*x = GetFilesByIdsReq{}
|
||||
mi := &file_pb_file_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *GetFilesByIdsReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetFilesByIdsReq) ProtoMessage() {}
|
||||
|
||||
func (x *GetFilesByIdsReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_pb_file_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 GetFilesByIdsReq.ProtoReflect.Descriptor instead.
|
||||
func (*GetFilesByIdsReq) Descriptor() ([]byte, []int) {
|
||||
return file_pb_file_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *GetFilesByIdsReq) GetIds() []string {
|
||||
if x != nil {
|
||||
return x.Ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type GetFilesByIdsResp struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Files []*FileInfo `protobuf:"bytes,1,rep,name=files,proto3" json:"files,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *GetFilesByIdsResp) Reset() {
|
||||
*x = GetFilesByIdsResp{}
|
||||
mi := &file_pb_file_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *GetFilesByIdsResp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetFilesByIdsResp) ProtoMessage() {}
|
||||
|
||||
func (x *GetFilesByIdsResp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_pb_file_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 GetFilesByIdsResp.ProtoReflect.Descriptor instead.
|
||||
func (*GetFilesByIdsResp) Descriptor() ([]byte, []int) {
|
||||
return file_pb_file_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *GetFilesByIdsResp) GetFiles() []*FileInfo {
|
||||
if x != nil {
|
||||
return x.Files
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_pb_file_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_pb_file_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\rpb/file.proto\x12\x04file\"2\n" +
|
||||
"\n" +
|
||||
"CommonResp\x12\x12\n" +
|
||||
"\x04code\x18\x01 \x01(\x03R\x04code\x12\x10\n" +
|
||||
"\x03msg\x18\x02 \x01(\tR\x03msg\"\xac\x01\n" +
|
||||
"\bFileInfo\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
|
||||
"\x04name\x18\x02 \x01(\tR\x04name\x12\x10\n" +
|
||||
"\x03url\x18\x03 \x01(\tR\x03url\x12\x10\n" +
|
||||
"\x03tag\x18\x04 \x01(\tR\x03tag\x12\x10\n" +
|
||||
"\x03key\x18\x05 \x01(\tR\x03key\x12\x16\n" +
|
||||
"\x06suffix\x18\x06 \x01(\tR\x06suffix\x12\x10\n" +
|
||||
"\x03md5\x18\a \x01(\tR\x03md5\x12\x1c\n" +
|
||||
"\tcreatedAt\x18\b \x01(\x03R\tcreatedAt\" \n" +
|
||||
"\x0eGetFileByIdReq\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\tR\x02id\"5\n" +
|
||||
"\x0fGetFileByIdResp\x12\"\n" +
|
||||
"\x04file\x18\x01 \x01(\v2\x0e.file.FileInfoR\x04file\"$\n" +
|
||||
"\x10GetFilesByIdsReq\x12\x10\n" +
|
||||
"\x03ids\x18\x01 \x03(\tR\x03ids\"9\n" +
|
||||
"\x11GetFilesByIdsResp\x12$\n" +
|
||||
"\x05files\x18\x01 \x03(\v2\x0e.file.FileInfoR\x05files2\x8b\x01\n" +
|
||||
"\vFileService\x12:\n" +
|
||||
"\vGetFileById\x12\x14.file.GetFileByIdReq\x1a\x15.file.GetFileByIdResp\x12@\n" +
|
||||
"\rGetFilesByIds\x12\x16.file.GetFilesByIdsReq\x1a\x17.file.GetFilesByIdsRespB\bZ\x06./fileb\x06proto3"
|
||||
|
||||
var (
|
||||
file_pb_file_proto_rawDescOnce sync.Once
|
||||
file_pb_file_proto_rawDescData []byte
|
||||
)
|
||||
|
||||
func file_pb_file_proto_rawDescGZIP() []byte {
|
||||
file_pb_file_proto_rawDescOnce.Do(func() {
|
||||
file_pb_file_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_pb_file_proto_rawDesc), len(file_pb_file_proto_rawDesc)))
|
||||
})
|
||||
return file_pb_file_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_pb_file_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
||||
var file_pb_file_proto_goTypes = []any{
|
||||
(*CommonResp)(nil), // 0: file.CommonResp
|
||||
(*FileInfo)(nil), // 1: file.FileInfo
|
||||
(*GetFileByIdReq)(nil), // 2: file.GetFileByIdReq
|
||||
(*GetFileByIdResp)(nil), // 3: file.GetFileByIdResp
|
||||
(*GetFilesByIdsReq)(nil), // 4: file.GetFilesByIdsReq
|
||||
(*GetFilesByIdsResp)(nil), // 5: file.GetFilesByIdsResp
|
||||
}
|
||||
var file_pb_file_proto_depIdxs = []int32{
|
||||
1, // 0: file.GetFileByIdResp.file:type_name -> file.FileInfo
|
||||
1, // 1: file.GetFilesByIdsResp.files:type_name -> file.FileInfo
|
||||
2, // 2: file.FileService.GetFileById:input_type -> file.GetFileByIdReq
|
||||
4, // 3: file.FileService.GetFilesByIds:input_type -> file.GetFilesByIdsReq
|
||||
3, // 4: file.FileService.GetFileById:output_type -> file.GetFileByIdResp
|
||||
5, // 5: file.FileService.GetFilesByIds:output_type -> file.GetFilesByIdsResp
|
||||
4, // [4:6] is the sub-list for method output_type
|
||||
2, // [2:4] 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_pb_file_proto_init() }
|
||||
func file_pb_file_proto_init() {
|
||||
if File_pb_file_proto != nil {
|
||||
return
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_pb_file_proto_rawDesc), len(file_pb_file_proto_rawDesc)),
|
||||
NumEnums: 0,
|
||||
NumMessages: 6,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_pb_file_proto_goTypes,
|
||||
DependencyIndexes: file_pb_file_proto_depIdxs,
|
||||
MessageInfos: file_pb_file_proto_msgTypes,
|
||||
}.Build()
|
||||
File_pb_file_proto = out.File
|
||||
file_pb_file_proto_goTypes = nil
|
||||
file_pb_file_proto_depIdxs = nil
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.6.1
|
||||
// - protoc v7.34.1
|
||||
// source: pb/file.proto
|
||||
|
||||
package file
|
||||
|
||||
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 (
|
||||
FileService_GetFileById_FullMethodName = "/file.FileService/GetFileById"
|
||||
FileService_GetFilesByIds_FullMethodName = "/file.FileService/GetFilesByIds"
|
||||
)
|
||||
|
||||
// FileServiceClient is the client API for FileService 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 FileServiceClient interface {
|
||||
// 根据ID获取文件信息
|
||||
GetFileById(ctx context.Context, in *GetFileByIdReq, opts ...grpc.CallOption) (*GetFileByIdResp, error)
|
||||
// 根据ID列表批量获取文件信息
|
||||
GetFilesByIds(ctx context.Context, in *GetFilesByIdsReq, opts ...grpc.CallOption) (*GetFilesByIdsResp, error)
|
||||
}
|
||||
|
||||
type fileServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewFileServiceClient(cc grpc.ClientConnInterface) FileServiceClient {
|
||||
return &fileServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *fileServiceClient) GetFileById(ctx context.Context, in *GetFileByIdReq, opts ...grpc.CallOption) (*GetFileByIdResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetFileByIdResp)
|
||||
err := c.cc.Invoke(ctx, FileService_GetFileById_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *fileServiceClient) GetFilesByIds(ctx context.Context, in *GetFilesByIdsReq, opts ...grpc.CallOption) (*GetFilesByIdsResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetFilesByIdsResp)
|
||||
err := c.cc.Invoke(ctx, FileService_GetFilesByIds_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// FileServiceServer is the server API for FileService service.
|
||||
// All implementations must embed UnimplementedFileServiceServer
|
||||
// for forward compatibility.
|
||||
type FileServiceServer interface {
|
||||
// 根据ID获取文件信息
|
||||
GetFileById(context.Context, *GetFileByIdReq) (*GetFileByIdResp, error)
|
||||
// 根据ID列表批量获取文件信息
|
||||
GetFilesByIds(context.Context, *GetFilesByIdsReq) (*GetFilesByIdsResp, error)
|
||||
mustEmbedUnimplementedFileServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedFileServiceServer 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 UnimplementedFileServiceServer struct{}
|
||||
|
||||
func (UnimplementedFileServiceServer) GetFileById(context.Context, *GetFileByIdReq) (*GetFileByIdResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetFileById not implemented")
|
||||
}
|
||||
func (UnimplementedFileServiceServer) GetFilesByIds(context.Context, *GetFilesByIdsReq) (*GetFilesByIdsResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetFilesByIds not implemented")
|
||||
}
|
||||
func (UnimplementedFileServiceServer) mustEmbedUnimplementedFileServiceServer() {}
|
||||
func (UnimplementedFileServiceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeFileServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to FileServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeFileServiceServer interface {
|
||||
mustEmbedUnimplementedFileServiceServer()
|
||||
}
|
||||
|
||||
func RegisterFileServiceServer(s grpc.ServiceRegistrar, srv FileServiceServer) {
|
||||
// If the following call panics, it indicates UnimplementedFileServiceServer 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(&FileService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _FileService_GetFileById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetFileByIdReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(FileServiceServer).GetFileById(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: FileService_GetFileById_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(FileServiceServer).GetFileById(ctx, req.(*GetFileByIdReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _FileService_GetFilesByIds_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetFilesByIdsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(FileServiceServer).GetFilesByIds(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: FileService_GetFilesByIds_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(FileServiceServer).GetFilesByIds(ctx, req.(*GetFilesByIdsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// FileService_ServiceDesc is the grpc.ServiceDesc for FileService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var FileService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "file.FileService",
|
||||
HandlerType: (*FileServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetFileById",
|
||||
Handler: _FileService_GetFileById_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetFilesByIds",
|
||||
Handler: _FileService_GetFilesByIds_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "pb/file.proto",
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
// Source: file.proto
|
||||
|
||||
package fileservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
CommonResp = file.CommonResp
|
||||
FileInfo = file.FileInfo
|
||||
GetFileByIdReq = file.GetFileByIdReq
|
||||
GetFileByIdResp = file.GetFileByIdResp
|
||||
GetFilesByIdsReq = file.GetFilesByIdsReq
|
||||
GetFilesByIdsResp = file.GetFilesByIdsResp
|
||||
|
||||
FileService interface {
|
||||
// 根据ID获取文件信息
|
||||
GetFileById(ctx context.Context, in *GetFileByIdReq, opts ...grpc.CallOption) (*GetFileByIdResp, error)
|
||||
// 根据ID列表批量获取文件信息
|
||||
GetFilesByIds(ctx context.Context, in *GetFilesByIdsReq, opts ...grpc.CallOption) (*GetFilesByIdsResp, error)
|
||||
}
|
||||
|
||||
defaultFileService struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewFileService(cli zrpc.Client) FileService {
|
||||
return &defaultFileService{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
// 根据ID获取文件信息
|
||||
func (m *defaultFileService) GetFileById(ctx context.Context, in *GetFileByIdReq, opts ...grpc.CallOption) (*GetFileByIdResp, error) {
|
||||
client := file.NewFileServiceClient(m.cli.Conn())
|
||||
return client.GetFileById(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 根据ID列表批量获取文件信息
|
||||
func (m *defaultFileService) GetFilesByIds(ctx context.Context, in *GetFilesByIdsReq, opts ...grpc.CallOption) (*GetFilesByIdsResp, error) {
|
||||
client := file.NewFileServiceClient(m.cli.Conn())
|
||||
return client.GetFilesByIds(ctx, in, opts...)
|
||||
}
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/zrpc"
|
||||
|
||||
type Config struct {
|
||||
zrpc.RpcServerConf
|
||||
DB struct {
|
||||
DataSource string
|
||||
}
|
||||
Minio struct {
|
||||
Endpoint string
|
||||
AccessKeyId string
|
||||
AccessKeySecret string
|
||||
BucketName string
|
||||
BucketUrl string
|
||||
UseSsl bool
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
fileModel "sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type GetFileByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetFileByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileByIdLogic {
|
||||
return &GetFileByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 根据ID获取文件信息
|
||||
func (l *GetFileByIdLogic) GetFileById(in *file.GetFileByIdReq) (*file.GetFileByIdResp, error) {
|
||||
var oss fileModel.SundynixOss
|
||||
err := l.svcCtx.DB.Where("id = ?", in.Id).First(&oss).Error
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil, status.Error(codes.NotFound, "文件不存在")
|
||||
}
|
||||
l.Errorf("查询文件失败: %v", err)
|
||||
return nil, status.Error(codes.Internal, "查询文件失败")
|
||||
}
|
||||
|
||||
return &file.GetFileByIdResp{
|
||||
File: convertOssToProto(&oss),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func convertOssToProto(oss *fileModel.SundynixOss) *file.FileInfo {
|
||||
return &file.FileInfo{
|
||||
Id: oss.ID,
|
||||
Name: oss.Name,
|
||||
Url: oss.Url,
|
||||
Tag: oss.Tag,
|
||||
Key: oss.Key,
|
||||
Suffix: oss.Suffix,
|
||||
Md5: oss.MD5,
|
||||
CreatedAt: oss.CreatedAt.Unix(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
fileModel "sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type GetFilesByIdsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetFilesByIdsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFilesByIdsLogic {
|
||||
return &GetFilesByIdsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 根据ID列表批量获取文件信息
|
||||
func (l *GetFilesByIdsLogic) GetFilesByIds(in *file.GetFilesByIdsReq) (*file.GetFilesByIdsResp, error) {
|
||||
if len(in.Ids) == 0 {
|
||||
return &file.GetFilesByIdsResp{Files: []*file.FileInfo{}}, nil
|
||||
}
|
||||
|
||||
var ossList []fileModel.SundynixOss
|
||||
err := l.svcCtx.DB.Where("id IN ?", in.Ids).Find(&ossList).Error
|
||||
if err != nil {
|
||||
l.Errorf("批量查询文件失败: %v", err)
|
||||
return nil, status.Error(codes.Internal, "批量查询文件失败")
|
||||
}
|
||||
|
||||
files := make([]*file.FileInfo, 0, len(ossList))
|
||||
for _, oss := range ossList {
|
||||
files = append(files, convertOssToProto(&oss))
|
||||
}
|
||||
|
||||
return &file.GetFilesByIdsResp{Files: files}, nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
// Source: file.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/file/rpc/file"
|
||||
"sundynix-micro-go/app/file/rpc/internal/logic"
|
||||
"sundynix-micro-go/app/file/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type FileServiceServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
file.UnimplementedFileServiceServer
|
||||
}
|
||||
|
||||
func NewFileServiceServer(svcCtx *svc.ServiceContext) *FileServiceServer {
|
||||
return &FileServiceServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 根据ID获取文件信息
|
||||
func (s *FileServiceServer) GetFileById(ctx context.Context, in *file.GetFileByIdReq) (*file.GetFileByIdResp, error) {
|
||||
l := logic.NewGetFileByIdLogic(ctx, s.svcCtx)
|
||||
return l.GetFileById(in)
|
||||
}
|
||||
|
||||
// 根据ID列表批量获取文件信息
|
||||
func (s *FileServiceServer) GetFilesByIds(ctx context.Context, in *file.GetFilesByIdsReq) (*file.GetFilesByIdsResp, error) {
|
||||
l := logic.NewGetFilesByIdsLogic(ctx, s.svcCtx)
|
||||
return l.GetFilesByIds(in)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
fileModel "sundynix-micro-go/app/file/model"
|
||||
"sundynix-micro-go/app/file/rpc/internal/config"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DB *gorm.DB
|
||||
MinioClient *minio.Client
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
// 初始化GORM
|
||||
db, err := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{})
|
||||
if err != nil {
|
||||
logx.Errorf("连接数据库失败: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
// 自动迁移
|
||||
if err := db.AutoMigrate(&fileModel.SundynixOss{}); err != nil {
|
||||
logx.Errorf("数据库迁移失败: %v", err)
|
||||
}
|
||||
|
||||
// 初始化MinIO客户端
|
||||
minioClient, err := minio.New(c.Minio.Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(c.Minio.AccessKeyId, c.Minio.AccessKeySecret, ""),
|
||||
Secure: c.Minio.UseSsl,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("初始化MinIO客户端失败: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DB: db,
|
||||
MinioClient: minioClient,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package file;
|
||||
|
||||
option go_package = "./file";
|
||||
|
||||
// ---------- 通用消息 ----------
|
||||
|
||||
message CommonResp {
|
||||
int64 code = 1;
|
||||
string msg = 2;
|
||||
}
|
||||
|
||||
// ---------- 文件信息 ----------
|
||||
|
||||
message FileInfo {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
string url = 3;
|
||||
string tag = 4;
|
||||
string key = 5;
|
||||
string suffix = 6;
|
||||
string md5 = 7;
|
||||
int64 createdAt = 8;
|
||||
}
|
||||
|
||||
// ---------- 请求/响应 ----------
|
||||
|
||||
message GetFileByIdReq {
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message GetFileByIdResp {
|
||||
FileInfo file = 1;
|
||||
}
|
||||
|
||||
message GetFilesByIdsReq {
|
||||
repeated string ids = 1;
|
||||
}
|
||||
|
||||
message GetFilesByIdsResp {
|
||||
repeated FileInfo files = 1;
|
||||
}
|
||||
|
||||
// ---------- 服务定义 ----------
|
||||
|
||||
service FileService {
|
||||
// 根据ID获取文件信息
|
||||
rpc GetFileById(GetFileByIdReq) returns (GetFileByIdResp);
|
||||
// 根据ID列表批量获取文件信息
|
||||
rpc GetFilesByIds(GetFilesByIdsReq) returns (GetFilesByIdsResp);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
Name: plant-api
|
||||
Host: 0.0.0.0
|
||||
Port: 9004
|
||||
|
||||
Auth:
|
||||
AccessSecret: 9149f2eb-d517-4a50-a03a-231dbcf0d872
|
||||
AccessExpire: 7200
|
||||
|
||||
# MySQL
|
||||
DB:
|
||||
DataSource: root:root@tcp(192.168.100.127:3307)/sundynix_micro_go?charset=utf8mb4&parseTime=True&loc=Local
|
||||
|
||||
# Redis
|
||||
Cache:
|
||||
- Host: 127.0.0.1:6379
|
||||
Pass: sundynix
|
||||
Type: node
|
||||
|
||||
# RPC 依赖
|
||||
UserRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 192.168.100.127:2379
|
||||
Key: user.rpc
|
||||
|
||||
FileRpc:
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 192.168.100.127:2379
|
||||
Key: file.rpc
|
||||
|
||||
# 百度植物识别
|
||||
BaiduImgClassify:
|
||||
ApiKey: hpBfjwy8ifv3qswYGYjUCNKN
|
||||
SecretKey: i5aXZdM4XZVuDroBslL0f3uIuwbAyXFS
|
||||
|
||||
# 微信支付
|
||||
WechatPay:
|
||||
MchId: "1735188493"
|
||||
MchCertificateSerialNumber: "3725BFCA9CA3AF819AEC5D0CB7D3540BBC67F2CF"
|
||||
MchApiV3Key: "a1B2c3D4e5F6g7H8i9J0k1L2m3N4o5P6"
|
||||
PrivateKeyPath: "/Users/blizzard/privateFolder/cert/apiclient_key.pem"
|
||||
PublicKeyPath: "/Users/blizzard/privateFolder/cert/pub_key.pem"
|
||||
NotifyUrl: "https://prod.sundynix.cn/api/wechatpay/notify"
|
||||
@@ -0,0 +1,39 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
Auth struct {
|
||||
AccessSecret string
|
||||
AccessExpire int64
|
||||
}
|
||||
DB struct {
|
||||
DataSource string
|
||||
}
|
||||
Cache []struct {
|
||||
Host string
|
||||
Pass string
|
||||
Type string
|
||||
}
|
||||
UserRpc zrpc.RpcClientConf
|
||||
FileRpc zrpc.RpcClientConf
|
||||
BaiduImgClassify struct {
|
||||
ApiKey string
|
||||
SecretKey string
|
||||
}
|
||||
WechatPay struct {
|
||||
MchId string
|
||||
MchCertificateSerialNumber string
|
||||
MchApiV3Key string
|
||||
PrivateKeyPath string
|
||||
PublicKeyPath string
|
||||
NotifyUrl string
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package ai
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/ai"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// AI问答
|
||||
func AiChatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AiChatReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := ai.NewAiChatLogic(r.Context(), svcCtx)
|
||||
err := l.AiChat(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package ai
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/ai"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 聊天历史
|
||||
func GetAiChatHistoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := ai.NewGetAiChatHistoryLogic(r.Context(), svcCtx)
|
||||
err := l.GetAiChatHistory()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package callback
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/callback"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 微信支付回调
|
||||
func WechatPayCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := callback.NewWechatPayCallbackLogic(r.Context(), svcCtx)
|
||||
err := l.WechatPayCallback()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/config"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 徽章配置列表
|
||||
func GetBadgeConfigListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.BadgeConfigListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := config.NewGetBadgeConfigListLogic(r.Context(), svcCtx)
|
||||
err := l.GetBadgeConfigList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/config"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 等级配置列表
|
||||
func GetLevelConfigListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.LevelConfigListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := config.NewGetLevelConfigListLogic(r.Context(), svcCtx)
|
||||
err := l.GetLevelConfigList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/exchange"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 兑换商品
|
||||
func CreateExchangeOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ExchangeOrderReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := exchange.NewCreateExchangeOrderLogic(r.Context(), svcCtx)
|
||||
err := l.CreateExchangeOrder(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/exchange"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 兑换商品列表
|
||||
func GetExchangeItemListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ExchangeItemListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := exchange.NewGetExchangeItemListLogic(r.Context(), svcCtx)
|
||||
err := l.GetExchangeItemList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 添加养护计划
|
||||
func AddCarePlanHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CarePlanReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := myPlant.NewAddCarePlanLogic(r.Context(), svcCtx)
|
||||
err := l.AddCarePlan(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 添加养护记录
|
||||
func AddCareRecordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CareRecordReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := myPlant.NewAddCareRecordLogic(r.Context(), svcCtx)
|
||||
err := l.AddCareRecord(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 添加成长记录
|
||||
func AddGrowthRecordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GrowthRecordReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := myPlant.NewAddGrowthRecordLogic(r.Context(), svcCtx)
|
||||
err := l.AddGrowthRecord(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建植物
|
||||
func CreatePlantHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreatePlantReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := myPlant.NewCreatePlantLogic(r.Context(), svcCtx)
|
||||
err := l.CreatePlant(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除植物
|
||||
func DeletePlantHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := myPlant.NewDeletePlantLogic(r.Context(), svcCtx)
|
||||
err := l.DeletePlant(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 我的植物列表
|
||||
func GetMyPlantListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PlantListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := myPlant.NewGetMyPlantListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetMyPlantList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 植物详情
|
||||
func GetPlantDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdPathReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := myPlant.NewGetPlantDetailLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetPlantDetail(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/myPlant"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新植物
|
||||
func UpdatePlantHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdatePlantReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := myPlant.NewUpdatePlantLogic(r.Context(), svcCtx)
|
||||
err := l.UpdatePlant(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package ocr
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/ocr"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// OCR植物识别
|
||||
func OcrClassifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.OcrReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := ocr.NewOcrClassifyLogic(r.Context(), svcCtx)
|
||||
err := l.OcrClassify(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/post"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 评论帖子
|
||||
func CommentPostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PostCommentReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := post.NewCommentPostLogic(r.Context(), svcCtx)
|
||||
err := l.CommentPost(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/post"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 发布帖子
|
||||
func CreatePostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreatePostReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := post.NewCreatePostLogic(r.Context(), svcCtx)
|
||||
err := l.CreatePost(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/post"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除帖子
|
||||
func DeletePostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := post.NewDeletePostLogic(r.Context(), svcCtx)
|
||||
err := l.DeletePost(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/post"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 帖子详情
|
||||
func GetPostDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdPathReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := post.NewGetPostDetailLogic(r.Context(), svcCtx)
|
||||
err := l.GetPostDetail(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/post"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 帖子列表
|
||||
func GetPostListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PostListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := post.NewGetPostListLogic(r.Context(), svcCtx)
|
||||
err := l.GetPostList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/post"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 点赞帖子
|
||||
func LikePostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := post.NewLikePostLogic(r.Context(), svcCtx)
|
||||
err := l.LikePost(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
ai "sundynix-micro-go/app/plant/api/internal/handler/ai"
|
||||
callback "sundynix-micro-go/app/plant/api/internal/handler/callback"
|
||||
config "sundynix-micro-go/app/plant/api/internal/handler/config"
|
||||
exchange "sundynix-micro-go/app/plant/api/internal/handler/exchange"
|
||||
myPlant "sundynix-micro-go/app/plant/api/internal/handler/myPlant"
|
||||
ocr "sundynix-micro-go/app/plant/api/internal/handler/ocr"
|
||||
post "sundynix-micro-go/app/plant/api/internal/handler/post"
|
||||
topic "sundynix-micro-go/app/plant/api/internal/handler/topic"
|
||||
userProfile "sundynix-micro-go/app/plant/api/internal/handler/userProfile"
|
||||
wiki "sundynix-micro-go/app/plant/api/internal/handler/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// AI问答
|
||||
Method: http.MethodPost,
|
||||
Path: "/ai/chat",
|
||||
Handler: ai.AiChatHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 聊天历史
|
||||
Method: http.MethodGet,
|
||||
Path: "/ai/history",
|
||||
Handler: ai.GetAiChatHistoryHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 微信支付回调
|
||||
Method: http.MethodPost,
|
||||
Path: "/callback/wechatpay",
|
||||
Handler: callback.WechatPayCallbackHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 徽章配置列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/badge/list",
|
||||
Handler: config.GetBadgeConfigListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 等级配置列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/config/level/list",
|
||||
Handler: config.GetLevelConfigListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 兑换商品列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/exchange/list",
|
||||
Handler: exchange.GetExchangeItemListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 兑换商品
|
||||
Method: http.MethodPost,
|
||||
Path: "/exchange/order",
|
||||
Handler: exchange.CreateExchangeOrderHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 植物详情
|
||||
Method: http.MethodGet,
|
||||
Path: "/my/:id",
|
||||
Handler: myPlant.GetPlantDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 添加养护计划
|
||||
Method: http.MethodPost,
|
||||
Path: "/my/carePlan",
|
||||
Handler: myPlant.AddCarePlanHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 添加养护记录
|
||||
Method: http.MethodPost,
|
||||
Path: "/my/careRecord",
|
||||
Handler: myPlant.AddCareRecordHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 创建植物
|
||||
Method: http.MethodPost,
|
||||
Path: "/my/create",
|
||||
Handler: myPlant.CreatePlantHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除植物
|
||||
Method: http.MethodDelete,
|
||||
Path: "/my/delete",
|
||||
Handler: myPlant.DeletePlantHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 添加成长记录
|
||||
Method: http.MethodPost,
|
||||
Path: "/my/growthRecord",
|
||||
Handler: myPlant.AddGrowthRecordHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 我的植物列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/my/list",
|
||||
Handler: myPlant.GetMyPlantListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新植物
|
||||
Method: http.MethodPut,
|
||||
Path: "/my/update",
|
||||
Handler: myPlant.UpdatePlantHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// OCR植物识别
|
||||
Method: http.MethodPost,
|
||||
Path: "/ocr/classify",
|
||||
Handler: ocr.OcrClassifyHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 帖子详情
|
||||
Method: http.MethodGet,
|
||||
Path: "/post/:id",
|
||||
Handler: post.GetPostDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 评论帖子
|
||||
Method: http.MethodPost,
|
||||
Path: "/post/comment",
|
||||
Handler: post.CommentPostHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 发布帖子
|
||||
Method: http.MethodPost,
|
||||
Path: "/post/create",
|
||||
Handler: post.CreatePostHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除帖子
|
||||
Method: http.MethodDelete,
|
||||
Path: "/post/delete",
|
||||
Handler: post.DeletePostHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 点赞帖子
|
||||
Method: http.MethodPost,
|
||||
Path: "/post/like",
|
||||
Handler: post.LikePostHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 帖子列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/post/list",
|
||||
Handler: post.GetPostListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 创建话题
|
||||
Method: http.MethodPost,
|
||||
Path: "/topic/create",
|
||||
Handler: topic.CreateTopicHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除话题
|
||||
Method: http.MethodDelete,
|
||||
Path: "/topic/delete",
|
||||
Handler: topic.DeleteTopicHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 话题列表
|
||||
Method: http.MethodGet,
|
||||
Path: "/topic/list",
|
||||
Handler: topic.GetTopicListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 获取用户资料
|
||||
Method: http.MethodGet,
|
||||
Path: "/profile/info",
|
||||
Handler: userProfile.GetUserProfileHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新用户资料
|
||||
Method: http.MethodPut,
|
||||
Path: "/profile/update",
|
||||
Handler: userProfile.UpdateUserProfileHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 百科详情
|
||||
Method: http.MethodGet,
|
||||
Path: "/wiki/:id",
|
||||
Handler: wiki.GetWikiDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 创建百科分类
|
||||
Method: http.MethodPost,
|
||||
Path: "/wiki/class/create",
|
||||
Handler: wiki.CreateWikiClassHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 百科分类列表
|
||||
Method: http.MethodGet,
|
||||
Path: "/wiki/class/list",
|
||||
Handler: wiki.GetWikiClassListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 百科列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/wiki/list",
|
||||
Handler: wiki.GetWikiListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 收藏/取消收藏百科
|
||||
Method: http.MethodPost,
|
||||
Path: "/wiki/star",
|
||||
Handler: wiki.ToggleWikiStarHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/plant"),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package topic
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/topic"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建话题
|
||||
func CreateTopicHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.TopicReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := topic.NewCreateTopicLogic(r.Context(), svcCtx)
|
||||
err := l.CreateTopic(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package topic
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/topic"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 删除话题
|
||||
func DeleteTopicHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := topic.NewDeleteTopicLogic(r.Context(), svcCtx)
|
||||
err := l.DeleteTopic(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package topic
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/topic"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 话题列表
|
||||
func GetTopicListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := topic.NewGetTopicListLogic(r.Context(), svcCtx)
|
||||
err := l.GetTopicList()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package userProfile
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/userProfile"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 获取用户资料
|
||||
func GetUserProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := userProfile.NewGetUserProfileLogic(r.Context(), svcCtx)
|
||||
err := l.GetUserProfile()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package userProfile
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/userProfile"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 更新用户资料
|
||||
func UpdateUserProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateProfileReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := userProfile.NewUpdateUserProfileLogic(r.Context(), svcCtx)
|
||||
err := l.UpdateUserProfile(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 创建百科分类
|
||||
func CreateWikiClassHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.WikiClassReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := wiki.NewCreateWikiClassLogic(r.Context(), svcCtx)
|
||||
err := l.CreateWikiClass(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 百科分类列表
|
||||
func GetWikiClassListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := wiki.NewGetWikiClassListLogic(r.Context(), svcCtx)
|
||||
err := l.GetWikiClassList()
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 百科详情
|
||||
func GetWikiDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdPathReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := wiki.NewGetWikiDetailLogic(r.Context(), svcCtx)
|
||||
err := l.GetWikiDetail(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 百科列表
|
||||
func GetWikiListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.WikiListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := wiki.NewGetWikiListLogic(r.Context(), svcCtx)
|
||||
err := l.GetWikiList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/plant/api/internal/logic/wiki"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
// 收藏/取消收藏百科
|
||||
func ToggleWikiStarHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
l := wiki.NewToggleWikiStarLogic(r.Context(), svcCtx)
|
||||
err := l.ToggleWikiStar(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package ai
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AiChatLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// AI问答
|
||||
func NewAiChatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AiChatLogic {
|
||||
return &AiChatLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AiChatLogic) AiChat(req *types.AiChatReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package ai
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
)
|
||||
|
||||
type GetAiChatHistoryLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 聊天历史
|
||||
func NewGetAiChatHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAiChatHistoryLogic {
|
||||
return &GetAiChatHistoryLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetAiChatHistoryLogic) GetAiChatHistory() error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package callback
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
)
|
||||
|
||||
type WechatPayCallbackLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 微信支付回调
|
||||
func NewWechatPayCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WechatPayCallbackLogic {
|
||||
return &WechatPayCallbackLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WechatPayCallbackLogic) WechatPayCallback() error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetBadgeConfigListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 徽章配置列表
|
||||
func NewGetBadgeConfigListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBadgeConfigListLogic {
|
||||
return &GetBadgeConfigListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetBadgeConfigListLogic) GetBadgeConfigList(req *types.BadgeConfigListReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetLevelConfigListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 等级配置列表
|
||||
func NewGetLevelConfigListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLevelConfigListLogic {
|
||||
return &GetLevelConfigListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetLevelConfigListLogic) GetLevelConfigList(req *types.LevelConfigListReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateExchangeOrderLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 兑换商品
|
||||
func NewCreateExchangeOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateExchangeOrderLogic {
|
||||
return &CreateExchangeOrderLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateExchangeOrderLogic) CreateExchangeOrder(req *types.ExchangeOrderReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetExchangeItemListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 兑换商品列表
|
||||
func NewGetExchangeItemListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetExchangeItemListLogic {
|
||||
return &GetExchangeItemListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetExchangeItemListLogic) GetExchangeItemList(req *types.ExchangeItemListReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
)
|
||||
|
||||
type AddCarePlanLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAddCarePlanLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCarePlanLogic {
|
||||
return &AddCarePlanLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *AddCarePlanLogic) AddCarePlan(req *types.CarePlanReq) error {
|
||||
userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
|
||||
plan := plantModel.SundynixCarePlan{
|
||||
UserID: userId, PlantID: req.PlantId, Name: req.Name,
|
||||
TargetAction: req.TargetAction, Period: req.Period, Icon: req.Icon,
|
||||
}
|
||||
if err := l.svcCtx.DB.Create(&plan).Error; err != nil {
|
||||
return fmt.Errorf("创建养护计划失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
)
|
||||
|
||||
type AddCareRecordLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAddCareRecordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCareRecordLogic {
|
||||
return &AddCareRecordLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *AddCareRecordLogic) AddCareRecord(req *types.CareRecordReq) error {
|
||||
userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
|
||||
record := plantModel.SundynixCareRecord{
|
||||
UserID: userId, PlantID: req.PlantId, PlanID: req.PlanId,
|
||||
Name: req.Action, Remark: req.Note,
|
||||
}
|
||||
if err := l.svcCtx.DB.Create(&record).Error; err != nil {
|
||||
return fmt.Errorf("创建养护记录失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
)
|
||||
|
||||
type AddGrowthRecordLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAddGrowthRecordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGrowthRecordLogic {
|
||||
return &AddGrowthRecordLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *AddGrowthRecordLogic) AddGrowthRecord(req *types.GrowthRecordReq) error {
|
||||
userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
|
||||
record := plantModel.SundynixGrowthRecord{
|
||||
PlantID: req.PlantId, UserID: userId, Content: req.Content,
|
||||
}
|
||||
if err := l.svcCtx.DB.Create(&record).Error; err != nil {
|
||||
return fmt.Errorf("创建成长记录失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CreatePlantLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreatePlantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreatePlantLogic {
|
||||
return &CreatePlantLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *CreatePlantLogic) CreatePlant(req *types.CreatePlantReq) error {
|
||||
userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
|
||||
plantTime, _ := time.Parse("2006-01-02", req.PlantTime)
|
||||
plant := plantModel.SundynixMyPlant{
|
||||
UserID: userId, Name: req.Name, PlantTime: plantTime, Placement: req.Placement,
|
||||
PotMaterial: req.PotMaterial, PotSize: req.PotSize, Sunlight: req.Sunlight,
|
||||
PlantingMaterial: req.PlantingMaterial, Status: 1,
|
||||
}
|
||||
if err := l.svcCtx.DB.Create(&plant).Error; err != nil {
|
||||
l.Errorf("创建植物失败: %v", err)
|
||||
return fmt.Errorf("创建植物失败")
|
||||
}
|
||||
if len(req.ImgIds) > 0 {
|
||||
for _, imgID := range req.ImgIds {
|
||||
l.svcCtx.DB.Create(&plantModel.SundynixMyPlantOss{MyPlantID: plant.ID, OssID: imgID})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
)
|
||||
|
||||
type DeletePlantLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeletePlantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeletePlantLogic {
|
||||
return &DeletePlantLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *DeletePlantLogic) DeletePlant(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&plantModel.SundynixMyPlant{}).Error; err != nil {
|
||||
return fmt.Errorf("删除植物失败")
|
||||
}
|
||||
// 清理关联数据
|
||||
l.svcCtx.DB.Where("plant_id IN ?", req.Ids).Delete(&plantModel.SundynixCarePlan{})
|
||||
l.svcCtx.DB.Where("plant_id IN ?", req.Ids).Delete(&plantModel.SundynixCareRecord{})
|
||||
l.svcCtx.DB.Where("plant_id IN ?", req.Ids).Delete(&plantModel.SundynixCareTask{})
|
||||
l.svcCtx.DB.Where("plant_id IN ?", req.Ids).Delete(&plantModel.SundynixGrowthRecord{})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
)
|
||||
|
||||
type GetMyPlantListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetMyPlantListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMyPlantListLogic {
|
||||
return &GetMyPlantListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetMyPlantListLogic) GetMyPlantList(req *types.PlantListReq) (resp interface{}, err error) {
|
||||
userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
|
||||
var plants []plantModel.SundynixMyPlant
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&plantModel.SundynixMyPlant{}).Where("user_id = ?", userId)
|
||||
if req.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+req.Name+"%")
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := req.Current, req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Offset((current - 1) * pageSize).Limit(pageSize).Order("created_at DESC").Find(&plants).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询植物列表失败")
|
||||
}
|
||||
return map[string]interface{}{"list": plants, "total": total, "current": current, "size": pageSize}, nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
)
|
||||
|
||||
type GetPlantDetailLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetPlantDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPlantDetailLogic {
|
||||
return &GetPlantDetailLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetPlantDetailLogic) GetPlantDetail(req *types.IdPathReq) (resp interface{}, err error) {
|
||||
var plant plantModel.SundynixMyPlant
|
||||
if err := l.svcCtx.DB.Where("id = ?", req.Id).First(&plant).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil, fmt.Errorf("植物不存在")
|
||||
}
|
||||
return nil, fmt.Errorf("查询植物失败")
|
||||
}
|
||||
// 查询关联图片ID
|
||||
var ossIds []string
|
||||
l.svcCtx.DB.Model(&plantModel.SundynixMyPlantOss{}).Where("sundynix_my_plant_id = ?", plant.ID).Pluck("sundynix_oss_id", &ossIds)
|
||||
// 查询养护计划
|
||||
var plans []plantModel.SundynixCarePlan
|
||||
l.svcCtx.DB.Where("plant_id = ?", plant.ID).Find(&plans)
|
||||
// 查询成长记录
|
||||
var records []plantModel.SundynixGrowthRecord
|
||||
l.svcCtx.DB.Where("plant_id = ?", plant.ID).Order("created_at DESC").Limit(10).Find(&records)
|
||||
|
||||
return map[string]interface{}{
|
||||
"plant": plant, "imgIds": ossIds, "carePlans": plans, "growthRecords": records,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package myPlant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
)
|
||||
|
||||
type UpdatePlantLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdatePlantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePlantLogic {
|
||||
return &UpdatePlantLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *UpdatePlantLogic) UpdatePlant(req *types.UpdatePlantReq) error {
|
||||
updates := map[string]interface{}{}
|
||||
if req.Name != "" {
|
||||
updates["name"] = req.Name
|
||||
}
|
||||
if req.Status > 0 {
|
||||
updates["status"] = req.Status
|
||||
}
|
||||
if req.Placement != "" {
|
||||
updates["placement"] = req.Placement
|
||||
}
|
||||
if req.PotMaterial != "" {
|
||||
updates["pot_material"] = req.PotMaterial
|
||||
}
|
||||
if req.PotSize != "" {
|
||||
updates["pot_size"] = req.PotSize
|
||||
}
|
||||
if req.Sunlight != "" {
|
||||
updates["sunlight"] = req.Sunlight
|
||||
}
|
||||
if req.PlantingMaterial != "" {
|
||||
updates["planting_material"] = req.PlantingMaterial
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
if err := l.svcCtx.DB.Model(&plantModel.SundynixMyPlant{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
|
||||
return fmt.Errorf("更新植物失败")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package ocr
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type OcrClassifyLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// OCR植物识别
|
||||
func NewOcrClassifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OcrClassifyLogic {
|
||||
return &OcrClassifyLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *OcrClassifyLogic) OcrClassify(req *types.OcrReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CommentPostLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 评论帖子
|
||||
func NewCommentPostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentPostLogic {
|
||||
return &CommentPostLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CommentPostLogic) CommentPost(req *types.PostCommentReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreatePostLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 发布帖子
|
||||
func NewCreatePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreatePostLogic {
|
||||
return &CreatePostLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreatePostLogic) CreatePost(req *types.CreatePostReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeletePostLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 删除帖子
|
||||
func NewDeletePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeletePostLogic {
|
||||
return &DeletePostLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeletePostLogic) DeletePost(req *types.IdsReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetPostDetailLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 帖子详情
|
||||
func NewGetPostDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPostDetailLogic {
|
||||
return &GetPostDetailLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetPostDetailLogic) GetPostDetail(req *types.IdPathReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetPostListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 帖子列表
|
||||
func NewGetPostListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPostListLogic {
|
||||
return &GetPostListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetPostListLogic) GetPostList(req *types.PostListReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type LikePostLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 点赞帖子
|
||||
func NewLikePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikePostLogic {
|
||||
return &LikePostLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LikePostLogic) LikePost(req *types.IdReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package topic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateTopicLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 创建话题
|
||||
func NewCreateTopicLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateTopicLogic {
|
||||
return &CreateTopicLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateTopicLogic) CreateTopic(req *types.TopicReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package topic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteTopicLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 删除话题
|
||||
func NewDeleteTopicLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteTopicLogic {
|
||||
return &DeleteTopicLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteTopicLogic) DeleteTopic(req *types.IdsReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package topic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
)
|
||||
|
||||
type GetTopicListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 话题列表
|
||||
func NewGetTopicListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTopicListLogic {
|
||||
return &GetTopicListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetTopicListLogic) GetTopicList() error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package userProfile
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
)
|
||||
|
||||
type GetUserProfileLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 获取用户资料
|
||||
func NewGetUserProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserProfileLogic {
|
||||
return &GetUserProfileLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUserProfileLogic) GetUserProfile() error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package userProfile
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateUserProfileLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 更新用户资料
|
||||
func NewUpdateUserProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserProfileLogic {
|
||||
return &UpdateUserProfileLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateUserProfileLogic) UpdateUserProfile(req *types.UpdateProfileReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateWikiClassLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 创建百科分类
|
||||
func NewCreateWikiClassLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateWikiClassLogic {
|
||||
return &CreateWikiClassLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateWikiClassLogic) CreateWikiClass(req *types.WikiClassReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
)
|
||||
|
||||
type GetWikiClassListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 百科分类列表
|
||||
func NewGetWikiClassListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWikiClassListLogic {
|
||||
return &GetWikiClassListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetWikiClassListLogic) GetWikiClassList() error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetWikiDetailLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 百科详情
|
||||
func NewGetWikiDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWikiDetailLogic {
|
||||
return &GetWikiDetailLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetWikiDetailLogic) GetWikiDetail(req *types.IdPathReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetWikiListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 百科列表
|
||||
func NewGetWikiListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWikiListLogic {
|
||||
return &GetWikiListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetWikiListLogic) GetWikiList(req *types.WikiListReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ToggleWikiStarLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 收藏/取消收藏百科
|
||||
func NewToggleWikiStarLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ToggleWikiStarLogic {
|
||||
return &ToggleWikiStarLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ToggleWikiStarLogic) ToggleWikiStar(req *types.IdReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package svc
|
||||
|
||||
import (
|
||||
"sundynix-micro-go/app/file/rpc/fileservice"
|
||||
"sundynix-micro-go/app/plant/api/internal/config"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
"sundynix-micro-go/app/user/rpc/userservice"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DB *gorm.DB
|
||||
UserRpc userservice.UserService
|
||||
FileRpc fileservice.FileService
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
db, err := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{})
|
||||
if err != nil {
|
||||
logx.Errorf("连接数据库失败: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 自动迁移
|
||||
if err := db.AutoMigrate(
|
||||
&plantModel.SundynixPlantUserProfile{},
|
||||
&plantModel.SundynixMyPlant{},
|
||||
&plantModel.SundynixCarePlan{},
|
||||
&plantModel.SundynixCareRecord{},
|
||||
&plantModel.SundynixCareTask{},
|
||||
&plantModel.SundynixGrowthRecord{},
|
||||
&plantModel.SundynixWiki{},
|
||||
&plantModel.SundynixWikiClass{},
|
||||
&plantModel.SundynixPost{},
|
||||
&plantModel.SundynixPostComment{},
|
||||
&plantModel.SundynixPostLike{},
|
||||
&plantModel.SundynixPostTopic{},
|
||||
&plantModel.SundynixUserStar{},
|
||||
&plantModel.SundynixExchangeItem{},
|
||||
&plantModel.SundynixExchangeOrder{},
|
||||
&plantModel.SundynixLevelConfig{},
|
||||
&plantModel.SundynixBadgeConfig{},
|
||||
&plantModel.SundynixUserBadge{},
|
||||
&plantModel.SundynixAiChatHistory{},
|
||||
); err != nil {
|
||||
logx.Errorf("数据库迁移失败: %v", err)
|
||||
}
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DB: db,
|
||||
UserRpc: userservice.NewUserService(zrpc.MustNewClient(c.UserRpc)),
|
||||
FileRpc: fileservice.NewFileService(zrpc.MustNewClient(c.FileRpc)),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.1
|
||||
|
||||
package types
|
||||
|
||||
type AiChatReq struct {
|
||||
Question string `json:"question"`
|
||||
}
|
||||
|
||||
type BadgeConfigListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Dimension string `json:"dimension,optional"`
|
||||
}
|
||||
|
||||
type CarePlanReq struct {
|
||||
PlantId string `json:"plantId"`
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon,optional"`
|
||||
TargetAction string `json:"targetAction"`
|
||||
Period int `json:"period"`
|
||||
}
|
||||
|
||||
type CareRecordReq struct {
|
||||
PlantId string `json:"plantId"`
|
||||
PlanId string `json:"planId"`
|
||||
Action string `json:"action"`
|
||||
Note string `json:"note,optional"`
|
||||
}
|
||||
|
||||
type CreatePlantReq struct {
|
||||
Name string `json:"name"`
|
||||
PlantTime string `json:"plantTime"`
|
||||
Status int `json:"status,optional"`
|
||||
Placement string `json:"placement,optional"`
|
||||
PotMaterial string `json:"potMaterial,optional"`
|
||||
PotSize string `json:"potSize,optional"`
|
||||
Sunlight string `json:"sunlight,optional"`
|
||||
PlantingMaterial string `json:"plantingMaterial,optional"`
|
||||
ImgIds []string `json:"imgIds,optional"`
|
||||
}
|
||||
|
||||
type CreatePostReq struct {
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Location string `json:"location,optional"`
|
||||
ImgIds []string `json:"imgIds,optional"`
|
||||
TopicId string `json:"topicId,optional"`
|
||||
}
|
||||
|
||||
type ExchangeItemListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
}
|
||||
|
||||
type ExchangeOrderReq struct {
|
||||
ItemId string `json:"itemId"`
|
||||
}
|
||||
|
||||
type GrowthRecordReq struct {
|
||||
PlantId string `json:"plantId"`
|
||||
Content string `json:"content,optional"`
|
||||
ImgIds []string `json:"imgIds,optional"`
|
||||
}
|
||||
|
||||
type IdPathReq struct {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
type IdReq struct {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type IdsReq struct {
|
||||
Ids []string `json:"ids"`
|
||||
}
|
||||
|
||||
type LevelConfigListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
}
|
||||
|
||||
type OcrReq struct {
|
||||
ImageUrl string `json:"imageUrl"`
|
||||
}
|
||||
|
||||
type PageReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Keyword string `json:"keyword,optional"`
|
||||
}
|
||||
|
||||
type PlantListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
}
|
||||
|
||||
type PostCommentReq struct {
|
||||
PostId string `json:"postId"`
|
||||
Content string `json:"content"`
|
||||
ParentId string `json:"parentId,optional"`
|
||||
}
|
||||
|
||||
type PostListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Keyword string `json:"keyword,optional"`
|
||||
TopicId string `json:"topicId,optional"`
|
||||
}
|
||||
|
||||
type TopicReq struct {
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon,optional"`
|
||||
Desc string `json:"desc,optional"`
|
||||
}
|
||||
|
||||
type UpdatePlantReq struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name,optional"`
|
||||
Status int `json:"status,optional"`
|
||||
Placement string `json:"placement,optional"`
|
||||
PotMaterial string `json:"potMaterial,optional"`
|
||||
PotSize string `json:"potSize,optional"`
|
||||
Sunlight string `json:"sunlight,optional"`
|
||||
PlantingMaterial string `json:"plantingMaterial,optional"`
|
||||
ImgIds []string `json:"imgIds,optional"`
|
||||
}
|
||||
|
||||
type UpdateProfileReq struct {
|
||||
Nickname string `json:"nickname,optional"`
|
||||
AvatarId string `json:"avatarId,optional"`
|
||||
}
|
||||
|
||||
type WikiClassReq struct {
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon,optional"`
|
||||
}
|
||||
|
||||
type WikiListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
ClassId string `json:"classId,optional"`
|
||||
IsHot int `json:"isHot,optional"`
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "植物业务服务API"
|
||||
desc: "我的植物、百科、社区、OCR、兑换、AI等HTTP接口"
|
||||
author: "sundynix"
|
||||
version: "v1.0.0"
|
||||
)
|
||||
|
||||
type (
|
||||
// ---------- 通用 ----------
|
||||
IdReq {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
IdPathReq {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
IdsReq {
|
||||
Ids []string `json:"ids"`
|
||||
}
|
||||
PageReq {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Keyword string `json:"keyword,optional"`
|
||||
}
|
||||
// ---------- 我的植物 ----------
|
||||
CreatePlantReq {
|
||||
Name string `json:"name"`
|
||||
PlantTime string `json:"plantTime"`
|
||||
Status int `json:"status,optional"`
|
||||
Placement string `json:"placement,optional"`
|
||||
PotMaterial string `json:"potMaterial,optional"`
|
||||
PotSize string `json:"potSize,optional"`
|
||||
Sunlight string `json:"sunlight,optional"`
|
||||
PlantingMaterial string `json:"plantingMaterial,optional"`
|
||||
ImgIds []string `json:"imgIds,optional"`
|
||||
}
|
||||
UpdatePlantReq {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name,optional"`
|
||||
Status int `json:"status,optional"`
|
||||
Placement string `json:"placement,optional"`
|
||||
PotMaterial string `json:"potMaterial,optional"`
|
||||
PotSize string `json:"potSize,optional"`
|
||||
Sunlight string `json:"sunlight,optional"`
|
||||
PlantingMaterial string `json:"plantingMaterial,optional"`
|
||||
ImgIds []string `json:"imgIds,optional"`
|
||||
}
|
||||
PlantListReq {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
}
|
||||
// ---------- 养护计划 ----------
|
||||
CarePlanReq {
|
||||
PlantId string `json:"plantId"`
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon,optional"`
|
||||
TargetAction string `json:"targetAction"`
|
||||
Period int `json:"period"`
|
||||
}
|
||||
// ---------- 养护记录 ----------
|
||||
CareRecordReq {
|
||||
PlantId string `json:"plantId"`
|
||||
PlanId string `json:"planId"`
|
||||
Action string `json:"action"`
|
||||
Note string `json:"note,optional"`
|
||||
}
|
||||
// ---------- 成长记录 ----------
|
||||
GrowthRecordReq {
|
||||
PlantId string `json:"plantId"`
|
||||
Content string `json:"content,optional"`
|
||||
ImgIds []string `json:"imgIds,optional"`
|
||||
}
|
||||
// ---------- 百科 ----------
|
||||
WikiListReq {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
ClassId string `json:"classId,optional"`
|
||||
IsHot int `json:"isHot,optional"`
|
||||
}
|
||||
WikiClassReq {
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon,optional"`
|
||||
}
|
||||
// ---------- 帖子 ----------
|
||||
CreatePostReq {
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Location string `json:"location,optional"`
|
||||
ImgIds []string `json:"imgIds,optional"`
|
||||
TopicId string `json:"topicId,optional"`
|
||||
}
|
||||
PostListReq {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Keyword string `json:"keyword,optional"`
|
||||
TopicId string `json:"topicId,optional"`
|
||||
}
|
||||
PostCommentReq {
|
||||
PostId string `json:"postId"`
|
||||
Content string `json:"content"`
|
||||
ParentId string `json:"parentId,optional"`
|
||||
}
|
||||
// ---------- 话题 ----------
|
||||
TopicReq {
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon,optional"`
|
||||
Desc string `json:"desc,optional"`
|
||||
}
|
||||
// ---------- OCR ----------
|
||||
OcrReq {
|
||||
ImageUrl string `json:"imageUrl"`
|
||||
}
|
||||
// ---------- 兑换 ----------
|
||||
ExchangeItemListReq {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
}
|
||||
ExchangeOrderReq {
|
||||
ItemId string `json:"itemId"`
|
||||
}
|
||||
// ---------- AI ----------
|
||||
AiChatReq {
|
||||
Question string `json:"question"`
|
||||
}
|
||||
// ---------- 用户资料 ----------
|
||||
UpdateProfileReq {
|
||||
Nickname string `json:"nickname,optional"`
|
||||
AvatarId string `json:"avatarId,optional"`
|
||||
}
|
||||
// ---------- 等级/徽章配置 ----------
|
||||
LevelConfigListReq {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
}
|
||||
BadgeConfigListReq {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Dimension string `json:"dimension,optional"`
|
||||
}
|
||||
)
|
||||
|
||||
// ========== 无需鉴权 ==========
|
||||
@server (
|
||||
prefix: /api/plant
|
||||
group: callback
|
||||
)
|
||||
service plant-api {
|
||||
@doc "微信支付回调"
|
||||
@handler WechatPayCallback
|
||||
post /callback/wechatpay
|
||||
}
|
||||
|
||||
// ========== 需要鉴权 ==========
|
||||
@server (
|
||||
prefix: /api/plant
|
||||
group: myPlant
|
||||
jwt: Auth
|
||||
)
|
||||
service plant-api {
|
||||
@doc "创建植物"
|
||||
@handler CreatePlant
|
||||
post /my/create (CreatePlantReq)
|
||||
|
||||
@doc "更新植物"
|
||||
@handler UpdatePlant
|
||||
put /my/update (UpdatePlantReq)
|
||||
|
||||
@doc "删除植物"
|
||||
@handler DeletePlant
|
||||
delete /my/delete (IdsReq)
|
||||
|
||||
@doc "我的植物列表"
|
||||
@handler GetMyPlantList
|
||||
post /my/list (PlantListReq)
|
||||
|
||||
@doc "植物详情"
|
||||
@handler GetPlantDetail
|
||||
get /my/:id (IdPathReq)
|
||||
|
||||
@doc "添加养护计划"
|
||||
@handler AddCarePlan
|
||||
post /my/carePlan (CarePlanReq)
|
||||
|
||||
@doc "添加养护记录"
|
||||
@handler AddCareRecord
|
||||
post /my/careRecord (CareRecordReq)
|
||||
|
||||
@doc "添加成长记录"
|
||||
@handler AddGrowthRecord
|
||||
post /my/growthRecord (GrowthRecordReq)
|
||||
}
|
||||
|
||||
@server (
|
||||
prefix: /api/plant
|
||||
group: wiki
|
||||
jwt: Auth
|
||||
)
|
||||
service plant-api {
|
||||
@doc "百科列表"
|
||||
@handler GetWikiList
|
||||
post /wiki/list (WikiListReq)
|
||||
|
||||
@doc "百科详情"
|
||||
@handler GetWikiDetail
|
||||
get /wiki/:id (IdPathReq)
|
||||
|
||||
@doc "百科分类列表"
|
||||
@handler GetWikiClassList
|
||||
get /wiki/class/list
|
||||
|
||||
@doc "创建百科分类"
|
||||
@handler CreateWikiClass
|
||||
post /wiki/class/create (WikiClassReq)
|
||||
|
||||
@doc "收藏/取消收藏百科"
|
||||
@handler ToggleWikiStar
|
||||
post /wiki/star (IdReq)
|
||||
}
|
||||
|
||||
@server (
|
||||
prefix: /api/plant
|
||||
group: post
|
||||
jwt: Auth
|
||||
)
|
||||
service plant-api {
|
||||
@doc "发布帖子"
|
||||
@handler CreatePost
|
||||
post /post/create (CreatePostReq)
|
||||
|
||||
@doc "帖子列表"
|
||||
@handler GetPostList
|
||||
post /post/list (PostListReq)
|
||||
|
||||
@doc "帖子详情"
|
||||
@handler GetPostDetail
|
||||
get /post/:id (IdPathReq)
|
||||
|
||||
@doc "删除帖子"
|
||||
@handler DeletePost
|
||||
delete /post/delete (IdsReq)
|
||||
|
||||
@doc "评论帖子"
|
||||
@handler CommentPost
|
||||
post /post/comment (PostCommentReq)
|
||||
|
||||
@doc "点赞帖子"
|
||||
@handler LikePost
|
||||
post /post/like (IdReq)
|
||||
}
|
||||
|
||||
@server (
|
||||
prefix: /api/plant
|
||||
group: topic
|
||||
jwt: Auth
|
||||
)
|
||||
service plant-api {
|
||||
@doc "话题列表"
|
||||
@handler GetTopicList
|
||||
get /topic/list
|
||||
|
||||
@doc "创建话题"
|
||||
@handler CreateTopic
|
||||
post /topic/create (TopicReq)
|
||||
|
||||
@doc "删除话题"
|
||||
@handler DeleteTopic
|
||||
delete /topic/delete (IdsReq)
|
||||
}
|
||||
|
||||
@server (
|
||||
prefix: /api/plant
|
||||
group: ocr
|
||||
jwt: Auth
|
||||
)
|
||||
service plant-api {
|
||||
@doc "OCR植物识别"
|
||||
@handler OcrClassify
|
||||
post /ocr/classify (OcrReq)
|
||||
}
|
||||
|
||||
@server (
|
||||
prefix: /api/plant
|
||||
group: exchange
|
||||
jwt: Auth
|
||||
)
|
||||
service plant-api {
|
||||
@doc "兑换商品列表"
|
||||
@handler GetExchangeItemList
|
||||
post /exchange/list (ExchangeItemListReq)
|
||||
|
||||
@doc "兑换商品"
|
||||
@handler CreateExchangeOrder
|
||||
post /exchange/order (ExchangeOrderReq)
|
||||
}
|
||||
|
||||
@server (
|
||||
prefix: /api/plant
|
||||
group: ai
|
||||
jwt: Auth
|
||||
)
|
||||
service plant-api {
|
||||
@doc "AI问答"
|
||||
@handler AiChat
|
||||
post /ai/chat (AiChatReq)
|
||||
|
||||
@doc "聊天历史"
|
||||
@handler GetAiChatHistory
|
||||
get /ai/history
|
||||
}
|
||||
|
||||
@server (
|
||||
prefix: /api/plant
|
||||
group: userProfile
|
||||
jwt: Auth
|
||||
)
|
||||
service plant-api {
|
||||
@doc "获取用户资料"
|
||||
@handler GetUserProfile
|
||||
get /profile/info
|
||||
|
||||
@doc "更新用户资料"
|
||||
@handler UpdateUserProfile
|
||||
put /profile/update (UpdateProfileReq)
|
||||
}
|
||||
|
||||
@server (
|
||||
prefix: /api/plant
|
||||
group: config
|
||||
jwt: Auth
|
||||
)
|
||||
service plant-api {
|
||||
@doc "等级配置列表"
|
||||
@handler GetLevelConfigList
|
||||
post /config/level/list (LevelConfigListReq)
|
||||
|
||||
@doc "徽章配置列表"
|
||||
@handler GetBadgeConfigList
|
||||
post /config/badge/list (BadgeConfigListReq)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/config"
|
||||
"sundynix-micro-go/app/plant/api/internal/handler"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/plant-api.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rest.MustNewServer(c.RestConf)
|
||||
defer server.Stop()
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"sundynix-micro-go/common/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ========== 用户扩展表(plant业务特有字段) ==========
|
||||
|
||||
// SundynixPlantUserProfile 植物服务用户扩展表
|
||||
type SundynixPlantUserProfile struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;uniqueIndex;column:user_id" json:"userId"`
|
||||
NickName string `gorm:"size:100;column:nick_name" json:"nickName"`
|
||||
AvatarID string `gorm:"size:50;column:avatar_id" json:"avatarId"`
|
||||
LevelID string `gorm:"size:50;column:level_id" json:"levelId"`
|
||||
CurrentSunlight int64 `gorm:"not null;default:0;column:current_sunlight" json:"currentSunlight"`
|
||||
TotalSunlight int64 `gorm:"not null;default:0;column:total_sunlight" json:"totalSunlight"`
|
||||
PlantCount int64 `gorm:"not null;default:0;column:plant_count" json:"plantCount"`
|
||||
CareCount int64 `gorm:"not null;default:0;column:care_count" json:"careCount"`
|
||||
PostCount int64 `gorm:"not null;default:0;column:post_count" json:"postCount"`
|
||||
WaterCount int64 `gorm:"not null;default:0;column:water_count" json:"waterCount"`
|
||||
FertilizeCount int64 `gorm:"not null;default:0;column:fertilize_count" json:"fertilizeCount"`
|
||||
RepotCount int64 `gorm:"not null;default:0;column:repot_count" json:"repotCount"`
|
||||
PruneCount int64 `gorm:"not null;default:0;column:prune_count" json:"pruneCount"`
|
||||
PhotoCount int64 `gorm:"not null;default:0;column:photo_count" json:"photoCount"`
|
||||
}
|
||||
|
||||
func (SundynixPlantUserProfile) TableName() string {
|
||||
return "sundynix_plant_user_profile"
|
||||
}
|
||||
|
||||
// ========== 我的植物 ==========
|
||||
|
||||
// SundynixMyPlant 我的植物
|
||||
type SundynixMyPlant struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;index;column:user_id" json:"userId"`
|
||||
Name string `gorm:"size:20;column:name" json:"name"`
|
||||
PlantTime time.Time `gorm:"column:plant_time" json:"plantTime"`
|
||||
Status int `gorm:"column:status" json:"status"`
|
||||
Placement string `gorm:"size:50;column:placement" json:"placement"`
|
||||
PotMaterial string `gorm:"size:50;column:pot_material" json:"potMaterial"`
|
||||
PotSize string `gorm:"size:50;column:pot_size" json:"potSize"`
|
||||
Sunlight string `gorm:"size:50;column:sunlight" json:"sunlight"`
|
||||
PlantingMaterial string `gorm:"size:50;column:planting_material" json:"plantingMaterial"`
|
||||
}
|
||||
|
||||
func (SundynixMyPlant) TableName() string {
|
||||
return "sundynix_my_plant"
|
||||
}
|
||||
|
||||
// SundynixMyPlantOss 植物图片关联表
|
||||
type SundynixMyPlantOss struct {
|
||||
MyPlantID string `gorm:"size:50;primaryKey;column:sundynix_my_plant_id" json:"myPlantId"`
|
||||
OssID string `gorm:"size:50;primaryKey;column:sundynix_oss_id" json:"ossId"`
|
||||
}
|
||||
|
||||
func (SundynixMyPlantOss) TableName() string {
|
||||
return "sundynix_my_plant_oss"
|
||||
}
|
||||
|
||||
// ========== 养护计划/记录 ==========
|
||||
|
||||
// SundynixCarePlan 养护计划
|
||||
type SundynixCarePlan struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;column:user_id" json:"userId"`
|
||||
PlantID string `gorm:"size:50;index;column:plant_id" json:"plantId"`
|
||||
Icon string `gorm:"type:text;column:icon" json:"icon"`
|
||||
Name string `gorm:"size:50;column:name" json:"name"`
|
||||
Period int `gorm:"column:period" json:"period"`
|
||||
TargetAction string `gorm:"size:32;index;column:target_action" json:"targetAction"`
|
||||
}
|
||||
|
||||
func (SundynixCarePlan) TableName() string {
|
||||
return "sundynix_care_plan"
|
||||
}
|
||||
|
||||
// SundynixCareRecord 养护记录
|
||||
type SundynixCareRecord struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;column:user_id" json:"userId"`
|
||||
PlantID string `gorm:"size:50;index;column:plant_id" json:"plantId"`
|
||||
PlanID string `gorm:"size:50;index;column:plan_id" json:"planId"`
|
||||
Name string `gorm:"size:50;column:name" json:"name"`
|
||||
Remark string `gorm:"size:200;column:remark" json:"remark"`
|
||||
Icon string `gorm:"type:text;column:icon" json:"icon"`
|
||||
}
|
||||
|
||||
func (SundynixCareRecord) TableName() string {
|
||||
return "sundynix_care_record"
|
||||
}
|
||||
|
||||
// SundynixCareTask 养护任务
|
||||
type SundynixCareTask struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;column:user_id" json:"userId"`
|
||||
PlantID string `gorm:"size:50;index;column:plant_id" json:"plantId"`
|
||||
PlanID string `gorm:"size:50;index;column:plan_id" json:"planId"`
|
||||
Name string `gorm:"size:50;column:name" json:"name"`
|
||||
Icon string `gorm:"type:text;column:icon" json:"icon"`
|
||||
TargetAction string `gorm:"size:32;column:target_action" json:"targetAction"`
|
||||
DueDate time.Time `gorm:"column:due_date" json:"dueDate"`
|
||||
Status int `gorm:"default:1;column:status" json:"status"`
|
||||
}
|
||||
|
||||
func (SundynixCareTask) TableName() string {
|
||||
return "sundynix_care_task"
|
||||
}
|
||||
|
||||
// SundynixGrowthRecord 成长记录
|
||||
type SundynixGrowthRecord struct {
|
||||
model.BaseModel
|
||||
PlantID string `gorm:"size:50;index;column:plant_id" json:"plantId"`
|
||||
UserID string `gorm:"size:50;index;column:user_id" json:"userId"`
|
||||
Name string `gorm:"size:50;column:name" json:"name"`
|
||||
Tag string `gorm:"size:50;column:tag" json:"tag"`
|
||||
Desc string `gorm:"size:200;column:desc" json:"desc"`
|
||||
Content string `gorm:"size:200;column:content" json:"content"`
|
||||
}
|
||||
|
||||
func (SundynixGrowthRecord) TableName() string {
|
||||
return "sundynix_growth_record"
|
||||
}
|
||||
|
||||
// ========== 百科 ==========
|
||||
|
||||
// SundynixWiki 植物百科
|
||||
type SundynixWiki struct {
|
||||
model.BaseModel
|
||||
IsHot int `gorm:"column:is_hot" json:"isHot"`
|
||||
Name string `gorm:"size:50;column:name" json:"name"`
|
||||
LatinName string `gorm:"size:100;column:latin_name" json:"latinName"`
|
||||
Aliases string `gorm:"size:100;column:aliases" json:"aliases"`
|
||||
DistributionArea string `gorm:"type:text;column:distribution_area" json:"distributionArea"`
|
||||
Genus string `gorm:"size:20;column:genus" json:"genus"`
|
||||
Difficulty int `gorm:"column:difficulty" json:"difficulty"`
|
||||
LifeCycle string `gorm:"type:text;column:life_cycle" json:"lifeCycle"`
|
||||
GrowthHabit string `gorm:"type:text;column:growth_habit" json:"growthHabit"`
|
||||
ReproductionMethod string `gorm:"size:200;column:reproduction_method" json:"reproductionMethod"`
|
||||
PestsDiseases string `gorm:"size:200;column:pests_diseases" json:"pestsDiseases"`
|
||||
LightIntensity string `gorm:"size:50;column:light_intensity" json:"lightIntensity"`
|
||||
LightType string `gorm:"size:50;column:light_type" json:"lightType"`
|
||||
OptimalTempPeriod string `gorm:"size:30;column:optimal_temp_period" json:"optimalTempPeriod"`
|
||||
Stem string `gorm:"size:200;column:stem" json:"stem"`
|
||||
FoliageType string `gorm:"size:200;column:foliage_type" json:"foliageType"`
|
||||
FoliageColor string `gorm:"size:200;column:foliage_color" json:"foliageColor"`
|
||||
FoliageShape string `gorm:"size:200;column:foliage_shape" json:"foliageShape"`
|
||||
Height int `gorm:"column:height" json:"height"`
|
||||
FloweringPeriod string `gorm:"size:100;column:flowering_period" json:"floweringPeriod"`
|
||||
FloweringColor string `gorm:"size:100;column:flowering_color" json:"floweringColor"`
|
||||
FloweringShape string `gorm:"size:100;column:flowering_shape" json:"floweringShape"`
|
||||
FlowerDiameter int `gorm:"column:flower_diameter" json:"flowerDiameter"`
|
||||
Fruit string `gorm:"size:200;column:fruit" json:"fruit"`
|
||||
}
|
||||
|
||||
func (SundynixWiki) TableName() string {
|
||||
return "sundynix_wiki"
|
||||
}
|
||||
|
||||
// SundynixWikiClass 百科分类
|
||||
type SundynixWikiClass struct {
|
||||
model.BaseModel
|
||||
Name string `gorm:"size:50;column:name" json:"name"`
|
||||
OssID string `gorm:"size:50;column:oss_id" json:"ossId"`
|
||||
}
|
||||
|
||||
func (SundynixWikiClass) TableName() string {
|
||||
return "sundynix_wiki_class"
|
||||
}
|
||||
|
||||
// SundynixUserStar 用户收藏
|
||||
type SundynixUserStar struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;index;column:user_id" json:"userId"`
|
||||
TargetID string `gorm:"size:50;index;column:target_id" json:"targetId"`
|
||||
Type string `gorm:"size:20;column:type" json:"type"` // wiki/post
|
||||
}
|
||||
|
||||
func (SundynixUserStar) TableName() string {
|
||||
return "sundynix_user_star"
|
||||
}
|
||||
|
||||
// ========== 社区 ==========
|
||||
|
||||
// SundynixPost 社区帖子
|
||||
type SundynixPost struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;index;column:user_id" json:"userId"`
|
||||
Title string `gorm:"size:100;column:title" json:"title"`
|
||||
Content string `gorm:"size:500;column:content" json:"content"`
|
||||
ViewCount int `gorm:"default:0;column:view_count" json:"viewCount"`
|
||||
CommentCount int `gorm:"default:0;column:comment_count" json:"commentCount"`
|
||||
LikeCount int `gorm:"default:0;column:like_count" json:"likeCount"`
|
||||
StarCount int `gorm:"default:0;column:star_count" json:"starCount"`
|
||||
Location string `gorm:"size:100;column:location" json:"location"`
|
||||
HasReviewed int `gorm:"default:0;column:has_reviewed" json:"hasReviewed"`
|
||||
}
|
||||
|
||||
func (SundynixPost) TableName() string {
|
||||
return "sundynix_post"
|
||||
}
|
||||
|
||||
// SundynixPostComment 帖子评论
|
||||
type SundynixPostComment struct {
|
||||
model.BaseModel
|
||||
PostID string `gorm:"size:50;index;column:post_id" json:"postId"`
|
||||
UserID string `gorm:"size:50;column:user_id" json:"userId"`
|
||||
Content string `gorm:"size:500;column:content" json:"content"`
|
||||
ParentID string `gorm:"size:50;column:parent_id" json:"parentId"`
|
||||
}
|
||||
|
||||
func (SundynixPostComment) TableName() string {
|
||||
return "sundynix_post_comment"
|
||||
}
|
||||
|
||||
// SundynixPostLike 帖子点赞
|
||||
type SundynixPostLike struct {
|
||||
model.BaseModel
|
||||
PostID string `gorm:"size:50;index;column:post_id" json:"postId"`
|
||||
UserID string `gorm:"size:50;index;column:user_id" json:"userId"`
|
||||
}
|
||||
|
||||
func (SundynixPostLike) TableName() string {
|
||||
return "sundynix_post_like"
|
||||
}
|
||||
|
||||
// SundynixPostTopic 话题
|
||||
type SundynixPostTopic struct {
|
||||
model.BaseModel
|
||||
Name string `gorm:"size:50;column:name" json:"name"`
|
||||
PostCount int `gorm:"default:0;column:post_count" json:"postCount"`
|
||||
}
|
||||
|
||||
func (SundynixPostTopic) TableName() string {
|
||||
return "sundynix_post_topic"
|
||||
}
|
||||
|
||||
// ========== 积分商城 ==========
|
||||
|
||||
// SundynixExchangeItem 兑换商品
|
||||
type SundynixExchangeItem struct {
|
||||
model.BaseModel
|
||||
Name string `gorm:"size:100;column:name" json:"name"`
|
||||
Desc string `gorm:"size:200;column:desc" json:"desc"`
|
||||
ImgID string `gorm:"size:50;column:img_id" json:"imgId"`
|
||||
Cost int64 `gorm:"column:cost" json:"cost"`
|
||||
Stock int `gorm:"column:stock" json:"stock"`
|
||||
Status int `gorm:"default:1;column:status" json:"status"`
|
||||
}
|
||||
|
||||
func (SundynixExchangeItem) TableName() string {
|
||||
return "sundynix_exchange_item"
|
||||
}
|
||||
|
||||
// SundynixExchangeOrder 兑换订单
|
||||
type SundynixExchangeOrder struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;index;column:user_id" json:"userId"`
|
||||
ItemID string `gorm:"size:50;column:item_id" json:"itemId"`
|
||||
Cost int64 `gorm:"column:cost" json:"cost"`
|
||||
Status int `gorm:"default:0;column:status" json:"status"`
|
||||
Address string `gorm:"size:200;column:address" json:"address"`
|
||||
}
|
||||
|
||||
func (SundynixExchangeOrder) TableName() string {
|
||||
return "sundynix_exchange_order"
|
||||
}
|
||||
|
||||
// ========== 等级/徽章配置 ==========
|
||||
|
||||
// SundynixLevelConfig 等级配置
|
||||
type SundynixLevelConfig struct {
|
||||
model.BaseModel
|
||||
Level int `gorm:"column:level" json:"level"`
|
||||
Title string `gorm:"size:50;column:title" json:"title"`
|
||||
MinSunlight int64 `gorm:"column:min_sunlight" json:"minSunlight"`
|
||||
Perks string `gorm:"size:200;column:perks" json:"perks"`
|
||||
}
|
||||
|
||||
func (SundynixLevelConfig) TableName() string {
|
||||
return "sundynix_level_config"
|
||||
}
|
||||
|
||||
// SundynixBadgeConfig 徽章配置
|
||||
type SundynixBadgeConfig struct {
|
||||
model.BaseModel
|
||||
Name string `gorm:"size:64;column:name" json:"name"`
|
||||
Description string `gorm:"size:255;column:description" json:"description"`
|
||||
IconID string `gorm:"size:50;column:icon_id" json:"iconId"`
|
||||
Dimension string `gorm:"size:32;index;column:dimension" json:"dimension"`
|
||||
GroupID string `gorm:"size:64;index;column:group_id" json:"groupId"`
|
||||
Tier int `gorm:"default:1;column:tier" json:"tier"`
|
||||
TargetAction string `gorm:"size:32;index;column:target_action" json:"targetAction"`
|
||||
Threshold int64 `gorm:"column:threshold" json:"threshold"`
|
||||
Comparator string `gorm:"size:10;default:'>=';column:comparator" json:"comparator"`
|
||||
RewardSunlight int64 `gorm:"column:reward_sunlight" json:"rewardSunlight"`
|
||||
Sort int `gorm:"default:1;column:sort" json:"sort"`
|
||||
}
|
||||
|
||||
func (SundynixBadgeConfig) TableName() string {
|
||||
return "sundynix_badge_config"
|
||||
}
|
||||
|
||||
// SundynixUserBadge 用户徽章
|
||||
type SundynixUserBadge struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;index;column:user_id" json:"userId"`
|
||||
BadgeID string `gorm:"size:50;index;column:badge_id" json:"badgeId"`
|
||||
}
|
||||
|
||||
func (SundynixUserBadge) TableName() string {
|
||||
return "sundynix_user_badge"
|
||||
}
|
||||
|
||||
// SundynixAiChatHistory AI聊天历史
|
||||
type SundynixAiChatHistory struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;index;column:user_id" json:"userId"`
|
||||
Role string `gorm:"size:20;column:role" json:"role"`
|
||||
Content string `gorm:"type:text;column:content" json:"content"`
|
||||
}
|
||||
|
||||
func (SundynixAiChatHistory) TableName() string {
|
||||
return "sundynix_ai_chat_history"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
Name: plant.rpc
|
||||
ListenOn: 0.0.0.0:8080
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 127.0.0.1:2379
|
||||
Key: plant.rpc
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user