Initial Commit

This commit is contained in:
2025-03-24 08:50:01 +01:00
commit 30611aa45d
26 changed files with 1477 additions and 0 deletions

80
cmd/model/cdsView.go Normal file
View 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
View 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
View 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)
}