Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
tal committed Feb 7, 2021
1 parent 9495511 commit 97c0007
Show file tree
Hide file tree
Showing 21 changed files with 552 additions and 0 deletions.
25 changes: 25 additions & 0 deletions NotifyScreenAPI.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30204.135
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotifyScreenAPI", "NotifyScreenAPI\NotifyScreenAPI.csproj", "{E51D5F1D-4EED-4CAB-8087-DE32CCD9F5DB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E51D5F1D-4EED-4CAB-8087-DE32CCD9F5DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E51D5F1D-4EED-4CAB-8087-DE32CCD9F5DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E51D5F1D-4EED-4CAB-8087-DE32CCD9F5DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E51D5F1D-4EED-4CAB-8087-DE32CCD9F5DB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7B599808-868D-4F28-A138-4429BFBF8505}
EndGlobalSection
EndGlobal
53 changes: 53 additions & 0 deletions NotifyScreenAPI/Controllers/FetchController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using NotifyScreenAPI.Models;
using NotifyScreenAPI.Models.Facebook;
using NotifyScreenAPI.Models.Instagram;
using NotifyScreenAPI.Models.YouTube;
using NotifyScreenAPI.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NotifyScreenAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class FetchController : ControllerBase
{
public ISocialDataService _ISocialDataService;
private readonly IConfiguration _config;
private Settings _settings;


public FetchController(ISocialDataService ISocialDataService, IConfiguration config,
IOptions<Settings> settings)
{
_ISocialDataService = ISocialDataService;
_config = config;
_settings = settings.Value;

}
[Route("getData")]
[HttpGet]
public async Task<ServiceResponse<FetchResponse>> getData()
{
var path = _settings.Path;
var facebookJson = await _ISocialDataService.Read<FacebookRequest>(path + "facebook.txt");
var instagramJson = await _ISocialDataService.Read<InstagramRequest>(path + "instagram.txt");
var youtubeJson = await _ISocialDataService.Read<YouTubeRequest>(path+ "youtube.txt");

var r = new FetchResponse();
r.facebook = new FacebookData() { Comments = facebookJson.CommentsCount, Likes = facebookJson.LikesCount };

r.instagram = new InstagramData() { Follows = instagramJson.NumberOfFollowers };
r.youtube = new YouTubeData() { Views = youtubeJson.NumberOfViews };

var res = new ServiceResponse<FetchResponse>() { Data = r, Message = "Success", Success = true };
return res;
}
}
}
84 changes: 84 additions & 0 deletions NotifyScreenAPI/Controllers/SocialDataController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using NotifyScreenAPI.Models;
using NotifyScreenAPI.Models.Facebook;
using NotifyScreenAPI.Models.Instagram;
using NotifyScreenAPI.Models.YouTube;
using NotifyScreenAPI.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NotifyScreenAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SocialDataController : ControllerBase
{
public ISocialDataService _ISocialDataService;
private Settings _settings;
public string path;
public SocialDataController(ISocialDataService ISocialDataService, IConfiguration config,
IOptions<Settings> settings)
{
_ISocialDataService = ISocialDataService;
_settings = settings.Value;
path = _settings.Path;
}
[Route("getFacebookData")]
[HttpPost]
public async Task<ServiceResponse<FacebookResponse>> GetFacebookData(FacebookRequest facebookRequest)
{
_ISocialDataService.Write(facebookRequest,path +"facebook.txt");
var fileJson = await _ISocialDataService.Read<FacebookRequest>(path +"facebook.txt");

var c = new Comment
{
Number = fileJson.CommentsCount
};

var l = new Like
{
Number = fileJson.LikesCount
};

var r = new FacebookResponse
{
Comments = c,
Likes = l
};


var res = new ServiceResponse<FacebookResponse>() { Data = r, Message = "Success", Success = true };
return res;
}

[Route("getInstagramData")]
[HttpPost]
public async Task<ServiceResponse<InstagramResponse>> GetInsatagramData(InstagramRequest instagramRequest)
{

_ISocialDataService.Write(instagramRequest, path + "instagram.txt");
var fileJson = await _ISocialDataService.Read<InstagramRequest>(path +"instagram.txt");
var r = new InstagramResponse() { NumberOfFollowers = fileJson.NumberOfFollowers };
var res = new ServiceResponse<InstagramResponse>() { Data = r, Message = "Success", Success = true };
return res;
}

[Route("getYoutubeData")]
[HttpPost]
public async Task<ServiceResponse<YouTubeResponse>> GetYouTubeData(YouTubeRequest youtubeRequest)
{

_ISocialDataService.Write(youtubeRequest, path + "youtube.txt");
var fileJson = await _ISocialDataService.Read<YouTubeRequest>(path +"youtube.txt");
var r = new YouTubeResponse() { NumberOfViews = fileJson.NumberOfViews };
var res = new ServiceResponse<YouTubeResponse>() { Data = r, Message = "Success", Success = true };

return res;
}
}
}
39 changes: 39 additions & 0 deletions NotifyScreenAPI/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace NotifyScreenAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}
13 changes: 13 additions & 0 deletions NotifyScreenAPI/Models/Facebook/FacebookRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NotifyScreenAPI.Models.Facebook
{
public class FacebookRequest
{
public int LikesCount { get; set; }
public int CommentsCount { get; set; }
}
}
23 changes: 23 additions & 0 deletions NotifyScreenAPI/Models/Facebook/FacebookResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NotifyScreenAPI.Models.Facebook
{
public class FacebookResponse
{
public Like Likes { get; set; }
public Comment Comments { get; set; }
}
public class Like
{
public int Number { get; set; }
}
public class Comment
{
public int Number { get; set; }

}
}

