Skip to content

Commit aaae148

Browse files
laidaoyuSRIDHAR24-cmd“SRIDHAR24-cmd”nehalaggarwal-bcgov
authored
MMI-3226 Commit Sridhar code changes (bcgov#2442)
* Create Test1 * Media Analytics Dev Changes * MMI-3226 Changes to TNOContext file to add MediaAnalytics code * MMI-3226 changes suggested on pull request * MMI-3226 changes in explicit operator * MMI-3226 Added data migrations * MMI-2918 Revert previous db migration - removed 1.3.26 migration scripts * MMI-2918 Re-created db migration - re-create db migration 1.3.27 * MMI-2918 Minor updates - removed test file - updated route names - added max length to the new table fields --------- Co-authored-by: SRIDHAR24-cmd <sridhar.balakrishnan@gov.bc.ca> Co-authored-by: “SRIDHAR24-cmd” <“sridhar.balakrishnan@gov.bc.ca”> Co-authored-by: nehalaggarwal-bcgov <nehal.aggarwal@gov.bc.ca>
1 parent 563d9d2 commit aaae148

File tree

11 files changed

+8924
-0
lines changed

11 files changed

+8924
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
using System.Net;
2+
using System.Net.Mime;
3+
using System.Text.Json;
4+
using Microsoft.AspNetCore.Http.Extensions;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Extensions.Options;
7+
using Swashbuckle.AspNetCore.Annotations;
8+
using TNO.API.Areas.Admin.Models.MediaAnalytics;
9+
using TNO.API.Models;
10+
using TNO.Core.Exceptions;
11+
using TNO.DAL.Services;
12+
using TNO.Entities;
13+
using TNO.Entities.Models;
14+
using TNO.Keycloak;
15+
16+
namespace TNO.API.Areas.Admin.Controllers;
17+
18+
/// <summary>
19+
/// MediaTypeController class, provides MediaType endpoints for the api.
20+
/// </summary>
21+
///[ClientRoleAuthorize(ClientRole.Administrator)]
22+
[ApiController]
23+
[Area("admin")]
24+
[ApiVersion("1.0")]
25+
[Route("api/v{version:apiVersion}/[area]/media-analytics")]
26+
[Route("api/[area]/media-analytics")]
27+
[Route("v{version:apiVersion}/[area]/media-analytics")]
28+
[Route("[area]/media-analytics")]
29+
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.Unauthorized)]
30+
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.Forbidden)]
31+
public class MediaAnalyticsController : ControllerBase
32+
{
33+
#region Variables
34+
private readonly IMediaAnalyticsService _service;
35+
private readonly JsonSerializerOptions _serializerOptions;
36+
#endregion
37+
38+
#region Constructors
39+
/// <summary>
40+
/// Creates a new instance of a MediaTypeController object, initializes with specified parameters.
41+
/// </summary>
42+
/// <param name="service"></param>
43+
/// <param name="serializerOptions"></param>
44+
public MediaAnalyticsController(IMediaAnalyticsService service, IOptions<JsonSerializerOptions> serializerOptions)
45+
{
46+
_service = service;
47+
_serializerOptions = serializerOptions.Value;
48+
}
49+
#endregion
50+
51+
#region Endpoints
52+
53+
/// <summary>
54+
/// Find a page of user for the specified query filter.
55+
/// </summary>
56+
/// <returns></returns>
57+
[HttpGet]
58+
[Produces(MediaTypeNames.Application.Json)]
59+
[ProducesResponseType(typeof(IPaged<MediaAnalyticsModel>), (int)HttpStatusCode.OK)]
60+
[SwaggerOperation(Tags = new[] { "User" })]
61+
public IActionResult Find()
62+
{
63+
var uri = new Uri(this.Request.GetDisplayUrl());
64+
var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(uri.Query);
65+
var result = _service.Find(new TNO.Models.Filters.MediaAnalyticsFilter(query));
66+
var page = new Paged<MediaAnalyticsModel>(result.Items.Select(u => new MediaAnalyticsModel(u, _serializerOptions)), result.Page, result.Quantity, result.Total);
67+
return new JsonResult(page);
68+
}
69+
70+
/// <summary>
71+
/// Find content for the specified 'id'.
72+
/// </summary>
73+
/// <param name="id"></param>
74+
/// <returns></returns>
75+
[HttpGet("{id}")]
76+
[Produces(MediaTypeNames.Application.Json)]
77+
[ProducesResponseType(typeof(MediaAnalyticsModel), (int)HttpStatusCode.OK)]
78+
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
79+
[SwaggerOperation(Tags = new[] { "MediaType" })]
80+
public IActionResult FindById(int id)
81+
{
82+
var result = _service.FindById(id) ?? throw new NoContentException();
83+
return new JsonResult(new MediaAnalyticsModel(result, _serializerOptions));
84+
}
85+
86+
/// <summary>
87+
/// Add content for the specified 'id'.
88+
/// </summary>
89+
/// <param name="model"></param>
90+
/// <returns></returns>
91+
[HttpPost]
92+
[Produces(MediaTypeNames.Application.Json)]
93+
[ProducesResponseType(typeof(MediaAnalyticsModel), (int)HttpStatusCode.Created)]
94+
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
95+
[SwaggerOperation(Tags = new[] { "MediaType" })]
96+
public IActionResult Add([FromBody] MediaAnalyticsModel model)
97+
{
98+
var result = _service.AddAndSave((Entities.MediaAnalytics)model);
99+
return CreatedAtAction(nameof(FindById), new { id = result.Id }, new MediaAnalyticsModel(result, _serializerOptions));
100+
}
101+
102+
/// <summary>
103+
/// Update content for the specified 'id'.
104+
/// </summary>
105+
/// <param name="model"></param>
106+
/// <returns></returns>
107+
[HttpPut("{id}")]
108+
[Produces(MediaTypeNames.Application.Json)]
109+
[ProducesResponseType(typeof(MediaAnalyticsModel), (int)HttpStatusCode.OK)]
110+
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
111+
[SwaggerOperation(Tags = new[] { "MediaType" })]
112+
public IActionResult Update([FromBody] MediaAnalyticsModel model)
113+
{
114+
var result = _service.UpdateAndSave((Entities.MediaAnalytics)model);
115+
return new JsonResult(new MediaAnalyticsModel(result, _serializerOptions));
116+
}
117+
118+
/// <summary>
119+
/// Delete content for the specified 'id'.
120+
/// </summary>
121+
/// <param name="model"></param>
122+
/// <returns></returns>
123+
[HttpDelete("{id}")]
124+
[Produces(MediaTypeNames.Application.Json)]
125+
[ProducesResponseType(typeof(MediaAnalyticsModel), (int)HttpStatusCode.OK)]
126+
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
127+
[SwaggerOperation(Tags = new[] { "MediaType" })]
128+
public IActionResult Delete([FromBody] MediaAnalyticsModel model)
129+
{
130+
_service.DeleteAndSave((Entities.MediaAnalytics)model);
131+
return new JsonResult(model);
132+
}
133+
#endregion
134+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
namespace TNO.DAL.Configuration;
2+
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
5+
using TNO.Entities;
6+
7+
public class MediaAnalyticsConfiguration : BaseTypeConfiguration<MediaAnalytics, int>
8+
{
9+
public override void Configure(EntityTypeBuilder<MediaAnalytics> builder)
10+
{
11+
builder.HasKey(m => m.Id);
12+
builder.Property(m => m.PublishedOn);
13+
builder.Property(m => m.SourceId);
14+
builder.Property(m => m.MediaTypeId);
15+
builder.Property(m => m.UniqueViews);
16+
builder.Property(m => m.TotalViews);
17+
builder.Property(m => m.AverageViews);
18+
builder.Property(m => m.MaleViewers);
19+
20+
builder.Property(m => m.AgeGroup1);
21+
builder.Property(m => m.AgeGroup1Label).HasMaxLength(250);
22+
builder.Property(m => m.AgeGroup2);
23+
builder.Property(m => m.AgeGroup2Label).HasMaxLength(250);
24+
builder.Property(m => m.AgeGroup3);
25+
builder.Property(m => m.AgeGroup3Label).HasMaxLength(250);
26+
builder.Property(m => m.AgeGroup4);
27+
builder.Property(m => m.AgeGroup4Label).HasMaxLength(250);
28+
29+
builder.Property(m => m.PageViews1);
30+
builder.Property(m => m.PageViews1Label).HasMaxLength(250);
31+
builder.Property(m => m.PageViews2);
32+
builder.Property(m => m.Page_Views2_Label).HasMaxLength(250);
33+
builder.Property(m => m.PageViews3);
34+
builder.Property(m => m.Page_Views3_Label).HasMaxLength(250);
35+
builder.Property(m => m.PageViews4);
36+
builder.Property(m => m.Page_Views4_Label).HasMaxLength(250);
37+
38+
builder.Property(m => m.WatchTime1);
39+
builder.Property(m => m.WatchTime1Label).HasMaxLength(250);
40+
builder.Property(m => m.WatchTime2);
41+
builder.Property(m => m.WatchTime2Label).HasMaxLength(250);
42+
builder.Property(m => m.WatchTime3);
43+
builder.Property(m => m.WatchTime3Label).HasMaxLength(250);
44+
builder.Property(m => m.WatchTime4);
45+
builder.Property(m => m.WatchTime4Label).HasMaxLength(250);
46+
47+
builder.HasOne(m => m.Source).WithMany().HasForeignKey(m => m.SourceId).OnDelete(DeleteBehavior.Cascade);
48+
builder.HasOne(m => m.MediaType).WithMany().HasForeignKey(m => m.MediaTypeId).OnDelete(DeleteBehavior.Cascade);
49+
builder.HasIndex(m => new { m.PublishedOn, m.SourceId, m.MediaTypeId })
50+
.IsUnique();
51+
52+
base.Configure(builder);
53+
}
54+
}

0 commit comments

Comments
 (0)