-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dto.fs
47 lines (38 loc) · 1.54 KB
/
Dto.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module FreshBooks2Harvest.Dto
open FreshBooks2Harvest.Domain
open FreshBooks2Harvest.Common
open FreshBooks2Harvest.Common.Result
type FreshBooksAuthorizationConfigDto = {
clientId : string
clientSecret : string
authorizationCode : string
redirectUrl : string
}
type AuthorizationConfigDto = {
freshBooks : FreshBooksAuthorizationConfigDto
}
type ConfigDto = {
dataDir : string
auth : AuthorizationConfigDto
}
module ConfigDto =
open System
let freshBooksAuthConfigToDomain freshBooks =
FreshBooksAuthorizationConfig.create
<^> notNull ClientId freshBooks.clientId
<*> notNull ClientSecret freshBooks.clientSecret
<*> notNull AuthorizationCode freshBooks.authorizationCode
<*> notNull RedirectUrl freshBooks.redirectUrl
let private authConfigToDomain auth =
AuthorizationConfig.create
<^> (notNull FreshBooks auth.freshBooks
>>= (freshBooksAuthConfigToDomain >> Result.wrapTag FreshBooksChild))
let toDomain configDto =
Config.create
<^> (notNull DataDir configDto.dataDir
|> Result.map
(fun dir -> dir.Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)))
>>= (createDirectory ExternalSource.DataDir >> Result.tag DataDir))
<*> (notNull Auth configDto.auth
>>= (authConfigToDomain >> Result.wrapTag AuthChild))
|> Result.mapError ConfigInvalid