client version
This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
@@ -5,10 +5,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Document struct {
|
type Document struct {
|
||||||
DocumentUUID *string
|
UUID *string
|
||||||
DocumentType int
|
Type int
|
||||||
DocumentName *string
|
Name *string
|
||||||
DocumentOriginalName string
|
OriginalName string
|
||||||
|
Version int
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -36,7 +37,7 @@ func IsDirectory(documentType int) bool {
|
|||||||
return DIRECTORY == documentType
|
return DIRECTORY == documentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDocument(documentName string, documentType int) (error, *Document) {
|
func NewDocument(documentName string, documentType int, documentVersion int) (error, *Document) {
|
||||||
|
|
||||||
documentTypeIsValid := IsDocumentTypeValid(documentType)
|
documentTypeIsValid := IsDocumentTypeValid(documentType)
|
||||||
|
|
||||||
@@ -45,24 +46,25 @@ func NewDocument(documentName string, documentType int) (error, *Document) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil, &Document{
|
return nil, &Document{
|
||||||
DocumentName: &documentName,
|
Name: &documentName,
|
||||||
DocumentType: documentType,
|
Type: documentType,
|
||||||
|
Version: documentVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Document) GetOriginalName() *string {
|
func (d *Document) GetOriginalName() *string {
|
||||||
|
|
||||||
return &d.DocumentOriginalName
|
return &d.OriginalName
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Document) GetName() *string {
|
func (d *Document) GetName() *string {
|
||||||
|
|
||||||
if d.DocumentName == nil {
|
if d.Name == nil {
|
||||||
return d.GetOriginalName()
|
return d.GetOriginalName()
|
||||||
}
|
}
|
||||||
|
|
||||||
return d.DocumentName
|
return d.Name
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,19 @@
|
|||||||
package services
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user