postgresrepo

package
v0.0.0-...-bd94320 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PostgresRepository

type PostgresRepository struct {
	// contains filtered or unexported fields
}

PostgresRepository is a repository for PostgreSQL database. It used to upload, download and delete metadata.

func New

func New(ctx context.Context, connStr string) (*PostgresRepository, error)

New creates a new instance of PostgresRepository using the provided connection string. It parses the connection string to configure the database connection and then establishes the connection. Returns a pointer to the created PostgresRepository and an error if any step fails.

func (PostgresRepository) AddUser

func (p PostgresRepository) AddUser(
	ctx context.Context,
	login, passHash string,
) (uuid.UUID, error)

AddUser add user to repository. Returns uuid of added user or error if user creation failed. Login must be unique, otherwise ErrUserAlreadyExists will be returned.

func (PostgresRepository) DeleteMetadata

func (p PostgresRepository) DeleteMetadata(ctx context.Context, id, userID uuid.UUID) error

DeleteMetadata delete metadata from repository. Returns error if delete failed.

func (PostgresRepository) GetMetadataByUserID

func (p PostgresRepository) GetMetadataByUserID(
	ctx context.Context,
	userID uuid.UUID,
) ([]models.Metadata, error)

GetMetadataByUserID retrieves metadata associated with a given user ID from the PostgreSQL database.

It queries the metadata table to fetch all metadata records belonging to the specified user ID. Each record includes information such as ID, name, MIME type, file status, public visibility, creation time, owner ID, JSON data, file size, and access grants.

Returns a slice of models.Metadata if successful, or an error if the query fails or if there is an issue scanning the rows.

func (PostgresRepository) GetUserByLogin

func (p PostgresRepository) GetUserByLogin(
	ctx context.Context,
	login string,
) (models.User, error)

GetUserByLogin retrieves a user from the PostgreSQL database using the given login. It executes a query to fetch the user's ID, login, and password hash. Returns a models.User if the query is successful. Returns ErrWrongCredentials if no user is found with the specified login. Returns an error for any other query failure.

func (PostgresRepository) UploadMetadata

func (p PostgresRepository) UploadMetadata(
	ctx context.Context,
	meta models.Metadata,
) (uuid.UUID, error)

UploadMetadata uploads metadata to the PostgreSQL database.

It begins a transaction, inserts metadata into the metadata table, and grants access to specified users by adding entries to the meta_access table.

If any step fails, the transaction is rolled back, and an error is returned.

Returns the UUID of the newly inserted metadata if successful, or an error if not.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL