Skip to content

Commit

Permalink
Switched validations from lists to arrays, because fuck linked lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottArbeit committed Nov 4, 2023
1 parent 828baa0 commit 04049af
Show file tree
Hide file tree
Showing 8 changed files with 704 additions and 698 deletions.
840 changes: 427 additions & 413 deletions src/Grace.Server/Branch.Server.fs

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions src/Grace.Server/Diff.Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open System.Threading.Tasks
open System.Text.Json

module Diff =
type Validations<'T when 'T :> DiffParameters> = 'T -> HttpContext -> Task<Result<unit, DiffError>> list
type Validations<'T when 'T :> DiffParameters> = 'T -> HttpContext -> Task<Result<unit, DiffError>> array

let activitySource = new ActivitySource("Repository")

Expand Down Expand Up @@ -120,10 +120,10 @@ module Diff =
task {
try
let validations (parameters: PopulateParameters) (context: HttpContext) =
[ Guid.isNotEmpty parameters.DirectoryId1 DiffError.InvalidDirectoryId
Guid.isNotEmpty parameters.DirectoryId2 DiffError.InvalidDirectoryId
Directory.directoryIdExists parameters.DirectoryId1 DiffError.DirectoryDoesNotExist
Directory.directoryIdExists parameters.DirectoryId2 DiffError.DirectoryDoesNotExist ]
[| Guid.isNotEmpty parameters.DirectoryId1 DiffError.InvalidDirectoryId
Guid.isNotEmpty parameters.DirectoryId2 DiffError.InvalidDirectoryId
Directory.directoryIdExists parameters.DirectoryId1 DiffError.DirectoryDoesNotExist
Directory.directoryIdExists parameters.DirectoryId2 DiffError.DirectoryDoesNotExist |]

let query (context: HttpContext) _ (actorProxy: IDiffActor) =
task {
Expand All @@ -143,10 +143,10 @@ module Diff =
task {
try
let validations (parameters: GetDiffParameters) (context: HttpContext) =
[ Guid.isNotEmpty parameters.DirectoryId1 DiffError.InvalidDirectoryId
Guid.isNotEmpty parameters.DirectoryId2 DiffError.InvalidDirectoryId
Directory.directoryIdExists parameters.DirectoryId1 DiffError.DirectoryDoesNotExist
Directory.directoryIdExists parameters.DirectoryId2 DiffError.DirectoryDoesNotExist ]
[| Guid.isNotEmpty parameters.DirectoryId1 DiffError.InvalidDirectoryId
Guid.isNotEmpty parameters.DirectoryId2 DiffError.InvalidDirectoryId
Directory.directoryIdExists parameters.DirectoryId1 DiffError.DirectoryDoesNotExist
Directory.directoryIdExists parameters.DirectoryId2 DiffError.DirectoryDoesNotExist |]

let query (context: HttpContext) _ (actorProxy: IDiffActor) =
task {
Expand All @@ -167,10 +167,10 @@ module Diff =
task {
try
let validations (parameters: GetDiffBySha256HashParameters) (context: HttpContext) =
[ String.isNotEmpty parameters.Sha256Hash1 DiffError.Sha256HashIsRequired
String.isNotEmpty parameters.Sha256Hash2 DiffError.Sha256HashIsRequired
String.isValidSha256Hash parameters.Sha256Hash1 DiffError.InvalidSha256Hash
String.isValidSha256Hash parameters.Sha256Hash2 DiffError.InvalidSha256Hash ]
[| String.isNotEmpty parameters.Sha256Hash1 DiffError.Sha256HashIsRequired
String.isNotEmpty parameters.Sha256Hash2 DiffError.Sha256HashIsRequired
String.isValidSha256Hash parameters.Sha256Hash1 DiffError.InvalidSha256Hash
String.isValidSha256Hash parameters.Sha256Hash2 DiffError.InvalidSha256Hash |]

let query (context: HttpContext) _ (actorProxy: IDiffActor) =
task {
Expand Down
52 changes: 26 additions & 26 deletions src/Grace.Server/Directory.Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open System.Threading.Tasks

module DirectoryVersion =

type Validations<'T when 'T :> DirectoryParameters> = 'T -> HttpContext -> Task<Result<unit, DirectoryError>> list
type Validations<'T when 'T :> DirectoryParameters> = 'T -> HttpContext -> Task<Result<unit, DirectoryError>> array
//type QueryResult<'T, 'U when 'T :> DirectoryParameters> = 'T -> int -> IDirectoryVersionActor ->Task<'U>

let activitySource = new ActivitySource("Branch")
Expand Down Expand Up @@ -88,9 +88,9 @@ module DirectoryVersion =
fun (next: HttpFunc) (context: HttpContext) ->
task {
let validations (parameters: CreateParameters) (context: HttpContext) =
[ Guid.isValidAndNotEmpty $"{parameters.DirectoryVersion.DirectoryId}" DirectoryError.InvalidDirectoryId
Guid.isValidAndNotEmpty $"{parameters.DirectoryVersion.RepositoryId}" DirectoryError.InvalidRepositoryId
Repository.repositoryIdExists $"{parameters.DirectoryVersion.RepositoryId}" DirectoryError.RepositoryDoesNotExist ]
[| Guid.isValidAndNotEmpty $"{parameters.DirectoryVersion.DirectoryId}" DirectoryError.InvalidDirectoryId
Guid.isValidAndNotEmpty $"{parameters.DirectoryVersion.RepositoryId}" DirectoryError.InvalidRepositoryId
Repository.repositoryIdExists $"{parameters.DirectoryVersion.RepositoryId}" DirectoryError.RepositoryDoesNotExist |]

let command (parameters: CreateParameters) (context: HttpContext) =
task {
Expand All @@ -108,10 +108,10 @@ module DirectoryVersion =
fun (next: HttpFunc) (context: HttpContext) ->
task {
let validations (parameters: GetParameters) (context: HttpContext) =
[ Guid.isValidAndNotEmpty $"{parameters.RepositoryId}" DirectoryError.InvalidRepositoryId
Guid.isValidAndNotEmpty $"{parameters.DirectoryId}" DirectoryError.InvalidRepositoryId
Repository.repositoryIdExists $"{parameters.RepositoryId}" DirectoryError.RepositoryDoesNotExist
Directory.directoryIdExists (Guid.Parse(parameters.DirectoryId)) DirectoryError.DirectoryDoesNotExist ]
[| Guid.isValidAndNotEmpty $"{parameters.RepositoryId}" DirectoryError.InvalidRepositoryId
Guid.isValidAndNotEmpty $"{parameters.DirectoryId}" DirectoryError.InvalidRepositoryId
Repository.repositoryIdExists $"{parameters.RepositoryId}" DirectoryError.RepositoryDoesNotExist
Directory.directoryIdExists (Guid.Parse(parameters.DirectoryId)) DirectoryError.DirectoryDoesNotExist |]

let query (context: HttpContext) (maxCount: int) (actorProxy: IDirectoryVersionActor) =
task {
Expand All @@ -128,10 +128,10 @@ module DirectoryVersion =
fun (next: HttpFunc) (context: HttpContext) ->
task {
let validations (parameters: GetParameters) (context: HttpContext) =
[ Guid.isValidAndNotEmpty $"{parameters.RepositoryId}" DirectoryError.InvalidRepositoryId
Guid.isValidAndNotEmpty $"{parameters.DirectoryId}" DirectoryError.InvalidRepositoryId
Repository.repositoryIdExists $"{parameters.RepositoryId}" DirectoryError.RepositoryDoesNotExist
Directory.directoryIdExists (Guid.Parse(parameters.DirectoryId)) DirectoryError.DirectoryDoesNotExist ]
[| Guid.isValidAndNotEmpty $"{parameters.RepositoryId}" DirectoryError.InvalidRepositoryId
Guid.isValidAndNotEmpty $"{parameters.DirectoryId}" DirectoryError.InvalidRepositoryId
Repository.repositoryIdExists $"{parameters.RepositoryId}" DirectoryError.RepositoryDoesNotExist
Directory.directoryIdExists (Guid.Parse(parameters.DirectoryId)) DirectoryError.DirectoryDoesNotExist |]

let query (context: HttpContext) (maxCount: int) (actorProxy: IDirectoryVersionActor) =
task {
Expand All @@ -148,9 +148,9 @@ module DirectoryVersion =
fun (next: HttpFunc) (context: HttpContext) ->
task {
let validations (parameters: GetByDirectoryIdsParameters) (context: HttpContext) =
[ Guid.isValidAndNotEmpty $"{parameters.RepositoryId}" DirectoryError.InvalidRepositoryId
Repository.repositoryIdExists $"{parameters.RepositoryId}" DirectoryError.RepositoryDoesNotExist
Directory.directoryIdsExist parameters.DirectoryIds DirectoryError.DirectoryDoesNotExist ]
[| Guid.isValidAndNotEmpty $"{parameters.RepositoryId}" DirectoryError.InvalidRepositoryId
Repository.repositoryIdExists $"{parameters.RepositoryId}" DirectoryError.RepositoryDoesNotExist
Directory.directoryIdsExist parameters.DirectoryIds DirectoryError.DirectoryDoesNotExist |]

let query (context: HttpContext) (maxCount: int) (actorProxy: IDirectoryVersionActor) =
task {
Expand All @@ -172,10 +172,10 @@ module DirectoryVersion =
fun (next: HttpFunc) (context: HttpContext) ->
task {
let validations (parameters: GetBySha256HashParameters) (context: HttpContext) =
[ Guid.isValidAndNotEmpty $"{parameters.DirectoryId}" DirectoryError.InvalidDirectoryId
Guid.isValidAndNotEmpty $"{parameters.RepositoryId}" DirectoryError.InvalidRepositoryId
String.isNotEmpty parameters.Sha256Hash DirectoryError.Sha256HashIsRequired
Repository.repositoryIdExists $"{parameters.RepositoryId}" DirectoryError.RepositoryDoesNotExist ]
[| Guid.isValidAndNotEmpty $"{parameters.DirectoryId}" DirectoryError.InvalidDirectoryId
Guid.isValidAndNotEmpty $"{parameters.RepositoryId}" DirectoryError.InvalidRepositoryId
String.isNotEmpty parameters.Sha256Hash DirectoryError.Sha256HashIsRequired
Repository.repositoryIdExists $"{parameters.RepositoryId}" DirectoryError.RepositoryDoesNotExist |]

let query (context: HttpContext) (maxCount: int) (actorProxy: IDirectoryVersionActor) =
task {
Expand All @@ -194,15 +194,15 @@ module DirectoryVersion =
fun (next: HttpFunc) (context: HttpContext) ->
task {
let validations (parameters: SaveDirectoryVersionsParameters) (context: HttpContext) =
let mutable allValidations: Task<Result<unit, DirectoryError>> list = List.Empty
let mutable allValidations: Task<Result<unit, DirectoryError>> array = Array.Empty()
for directoryVersion in parameters.DirectoryVersions do
let validations =
[ Guid.isValidAndNotEmpty $"{directoryVersion.DirectoryId}" DirectoryError.InvalidDirectoryId
Guid.isValidAndNotEmpty $"{directoryVersion.RepositoryId}" DirectoryError.InvalidRepositoryId
String.isNotEmpty $"{directoryVersion.Sha256Hash}" DirectoryError.Sha256HashIsRequired
String.isNotEmpty $"{directoryVersion.RelativePath}" DirectoryError.RelativePathMustNotBeEmpty
Repository.repositoryIdExists $"{directoryVersion.RepositoryId}" DirectoryError.RepositoryDoesNotExist ]
allValidations <- List.append allValidations validations
[| Guid.isValidAndNotEmpty $"{directoryVersion.DirectoryId}" DirectoryError.InvalidDirectoryId
Guid.isValidAndNotEmpty $"{directoryVersion.RepositoryId}" DirectoryError.InvalidRepositoryId
String.isNotEmpty $"{directoryVersion.Sha256Hash}" DirectoryError.Sha256HashIsRequired
String.isNotEmpty $"{directoryVersion.RelativePath}" DirectoryError.RelativePathMustNotBeEmpty
Repository.repositoryIdExists $"{directoryVersion.RepositoryId}" DirectoryError.RepositoryDoesNotExist |]
allValidations <- Array.append allValidations validations
allValidations

let command (parameters: SaveDirectoryVersionsParameters) (context: HttpContext) =
Expand Down
Loading

0 comments on commit 04049af

Please sign in to comment.