27 changes: 27 additions & 0 deletions NotifyScreenAPI/Models/FetchResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NotifyScreenAPI.Models
{
public class FetchResponse
{
public FacebookData facebook { get; set; }
public InstagramData instagram { get; set; }
public YouTubeData youtube { get; set; }
}
public class FacebookData
{
public int Likes { get; set; }
public int Comments { get; set; }
}
public class InstagramData
{
public int Follows { get; set; }
}
public class YouTubeData
{
public int Views { get; set; }
}
}
12 changes: 12 additions & 0 deletions NotifyScreenAPI/Models/Instagram/InstagramRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NotifyScreenAPI.Models.Instagram
{
public class InstagramRequest
{
public int NumberOfFollowers { get; set; }
}
}
12 changes: 12 additions & 0 deletions NotifyScreenAPI/Models/Instagram/InstagramResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NotifyScreenAPI.Models.Instagram
{
public class InstagramResponse
{
public int NumberOfFollowers { get; set; }
}
}
15 changes: 15 additions & 0 deletions NotifyScreenAPI/Models/ServiceResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NotifyScreenAPI.Models
{
public class ServiceResponse<T>
{
public T Data { get; set; }
public bool Success { get; set; }
public string Message { get; set; }

}
}
12 changes: 12 additions & 0 deletions NotifyScreenAPI/Models/Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NotifyScreenAPI.Models
{
public class Settings
{
public string Path { get; set; }
}
}
12 changes: 12 additions & 0 deletions NotifyScreenAPI/Models/YouTube/YouTubeRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NotifyScreenAPI.Models.YouTube
{
public class YouTubeRequest
{
public int NumberOfViews { get; set; }
}
}
12 changes: 12 additions & 0 deletions NotifyScreenAPI/Models/YouTube/YouTubeResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NotifyScreenAPI.Models.YouTube
{
public class YouTubeResponse
{
public int NumberOfViews { get; set; }
}
}
12 changes: 12 additions & 0 deletions NotifyScreenAPI/NotifyScreenAPI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions NotifyScreenAPI/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace NotifyScreenAPI
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Loading

0 comments on commit 97c0007

Please sign in to comment.