Skip to content

Commit

Permalink
Categories out of subscriptions of user
Browse files Browse the repository at this point in the history
  • Loading branch information
brase committed Feb 18, 2020
1 parent 00175de commit a91014c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/Server/FeedCompositions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ module FeedCompositions =

let getCategoriesComposition eventStore =
let events = allFeedsEvents eventStore
ok (getCategories events)
let feeds = getFeeds events
ok (getCategories feeds)

let getCategoriesOfFeedsComposition eventStore feedIds =
let events = allFeedsEvents eventStore
let feeds = getFeeds events
|> List.filter (fun f -> List.contains f.Id feedIds)
ok (getCategories feeds)

let addEpisodeComposition eventStore feedId rendition =
let (events, version) = getAllEventsFromStreamById eventStore (getFeedStreamId feedId)
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Feeds.fs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ module FeedSource =
Length = rendition.Length
ReleaseDate = rendition.ReleaseDate }

let getCategories events =
getFeeds events
let getCategories (feeds:FeedListItemRendition list) =
feeds
|> List.map (fun s -> s.Category)
|> List.distinct
|> List.filter (System.String.IsNullOrWhiteSpace >> not)
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Server.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
Expand All @@ -17,11 +17,11 @@
<Compile Include="Http.fs" />
<Compile Include="Feeds.fs" />
<Compile Include="FeedCompositions.fs" />
<Compile Include="Subscriptions.fs" />
<Compile Include="Smapi.fs" />
<Compile Include="SmapiComposition.fs" />
<Compile Include="Users.fs" />
<Compile Include="UserCompositions.fs" />
<Compile Include="Subscriptions.fs" />
<Compile Include="Server.fs" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
Expand Down
3 changes: 2 additions & 1 deletion src/Server/Smapi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open FSharp.Data
open System.Text.RegularExpressions

open FeedCompositions
open SubscriptionCompositions

type SmapiMethod =
| GetMetadata of string*(UserId option)
Expand Down Expand Up @@ -92,7 +93,7 @@ module Smapi =
| Some t -> Some t.UserId

let getCategories eventStore userId =
let result = getCategoriesComposition eventStore
let result = SubscriptionCompositions.getSubscriptionsCategoriesComposition eventStore userId
match result with
| Success (categories) -> categories
|> List.sort
Expand Down
8 changes: 8 additions & 0 deletions src/Server/Subscriptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ module SubscriptionCompositions =
let evs = subscriptionEvents eventStore user.Id
ok (getSubscriptions evs)

let getSubscriptionsCategoriesComposition eventStore userId =
let feedIds = subscriptionEvents eventStore userId
|> getSubscriptions
|> List.map (fun s -> s.FeedId)
|> List.distinct
FeedCompositions.getCategoriesOfFeedsComposition eventStore feedIds


let subscriptionsRouter eventStore = router {
pipe_through authorize
get "" (processAuthorizedAsync getSubscriptionsComposition eventStore)
Expand Down

0 comments on commit a91014c

Please sign in to comment.