Skip to content

Commit

Permalink
added document builder type check for modes
Browse files Browse the repository at this point in the history
  • Loading branch information
beebeeoii committed Jan 8, 2022
1 parent 2a91edb commit 9c97c42
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Website = "https://github.com/beebeeoii/lominus"
Name = "Lominus"
ID = "com.beebeeoii.lominus"
Version = "1.1.4"
Build = 71
Build = 77
16 changes: 13 additions & 3 deletions pkg/api/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,27 @@ func BuildDocumentRequest(builder interface{}, mode int) (DocumentRequest, error

switch mode {
case GET_ALL_FOLDERS:
_, isModule := builder.(Module)
_, isFolder := builder.(Folder)
if !isModule && !isFolder {
return DocumentRequest{}, errors.New("invalid mode: DocumentRequest must be built using Module or Folder to have mode=GET_ALL_FOLDERS")
}
urlEndpoint = FOLDER_URL_ENDPOINT
case GET_ALL_FILES:
_, isModule := builder.(Module)
_, isFolder := builder.(Folder)
if !isModule && !isFolder {
return DocumentRequest{}, errors.New("invalid mode: DocumentRequest must be built using Module or Folder to have mode=GET_ALL_FILES")
}
urlEndpoint = FILE_URL_ENDPOINT
case DOWNLOAD_FILE:
_, isFile := builder.(File)
if !isFile {
return DocumentRequest{}, errors.New("invalid arguments: DocumentRequest must be built using File to download")
return DocumentRequest{}, errors.New("invalid mode: DocumentRequest must be built using File to download")
}
urlEndpoint = DOWNLOAD_URL_ENDPOINT
default:
return DocumentRequest{}, errors.New("invalid arguments: mode provided is not a valid mode")
return DocumentRequest{}, errors.New("invalid mode: mode provided is invalid. Valid modes are GET_ALL_FOLDERS (0), GET_ALL_FILES (1), DOWNLOAD_FILE (2)")
}

switch builder := builder.(type) {
Expand Down Expand Up @@ -152,7 +162,7 @@ func BuildDocumentRequest(builder interface{}, mode int) (DocumentRequest, error
Mode: mode,
}, nil
default:
return DocumentRequest{}, errors.New("invalid arguments: DocumentRequest must be built using Module or Folder only")
return DocumentRequest{}, errors.New("invalid builder: DocumentRequest must be built using Module, Folder or File only")
}
}

Expand Down

0 comments on commit 9c97c42

Please sign in to comment.