diff --git a/backend/entities/clients.go b/backend/entities/clients.go new file mode 100644 index 0000000..24e51eb --- /dev/null +++ b/backend/entities/clients.go @@ -0,0 +1,53 @@ +package entities + +import "fmt" + +const SERVER_VERSION = 1 + +type Client interface { + GetClientVersion() int +} + +func NewClient(clientVersion int) (error, Client) { + + isCompatible := ServerClientIsCompatibleWithClient(clientVersion) + + if !isCompatible { + return fmt.Errorf("You client version %n is not compatible with the server verison %n", clientVersion, SERVER_VERSION), nil + } + + client := ClientVerisonOne{ + Version: clientVersion, + } + + return nil, &client + +} + +func ServerClientIsCompatibleWithClient(clientVersion int) bool { + + switch clientVersion { + case 1: + + serverCompatibleVersion := []int{1} + + for _, serverVersion := range serverCompatibleVersion { + if serverVersion == clientVersion { + return true + } + } + + return false + default: + return false + } + +} + +type ClientVerisonOne struct { + Version int +} + +func (c *ClientVerisonOne) GetClientVersion() int { + return c.Version +} diff --git a/backend/entities/documents.go b/backend/entities/documents.go index 162585c..6048da9 100644 --- a/backend/entities/documents.go +++ b/backend/entities/documents.go @@ -5,10 +5,11 @@ import ( ) type Document struct { - DocumentUUID *string - DocumentType int - DocumentName *string - DocumentOriginalName string + UUID *string + Type int + Name *string + OriginalName string + Version int } const ( @@ -36,7 +37,7 @@ func IsDirectory(documentType int) bool { return DIRECTORY == documentType } -func NewDocument(documentName string, documentType int) (error, *Document) { +func NewDocument(documentName string, documentType int, documentVersion int) (error, *Document) { documentTypeIsValid := IsDocumentTypeValid(documentType) @@ -45,24 +46,25 @@ func NewDocument(documentName string, documentType int) (error, *Document) { } return nil, &Document{ - DocumentName: &documentName, - DocumentType: documentType, + Name: &documentName, + Type: documentType, + Version: documentVersion, } } func (d *Document) GetOriginalName() *string { - return &d.DocumentOriginalName + return &d.OriginalName } func (d *Document) GetName() *string { - if d.DocumentName == nil { + if d.Name == nil { return d.GetOriginalName() } - return d.DocumentName + return d.Name } diff --git a/backend/services/folders.go b/backend/services/folders.go new file mode 100644 index 0000000..2903e3b --- /dev/null +++ b/backend/services/folders.go @@ -0,0 +1,14 @@ +package services + +import "github.com/vaultdrop/backend/entities" + +func (s *Services) CreateFolder(folderName string, destination *entities.Document) (error, *entities.Document) { + + err, directory := entities.NewDocument(folderName, entities.DIRECTORY) + if err != nil { + return err, nil + } + + return nil, directory + +} diff --git a/backend/services/upload.go b/backend/services/upload.go index 864a17f..448a905 100644 --- a/backend/services/upload.go +++ b/backend/services/upload.go @@ -1,5 +1,19 @@ package services -func (s *Services) UploadDocument() { +import ( + "fmt" + + "github.com/vaultdrop/backend/entities" +) + +func (s *Services) UploadDocument(file *string, destination *entities.Document) error { + + if canEdit, _ := UserCanEditDocument(s.ConnectedUser, destination); !canEdit { + return fmt.Errorf("Can not edit") + } + + entities.NewDocument("test", entities.FILE) + + return nil }