MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / ListModels

Method ListModels

pkg/devicerepository/grpc.go:120–146  ·  view source on GitHub ↗

ListModels implements the ttnpb.DeviceRepositoryServer interface.

(
	ctx context.Context,
	req *ttnpb.ListEndDeviceModelsRequest,
)

Source from the content-addressed store, hash-verified

118
119// ListModels implements the ttnpb.DeviceRepositoryServer interface.
120func (dr *DeviceRepository) ListModels(
121 ctx context.Context,
122 req *ttnpb.ListEndDeviceModelsRequest,
123) (*ttnpb.ListEndDeviceModelsResponse, error) {
124 if err := rights.RequireAuthenticated(ctx); err != nil {
125 return nil, err
126 }
127 if req.Limit > defaultLimit || req.Limit == 0 {
128 req.Limit = defaultLimit
129 }
130 response, err := dr.store.GetModels(store.GetModelsRequest{
131 BrandID: req.BrandId,
132 Limit: req.Limit,
133 Page: req.Page,
134 Paths: withDefaultModelFields(req.FieldMask.GetPaths()),
135 Search: req.Search,
136 OrderBy: req.OrderBy,
137 })
138 if err != nil {
139 return nil, err
140 }
141 dr.ensureBaseAssetURLs(response.Models)
142 grpc.SetHeader(ctx, metadata.Pairs("x-total-count", strconv.FormatUint(uint64(response.Total), 10)))
143 return &ttnpb.ListEndDeviceModelsResponse{
144 Models: response.Models,
145 }, nil
146}
147
148var errModelNotFound = errors.DefineNotFound("model_not_found", "model `{brand_id}/{model_id}` not found")
149

Callers

nothing calls this directly

Calls 5

ensureBaseAssetURLsMethod · 0.95
RequireAuthenticatedFunction · 0.92
withDefaultModelFieldsFunction · 0.85
GetModelsMethod · 0.65
SetHeaderMethod · 0.45

Tested by

no test coverage detected