github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/names/crud.go (about) 1 // Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved. 2 // Use of this source code is governed by a license that can 3 // be found in the LICENSE file. 4 /* 5 * Parts of this file were auto generated. Edit only those parts of 6 * the code inside of 'EXISTING_CODE' tags. 7 */ 8 9 package namesPkg 10 11 import ( 12 "net/http" 13 14 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 15 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/crud" 16 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 17 ) 18 19 func (opts *NamesOptions) getType() types.Parts { 20 var ret types.Parts 21 22 if opts.Custom || opts.All || opts.anyCrud() { 23 ret |= types.Custom 24 } 25 26 if opts.Prefund || opts.All { 27 ret |= types.Prefund 28 } 29 30 if (!opts.Custom && !opts.Prefund) || opts.All { 31 ret |= types.Regular 32 } 33 34 if opts.MatchCase { 35 ret |= types.MatchCase 36 } 37 38 if opts.Expand { 39 ret |= types.Expanded 40 } 41 42 if opts.Tags { 43 ret |= types.Tags 44 } 45 46 if opts.Globals.TestMode { 47 ret |= types.Testing 48 } 49 50 return ret 51 } 52 53 func (opts *NamesOptions) LoadCrudDataIfNeeded(request *http.Request) error { 54 if opts.Delete || opts.Undelete || opts.Remove { 55 opts.crudData = &crud.NameCrud{ 56 Address: crud.Field[base.Address]{ 57 Value: base.HexToAddress(opts.Terms[0]), 58 }, 59 } 60 return nil 61 } 62 63 if !opts.Create && !opts.Update { 64 return nil 65 } 66 67 var err error 68 opts.crudData, err = crud.NewNameCrud(len(opts.Autoname) > 0, request) 69 return err 70 }