-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modify structure of domain layer to fully adhere to domain driven design
- Loading branch information
1 parent
c33849b
commit c119608
Showing
18 changed files
with
198 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package blobs | ||
|
||
// BlobManagement defines methods for managing blob operations. | ||
type BlobManagement interface { | ||
// Upload handles the upload of blobs from file paths. | ||
// Returns the created Blobs metadata and any error encountered. | ||
Upload(filePath []string) ([]*Blob, error) | ||
|
||
// Download retrieves a blob by its ID and name, returning the metadata and file data. | ||
// Returns the Blob metadata, file data as a byte slice, and any error. | ||
Download(blobId, blobName string) (*Blob, []byte, error) | ||
|
||
// DeleteByID removes a blob by its ID. | ||
// Returns any error encountered. | ||
DeleteByID(blobId string) error | ||
} | ||
|
||
// BlobMetadataManagement defines the methods for managing Blob metadata | ||
type BlobMetadataManagement interface { | ||
// Create creates a new blob | ||
Create(blob *Blob) (*Blob, error) | ||
// GetByID retrieves blob by ID | ||
GetByID(blobID string) (*Blob, error) | ||
// UpdateByID updates a blob's metadata | ||
UpdateByID(blobID string, updates *Blob) (*Blob, error) | ||
// DeleteByID deletes a blob by ID | ||
DeleteByID(blobID string) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package blobs | ||
|
||
import ( | ||
"crypto_vault_service/internal/domain/keys" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/go-playground/validator/v10" | ||
) | ||
|
||
// Blob represents metadata on the actual blob being stored | ||
type Blob struct { | ||
ID string `gorm:"primaryKey" validate:"required,uuid4"` // ID is required and must be a valid UUID | ||
UploadTime time.Time `validate:"required"` // UploadTime is required | ||
UserID string `validate:"required,uuid4"` // UserID is required and must be a valid UUID | ||
Name string `validate:"required,min=1,max=255"` // Name is required, and its length must be between 1 and 255 characters | ||
Size int64 `validate:"required,min=1"` // Size must be greater than 0 | ||
Type string `validate:"required,min=1,max=50"` // Type is required, and its length must be between 1 and 50 characters | ||
EncryptionAlgorithm string `validate:"omitempty,oneof=AES RSA ECDSA"` // EncryptionAlgorithm is optional and must be one of the listed algorithms | ||
HashAlgorithm string `validate:"omitempty,oneof=SHA256 SHA512 MD5"` // HashAlgorithm is optional and must be one of the listed algorithms | ||
IsEncrypted bool `validate:"-"` // IsEncrypted is required (true/false) | ||
IsSigned bool `validate:"-"` // IsSigned is required (true/false) | ||
CryptographicKey keys.CryptographicKey `gorm:"foreignKey:KeyID" validate:"required"` // CryptographicKey is required | ||
KeyID string `validate:"omitempty,uuid4"` // KeyID is optional and must be a valid UUID | ||
} | ||
|
||
// Validate for validating Blob struct | ||
func (b *Blob) Validate() error { | ||
// Initialize the validator | ||
validate := validator.New() | ||
|
||
// Validate the struct | ||
err := validate.Struct(b) | ||
if err != nil { | ||
// If validation fails, return a formatted error | ||
var validationErrors []string | ||
for _, err := range err.(validator.ValidationErrors) { | ||
validationErrors = append(validationErrors, fmt.Sprintf("Field: %s, Tag: %s", err.Field(), err.Tag())) | ||
} | ||
return fmt.Errorf("Validation failed: %v", validationErrors) | ||
} | ||
return nil // Return nil if validation passes | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
39 changes: 38 additions & 1 deletion
39
internal/domain/contracts/key_operations.go → internal/domain/keys/contract.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package model | ||
package keys | ||
|
||
import ( | ||
"fmt" | ||
|
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.