Initial Commit
This commit is contained in:
80
cmd/model/cdsView.go
Normal file
80
cmd/model/cdsView.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sap-cds-search/cmd/database/table"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
type CDSViewFieldModel struct {
|
||||
table.CDSViewField
|
||||
DataTypeTitle string
|
||||
FieldLengthOut string
|
||||
DescriptionOut string
|
||||
}
|
||||
|
||||
type CDSViewModel struct {
|
||||
*table.CDSView
|
||||
StateTitle string
|
||||
Fields *[]CDSViewFieldModel
|
||||
}
|
||||
|
||||
var englishCases = cases.Title(language.English)
|
||||
|
||||
func GetCDSViewModel(TechnicalName string) (*CDSViewModel, error) {
|
||||
var model CDSViewModel
|
||||
|
||||
cdsView, err := table.GetCDSView(TechnicalName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
model.CDSView = cdsView
|
||||
|
||||
model.StateTitle = englishCases.String(model.State)
|
||||
|
||||
fields, err := table.GetCDSViewFields(TechnicalName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var fieldModel CDSViewFieldModel
|
||||
var fieldsModel []CDSViewFieldModel
|
||||
for _, field := range *fields {
|
||||
fieldModel.CDSViewField = field
|
||||
fieldModel.DataTypeTitle = englishCases.String(field.DataType)
|
||||
fieldModel.FieldLengthOut = strings.TrimLeft(field.FieldLength, "0")
|
||||
fieldModel.DescriptionOut = field.Description
|
||||
if fieldModel.DescriptionOut == "" {
|
||||
fieldModel.DescriptionOut = "-"
|
||||
}
|
||||
fieldsModel = append(fieldsModel, fieldModel)
|
||||
}
|
||||
|
||||
model.Fields = &fieldsModel
|
||||
|
||||
return &model, nil
|
||||
}
|
||||
|
||||
func GetAllCDSViewModels() (*[]CDSViewModel, error) {
|
||||
cdsViewTechnicalNames, err := table.QueryAllCDSViewTechnicalNames()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var cdsViewModels []CDSViewModel
|
||||
for _, cdsViewTechnicalName := range *cdsViewTechnicalNames {
|
||||
cdsViewModel, err := GetCDSViewModel(cdsViewTechnicalName)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
|
||||
cdsViewModels = append(cdsViewModels, *cdsViewModel)
|
||||
}
|
||||
|
||||
return &cdsViewModels, nil
|
||||
}
|
||||
12
cmd/model/keyword.go
Normal file
12
cmd/model/keyword.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package model
|
||||
|
||||
import "sap-cds-search/cmd/database/table"
|
||||
|
||||
func GetKeywordsModel() (*[]table.Keyword, error) {
|
||||
keywords, err := table.GetAllKeywords()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return keywords, nil
|
||||
}
|
||||
20
cmd/model/results.go
Normal file
20
cmd/model/results.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package model
|
||||
|
||||
type ResultsModel struct {
|
||||
SearchTerm string
|
||||
CurrentPage int
|
||||
MaxPage int
|
||||
Views []CDSViewModel
|
||||
}
|
||||
|
||||
type ResultsModelBuffer struct {
|
||||
Views []CDSViewModel
|
||||
}
|
||||
|
||||
func NewResultsModel() *ResultsModel {
|
||||
return &ResultsModel{}
|
||||
}
|
||||
|
||||
func (r *ResultsModel) AppendResultsModelViews(cdsView *CDSViewModel) {
|
||||
r.Views = append(r.Views, *cdsView)
|
||||
}
|
||||
Reference in New Issue
Block a user