refactor: reorganize modules and add Linux build tooling
This commit is contained in:
56
module/ec/address/internal/logic/library/create.go
Normal file
56
module/ec/address/internal/logic/library/create.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/address/internal/models"
|
||||
pb "bsm/full/module/ec/address/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 新增地址
|
||||
func Create(ctx context.Context, in *pb.AddressCreateRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
address := &models.AddressLibrary{
|
||||
Country: in.Country,
|
||||
Phone: in.Phone,
|
||||
Province: in.Province,
|
||||
City: in.City,
|
||||
Area: in.Area,
|
||||
Detail: in.Detail,
|
||||
Contact: in.Contact,
|
||||
Name: in.Name,
|
||||
Pics: in.Pics,
|
||||
}
|
||||
address.Identity = utils.UUID()
|
||||
address.OwnerID = auth.ID
|
||||
address.OwnerIdentity = auth.Identity
|
||||
address.Status = int8(in.Status)
|
||||
|
||||
if address.Status == 2 {
|
||||
models.DBService.Model(&models.AddressLibrary{}).Where("owner_id = ? and status=2", auth.ID).UpdateColumn("status", "1")
|
||||
}
|
||||
|
||||
err = models.DBService.Create(address).Error
|
||||
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
34
module/ec/address/internal/logic/library/delete.go
Normal file
34
module/ec/address/internal/logic/library/delete.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/address/internal/models"
|
||||
pb "bsm/full/module/ec/address/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 删除一个地址
|
||||
func Delete(ctx context.Context, in *pb.AddressDeleteRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.DBService.Delete(&models.AddressLibrary{}, "id in ?", in.Id).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
60
module/ec/address/internal/logic/library/fetch.go
Normal file
60
module/ec/address/internal/logic/library/fetch.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bsm/full/module/ec/address/internal/models"
|
||||
pb "bsm/full/module/ec/address/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 获取地址列表
|
||||
func Fetch(ctx context.Context, in *pb.IdentRequest) (reply *pb.AddressListReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
address = make([]*models.AddressLibrary, 0)
|
||||
result = make([]*pb.AddressItem, 0)
|
||||
)
|
||||
|
||||
err = models.DBService.Where("owner_identity=?", auth.Identity).Find(&address).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
for _, item := range address {
|
||||
result = append(result, ReflectProtoAddress(item))
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func ReflectProtoAddress(v *models.AddressLibrary) *pb.AddressItem {
|
||||
if nil == v {
|
||||
return nil
|
||||
}
|
||||
result := &pb.AddressItem{
|
||||
Id: int64(v.ID),
|
||||
Identity: v.Identity,
|
||||
Country: v.Country,
|
||||
Phone: v.Phone,
|
||||
Province: v.Province,
|
||||
City: v.City,
|
||||
Area: v.Area,
|
||||
Detail: v.Detail,
|
||||
Contact: v.Contact,
|
||||
Name: v.Name,
|
||||
Pics: v.Pics,
|
||||
Status: int32(v.Status),
|
||||
}
|
||||
return result
|
||||
}
|
||||
51
module/ec/address/internal/logic/library/get.go
Normal file
51
module/ec/address/internal/logic/library/get.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"bsm/full/module/ec/address/internal/models"
|
||||
pb "bsm/full/module/ec/address/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 获取一条地址
|
||||
func Get(ctx context.Context, in *pb.IdentRequest) (reply *pb.AddressItem, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetId() == 0 {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
address := new(models.AddressLibrary)
|
||||
err = models.DBService.Where("id=?", in.Id).First(&address).Error
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrNotFound) {
|
||||
return nil, errcode.ErrRecordNotFound
|
||||
}
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.AddressItem{
|
||||
Id: int64(address.ID),
|
||||
Identity: address.Identity,
|
||||
Name: address.Name,
|
||||
Phone: address.Phone,
|
||||
Province: address.Province,
|
||||
City: address.City,
|
||||
Area: address.Area,
|
||||
Detail: address.Detail,
|
||||
Country: address.Country,
|
||||
Pics: address.Pics,
|
||||
Contact: address.Contact,
|
||||
Status: int32(address.Status),
|
||||
}, nil
|
||||
}
|
||||
49
module/ec/address/internal/logic/library/modify.go
Normal file
49
module/ec/address/internal/logic/library/modify.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/address/internal/models"
|
||||
pb "bsm/full/module/ec/address/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 修改地址
|
||||
func Modify(ctx context.Context, in *pb.AddressItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
address := &models.AddressLibrary{
|
||||
Country: in.Country,
|
||||
Phone: in.Phone,
|
||||
Province: in.Province,
|
||||
City: in.City,
|
||||
Area: in.Area,
|
||||
Detail: in.Detail,
|
||||
Contact: in.Contact,
|
||||
}
|
||||
address.Status = int8(in.Status)
|
||||
|
||||
if address.Status == 2 {
|
||||
models.DBService.Model(&models.AddressLibrary{}).Where("owner_id = ? and status=2", auth.ID).UpdateColumn("status", "1")
|
||||
}
|
||||
|
||||
err = models.DBService.Where("id=?", in.Id).Updates(&address).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user