MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / Create

Method Create

service/universally/create.go:39–77  ·  view source on GitHub ↗
(ctx context.Context, input *INPUT, appendLabels ...string)

Source from the content-addressed store, hash-verified

37}
38
39func (p *imlServiceCreate[INPUT, E]) Create(ctx context.Context, input *INPUT, appendLabels ...string) error {
40 operator := utils.UserId(ctx)
41 uniquest := p.uniquestHandler(input)
42
43 err := p.store.Transaction(ctx, func(ctx context.Context) error {
44 if uniquest != nil {
45 // check
46
47 for _, v := range uniquest {
48
49 o, err := p.store.First(ctx, v)
50 if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
51 return err
52 }
53 if o != nil {
54 return fmt.Errorf("%s %v already exists", p.name, v)
55 }
56 }
57 }
58
59 ne := p.createEntityHandler(input)
60 auto.Auto("creator", operator, ne)
61 auto.Auto("updater", operator, ne)
62 err := p.store.Insert(ctx, ne)
63 if err != nil {
64 return err
65 }
66 labels := appendLabels
67 for _, hd := range p.labelHandler {
68 labels = append(labels, hd(ne)...)
69 }
70 return p.store.SetLabels(ctx, idValue(ne), labels...)
71 //return p.store.SetLabels(ctx, ne.Id, pn.UUID, pn.Name, pn.Url, pn.Prefix, pn.Resume)
72 })
73 if err != nil {
74 return err
75 }
76 return nil
77}

Callers

nothing calls this directly

Calls 3

idValueFunction · 0.85
uniquestHandlerMethod · 0.45
createEntityHandlerMethod · 0.45

Tested by

no test coverage detected