package service import ( "baize-demo/project/server/application/domain/class" "git.sxidc.com/go-framework/baize/convenient/domain/operate_log" "git.sxidc.com/go-framework/baize/convenient/entity_crud" "git.sxidc.com/go-framework/baize/framework/binding" "git.sxidc.com/go-framework/baize/framework/core/api" "git.sxidc.com/go-framework/baize/framework/core/api/request" "git.sxidc.com/go-framework/baize/framework/core/application" "git.sxidc.com/go-framework/baize/framework/core/domain" "git.sxidc.com/go-framework/baize/framework/core/domain/entity" "git.sxidc.com/go-framework/baize/framework/core/infrastructure" "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database" "git.sxidc.com/service-supports/fslog" ) var classService = &ClassService{} type ClassService struct{} func (svc *ClassService) Init(appInstance *application.App) error { svc.v1(appInstance) return nil } func (svc *ClassService) Destroy() error { return nil } func (svc *ClassService) v1(appInstance *application.App) { v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"), appInstance.Infrastructure()) entity_crud.BindSimple[class.Info](v1Binder, &entity_crud.Simple[class.Info]{ Entity: &class.Entity{}, Schema: dbSchema, CreateJsonBody: &class.CreateClassJsonBody{}, DeleteQueryParams: &class.DeleteClassQueryParams{}, UpdateJsonBody: &class.UpdateClassJsonBody{}, QueryQueryParams: &class.GetClassesQueryParams{}, GetByIDQueryParams: &class.GetClassByIDQueryParams{}, }, entity_crud.WithCreateCallbacks(&entity_crud.CreateCallbacks{ After: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error { go func() { classEntity, err := domain.ToConcrete[*class.Entity](e) if err != nil { fslog.Error(err) return } err = operate_log.WriteLog(i.DBExecutor(), dbSchema, "create", classEntity) if err != nil { fslog.Error(err) return } }() return nil }, })) }