class.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package service
  2. import (
  3. "baize-demo/project/server_ds/application/domain/class"
  4. "git.sxidc.com/go-framework/baize/convenient/domain/operate_log"
  5. "git.sxidc.com/go-framework/baize/convenient/entity_crud"
  6. "git.sxidc.com/go-framework/baize/framework/binding"
  7. "git.sxidc.com/go-framework/baize/framework/core/api"
  8. "git.sxidc.com/go-framework/baize/framework/core/api/request"
  9. "git.sxidc.com/go-framework/baize/framework/core/application"
  10. "git.sxidc.com/go-framework/baize/framework/core/domain"
  11. "git.sxidc.com/go-framework/baize/framework/core/domain/entity"
  12. "git.sxidc.com/go-framework/baize/framework/core/infrastructure"
  13. "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database"
  14. "git.sxidc.com/service-supports/fslog"
  15. )
  16. var classService = &ClassService{}
  17. type ClassService struct{}
  18. func (svc *ClassService) Init(appInstance *application.App) error {
  19. svc.v1(appInstance)
  20. return nil
  21. }
  22. func (svc *ClassService) Destroy() error {
  23. return nil
  24. }
  25. func (svc *ClassService) v1(appInstance *application.App) {
  26. v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"), appInstance.Infrastructure())
  27. entity_crud.BindSimple[class.Info](v1Binder, &entity_crud.Simple[class.Info]{
  28. Entity: &class.Entity{},
  29. Schema: dbSchema,
  30. CreateJsonBody: &class.CreateClassJsonBody{},
  31. DeleteQueryParams: &class.DeleteClassQueryParams{},
  32. UpdateJsonBody: &class.UpdateClassJsonBody{},
  33. QueryQueryParams: &class.GetClassesQueryParams{},
  34. GetByIDQueryParams: &class.GetClassByIDQueryParams{},
  35. }, entity_crud.WithCreateCallbacks(&entity_crud.CreateCallbacks{
  36. After: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
  37. go func() {
  38. classEntity, err := domain.ToConcrete[*class.Entity](e)
  39. if err != nil {
  40. fslog.Error(err)
  41. return
  42. }
  43. err = operate_log.WriteLog(i.DBExecutor(), dbSchema, "create", classEntity)
  44. if err != nil {
  45. fslog.Error(err)
  46. return
  47. }
  48. }()
  49. return nil
  50. },
  51. }))
  52. }