Mainflux.mainflux/things/things.go

74 lines
2.4 KiB
Go
Raw Normal View History

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package things
2019-07-18 21:01:09 +08:00
import "context"
MF-859 - Channels metadata search (#867) * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * run.sh Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * change metadata type, add error handling Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add pause Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove extra char Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * retype from string to []byte Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add wait logic for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * few small fixes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix identityRes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * testing query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Update requests.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Delete pwdrecovery.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change in comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove unused struct Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-10-01 20:12:52 +08:00
// Metadata to be used for mainflux thing or channel for customized
// describing of particular thing or channel.
type Metadata map[string]interface{}
NOISSUE - Search by metadata (#849) * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add space Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * metadata test case Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add docs and update swagger Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add test for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add test for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove commented out section Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change to test Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove debug printf Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small fix for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix tests Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * and => and/or Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add line Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix mixed func params Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * metadata will be added to channels later Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix return type Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix typings Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix typings Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add migration Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove var Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * respecting the order of migrations Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-09-17 21:46:24 +08:00
// Thing represents a Mainflux thing. Each thing is owned by one user, and
// it is assigned with the unique identifier and (temporary) access key.
type Thing struct {
MF-475 - Replace increment ID with UUID (#490) * Update increment ID to UUID in things service Update increment ID to UUID for things and channels in things service and proto files. Also, update ID type from uint to string. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in http adapter Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in ws adapter Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in CoAP adapter Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in normalizer service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in writer services Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in reader services Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in SDK Update increment ID to UUID in SDK. Update id type to string. Update tests. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in mqtt adapter Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unnecessary case from influxdb reader Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update tests in order to increase code coverage Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update lora adapter to use string ID instead of unsigned int Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2018-12-05 20:09:25 +08:00
ID string
Owner string
Name string
Key string
MF-859 - Channels metadata search (#867) * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * run.sh Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * change metadata type, add error handling Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add pause Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove extra char Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * retype from string to []byte Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add wait logic for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * few small fixes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix identityRes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * testing query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Update requests.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Delete pwdrecovery.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change in comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove unused struct Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-10-01 20:12:52 +08:00
Metadata Metadata
}
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 18:53:24 +08:00
// ThingsPage contains page related metadata as well as list of things that
// belong to this page.
type ThingsPage struct {
PageMetadata
Things []Thing
}
// ThingRepository specifies a thing persistence API.
type ThingRepository interface {
// Save persists multiple things. Things are saved using a transaction. If one thing
// fails then none will be saved. Successful operation is indicated by non-nil
// error response.
Save(context.Context, ...Thing) ([]Thing, error)
// Update performs an update to the existing thing. A non-nil error is
// returned to indicate operation failure.
2019-07-18 21:01:09 +08:00
Update(context.Context, Thing) error
// UpdateKey updates key value of the existing thing. A non-nil error is
// returned to indicate operation failure.
2019-07-18 21:01:09 +08:00
UpdateKey(context.Context, string, string, string) error
// RetrieveByID retrieves the thing having the provided identifier, that is owned
// by the specified user.
2019-07-18 21:01:09 +08:00
RetrieveByID(context.Context, string, string) (Thing, error)
// RetrieveByKey returns thing ID for given thing key.
2019-07-18 21:01:09 +08:00
RetrieveByKey(context.Context, string) (string, error)
// RetrieveAll retrieves the subset of things owned by the specified user.
MF-859 - Channels metadata search (#867) * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * run.sh Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * change metadata type, add error handling Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add pause Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove extra char Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * retype from string to []byte Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add wait logic for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * few small fixes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix identityRes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * testing query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Update requests.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Delete pwdrecovery.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change in comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove unused struct Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-10-01 20:12:52 +08:00
RetrieveAll(context.Context, string, uint64, uint64, string, Metadata) (ThingsPage, error)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 18:53:24 +08:00
// RetrieveByChannel retrieves the subset of things owned by the specified
// user and connected to specified channel.
2019-07-18 21:01:09 +08:00
RetrieveByChannel(context.Context, string, string, uint64, uint64) (ThingsPage, error)
// Remove removes the thing having the provided identifier, that is owned
// by the specified user.
2019-07-18 21:01:09 +08:00
Remove(context.Context, string, string) error
}
// ThingCache contains thing caching interface.
type ThingCache interface {
// Save stores pair thing key, thing id.
2019-07-18 21:01:09 +08:00
Save(context.Context, string, string) error
// ID returns thing ID for given key.
2019-07-18 21:01:09 +08:00
ID(context.Context, string) (string, error)
// Removes thing from cache.
2019-07-18 21:01:09 +08:00
Remove(context.Context, string) error
}