ListBrands implements the ttnpb.DeviceRepositoryServer interface.
( ctx context.Context, req *ttnpb.ListEndDeviceBrandsRequest, )
| 62 | |
| 63 | // ListBrands implements the ttnpb.DeviceRepositoryServer interface. |
| 64 | func (dr *DeviceRepository) ListBrands( |
| 65 | ctx context.Context, |
| 66 | req *ttnpb.ListEndDeviceBrandsRequest, |
| 67 | ) (*ttnpb.ListEndDeviceBrandsResponse, error) { |
| 68 | if err := rights.RequireAuthenticated(ctx); err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | if req.Limit > defaultLimit || req.Limit == 0 { |
| 72 | req.Limit = defaultLimit |
| 73 | } |
| 74 | response, err := dr.store.GetBrands(store.GetBrandsRequest{ |
| 75 | Limit: req.Limit, |
| 76 | Page: req.Page, |
| 77 | OrderBy: req.OrderBy, |
| 78 | Paths: withDefaultBrandFields(req.FieldMask.GetPaths()), |
| 79 | Search: req.Search, |
| 80 | }) |
| 81 | if err != nil { |
| 82 | return nil, err |
| 83 | } |
| 84 | for _, brand := range response.Brands { |
| 85 | brand.Logo = dr.assetURL(brand.BrandId, brand.Logo) |
| 86 | } |
| 87 | grpc.SetHeader(ctx, metadata.Pairs("x-total-count", strconv.FormatUint(uint64(response.Total), 10))) |
| 88 | return &ttnpb.ListEndDeviceBrandsResponse{ |
| 89 | Brands: response.Brands, |
| 90 | }, nil |
| 91 | } |
| 92 | |
| 93 | var errBrandNotFound = errors.DefineNotFound("brand_not_found", "brand `{brand_id}` not found") |
| 94 |
nothing calls this directly
no test coverage detected