Merge branch 'main' of https://github.com/APIParkLab/APIPark into feature/sunanzhi/1.6

# Conflicts:
#	.gitignore
This commit is contained in:
sunanzhi
2025-03-06 18:33:21 +08:00
13 changed files with 195 additions and 40 deletions
+2 -1
View File
@@ -3,9 +3,10 @@ package service_doc
import (
"context"
"errors"
"github.com/APIParkLab/APIPark/service/universally/commit"
"time"
"github.com/APIParkLab/APIPark/service/universally/commit"
"github.com/eolinker/go-common/utils"
"gorm.io/gorm"
+2 -1
View File
@@ -2,9 +2,10 @@ package service_doc
import (
"context"
"github.com/APIParkLab/APIPark/service/universally/commit"
"reflect"
"github.com/APIParkLab/APIPark/service/universally/commit"
"github.com/eolinker/go-common/autowire"
)
+67
View File
@@ -0,0 +1,67 @@
package service_model_mapping
import (
"context"
"errors"
"time"
"github.com/APIParkLab/APIPark/stores/service"
"github.com/eolinker/go-common/utils"
"gorm.io/gorm"
)
var _ IServiceModelMappingService = (*imlServiceModelMappingService)(nil)
type imlServiceModelMappingService struct {
store service.IServiceModelMappingStore `autowired:""`
}
func (i *imlServiceModelMappingService) Get(ctx context.Context, sid string) (*ModelMapping, error) {
entity, err := i.store.First(ctx, map[string]interface{}{"sid": sid})
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return &ModelMapping{
Sid: sid,
Content: "",
}, nil
}
return nil, err
}
return FromEntity(entity), nil
}
func FromEntity(e *service.ModelMapping) *ModelMapping {
content := ""
if e.Content != "" {
content = e.Content
}
return &ModelMapping{
ID: e.Id,
Sid: e.Sid,
Content: content,
CreateAt: e.CreateAt,
UpdateAt: e.UpdateAt,
}
}
func (i *imlServiceModelMappingService) Save(ctx context.Context, input *Save) error {
info, err := i.store.First(ctx, map[string]interface{}{"sid": input.Sid})
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
userID := utils.UserId(ctx)
if info != nil {
info.Content = input.Content
info.Updater = userID
info.UpdateAt = time.Now()
return i.store.Save(ctx, info)
}
return i.store.Insert(ctx, &service.ModelMapping{
Sid: input.Sid,
Content: input.Content,
CreateAt: time.Now(),
UpdateAt: time.Now(),
Creator: userID,
Updater: userID,
})
}
+20
View File
@@ -0,0 +1,20 @@
package service_model_mapping
import (
"time"
)
type ModelMapping struct {
ID int64 `json:"id"`
Sid string `json:"sid"`
Content string `json:"content"`
Creator string `json:"creator"`
Updater string `json:"updater"`
CreateAt time.Time `json:"create_at"`
UpdateAt time.Time `json:"update_at"`
}
type Save struct {
Sid string `json:"sid" validate:"required"`
Content string `json:"content" validate:"required"`
}
+19
View File
@@ -0,0 +1,19 @@
package service_model_mapping
import (
"context"
"reflect"
"github.com/eolinker/go-common/autowire"
)
type IServiceModelMappingService interface {
Get(ctx context.Context, sid string) (*ModelMapping, error)
Save(ctx context.Context, input *Save) error
}
func init() {
autowire.Auto[IServiceModelMappingService](func() reflect.Value {
return reflect.ValueOf(new(imlServiceModelMappingService))
})
}
+3 -3
View File
@@ -14,9 +14,7 @@ import (
"github.com/APIParkLab/APIPark/stores/service"
)
var (
_ IServiceService = (*imlServiceService)(nil)
)
var _ IServiceService = (*imlServiceService)(nil)
type imlServiceService struct {
store service.IServiceStore `autowired:""`
@@ -154,9 +152,11 @@ func (i *imlServiceService) OnComplete() {
func labelHandler(e *service.Service) []string {
return []string{e.Name, e.UUID, e.Description}
}
func uniquestHandler(i *Create) []map[string]interface{} {
return []map[string]interface{}{{"uuid": i.Id}}
}
func createEntityHandler(i *Create) *service.Service {
cfg, _ := json.Marshal(i.AdditionalConfig)
now := time.Now()
+4 -6
View File
@@ -4,15 +4,14 @@ import (
"context"
"errors"
"fmt"
"github.com/eolinker/go-common/auto"
"github.com/eolinker/go-common/store"
"github.com/eolinker/go-common/utils"
"gorm.io/gorm"
)
var (
_ IServiceDelete = (*imlServiceDelete[any])(nil)
)
var _ IServiceDelete = (*imlServiceDelete[any])(nil)
type IServiceDelete interface {
Delete(ctx context.Context, uuid string) error
@@ -26,10 +25,12 @@ func NewDelete[E any](store store.ISearchStore[E]) IServiceDelete {
assert(new(E))
return &imlServiceDelete[E]{store: store}
}
func NewSoftDelete[E any](s store.ISearchStore[E]) IServiceDelete {
assert(new(E))
return &imlServiceSoftDelete[E]{store: s}
}
func (p *imlServiceDelete[E]) Delete(ctx context.Context, uuid string) error {
return p.store.Transaction(ctx, func(ctx context.Context) error {
o, err := p.store.First(ctx, map[string]interface{}{"uuid": uuid})
@@ -46,7 +47,6 @@ func (p *imlServiceDelete[E]) Delete(ctx context.Context, uuid string) error {
}
return p.store.SetLabels(ctx, idValue(o))
})
}
type imlServiceSoftDelete[E any] struct {
@@ -66,7 +66,5 @@ func (p *imlServiceSoftDelete[E]) Delete(ctx context.Context, uuid string) error
auto.Auto("operator", operator, o)
return p.store.SoftDelete(ctx, map[string]interface{}{"uuid": uuid})
})
}