2019-10-07 08:14:47 -06:00
|
|
|
// Copyright (c) Mainflux
|
2018-08-26 13:15:48 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
package things
|
|
|
|
|
2020-03-30 15:22:18 +02:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
2019-07-18 15:01:09 +02:00
|
|
|
|
2019-10-01 14:12:52 +02:00
|
|
|
// Metadata to be used for mainflux thing or channel for customized
|
|
|
|
// describing of particular thing or channel.
|
|
|
|
type Metadata map[string]interface{}
|
2019-09-17 13:46:24 +00:00
|
|
|
|
2018-05-15 17:13:09 +02: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 {
|
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-10-01 14:12:52 +02:00
|
|
|
Metadata Metadata
|
2018-05-15 17:13:09 +02:00
|
|
|
}
|
|
|
|
|
2020-04-15 15:15:30 +02:00
|
|
|
// Page contains page related metadata as well as list of things that
|
2019-01-08 11:53:24 +01:00
|
|
|
// belong to this page.
|
2020-04-15 15:15:30 +02:00
|
|
|
type Page struct {
|
2019-01-08 11:53:24 +01:00
|
|
|
PageMetadata
|
|
|
|
Things []Thing
|
|
|
|
}
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
// ThingRepository specifies a thing persistence API.
|
|
|
|
type ThingRepository interface {
|
2019-11-04 13:14:17 -07:00
|
|
|
// 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
|
2018-05-15 17:13:09 +02:00
|
|
|
// error response.
|
2020-04-15 15:15:30 +02:00
|
|
|
Save(ctx context.Context, ths ...Thing) ([]Thing, error)
|
2019-10-29 05:59:54 -06:00
|
|
|
|
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.
|
2020-04-15 15:15:30 +02:00
|
|
|
Update(ctx context.Context, t Thing) error
|
2018-05-15 17:13:09 +02:00
|
|
|
|
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.
|
2020-04-15 15:15:30 +02:00
|
|
|
UpdateKey(ctx context.Context, owner, id, key string) error
|
2019-04-25 14:37:51 +02:00
|
|
|
|
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.
|
2020-04-15 15:15:30 +02:00
|
|
|
RetrieveByID(ctx context.Context, owner, id 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.
|
2020-04-15 15:15:30 +02:00
|
|
|
RetrieveByKey(ctx context.Context, key string) (string, error)
|
2018-05-17 20:17:02 +02:00
|
|
|
|
|
|
|
// RetrieveAll retrieves the subset of things owned by the specified user.
|
2020-04-15 15:15:30 +02:00
|
|
|
RetrieveAll(ctx context.Context, owner string, offset, limit uint64, name string, m Metadata) (Page, 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.
|
2020-04-15 15:15:30 +02:00
|
|
|
RetrieveByChannel(ctx context.Context, owner, channel string, offset, limit uint64) (Page, error)
|
2018-05-15 17:13:09 +02:00
|
|
|
|
|
|
|
// Remove removes the thing having the provided identifier, that is owned
|
|
|
|
// by the specified user.
|
2020-04-15 15:15:30 +02:00
|
|
|
Remove(ctx context.Context, owner, id 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.
|
2019-07-18 15:01:09 +02:00
|
|
|
Save(context.Context, string, string) error
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// ID returns thing ID for given key.
|
2019-07-18 15:01:09 +02:00
|
|
|
ID(context.Context, string) (string, error)
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// Removes thing from cache.
|
2019-07-18 15:01:09 +02:00
|
|
|
Remove(context.Context, string) error
|
2018-09-04 22:19:43 +02:00
|
|
|
}
|