using System; using System.Collections.Generic; using System.Linq; using Nancy; using Newtonsoft.Json; using Sony.Filtr.AppleMusic; using Sony.Filtr.AppleMusic.Streams; using Sony.Filtr.Contracts.Abstractions; using Sony.Filtr.Contracts.Definitions; using Sony.Filtr.Utility; using Sony.Filtr.Utility.Serialization; namespace Sony.Filtr.AdminAPI.Modules.AppleMusic { public class AppleMusicContainerStreamsModule : BaseModule { public AppleMusicContainerStreamsModule(IApplicationInstanceManager applicationInstanceManager, AppleMusicTrackStreamsManager appleMusicTrackStreamsManager) : base(applicationInstanceManager) { Get["GetAppleMusicAnalyticsContainerStreams", "/appleMusic/analytics/container/streams", true] = async (parameters, cx) => { DateTime startDate = Maybe.ToDateTimeOrFallback((string)Request.Query.startDate, DateTime.Today.AddDays(-30)); DateTime endDate = Maybe.ToDateTimeOrFallback((string)Request.Query.endDate, DateTime.Today); string countryCode = (string)Request.Query.countryCode; var containerId = (string)Request.Query.containerId; if (string.IsNullOrWhiteSpace(containerId)) return HttpStatusCode.BadRequest; var streams = await appleMusicTrackStreamsManager.GetContainerStreamsAsync(containerId, startDate, endDate, countryCode); var viewModels = AutoMapper.Mapper.Instance.Map>(streams); return Response.AsJson(viewModels); }; Get["GetAppleMusicAnalyticsContainerStreamDates", "/appleMusic/analytics/container/dates", true] = async (parameters, cx) => { DateTime startDate = Maybe.ToDateTimeOrFallback((string)Request.Query.startDate, DateTime.Today.AddDays(-30)); DateTime endDate = Maybe.ToDateTimeOrFallback((string)Request.Query.endDate, DateTime.Today); var dates = appleMusicTrackStreamsManager.GetDates(AppleS3FileType.StreamsContainers, startDate, endDate); var sonyDates = dates.Where(p => p.DistributerId == (int)SpotifyAnalyticsAccount.Sony); var viewModels = sonyDates.GroupBy(p => p.Date).Select(p => new AppleMusicDateViewModel() { Date = p.Key, Vendors = p.Select(pi => pi.VendorId).ToList() }); return Response.AsJson(viewModels); }; Get["GetAppleMusicAnalyticsContainerStreamDates", "/appleMusic/analytics/container/dates/latest", true] = async (parameters, cx) => { var date = appleMusicTrackStreamsManager.GetLatestDates(AppleS3FileType.StreamsContainers); return Response.AsJson(new AppleMusicLatestDateViewModel { Date = date }); }; } } public class AppleMusicLatestDateViewModel { [JsonConverter(typeof(DateNoTimeConverter))] public DateTime Date { get; set; } } public class AppleMusicDateViewModel { [JsonConverter(typeof(DateNoTimeConverter))] public DateTime Date { get; set; } public List Vendors { get; set; } } public class AppleMusicContainerStreamViewModel { [JsonConverter(typeof(DateNoTimeConverter))] public DateTime Date { get; set; } public string CountryCode { get; set; } public string ReportVendorId { get; set; } public string ContainerId { get; set; } public string ContainerName { get; set; } public string ContainerSubType { get; set; } public DateTime ReportDate { get; set; } public long ActionType1 { get; set; } public long ContainerSubtype0 { get; set; } public long ContainerSubtype1 { get; set; } public long ContainerSubtype10 { get; set; } public long ContainerSubtype11 { get; set; } public long ContainerSubtype2 { get; set; } public long ContainerSubtype3 { get; set; } public long ContainerSubtype4 { get; set; } public long ContainerSubtype5 { get; set; } public long ContainerSubtype6 { get; set; } public long ContainerSubtype7 { get; set; } public long ContainerSubtype8 { get; set; } public long ContainerSubtype9 { get; set; } public long ContainerType0 { get; set; } public long ContainerType1 { get; set; } public long ContainerType2 { get; set; } public long ContainerType3 { get; set; } public long ContainerType4 { get; set; } public long DeviceOs0 { get; set; } public long DeviceOs1 { get; set; } public long DeviceOs2 { get; set; } public long DeviceOs3 { get; set; } public long DeviceOs4 { get; set; } public long DeviceOs5 { get; set; } public long DeviceOs6 { get; set; } public long DeviceType0 { get; set; } public long DeviceType1 { get; set; } public long DeviceType2 { get; set; } public long EndReason0 { get; set; } public long EndReason1 { get; set; } public long EndReason2 { get; set; } public long Offline0 { get; set; } public long Offline1 { get; set; } public long Source0 { get; set; } public long Source1 { get; set; } public long Source2 { get; set; } public long Source3 { get; set; } public long Source4 { get; set; } public long Streams { get; set; } } }