child.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package data
  2. import (
  3. "context"
  4. "sikey/w303a/http/internal/biz"
  5. "sikey/w303a/http/internal/data/ent/child"
  6. )
  7. var _ biz.ChildRepo = (*childRepo)(nil)
  8. type childRepo struct {
  9. data *Data
  10. }
  11. func (repo *childRepo) FindByPhoneNumber(ctx context.Context, phoneNumber *biz.PhoneNumber) (*biz.Child, error) {
  12. mod, err := repo.data.db.Child.Query().
  13. Where(child.PhoneNumber(phoneNumber.Phone), child.AreaCode(phoneNumber.AreaCode)).
  14. WithChildRefs().
  15. Only(ctx)
  16. if err != nil {
  17. return nil, err
  18. }
  19. var refs []*biz.ChildRef
  20. for _, refMod := range mod.Edges.ChildRefs {
  21. refs = append(refs, &biz.ChildRef{
  22. UserID: refMod.UserID.String(),
  23. ChildID: refMod.ChildID.String(),
  24. })
  25. }
  26. return &biz.Child{
  27. ID: mod.ID.String(),
  28. Name: mod.ChildName,
  29. Avatar: mod.Avatar,
  30. Height: mod.Height,
  31. Weight: mod.Weight,
  32. Birthday: mod.Birthday,
  33. Gender: mod.Gender,
  34. PhoneNumber: biz.NewPhoneNumber(mod.PhoneNumber, mod.AreaCode),
  35. Refs: refs,
  36. }, nil
  37. }
  38. func (repo *childRepo) FindByChildID(ctx context.Context, cid string) (*biz.Child, error) {
  39. //TODO implement me
  40. panic("implement me")
  41. }
  42. func (repo *childRepo) FindByUserID(ctx context.Context, uid string) ([]*biz.Child, error) {
  43. //TODO implement me
  44. panic("implement me")
  45. }
  46. func (repo *childRepo) Create(ctx context.Context, child *biz.Child) error {
  47. //TODO implement me
  48. panic("implement me")
  49. }
  50. func (repo *childRepo) Update(ctx context.Context, child *biz.Child) error {
  51. //TODO implement me
  52. panic("implement me")
  53. }
  54. func (repo *childRepo) Delete(ctx context.Context, cid string) error {
  55. //TODO implement me
  56. panic("implement me")
  57. }
  58. func NewChildRepo(data *Data) biz.ChildRepo {
  59. return &childRepo{data: data}
  60. }