@@ -2,20 +2,19 @@ package bizgebura
22
33import (
44 "context"
5+ "time"
56
67 "github.com/tuihub/librarian/internal/biz/bizutils"
78 "github.com/tuihub/librarian/internal/lib/libauth"
89 "github.com/tuihub/librarian/internal/model"
910 "github.com/tuihub/librarian/internal/model/modelgebura"
1011 pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1"
11-
12- "github.com/go-kratos/kratos/v2/errors"
1312)
1413
1514func (g * Gebura ) CreateApp (
1615 ctx context.Context ,
1716 a * modelgebura.App ,
18- ) (* modelgebura.App , * errors. Error ) {
17+ ) (* modelgebura.App , error ) {
1918 claims := libauth .FromContextAssertUserType (ctx )
2019 if claims == nil {
2120 return nil , bizutils .NoPermissionError ()
@@ -25,18 +24,27 @@ func (g *Gebura) CreateApp(
2524 return nil , pb .ErrorErrorReasonUnspecified ("%s" , err )
2625 }
2726 a .ID = id
27+ a .VersionNumber = 1
28+ a .VersionDate = time .Now ()
2829 if err = g .repo .CreateApp (ctx , claims .UserID , a ); err != nil {
2930 return nil , pb .ErrorErrorReasonUnspecified ("%s" , err .Error ())
3031 }
3132 return a , nil
3233}
3334
34- func (g * Gebura ) UpdateApp (ctx context.Context , a * modelgebura.App ) * errors. Error {
35+ func (g * Gebura ) UpdateApp (ctx context.Context , a * modelgebura.App ) error {
3536 claims := libauth .FromContextAssertUserType (ctx )
3637 if claims == nil {
3738 return bizutils .NoPermissionError ()
3839 }
39- err := g .repo .UpdateApp (ctx , claims .UserID , a )
40+ old , err := g .repo .GetApp (ctx , a .ID )
41+ if err != nil {
42+ return pb .ErrorErrorReasonUnspecified ("%s" , err .Error ())
43+ }
44+ if old .BoundStoreAppID != 0 && ! a .StopStoreManage {
45+ return pb .ErrorErrorReasonBadRequest ("under store manage" )
46+ }
47+ err = g .repo .UpdateApp (ctx , claims .UserID , a )
4048 if err != nil {
4149 return pb .ErrorErrorReasonUnspecified ("%s" , err .Error ())
4250 }
@@ -47,9 +55,8 @@ func (g *Gebura) ListApps(
4755 ctx context.Context ,
4856 paging model.Paging ,
4957 ownerIDs []model.InternalID ,
50- appInfoIDs []model.InternalID ,
5158 ids []model.InternalID ,
52- ) ([]* modelgebura.App , int , * errors. Error ) {
59+ ) ([]* modelgebura.App , int , error ) {
5360 claims := libauth .FromContextAssertUserType (ctx )
5461 if claims == nil {
5562 return nil , 0 , bizutils .NoPermissionError ()
@@ -59,43 +66,43 @@ func (g *Gebura) ListApps(
5966 ownerIDs = []model.InternalID {claims .UserID }
6067 publicOnly = false
6168 }
62- res , total , err := g .repo .ListApps (ctx , paging , ownerIDs , appInfoIDs , ids , publicOnly )
69+ res , total , err := g .repo .ListApps (ctx , paging , ownerIDs , ids , publicOnly )
6370 if err != nil {
6471 return nil , 0 , pb .ErrorErrorReasonUnspecified ("%s" , err .Error ())
6572 }
6673 return res , total , nil
6774}
6875
69- func (g * Gebura ) AssignApp (
70- ctx context.Context ,
71- appID model.InternalID ,
72- appInfoID model.InternalID ,
73- ) * errors. Error {
74- claims := libauth .FromContextAssertUserType (ctx )
75- if claims == nil {
76- return bizutils .NoPermissionError ()
77- }
78- err := g .repo .AssignApp (ctx , claims .UserID , appID , appInfoID )
79- if err != nil {
80- return pb .ErrorErrorReasonUnspecified ("%s" , err )
81- }
82- return nil
83- }
84-
85- func (g * Gebura ) UnAssignApp (ctx context.Context , appID model.InternalID ) * errors. Error {
86- claims := libauth .FromContextAssertUserType (ctx )
87- if claims == nil {
88- return bizutils .NoPermissionError ()
89- } else {
90- err := g .repo .UnAssignApp (ctx , claims .UserID , appID )
91- if err != nil {
92- return pb .ErrorErrorReasonUnspecified ("%s" , err )
93- }
94- }
95- return nil
96- }
76+ // func (g *Gebura) AssignApp(
77+ // ctx context.Context,
78+ // appID model.InternalID,
79+ // appInfoID model.InternalID,
80+ // ) error {
81+ // claims := libauth.FromContextAssertUserType(ctx)
82+ // if claims == nil {
83+ // return bizutils.NoPermissionError()
84+ // }
85+ // err := g.repo.AssignApp(ctx, claims.UserID, appID, appInfoID)
86+ // if err != nil {
87+ // return pb.ErrorErrorReasonUnspecified("%s", err)
88+ // }
89+ // return nil
90+ // }
91+ //
92+ // func (g *Gebura) UnAssignApp(ctx context.Context, appID model.InternalID) error {
93+ // claims := libauth.FromContextAssertUserType(ctx)
94+ // if claims == nil {
95+ // return bizutils.NoPermissionError()
96+ // } else {
97+ // err := g.repo.UnAssignApp(ctx, claims.UserID, appID)
98+ // if err != nil {
99+ // return pb.ErrorErrorReasonUnspecified("%s", err)
100+ // }
101+ // }
102+ // return nil
103+ // }
97104
98- // func (g *Gebura) NewReportAppPackageHandler(ctx context.Context) (ReportAppPackageHandler, *errors.Error ) {
105+ // func (g *Gebura) NewReportAppPackageHandler(ctx context.Context) (ReportAppPackageHandler, error ) {
99106// claims := libauth.FromContext(ctx)
100107// if claims == nil {
101108// return nil, bizutils.NoPermissionError()
@@ -118,7 +125,7 @@ func (g *Gebura) UnAssignApp(ctx context.Context, appID model.InternalID) *error
118125// sha256 []string
119126//}
120127//
121- // func (r *reportAppPackageHandler) Handle(ctx context.Context, binaries []*modelgebura.AppBinary) *errors.Error {
128+ // func (r *reportAppPackageHandler) Handle(ctx context.Context, binaries []*modelgebura.AppBinary) error {
122129// var vl []*mapper.Vertex
123130// packages := make([]*modelgebura.App, 0, len(binaries))
124131// ids, err := r.g.searcher.NewBatchIDs(ctx, len(binaries))
0 commit comments