2018-08-26 13:15:48 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2018
|
|
|
|
// Mainflux
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
package things
|
|
|
|
|
|
|
|
// 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 {
|
2018-12-05 13:09:25 +01:00
|
|
|
ID string
|
2018-10-24 11:21:03 +02:00
|
|
|
Owner string
|
|
|
|
Name string
|
|
|
|
Key string
|
2019-04-16 14:58:56 +02:00
|
|
|
Metadata map[string]interface{}
|
2018-05-15 17:13:09 +02:00
|
|
|
}
|
|
|
|
|
2019-01-08 11:53:24 +01:00
|
|
|
// ThingsPage contains page related metadata as well as list of things that
|
|
|
|
// belong to this page.
|
|
|
|
type ThingsPage struct {
|
|
|
|
PageMetadata
|
|
|
|
Things []Thing
|
|
|
|
}
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
// Validate returns an error if thing representation is invalid.
|
|
|
|
func (c *Thing) Validate() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ThingRepository specifies a thing persistence API.
|
|
|
|
type ThingRepository interface {
|
|
|
|
// Save persists the thing. Successful operation is indicated by non-nil
|
|
|
|
// error response.
|
2018-12-05 13:09:25 +01:00
|
|
|
Save(Thing) (string, error)
|
2018-05-15 17:13:09 +02:00
|
|
|
|
|
|
|
// Update performs an update to the existing thing. A non-nil error is
|
|
|
|
// returned to indicate operation failure.
|
|
|
|
Update(Thing) error
|
|
|
|
|
2019-04-25 14:37:51 +02:00
|
|
|
// UpdateKey updates key value of the existing thing. A non-nil error is
|
|
|
|
// returned to indicate operation failure.
|
|
|
|
UpdateKey(string, string, string) error
|
|
|
|
|
2018-05-17 20:17:02 +02:00
|
|
|
// RetrieveByID retrieves the thing having the provided identifier, that is owned
|
2018-05-15 17:13:09 +02:00
|
|
|
// by the specified user.
|
2018-12-05 13:09:25 +01:00
|
|
|
RetrieveByID(string, string) (Thing, error)
|
2018-05-15 17:13:09 +02:00
|
|
|
|
2018-05-17 20:17:02 +02:00
|
|
|
// RetrieveByKey returns thing ID for given thing key.
|
2018-12-05 13:09:25 +01:00
|
|
|
RetrieveByKey(string) (string, error)
|
2018-05-17 20:17:02 +02:00
|
|
|
|
|
|
|
// RetrieveAll retrieves the subset of things owned by the specified user.
|
2019-05-30 15:33:49 +02:00
|
|
|
RetrieveAll(string, uint64, uint64, string) (ThingsPage, error)
|
2019-01-08 11:53:24 +01:00
|
|
|
|
|
|
|
// RetrieveByChannel retrieves the subset of things owned by the specified
|
|
|
|
// user and connected to specified channel.
|
2019-05-10 18:55:13 +02:00
|
|
|
RetrieveByChannel(string, string, uint64, uint64) (ThingsPage, error)
|
2018-05-15 17:13:09 +02:00
|
|
|
|
|
|
|
// Remove removes the thing having the provided identifier, that is owned
|
|
|
|
// by the specified user.
|
2018-12-05 13:09:25 +01:00
|
|
|
Remove(string, string) error
|
2018-05-15 17:13:09 +02:00
|
|
|
}
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// ThingCache contains thing caching interface.
|
|
|
|
type ThingCache interface {
|
|
|
|
// Save stores pair thing key, thing id.
|
2018-12-05 13:09:25 +01:00
|
|
|
Save(string, string) error
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// ID returns thing ID for given key.
|
2018-12-05 13:09:25 +01:00
|
|
|
ID(string) (string, error)
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// Removes thing from cache.
|
2018-12-05 13:09:25 +01:00
|
|
|
Remove(string) error
|
2018-09-04 22:19:43 +02:00
|
|
|
}
|