Commit f24a7fa1 authored by zhengyaoqiu's avatar zhengyaoqiu

feat(database): 核心表

parent eae0a50b
...@@ -4,7 +4,7 @@ go 1.24.3 ...@@ -4,7 +4,7 @@ go 1.24.3
require ( require (
git.chillcy.com/golang/chillcy/pkg v0.0.0-20250627035541-7956996f27ce git.chillcy.com/golang/chillcy/pkg v0.0.0-20250627035541-7956996f27ce
github.com/iancoleman/strcase v0.3.0 git.chillcy.com/golang/chillcy/project/pc4 v0.0.0-20250630014959-9d2b4facb28b
github.com/zeromicro/go-zero v1.8.4 github.com/zeromicro/go-zero v1.8.4
google.golang.org/grpc v1.73.0 google.golang.org/grpc v1.73.0
google.golang.org/protobuf v1.36.6 google.golang.org/protobuf v1.36.6
...@@ -43,7 +43,7 @@ require ( ...@@ -43,7 +43,7 @@ require (
github.com/jinzhu/now v1.1.5 // indirect github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect github.com/klauspost/compress v1.18.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
......
...@@ -2,6 +2,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= ...@@ -2,6 +2,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
git.chillcy.com/golang/chillcy/pkg v0.0.0-20250627035541-7956996f27ce h1:JBhBnnNR7DCqi67fxfLC7ZIJJXJP4jMTtP8DeW9XcJQ= git.chillcy.com/golang/chillcy/pkg v0.0.0-20250627035541-7956996f27ce h1:JBhBnnNR7DCqi67fxfLC7ZIJJXJP4jMTtP8DeW9XcJQ=
git.chillcy.com/golang/chillcy/pkg v0.0.0-20250627035541-7956996f27ce/go.mod h1:1N8ux+rPaW+/OT74EGSz2oX51NvsEK3H4nlBZ+5Xx0M= git.chillcy.com/golang/chillcy/pkg v0.0.0-20250627035541-7956996f27ce/go.mod h1:1N8ux+rPaW+/OT74EGSz2oX51NvsEK3H4nlBZ+5Xx0M=
git.chillcy.com/golang/chillcy/project/pc4 v0.0.0-20250630014959-9d2b4facb28b h1:Lr5xxH47rdzrsMiClgZ5UH51RLMp/It08GSA+gfIsxg=
git.chillcy.com/golang/chillcy/project/pc4 v0.0.0-20250630014959-9d2b4facb28b/go.mod h1:+oGrruo/MyXkrh5VPjDu/jvHN7tZGNkdZiKMJ/gIi4c=
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI= github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM= github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
...@@ -75,8 +77,6 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1 ...@@ -75,8 +77,6 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
...@@ -87,8 +87,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr ...@@ -87,8 +87,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
......
...@@ -12,6 +12,13 @@ type Manager struct { ...@@ -12,6 +12,13 @@ type Manager struct {
CompleteSpuRepository repository.CompleteSpuInterface CompleteSpuRepository repository.CompleteSpuInterface
ColorSpuRepository repository.ColorSpuInterface ColorSpuRepository repository.ColorSpuInterface
SkuRepository repository.SkuInterface SkuRepository repository.SkuInterface
CategoryRepository repository.CategoryInterface
CompositionRepository repository.CompositionInterface
FitRepository repository.FitInterface
GenderRepository repository.GenderInterface
ImageRepository repository.ImageInterface
ModelRepository repository.ModelInterface
ProductRepository repository.ProductInterface
} }
func (receiver *Manager) init() error { func (receiver *Manager) init() error {
...@@ -58,6 +65,13 @@ func NewManager(dsn string) (*Manager, error) { ...@@ -58,6 +65,13 @@ func NewManager(dsn string) (*Manager, error) {
CompleteSpuRepository: repository.NewCompleteSpu(db), CompleteSpuRepository: repository.NewCompleteSpu(db),
ColorSpuRepository: repository.NewColorSpu(db), ColorSpuRepository: repository.NewColorSpu(db),
SkuRepository: repository.NewSku(db), SkuRepository: repository.NewSku(db),
CategoryRepository: repository.NewCategory(db),
CompositionRepository: repository.NewComposition(db),
FitRepository: repository.NewFit(db),
GenderRepository: repository.NewGender(db),
ImageRepository: repository.NewImage(db),
ModelRepository: repository.NewModel(db),
ProductRepository: repository.NewProduct(db),
} }
err = manager.init() err = manager.init()
return manager, err return manager, err
......
package model
import "gorm.io/gorm"
type Category struct {
gorm.Model
Code string `gorm:"uniqueIndex; size:50"`
Name string `gorm:"size:50"`
Level int `gorm:"not null"`
}
type Categories []Category
...@@ -4,10 +4,21 @@ import "gorm.io/gorm" ...@@ -4,10 +4,21 @@ import "gorm.io/gorm"
type ColorSpu struct { type ColorSpu struct {
gorm.Model gorm.Model
StyleNumber string `gorm:"uniqueIndex:style; size:50; not null"` CompleteSpuStyleNumber string `gorm:"uniqueIndex:style; size:50; not null"`
ColorCode string `gorm:"uniqueIndex:style; size:50; not null"` ColorCode string `gorm:"uniqueIndex:style; size:50; not null"`
Color Color `gorm:"embedded;embeddedPrefix:color_"`
// 外键 // 外键
Skus Skus `gorm:"foreignKey:StyleNumber,ColorCode; references:StyleNumber,ColorCode; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // 多对一
Skus []Sku `gorm:"foreignKey:ColorSpuStyleNumber,ColorSpuColorCode; references:CompleteSpuStyleNumber,ColorCode; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Images []Image `gorm:"foreignKey:ColorSpuStyleNumber,ColorSpuColorCode; references:CompleteSpuStyleNumber,ColorCode; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
} }
type ColorSpus []ColorSpu type ColorSpus []ColorSpu
type Color struct {
Id string `gorm:"size:50; not null"`
Name string `gorm:"size:50; not null"`
BasicId string `gorm:"size:50; not null"`
BasicName string `gorm:"size:50; not null"`
}
...@@ -5,10 +5,30 @@ import "gorm.io/gorm" ...@@ -5,10 +5,30 @@ import "gorm.io/gorm"
type CompleteSpu struct { type CompleteSpu struct {
gorm.Model gorm.Model
StyleNumber string `gorm:"uniqueIndex; size:50; not null"` StyleNumber string `gorm:"uniqueIndex; size:50; not null"`
Title string `gorm:"size:100"` Title Title `gorm:"embedded;embeddedPrefix:title_"`
Description string `gorm:"type:text"` Description string `gorm:"type:text"`
Gender string `gorm:"size:20; not null"`
Season string `gorm:"size:20"` Season string `gorm:"size:20"`
BrandId string `gorm:"size:50"`
Care string `gorm:"type:text"`
MadeIn string `gorm:"size:50"`
HsCode string `gorm:"size:50"`
// 外键 // 外键
ColorSpus ColorSpus `gorm:"foreignKey:StyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // 多对一
ColorSpus ColorSpus `gorm:"foreignKey:CompleteSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Products Products `gorm:"foreignKey:CompleteSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Compositions Compositions `gorm:"foreignKey:CompleteSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Skus Skus `gorm:"foreignKey:ColorSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Models Models `gorm:"foreignKey:CompleteSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Fits Fits `gorm:"foreignKey:CompleteSpuStyleNumber; references:StyleNumber; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
// 多对多
Genders Genders `gorm:"many2many:completespu_genders;foreignKey:StyleNumber; References:Code;"`
Categories Categories `gorm:"many2many:completespu_categories;foreignKey:StyleNumber; References:Code;"`
}
type CompleteSpus []CompleteSpu
type Title struct {
En string `gorm:"size:100"`
Cn string `gorm:"size:100"`
} }
package model
import "gorm.io/gorm"
type Composition struct {
gorm.Model
CompleteSpuStyleNumber string `gorm:"index; size:50; not null"`
Part string `gorm:"size:50"`
Material string `gorm:"size:50"`
Value string `gorm:"size:50"`
}
type Compositions []Composition
package model
import "gorm.io/gorm"
type Fit struct {
gorm.Model
CompleteSpuStyleNumber string `gorm:"index; size:50; not null"`
Content string `gorm:"type:text"`
}
type Fits []Fit
package model
import "gorm.io/gorm"
type Gender struct {
gorm.Model
Code string `gorm:"uniqueIndex; size:20; not null"`
Name string `gorm:"size:20; not null"`
}
type Genders []Gender
package model
import "gorm.io/gorm"
type Image struct {
gorm.Model
ColorSpuStyleNumber string `gorm:"index:style; size:50; not null"`
ColorSpuColorCode string `gorm:"index:style; size:50; not null"`
Url string `gorm:"size:256"`
}
type Images []Image
package model
import "gorm.io/gorm"
type Model struct {
gorm.Model
CompleteSpuStyleNumber string `gorm:"index; size:50; not null"`
Content string `gorm:"type:text"`
}
type Models []Model
package model
import "gorm.io/gorm"
type Product struct {
gorm.Model
Pc3IdHex string `gorm:"uniqueIndex; not null; size:24"`
CompleteSpuStyleNumber string `gorm:"index; size:50; not null"`
}
type Products []Product
...@@ -5,8 +5,8 @@ import "gorm.io/gorm" ...@@ -5,8 +5,8 @@ import "gorm.io/gorm"
type Sku struct { type Sku struct {
gorm.Model gorm.Model
Pc3SkuId string `gorm:"uniqueIndex; not null; size:24"` Pc3SkuId string `gorm:"uniqueIndex; not null; size:24"`
StyleNumber string `gorm:"size:50; not null"` ColorSpuStyleNumber string `gorm:"size:50; not null"`
ColorCode string `gorm:"size:50; not null"` ColorSpuColorCode string `gorm:"size:50; not null"`
Source string `gorm:"size:50; not null"` Source string `gorm:"size:50; not null"`
Site string `gorm:"size:50; not null"` Site string `gorm:"size:50; not null"`
Size string `gorm:"size:50; not null"` Size string `gorm:"size:50; not null"`
......
package repository
import (
"git.chillcy.com/golang/colorway/internal/pkg/database/model"
"gorm.io/gorm"
)
type CategoryInterface interface {
BaseInterface
}
type Category struct {
*Base[model.Category]
}
func NewCategory(db *gorm.DB) *Category {
return &Category{
Base: NewBase[model.Category](db),
}
}
package repository
import (
"git.chillcy.com/golang/colorway/internal/pkg/database/model"
"gorm.io/gorm"
)
type CompositionInterface interface {
BaseInterface
}
type Composition struct {
*Base[model.Composition]
}
func NewComposition(db *gorm.DB) *Composition {
return &Composition{
Base: NewBase[model.Composition](db),
}
}
package repository
import (
"git.chillcy.com/golang/colorway/internal/pkg/database/model"
"gorm.io/gorm"
)
type FitInterface interface {
BaseInterface
}
type Fit struct {
*Base[model.Fit]
}
func NewFit(db *gorm.DB) *Fit {
return &Fit{
Base: NewBase[model.Fit](db),
}
}
package repository
import (
"git.chillcy.com/golang/colorway/internal/pkg/database/model"
"gorm.io/gorm"
)
type GenderInterface interface {
BaseInterface
}
type Gender struct {
*Base[model.Gender]
}
func NewGender(db *gorm.DB) *Gender {
return &Gender{
Base: NewBase[model.Gender](db),
}
}
package repository
import (
"git.chillcy.com/golang/colorway/internal/pkg/database/model"
"gorm.io/gorm"
)
type ImageInterface interface {
BaseInterface
}
type Image struct {
*Base[model.Image]
}
func NewImage(db *gorm.DB) *Image {
return &Image{
Base: NewBase[model.Image](db),
}
}
package repository
import (
"git.chillcy.com/golang/colorway/internal/pkg/database/model"
"gorm.io/gorm"
)
type ModelInterface interface {
BaseInterface
}
type Model struct {
*Base[model.Model]
}
func NewModel(db *gorm.DB) *Model {
return &Model{
Base: NewBase[model.Model](db),
}
}
package repository
import (
"git.chillcy.com/golang/colorway/internal/pkg/database/model"
"gorm.io/gorm"
)
type ProductInterface interface {
BaseInterface
}
type Product struct {
*Base[model.Product]
}
func NewProduct(db *gorm.DB) *Product {
return &Product{
Base: NewBase[model.Product](db),
}
}
...@@ -13,6 +13,8 @@ import ( ...@@ -13,6 +13,8 @@ import (
) )
type ( type (
ProductUploadRequest = colorway.ProductUploadRequest
ProductUploadResponse = colorway.ProductUploadResponse
Request = colorway.Request Request = colorway.Request
Response = colorway.Response Response = colorway.Response
......
// Code generated by goctl. DO NOT EDIT.
// Source: colorway.proto
package product
import (
"context"
"git.chillcy.com/golang/colorway/internal/rpc/pb/colorway"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
ProductUploadRequest = colorway.ProductUploadRequest
ProductUploadResponse = colorway.ProductUploadResponse
Request = colorway.Request
Response = colorway.Response
Product interface {
Upload(ctx context.Context, in *ProductUploadRequest, opts ...grpc.CallOption) (*ProductUploadResponse, error)
}
defaultProduct struct {
cli zrpc.Client
}
)
func NewProduct(cli zrpc.Client) Product {
return &defaultProduct{
cli: cli,
}
}
func (m *defaultProduct) Upload(ctx context.Context, in *ProductUploadRequest, opts ...grpc.CallOption) (*ProductUploadResponse, error) {
client := colorway.NewProductClient(m.cli.Conn())
return client.Upload(ctx, in, opts...)
}
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"git.chillcy.com/golang/colorway/internal/rpc/internal/config" "git.chillcy.com/golang/colorway/internal/rpc/internal/config"
colorwayServer "git.chillcy.com/golang/colorway/internal/rpc/internal/server/colorway" colorwayServer "git.chillcy.com/golang/colorway/internal/rpc/internal/server/colorway"
productServer "git.chillcy.com/golang/colorway/internal/rpc/internal/server/product"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc" "git.chillcy.com/golang/colorway/internal/rpc/internal/svc"
"git.chillcy.com/golang/colorway/internal/rpc/pb/colorway" "git.chillcy.com/golang/colorway/internal/rpc/pb/colorway"
...@@ -27,6 +28,7 @@ func main() { ...@@ -27,6 +28,7 @@ func main() {
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
colorway.RegisterColorwayServer(grpcServer, colorwayServer.NewColorwayServer(ctx)) colorway.RegisterColorwayServer(grpcServer, colorwayServer.NewColorwayServer(ctx))
colorway.RegisterProductServer(grpcServer, productServer.NewProductServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode { if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer) reflection.Register(grpcServer)
......
...@@ -3,6 +3,8 @@ syntax = "proto3"; ...@@ -3,6 +3,8 @@ syntax = "proto3";
package colorway; package colorway;
option go_package="./colorway"; option go_package="./colorway";
// ============================================================
message Request { message Request {
string ping = 1; string ping = 1;
} }
...@@ -14,3 +16,13 @@ message Response { ...@@ -14,3 +16,13 @@ message Response {
service Colorway { service Colorway {
rpc Ping(Request) returns(Response); rpc Ping(Request) returns(Response);
} }
message ProductUploadRequest {
repeated string style_numbers = 1;
}
message ProductUploadResponse {}
service Product {
rpc Upload(ProductUploadRequest) returns(ProductUploadResponse);
}
package productlogic
import (
"context"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/client/product"
"log"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc"
"git.chillcy.com/golang/colorway/internal/rpc/pb/colorway"
"github.com/zeromicro/go-zero/core/logx"
)
type UploadLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogic {
return &UploadLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UploadLogic) Upload(in *colorway.ProductUploadRequest) (*colorway.ProductUploadResponse, error) {
productList, err := l.svcCtx.Pc4RpcService.Product.GetListByDesignerIds(l.ctx, &product.ProductGetListByDesignerIdsRequest{
DesignerIds: in.GetStyleNumbers(),
})
if err != nil {
return nil, err
}
log.Println(productList)
return &colorway.ProductUploadResponse{}, nil
}
// Code generated by goctl. DO NOT EDIT.
// Source: colorway.proto
package server
import (
"context"
"git.chillcy.com/golang/colorway/internal/rpc/internal/logic/product"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc"
"git.chillcy.com/golang/colorway/internal/rpc/pb/colorway"
)
type ProductServer struct {
svcCtx *svc.ServiceContext
colorway.UnimplementedProductServer
}
func NewProductServer(svcCtx *svc.ServiceContext) *ProductServer {
return &ProductServer{
svcCtx: svcCtx,
}
}
func (s *ProductServer) Upload(ctx context.Context, in *colorway.ProductUploadRequest) (*colorway.ProductUploadResponse, error) {
l := productlogic.NewUploadLogic(ctx, s.svcCtx)
return l.Upload(in)
}
...@@ -2,13 +2,16 @@ package svc ...@@ -2,13 +2,16 @@ package svc
import ( import (
"git.chillcy.com/golang/chillcy/pkg/etcd" "git.chillcy.com/golang/chillcy/pkg/etcd"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/client/product"
"git.chillcy.com/golang/colorway/internal/pkg/database" "git.chillcy.com/golang/colorway/internal/pkg/database"
"git.chillcy.com/golang/colorway/internal/rpc/internal/config" "git.chillcy.com/golang/colorway/internal/rpc/internal/config"
"github.com/zeromicro/go-zero/zrpc"
) )
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
DatabaseManager *database.Manager DatabaseManager *database.Manager
Pc4RpcService Pc4RpcService
} }
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
...@@ -19,8 +22,17 @@ func NewServiceContext(c config.Config) *ServiceContext { ...@@ -19,8 +22,17 @@ func NewServiceContext(c config.Config) *ServiceContext {
if err != nil { if err != nil {
panic(err) panic(err)
} }
// todo etcd config
pc4RpcProductServiceTarget := "127.0.0.1:5100"
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,
DatabaseManager: manager, DatabaseManager: manager,
Pc4RpcService: Pc4RpcService{
Product: product.NewProduct(zrpc.MustNewClient(zrpc.RpcClientConf{Target: pc4RpcProductServiceTarget})),
},
} }
} }
type Pc4RpcService struct {
Product product.Product
}
...@@ -114,6 +114,91 @@ func (x *Response) GetPong() string { ...@@ -114,6 +114,91 @@ func (x *Response) GetPong() string {
return "" return ""
} }
type ProductUploadRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
StyleNumbers []string `protobuf:"bytes,1,rep,name=style_numbers,json=styleNumbers,proto3" json:"style_numbers,omitempty"`
}
func (x *ProductUploadRequest) Reset() {
*x = ProductUploadRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_colorway_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ProductUploadRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ProductUploadRequest) ProtoMessage() {}
func (x *ProductUploadRequest) ProtoReflect() protoreflect.Message {
mi := &file_colorway_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ProductUploadRequest.ProtoReflect.Descriptor instead.
func (*ProductUploadRequest) Descriptor() ([]byte, []int) {
return file_colorway_proto_rawDescGZIP(), []int{2}
}
func (x *ProductUploadRequest) GetStyleNumbers() []string {
if x != nil {
return x.StyleNumbers
}
return nil
}
type ProductUploadResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *ProductUploadResponse) Reset() {
*x = ProductUploadResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_colorway_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ProductUploadResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ProductUploadResponse) ProtoMessage() {}
func (x *ProductUploadResponse) ProtoReflect() protoreflect.Message {
mi := &file_colorway_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ProductUploadResponse.ProtoReflect.Descriptor instead.
func (*ProductUploadResponse) Descriptor() ([]byte, []int) {
return file_colorway_proto_rawDescGZIP(), []int{3}
}
var File_colorway_proto protoreflect.FileDescriptor var File_colorway_proto protoreflect.FileDescriptor
var file_colorway_proto_rawDesc = []byte{ var file_colorway_proto_rawDesc = []byte{
...@@ -122,12 +207,23 @@ var file_colorway_proto_rawDesc = []byte{ ...@@ -122,12 +207,23 @@ var file_colorway_proto_rawDesc = []byte{
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x1e, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x1e, 0x0a, 0x08, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x32, 0x39, 0x0a, 0x08, 0x43, 0x6f, 0x6c, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x22, 0x3b, 0x0a, 0x14, 0x50, 0x72, 0x6f,
0x6f, 0x72, 0x77, 0x61, 0x79, 0x12, 0x2d, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x11, 0x2e, 0x64, 0x75, 0x63, 0x74, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x77, 0x61, 0x79, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x74, 0x12, 0x23, 0x0a, 0x0d, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65,
0x1a, 0x12, 0x2e, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x77, 0x61, 0x79, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x4e,
0x6f, 0x6e, 0x73, 0x65, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x77, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x22, 0x17, 0x0a, 0x15, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63,
0x61, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x74, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32,
0x39, 0x0a, 0x08, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x77, 0x61, 0x79, 0x12, 0x2d, 0x0a, 0x04, 0x50,
0x69, 0x6e, 0x67, 0x12, 0x11, 0x2e, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x77, 0x61, 0x79, 0x2e, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x77, 0x61,
0x79, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x54, 0x0a, 0x07, 0x50, 0x72,
0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x49, 0x0a, 0x06, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x12,
0x1e, 0x2e, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x77, 0x61, 0x79, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75,
0x63, 0x74, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x1f, 0x2e, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x77, 0x61, 0x79, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75,
0x63, 0x74, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x77, 0x61, 0x79, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
...@@ -142,16 +238,20 @@ func file_colorway_proto_rawDescGZIP() []byte { ...@@ -142,16 +238,20 @@ func file_colorway_proto_rawDescGZIP() []byte {
return file_colorway_proto_rawDescData return file_colorway_proto_rawDescData
} }
var file_colorway_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_colorway_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_colorway_proto_goTypes = []interface{}{ var file_colorway_proto_goTypes = []interface{}{
(*Request)(nil), // 0: colorway.Request (*Request)(nil), // 0: colorway.Request
(*Response)(nil), // 1: colorway.Response (*Response)(nil), // 1: colorway.Response
(*ProductUploadRequest)(nil), // 2: colorway.ProductUploadRequest
(*ProductUploadResponse)(nil), // 3: colorway.ProductUploadResponse
} }
var file_colorway_proto_depIdxs = []int32{ var file_colorway_proto_depIdxs = []int32{
0, // 0: colorway.Colorway.Ping:input_type -> colorway.Request 0, // 0: colorway.Colorway.Ping:input_type -> colorway.Request
1, // 1: colorway.Colorway.Ping:output_type -> colorway.Response 2, // 1: colorway.Product.Upload:input_type -> colorway.ProductUploadRequest
1, // [1:2] is the sub-list for method output_type 1, // 2: colorway.Colorway.Ping:output_type -> colorway.Response
0, // [0:1] is the sub-list for method input_type 3, // 3: colorway.Product.Upload:output_type -> colorway.ProductUploadResponse
2, // [2:4] is the sub-list for method output_type
0, // [0:2] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name 0, // [0:0] is the sub-list for field type_name
...@@ -187,6 +287,30 @@ func file_colorway_proto_init() { ...@@ -187,6 +287,30 @@ func file_colorway_proto_init() {
return nil return nil
} }
} }
file_colorway_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ProductUploadRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_colorway_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ProductUploadResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
} }
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
...@@ -194,9 +318,9 @@ func file_colorway_proto_init() { ...@@ -194,9 +318,9 @@ func file_colorway_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_colorway_proto_rawDesc, RawDescriptor: file_colorway_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 2, NumMessages: 4,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 2,
}, },
GoTypes: file_colorway_proto_goTypes, GoTypes: file_colorway_proto_goTypes,
DependencyIndexes: file_colorway_proto_depIdxs, DependencyIndexes: file_colorway_proto_depIdxs,
......
...@@ -107,3 +107,93 @@ var Colorway_ServiceDesc = grpc.ServiceDesc{ ...@@ -107,3 +107,93 @@ var Colorway_ServiceDesc = grpc.ServiceDesc{
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "colorway.proto", Metadata: "colorway.proto",
} }
const (
Product_Upload_FullMethodName = "/colorway.Product/Upload"
)
// ProductClient is the client API for Product 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 ProductClient interface {
Upload(ctx context.Context, in *ProductUploadRequest, opts ...grpc.CallOption) (*ProductUploadResponse, error)
}
type productClient struct {
cc grpc.ClientConnInterface
}
func NewProductClient(cc grpc.ClientConnInterface) ProductClient {
return &productClient{cc}
}
func (c *productClient) Upload(ctx context.Context, in *ProductUploadRequest, opts ...grpc.CallOption) (*ProductUploadResponse, error) {
out := new(ProductUploadResponse)
err := c.cc.Invoke(ctx, Product_Upload_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// ProductServer is the server API for Product service.
// All implementations must embed UnimplementedProductServer
// for forward compatibility
type ProductServer interface {
Upload(context.Context, *ProductUploadRequest) (*ProductUploadResponse, error)
mustEmbedUnimplementedProductServer()
}
// UnimplementedProductServer must be embedded to have forward compatible implementations.
type UnimplementedProductServer struct {
}
func (UnimplementedProductServer) Upload(context.Context, *ProductUploadRequest) (*ProductUploadResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Upload not implemented")
}
func (UnimplementedProductServer) mustEmbedUnimplementedProductServer() {}
// UnsafeProductServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to ProductServer will
// result in compilation errors.
type UnsafeProductServer interface {
mustEmbedUnimplementedProductServer()
}
func RegisterProductServer(s grpc.ServiceRegistrar, srv ProductServer) {
s.RegisterService(&Product_ServiceDesc, srv)
}
func _Product_Upload_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ProductUploadRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ProductServer).Upload(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Product_Upload_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ProductServer).Upload(ctx, req.(*ProductUploadRequest))
}
return interceptor(ctx, in, info, handler)
}
// Product_ServiceDesc is the grpc.ServiceDesc for Product service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Product_ServiceDesc = grpc.ServiceDesc{
ServiceName: "colorway.Product",
HandlerType: (*ProductServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Upload",
Handler: _Product_Upload_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "colorway.proto",
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment