@startuml ' title =**Upload Episode Actions** participant EpisodeActionController << (C, #ADD1B2) @Controller >> -> EpisodeActionController: ""POST /api/2/episodes/{username}.json"" \n//@RequestBody EpisodeActionPostRequest episodeActionPostRequest// \n\n-> addEpisodeActions(""username"", //episodeActionPostRequest//) activate EpisodeActionController participant EpisodeActionService << (C, #ADD1B2) @Service >> EpisodeActionController -> EpisodeActionService: addEpisodeActions(""username"", \nepisodeActionPosts = //episodeActionPostRequest//.getEpisodeActionPosts()) activate EpisodeActionService participant EpisodeActionDataAccessService << (C, #ADD1B2) @Repository >> EpisodeActionService -> EpisodeActionDataAccessService: addEpisodeActions(""username"", episodeActionPosts) database Database activate EpisodeActionDataAccessService loop for each EpisodeActionPost in episodeActionPosts -> episodeAction = episodeActionPost.getEpisodeAction() opt episodeAction.getAction().equals(Action.PLAY) EpisodeActionDataAccessService -> Database: set episodeID field of episodeAction for this ""username"" via podcastURL and episodeURL activate Database Database --> EpisodeActionDataAccessService EpisodeActionDataAccessService -> Database: get last EpisodeAction with this episodeID if present Database --> EpisodeActionDataAccessService: Optional lastEpisodeAction opt lastEpisodeAction.isPresent() EpisodeActionDataAccessService -> Database: replace lastEpisodeAction with episodeAction else else EpisodeActionDataAccessService -> Database: add episodeAction to DB as new entry end Database --> EpisodeActionDataAccessService deactivate Database end end EpisodeActionDataAccessService --> EpisodeActionService: long latestTimestamp deactivate EpisodeActionDataAccessService EpisodeActionService --> EpisodeActionController: LocalDateTime timestamp = LocalDateTime.ofEpochSecond(latestTimestamp, 0, ZoneOffset.UTC) deactivate EpisodeActionService <-- EpisodeActionController: ResponseEntity \n(with empty list for updateURLs) \n\n-> ""HTTP status code"" \n-> ""JSON"" deactivate EpisodeActionController @enduml