host.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package repository
  2. import (
  3. "context"
  4. v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
  5. "github.com/go-nunu/nunu-layout-advanced/internal/model"
  6. )
  7. type HostRepository interface {
  8. GetHost(ctx context.Context, id int64) (*model.Host, error)
  9. GetHostConfig(ctx context.Context, hostId int) ([]*model.Host, error)
  10. GetProductConfigOption(ctx context.Context, id []int) ([]v1.ProductConfigOption, error)
  11. GetProductConfigOptionSub(ctx context.Context, id []int) ([]v1.ProductConfigOptionSub, error)
  12. }
  13. func NewHostRepository(
  14. repository *Repository,
  15. ) HostRepository {
  16. return &hostRepository{
  17. Repository: repository,
  18. }
  19. }
  20. type hostRepository struct {
  21. *Repository
  22. }
  23. func (r *hostRepository) GetHost(ctx context.Context, id int64) (*model.Host, error) {
  24. var host model.Host
  25. return &host, nil
  26. }
  27. func (r *hostRepository) GetHostConfig(ctx context.Context, hostId int) ([]*model.Host, error) {
  28. var res []*model.Host
  29. if err := r.DB(ctx).Where("relid = ?", hostId).Find(&res).Error; err != nil {
  30. return nil, err
  31. }
  32. return res, nil
  33. }
  34. func (r *hostRepository) GetProductConfigOption(ctx context.Context, id []int) ([]v1.ProductConfigOption, error) {
  35. var res []v1.ProductConfigOption
  36. if err := r.DB(ctx).Table("shd_product_config_options").Where("id IN ?", id).Find(&res).Error; err != nil {
  37. return nil, err
  38. }
  39. return res, nil
  40. }
  41. func (r *hostRepository) GetProductConfigOptionSub(ctx context.Context, id []int) ([]v1.ProductConfigOptionSub, error) {
  42. var res []v1.ProductConfigOptionSub
  43. if err := r.DB(ctx).Table("shd_product_config_options_sub").Where("id IN ?", id).Find(&res).Error; err != nil {
  44. return nil, err
  45. }
  46. return res, nil
  47. }