entity.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package hobby
  2. import (
  3. "git.sxidc.com/go-framework/baize/framework/core/domain/entity"
  4. "git.sxidc.com/go-framework/baize/framework/core/tag/check"
  5. "git.sxidc.com/go-tools/utils/strutils"
  6. )
  7. type Entity struct {
  8. ID string `sqlmapping:"-" sqlresult:"-" check:"required,len=32"`
  9. StudentIDs []string `sqlmapping:"-" sqlresult:"-"`
  10. }
  11. func (e *Entity) DBSchema() string {
  12. return ""
  13. }
  14. func (e *Entity) GenerateID() error {
  15. e.ID = strutils.SimpleUUID()
  16. return nil
  17. }
  18. func (e *Entity) GetID() string {
  19. return e.ID
  20. }
  21. func (e *Entity) DomainCNName() string {
  22. return "爱好"
  23. }
  24. func (e *Entity) DomainCamelName() string {
  25. return "Hobby"
  26. }
  27. func (e *Entity) ForCreate() error {
  28. err := e.CheckFieldID()
  29. if err != nil {
  30. return err
  31. }
  32. return nil
  33. }
  34. func (e *Entity) ForDelete() error {
  35. return e.CheckFieldID()
  36. }
  37. func (e *Entity) ForUpdate() error {
  38. err := e.CheckFieldID()
  39. if err != nil {
  40. return err
  41. }
  42. return nil
  43. }
  44. func (e *Entity) CheckFieldID() error {
  45. checkResult := check.Struct(e, map[string]string{entity.FieldID: e.DomainCNName() + "ID"})
  46. err := entity.CheckFieldIDResult(checkResult)
  47. if err != nil {
  48. return err
  49. }
  50. return nil
  51. }