-
Notifications
You must be signed in to change notification settings - Fork 3
/
Genre.fs
39 lines (31 loc) · 862 Bytes
/
Genre.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
module FreyaMusicStore.Genre
open Arachne.Http
open Chiron
open Chiron.Operators
open Freya.Core
open Freya.Machine
open Freya.Machine.Extensions.Http
open Freya.Router
type Genre =
{ Name : string
Albums : Album.Album [] }
static member ToJson (x: Genre) =
Json.write "name" x.Name
*> Json.write "albums" x.Albums
let name =
freya {
let! name = Freya.getLensPartial (Route.Atom_ "0")
return name.Value
}
let fetch : Freya<Db.DbContext -> _> =
freya {
let! name = name
return
Db.getAlbumsForGenre name
>> Array.map Album.Album.fromDb
>> (fun albums -> { Name = name; Albums = albums })
}
let pipe =
freyaMachine {
including (res fetch "genre")
methodsSupported (Freya.init [GET]) } |> FreyaMachine.toPipeline