goshort/internal/storage/storage.go
Gustavo Maronato 949ea57dd9
Some checks failed
Build / build (push) Has been cancelled
I'm done
2023-08-24 22:03:58 -03:00

61 lines
2.5 KiB
Go

package storage
import (
"context"
"git.maronato.dev/maronato/goshort/internal/storage/models"
)
type Storage interface {
// Lifecycle
Start(ctx context.Context) error
Stop(ctx context.Context) error
Ping(ctx context.Context) error
// Short Storage
// FindShort finds a short in the storage using its name.
FindShort(ctx context.Context, name string) (*models.Short, error)
// FindShortByID finds a short in the storage using its ID.
FindShortByID(ctx context.Context, id string) (*models.Short, error)
// FindShorts finds all shorts in the storage that belong to a user.
ListShorts(ctx context.Context, user *models.User) ([]*models.Short, error)
// CreateShort creates a short in the storage.
CreateShort(ctx context.Context, short *models.Short) (*models.Short, error)
// DeleteShort deletes a short from the storage.
DeleteShort(ctx context.Context, short *models.Short) error
// ShortLog Storage
// CreateShortLog creates a short log in the storage.
CreateShortLog(ctx context.Context, shortLog *models.ShortLog) error
// ListShortLogs finds all short logs in the storage that belong to a short.
ListShortLogs(ctx context.Context, short *models.Short) ([]*models.ShortLog, error)
// User Storage
// FindUser finds a user in the storage using its username.
FindUser(ctx context.Context, username string) (*models.User, error)
// FindUserByID finds a user in the storage using its ID.
FindUserByID(ctx context.Context, id string) (*models.User, error)
// CreateUser creates a user in the storage.
CreateUser(ctx context.Context, user *models.User) (*models.User, error)
// DeleteUser deletes a user and all their shorts from the storage.
DeleteUser(ctx context.Context, user *models.User) error
// Token Storage
// FindToken finds a token in the storage using its value.
FindToken(ctx context.Context, value string) (*models.Token, error)
// FindTokenByID finds a token in the storage using its ID.
FindTokenByID(ctx context.Context, id string) (*models.Token, error)
// ListTokens finds all tokens in the storage that belong to a user.
ListTokens(ctx context.Context, user *models.User) ([]*models.Token, error)
// CreateToken creates a token in the storage.
CreateToken(ctx context.Context, token *models.Token) (*models.Token, error)
// ChangeTokenName changes the name of a token
ChangeTokenName(ctx context.Context, token *models.Token, name string) (*models.Token, error)
// DeleteToken deletes a token from the storage.
DeleteToken(ctx context.Context, token *models.Token) error
}