F#: Domain Modeling Workflows (vol. 5)

Portfolio.Workflow

module Workflows.Commands

open Commands
open Events

type private LinksWorkflow =  LinkCommand   -> LinksEvent  list
type private TopicsWorkflow = TopicsCommand -> TopicsEvent list

let handleLinks : LinksWorkflow = fun command -> command |> function
    | LinkCommand.Feature   linkId -> 
                            linkId |> Try.featureLink
                                   |> ResultOf.Link.Feature
                                   |> Handle.Registration.result
                                   
    | LinkCommand.Unfeature linkId -> 
                            linkId |> Try.unfeatureLink
                                   |> ResultOf.Link.Feature
                                   |> Handle.Registration.result

let handleTopics : TopicsWorkflow = fun command -> command |> function
    TopicsCommand.Feature topicIds ->
                          topicIds |> Try.featureTopics
                                   |> ResultOf.Topics.Feature
                                   |> Handle.Topics.result

Portfolio.Logic

module internal Handle

open Events
open Commands
open Commands.ResultOf

module Registration =

    type private LinkResult =   ResultOf.Link   -> LinksEvent list

    let linkResult : LinkResult =
        fun response ->
            response |> function
                        | Link.Feature   result -> 
                                         result |> function
                                                   | Ok    linkId -> [LinkFeatured       linkId]
                                                   | Error linkId -> [LinkFeaturedFailed linkId]
                        | Link.Unfeature result -> 
                                         result |> function
                                                   | Ok    linkId -> [LinkUnfeatured       linkId]
                                                   | Error linkId -> [LinkUnfeaturedFailed linkId]

module Topics =
    type private TopicsResult = ResultOf.Topics -> TopicsEvent list

    let result : TopicsResult =
        fun response ->
            response |> function
                        Topics.Feature result -> 
                                       result |> function
                                                 | Ok    topicIds -> [TopicsFeatured       topicIds]
                                                 | Error topicIds -> [TopicsFeaturedFailed topicIds]
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s