Skip to content

Commit

Permalink
feeds of categories and playSecondsReported
Browse files Browse the repository at this point in the history
  • Loading branch information
brase committed Feb 18, 2020
1 parent 3fe3acc commit d49139f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 29 deletions.
5 changes: 3 additions & 2 deletions src/Server/FeedCompositions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ module FeedCompositions =
ok (getFeed events)

let getFeedsOfCategoryComposition eventStore category =
let events = allFeedsEvents eventStore
ok (getFeedsOfCategory category events)
let feeds = allFeedsEvents eventStore
|> getFeeds
ok (getFeedsOfCategory category feeds)

let getEpisodesOfFeedComposition eventStore id =
let (events, _) = getAllEventsFromStreamById eventStore (getFeedStreamId id)
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Feeds.fs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ module FeedSource =
|> List.distinct
|> List.filter (System.String.IsNullOrWhiteSpace >> not)

let getFeedsOfCategory category events =
getFeeds events
let getFeedsOfCategory category (feeds:FeedListItemRendition list) =
feeds
|> List.filter (fun s -> s.Category = category)

let getEpisodes events =
Expand Down
42 changes: 20 additions & 22 deletions src/Server/Smapi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ module Smapi =
CanPlay = false }]
|> Seq.ofList

let private getPlayEpisodeStreamId userId feedId episodeId =
sprintf "PlayEpisode__%A__%A__%A" userId feedId episodeId

let getUserFromHeader (db:Database.DatabaseConnection) xml =
let header = Header.Parse xml
let loginToken = header.Header.Credentials.LoginToken
Expand All @@ -105,7 +108,7 @@ module Smapi =
| _ -> failwith("bla")

let getPodcastsOfCategory eventStore userId c =
let result = getFeedsOfCategoryComposition eventStore c
let result = getPodcastsOfCategoriesForUser eventStore userId c
match result with
| Success (feeds) -> feeds
|> List.sortBy (fun s -> s.Name)
Expand Down Expand Up @@ -210,27 +213,22 @@ module Smapi =
PollIntervall = 500 }
ok (toLastUpdateXml result)

let processReportPlaySecondsRequest eventstore s =
// let req = ReportPlaySecondsRequest.Parse s
// let id = req.Body.ReportPlaySeconds.Id
// let position = req.Body.ReportPlaySeconds.OffsetMillis

// let (episodeId, feedId) = match id with
// | MediaMetadataId (feedId, episodeId) -> (episodeId, feedId)
// | _ -> failwithf "unknown Id for play seconds reported: %s" id
// let streamId = (getFeedStreamId (string feedId))
// let version = match eventstore.GetEvents streamId with
// | Success (version, _) -> version
// | _ -> StreamVersion 0

// let ev = PlaySecondsReported { Id = episodeId
// FeedId = FeedId feedId
// Position = position }
// match eventstore.SaveEvents streamId version [ev] with
// | Success _ -> ()
// | Failure (error:Error) -> failwith (string error)

()
let processReportPlaySecondsRequest eventstore s (UserId u) =
let req = ReportPlaySecondsRequest.Parse s
let id = req.Body.ReportPlaySeconds.Id
let position = req.Body.ReportPlaySeconds.OffsetMillis

//FeedId is SubscriptionId? Which user?
let (episodeId, feedId) =
match id with
| MediaMetadataId (feedId, episodeId) -> (episodeId, feedId)
| _ -> failwithf "unknown Id for play seconds reported: %s" id

let streamId = getPlayEpisodeStreamId u feedId episodeId
let ev = PlaySecondsReported { Id = episodeId
FeedId = FeedId feedId
Position = position }
storeEvent eventstore (fun _ -> streamId) ev

let processGetAppLink (db:Database.DatabaseConnection) s =
let req = GetAppLinkRequest.Parse s
Expand Down
7 changes: 4 additions & 3 deletions src/Server/SmapiComposition.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ module SmapiCompositions =
| GetMetadata (_, None) -> fail "User not found"
| GetMediaMetadata (s,u) -> processGetMediaMetadata eventStore (GetMediaMetadataRequest.Parse s)
| GetLastUpdate (s,u) -> processGetLastUpdate (GetLastUpdateRequest.Parse s)
| GetMediaURI (s,u) -> processGetMediaURI eventStore s
| ReportPlaySeconds (s,u) ->
processReportPlaySecondsRequest eventStore s
| GetMediaURI (s, _) -> processGetMediaURI eventStore s
| ReportPlaySeconds (s, Some u) ->
processReportPlaySecondsRequest eventStore s u
ok("")
| ReportPlaySeconds (_, None) -> fail "user not found"
| ReportPlayStatus _ -> ok("")
| SetPlayedSeconds _ -> ok("")
| GetAppLink (s,u) -> processGetAppLink db s
Expand Down
6 changes: 6 additions & 0 deletions src/Server/Subscriptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ module SubscriptionCompositions =
feedsOfUser eventStore userId
|> getCategoriesOfFeedsComposition eventStore

let getPodcastsOfCategoriesForUser eventStore userId c =
let feedIds = feedsOfUser eventStore userId
match getFeedsOfCategoryComposition eventStore c with
| Success feeds -> ok (feeds |> List.filter (fun f -> List.contains f.Id feedIds))
| Failure _ -> failwith "Bla"

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

0 comments on commit d49139f

Please sign in to comment.