README.md

Trixstar #

trixstar add tokens posts messages auth:complex user_actions:complex dms:complex

if the db.yaml file doesn't exist it gets created with the data provided

if the db.yaml already exists trixstar reads it and appends to the services the new provided by the user via the cli

# db.yaml
version: 1
vcs: codeberg.org/iuri/backend
services:
-tokens: # this gets added to the db
    is-crud: true
-users:
    is-crud: true
-messages:
    is-crud: true
-posts:
    is-crud: true
-auth:
    is-crud: false
-user_actions:
    is-crud: false
-dms:
    is-crud: false

sample of a service being added to the db #

trixstar add drawings
# db.yaml
version: 1
vcs: codeberg.org/iuri/backend
services:
-tokens: # this gets added to the db
    is-crud: true
-users:
    is-crud: true
-messages:
    is-crud: true
-posts:
    is-crud: true
-auth:
    is-crud: false
-user_actions:
    is-crud: false
-dms:
    is-crud: false
-drawings:
    is-crud: true

trixstar reads the db file and just recreates all the files for the stuff

// this is a basic crud service trixstar -add lots

// this is not a basic crud service, which means the user will change some stuff trixstar -add madoka -complex

// ./cmd/api/crud.trixstar.go
type CRUDServices struct {
    {{for CrudServices c}}
        {{c.Snake.Lower}}: {{c.Package}}.Service
    {{end}}
}

type CRUDHandlers struct {
    {{for CrudServices c}}
        {{c.Snake.Lower}}: {{c.Package}}.Handler
    {{end}}
}

type CRUD struct {
    handlers: CRUDHandlers
    services: CRUDServices
}

func GetCRUDHandlersAndServices(queries repo.QuerierTX) CRUD {

    services :=  CRUDServices{
        {{for CrudServices }}
            {{.Snake.Lower}}: {{.Provider}}.New{{.Singular}}Repo(queries),
        {{end}}
    },

    handlers:   CRUDHandlers{
        {{for CrudHandlers c }}
            {{c.Snake.Lower}} : services.{{.Snake.Lower}},
        {{end}}
    },

	return {
        handlers,
        services,
    } 
}
// ./cmd/api/setup.go this just gets generated once per run

type Handlers  struct {
    crud CRUDHandlers
}

type Services  struct {
    crud CRUDServices
}

func (app *Application) SetupServicesAndHandlers() {
    crud := GetCRUDHandlersAndServices(app.DB)

    // custom service that depends on more stuff
	madokaSvc := madoka.NewSVC(
		crud.lots,
		crud.wagons,
		crud.daily_harvests,
		crud.seeds,
		crud.drivers,
		crud.aweta_current_report,
		crud.aweta_current_engine,
		crud.aweta_reports,
		crud.aweta_current_performance,
		crud.aweta_performance_history,
		crud.multiscan_current_report,
		crud.multiscan_reports,
	)

	services := Services{
        crud: crud.services,
		madoka:        madokaSvc,
	}

	handlers := Handlers{
        crud: crud.handlers,
		madoka:        madoka.NewHandler(madokaSvc),
	}

	app.Handlers = handlers
	app.Services = services
}