host.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. GetDomainById(ctx context.Context, id int) (string, error)
  13. }
  14. func NewHostRepository(
  15. repository *Repository,
  16. ) HostRepository {
  17. return &hostRepository{
  18. Repository: repository,
  19. }
  20. }
  21. type hostRepository struct {
  22. *Repository
  23. }
  24. func (r *hostRepository) GetHost(ctx context.Context, id int64) (*model.Host, error) {
  25. var host model.Host
  26. return &host, nil
  27. }
  28. func (r *hostRepository) GetHostConfig(ctx context.Context, hostId int) ([]*model.Host, error) {
  29. var res []*model.Host
  30. if err := r.DB(ctx).Where("relid = ?", hostId).Find(&res).Error; err != nil {
  31. return nil, err
  32. }
  33. return res, nil
  34. }
  35. func (r *hostRepository) GetProductConfigOption(ctx context.Context, id []int) ([]v1.ProductConfigOption, error) {
  36. var res []v1.ProductConfigOption
  37. if err := r.DB(ctx).Table("shd_product_config_options").Where("id IN ?", id).Find(&res).Error; err != nil {
  38. return nil, err
  39. }
  40. return res, nil
  41. }
  42. func (r *hostRepository) GetProductConfigOptionSub(ctx context.Context, id []int) ([]v1.ProductConfigOptionSub, error) {
  43. var res []v1.ProductConfigOptionSub
  44. if err := r.DB(ctx).Table("shd_product_config_options_sub").Where("id IN ?", id).Find(&res).Error; err != nil {
  45. return nil, err
  46. }
  47. return res, nil
  48. }
  49. func (r *hostRepository) GetDomainById(ctx context.Context, id int) (string, error) {
  50. var res string
  51. if err := r.DB(ctx).Table("shd_host").
  52. Where("id = ?", id).
  53. Pluck("domain", &res).Error; err != nil {
  54. return "", err
  55. }
  56. return res, nil
  57. }