refactor(backend): layout canonique cmd/server + models/service/ocr/pkg + fix compilation héritée
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
err, config := config.LoadApplicationConfig()
|
err, _ := config.LoadApplicationConfig()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
|
|||||||
@@ -4,17 +4,17 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/vaultdrop/backend/entities"
|
"github.com/vaultdrop/backend/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUserCreation(t *testing.T) {
|
func TestUserCreation(t *testing.T) {
|
||||||
|
|
||||||
err, userAntoine := entities.NewUser("antoine")
|
err, userAntoine := models.NewUser("antoine")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf(`Error creating antoine user %v`, err)
|
t.Errorf(`Error creating antoine user %v`, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err, userBob := entities.NewUser("bob")
|
err, userBob := models.NewUser("bob")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf(`Error creating bob user %v`, err)
|
t.Errorf(`Error creating bob user %v`, err)
|
||||||
}
|
}
|
||||||
@@ -25,16 +25,16 @@ func TestUserCreation(t *testing.T) {
|
|||||||
|
|
||||||
func TestCreateDocument(t *testing.T) {
|
func TestCreateDocument(t *testing.T) {
|
||||||
|
|
||||||
err, document := entities.NewDocument("paper.pdf", entities.FILE)
|
err, document := models.NewDocument("paper.pdf", models.FILE, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf(`Error creating document %v`, err)
|
t.Errorf(`Error creating document %v`, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err, directory := entities.NewDocument("bob", entities.DIRECTORY)
|
err, directory := models.NewDocument("bob", models.DIRECTORY, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf(`Error creating bob directory %v`, err)
|
t.Errorf(`Error creating bob directory %v`, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(document, directory)
|
fmt.Println(document, directory)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
# Gin HTTP handlers land here (bind the routes, current 501 stubs).
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package entities
|
package models
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ func NewClient(clientVersion int) (error, Client) {
|
|||||||
isCompatible := ServerClientIsCompatibleWithClient(clientVersion)
|
isCompatible := ServerClientIsCompatibleWithClient(clientVersion)
|
||||||
|
|
||||||
if !isCompatible {
|
if !isCompatible {
|
||||||
return fmt.Errorf("You client version %n is not compatible with the server verison %n", clientVersion, SERVER_VERSION), nil
|
return fmt.Errorf("You client version %d is not compatible with the server verison %d", clientVersion, SERVER_VERSION), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
client := ClientVerisonOne{
|
client := ClientVerisonOne{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package entities
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
package entities
|
package models
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package entities
|
package models
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Username string
|
Username string
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package ocr
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
// Engine extracts text from a document (image or PDF) located at filePath.
|
||||||
|
// The V1 implementation is a Tesseract system call (OCR_LANG, défaut fra+eng);
|
||||||
|
// swapping to a remote service later only changes the injection point.
|
||||||
|
type Engine interface {
|
||||||
|
ExtractText(ctx context.Context, filePath string, lang string) (string, error)
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
# Postgres repositories land here (golang-migrate migrations, lib/pq).
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package services
|
package service
|
||||||
|
|
||||||
import "github.com/vaultdrop/backend/entities"
|
import "github.com/vaultdrop/backend/models"
|
||||||
|
|
||||||
func (s *Services) CreateFolder(folderName string, destination *entities.Document) (error, *entities.Document) {
|
func (s *Services) CreateFolder(folderName string, destination *models.Document) (error, *models.Document) {
|
||||||
|
|
||||||
err, directory := entities.NewDocument(folderName, entities.DIRECTORY)
|
err, directory := models.NewDocument(folderName, models.DIRECTORY, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
package services
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/vaultdrop/backend/entities"
|
"github.com/vaultdrop/backend/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Services) MoveDocumentIntoDocument(from *entities.Document, to *entities.Document) error {
|
func (s *Services) MoveDocumentIntoDocument(from *models.Document, to *models.Document) error {
|
||||||
|
|
||||||
if from.DocumentUUID == nil {
|
if from.UUID == nil {
|
||||||
return fmt.Errorf(entities.ERROR_DOCUMENT_NOT_PERCISTED)
|
return fmt.Errorf(models.ERROR_DOCUMENT_NOT_PERCISTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
if to.DocumentType != entities.DIRECTORY {
|
if to.Type != models.DIRECTORY {
|
||||||
return fmt.Errorf("The destination document must be a directory")
|
return fmt.Errorf("The destination document must be a directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ func (s *Services) MoveDocumentIntoDocument(from *entities.Document, to *entitie
|
|||||||
|
|
||||||
// Check if document exist and move the document into document if is directory
|
// Check if document exist and move the document into document if is directory
|
||||||
|
|
||||||
fmt.Println("To implement move to ", to.DocumentUUID)
|
fmt.Println("To implement move to ", to.UUID)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
package services
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/vaultdrop/backend/entities"
|
"github.com/vaultdrop/backend/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMoveDocument(t *testing.T) {
|
func TestMoveDocument(t *testing.T) {
|
||||||
|
|
||||||
err, userAntoine := entities.NewUser("antoine")
|
err, userAntoine := models.NewUser("antoine")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf(`Error creating antoine user %v`, err)
|
t.Errorf(`Error creating antoine user %v`, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fakeUUID := "dsqdsq"
|
fakeUUID := "dsqdsq"
|
||||||
err, document := entities.NewDocument("test.pdf", entities.FILE)
|
err, document := models.NewDocument("test.pdf", models.FILE, 1)
|
||||||
document.DocumentUUID = &fakeUUID
|
document.UUID = &fakeUUID
|
||||||
|
|
||||||
err, folder := entities.NewDocument("orga", entities.DIRECTORY)
|
err, folder := models.NewDocument("orga", models.DIRECTORY, 1)
|
||||||
folder.DocumentUUID = &fakeUUID
|
folder.UUID = &fakeUUID
|
||||||
|
|
||||||
service := New(userAntoine)
|
service := New(userAntoine)
|
||||||
|
|
||||||
@@ -32,14 +32,14 @@ func TestMoveDocument(t *testing.T) {
|
|||||||
|
|
||||||
func TestMoveDocumentToAFile(t *testing.T) {
|
func TestMoveDocumentToAFile(t *testing.T) {
|
||||||
|
|
||||||
err, userAntoine := entities.NewUser("antoine")
|
err, userAntoine := models.NewUser("antoine")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf(`Error creating antoine user %v`, err)
|
t.Errorf(`Error creating antoine user %v`, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err, document := entities.NewDocument("test.pdf", entities.FILE)
|
err, document := models.NewDocument("test.pdf", models.FILE, 1)
|
||||||
|
|
||||||
err, notAFolder := entities.NewDocument("orga", entities.FILE)
|
err, notAFolder := models.NewDocument("orga", models.FILE, 1)
|
||||||
|
|
||||||
service := New(userAntoine)
|
service := New(userAntoine)
|
||||||
|
|
||||||
@@ -49,4 +49,4 @@ func TestMoveDocumentToAFile(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
package services
|
package service
|
||||||
|
|
||||||
import "github.com/vaultdrop/backend/entities"
|
import "github.com/vaultdrop/backend/models"
|
||||||
|
|
||||||
// import "github.com/vaultdrop/backend/entities"
|
|
||||||
|
|
||||||
type Services struct {
|
type Services struct {
|
||||||
ConnectedUser *entities.User
|
ConnectedUser *models.User
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(connectedUser *entities.User) *Services {
|
func New(connectedUser *models.User) *Services {
|
||||||
|
|
||||||
return &Services{
|
return &Services{
|
||||||
ConnectedUser: connectedUser,
|
ConnectedUser: connectedUser,
|
||||||
@@ -16,18 +14,18 @@ func New(connectedUser *entities.User) *Services {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserCanReadDocument(connectedUser *entities.User, document *entities.Document) (bool, string) {
|
func UserCanReadDocument(connectedUser *models.User, document *models.Document) (bool, string) {
|
||||||
return true, ""
|
return true, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserCanEditDocument(connectedUser *entities.User, document *entities.Document) (bool, string) {
|
func UserCanEditDocument(connectedUser *models.User, document *models.Document) (bool, string) {
|
||||||
return true, ""
|
return true, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserCanDeleteDocument(connectedUser *entities.User, document *entities.Document) (bool, string) {
|
func UserCanDeleteDocument(connectedUser *models.User, document *models.Document) (bool, string) {
|
||||||
return true, ""
|
return true, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserCanCreateDocument(connectedUser *entities.User, document *entities.Document) (bool, string) {
|
func UserCanCreateDocument(connectedUser *models.User, document *models.Document) (bool, string) {
|
||||||
return true, ""
|
return true, ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
package services
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/vaultdrop/backend/entities"
|
"github.com/vaultdrop/backend/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Services) UploadDocument(file *string, destination *entities.Document) error {
|
func (s *Services) UploadDocument(file *string, destination *models.Document) error {
|
||||||
|
|
||||||
if canEdit, _ := UserCanEditDocument(s.ConnectedUser, destination); !canEdit {
|
if canEdit, _ := UserCanEditDocument(s.ConnectedUser, destination); !canEdit {
|
||||||
return fmt.Errorf("Can not edit")
|
return fmt.Errorf("Can not edit")
|
||||||
}
|
}
|
||||||
|
|
||||||
entities.NewDocument("test", entities.FILE)
|
models.NewDocument("test", models.FILE, 1)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
# Uploaded files (MAX_FILE_SIZE_MB = 50 by default).
|
||||||
Reference in New Issue
Block a user