domain

package
v0.0.0-...-2e0f99f Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileAlreadyClaimed      = errors.New("file already claimed")
	ErrFileOutOfDate           = errors.New("file out of date")
	ErrUserNotOwner            = errors.New("user not owner")
	ErrInvalidClaimMode        = errors.New("invalid claim mode")
	ErrorFileNotMissing        = errors.New("file not missing")
	ErrFileInfoInvariantBroken = errors.New("file info invariant broken")
)

Functions

This section is empty.

Types

type ClaimMode

type ClaimMode int32

Enum for claim mode Should be kept in sync with the protobuf file.

const (
	ClaimMode_Unclaimed ClaimMode = iota
	ClaimMode_Shared
	ClaimMode_Exclusive
)

type ClaimRequest

type ClaimRequest interface {
	FilesRequest
	GetBranchName() string
	GetIsSoftClaim() bool
	GetRequests() []FileClaim
}

ClaimRequest is an interface for requests that claim files.

func NewClaimRequest

func NewClaimRequest(branchName string, softClaim bool, requests []FileClaim) ClaimRequest

NewClaimRequest creates a new claim request.

type ColabDatabase

type ColabDatabase interface {
	Ping() error
	List(ctx context.Context, logger zerolog.Logger, projectId string, cursor uint64, pageSize int64, folderPath string) ([]*FileInfo, uint64, error)
	Claim(ctx context.Context, logger zerolog.Logger, userId string, projectId string, request ClaimRequest) ([]*FileInfo, error)
	Update(ctx context.Context, logger zerolog.Logger, userId string, projectId string, request UpdateRequest) ([]*FileInfo, error)
	Release(ctx context.Context, logger zerolog.Logger, userId string, projectId string, branchId string, request FilesRequest) ([]*FileInfo, error)
}

ColabDatabase is the interface for the database.

type FileClaim

type FileClaim interface {
	GetFileId() string
	GetFileHash() string
	GetClaimMode() ClaimMode
}

FileClaim is an interface on how a file should be claimed.

func NewFileClaim

func NewFileClaim(fileId string, fileHash string, claimMode ClaimMode) FileClaim

NewFileClaim creates a new file claim.

type FileInfo

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

FileInfo represents a file in the system

TODO: Look into: https://pkg.go.dev/github.com/redis/rueidis/om#section-readme TODO: Look into: https://stackoverflow.com/questions/11126793/json-and-dealing-with-unexported-fields

func NewBlankFileInfo

func NewBlankFileInfo() *FileInfo

NewBlankFileInfo creates a new blank without the need for parameters.

Ideal for creating a new FileInfo that will be populated later on such as unmarshalling from a database.

func NewFileInfo

func NewFileInfo(fileId string, fileHash string, branchName string) *FileInfo

NewFileInfo creates a new FileInfo that meets the invariants of the struct

func NewFullFileInfo

func NewFullFileInfo(fileId string, fileHash string, userIds []string, branchName string, claimMode ClaimMode, rejectReason RejectReason) (*FileInfo, error)

NewFullFileInfo creates a new FileInfo with all the fields set. Can error if the claim mode is not Unclaimed and there are no user IDs.

func NewMissingFileInfo

func NewMissingFileInfo(fileId string) *FileInfo

NewMissingFileInfo creates a new FileInfo for a file that is missing.

func (*FileInfo) CheckOwner

func (fi *FileInfo) CheckOwner(userId string) bool

CheckOwner checks if a user is an owner of a file

func (*FileInfo) Claim

func (fi *FileInfo) Claim(userId string, fileHash string, claimMode ClaimMode) error

Claim claims a file for a user

func (*FileInfo) GetBranchName

func (fi *FileInfo) GetBranchName() string

GetBranchName returns the branchName of the FileInfo

func (*FileInfo) GetClaimMode

func (fi *FileInfo) GetClaimMode() ClaimMode

GetClaimMode returns the claimMode of the FileInfo

func (*FileInfo) GetFileHash

func (fi *FileInfo) GetFileHash() string

GetFileHash returns the fileHash of the FileInfo

func (*FileInfo) GetFileId

func (fi *FileInfo) GetFileId() string

GetFileId returns the fileId of the FileInfo

func (*FileInfo) GetRejectReason

func (fi *FileInfo) GetRejectReason() RejectReason

GetRejectReason returns the rejectReason of the FileInfo

func (*FileInfo) GetUserIds

func (fi *FileInfo) GetUserIds() []string

GetUserIds returns the userIds of the FileInfo

func (*FileInfo) Release

func (fi *FileInfo) Release(userId string) error

Release releases a file from a user if they are an owner

func (*FileInfo) Update

func (fi *FileInfo) Update(userId string, branchName string, oldHash string, fileHash string) error

Update updates the file hash for a file only if the user is an owner

func (*FileInfo) UpgradeMissingToNew

func (fi *FileInfo) UpgradeMissingToNew(fileHash string, branchName string) error

UpgradeMissingToNew upgrades a missing file to a new file setting up the object invariants. Can error if the file is not missing.

type FileUpdate

type FileUpdate interface {
	GetFileId() string
	GetFileHash() string
	GetOldHash() string
}

func NewFileUpdate

func NewFileUpdate(fileId string, fileHash string, oldHash string) FileUpdate

NewFileUpdate creates a new file update request.

type FilesRequest

type FilesRequest interface {
	GetFileIDs() []string
}

FilesRequest is an interface for requests that contain lists of files whos IDs can be retrieved.

func NewFilesRequest

func NewFilesRequest(fileIds []string) FilesRequest

NewFilesRequest creates a new files request.

type RejectReason

type RejectReason int32

Enum for reject reason Should be kept in sync with the protobuf file.

const (
	RejectReason_None RejectReason = iota
	RejectReason_AlreadyClaimed
	RejectReason_OutOfDate
	RejectReason_NotOwner
	RejectReason_InvalidClaimMode
	RejectReason_Missing
)

type UpdateRequest

type UpdateRequest interface {
	FilesRequest
	GetBranchName() string
	GetRequests() []FileUpdate
}

func NewUpdateRequest

func NewUpdateRequest(branchName string, requests []FileUpdate) UpdateRequest

NewUpdateRequest creates a new update request.

Jump to

Keyboard shortcuts

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