Skip to content

Commit ab4bac7

Browse files
committed
Initial Refactoring
This is the initial set of refactoring changes before I rename the directory for the solution as that might be ugly.
1 parent 77ab5e8 commit ab4bac7

35 files changed

Lines changed: 195 additions & 196 deletions

RadarrAPI/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace RadarrAPI
1+
namespace LidarrAPI
22
{
33
public class Config
44
{

RadarrAPI/Controllers/PingController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.AspNetCore.Mvc;
22

3-
namespace RadarrAPI.Controllers
3+
namespace LidarrAPI.Controllers
44
{
55
[Route("v1/[controller]")]
66
public class PingController

RadarrAPI/Controllers/TraktController.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
using System.Linq;
33
using System.Text;
44
using System.Threading.Tasks;
5+
using LidarrAPI.Database;
6+
using LidarrAPI.Database.Models;
57
using Microsoft.AspNetCore.Mvc;
6-
using RadarrAPI.Database;
7-
using RadarrAPI.Database.Models;
88
using TraktApiSharp;
99
using TraktApiSharp.Exceptions;
1010

11-
namespace RadarrAPI.Controllers
11+
namespace LidarrAPI.Controllers
1212
{
1313
[Route("v1/[controller]")]
1414
public class TraktController : Controller
@@ -27,7 +27,8 @@ public TraktController(DatabaseContext database, TraktClient trakt)
2727
[HttpGet]
2828
public async Task<IActionResult> RedirectToTrakt([FromQuery(Name = "target")] string target)
2929
{
30-
var validTarget = Uri.TryCreate(target, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == "http" || uriResult.Scheme == "https");
30+
var validTarget = Uri.TryCreate(target, UriKind.Absolute, out Uri uriResult) &&
31+
(uriResult.Scheme == "http" || uriResult.Scheme == "https");
3132
if (!validTarget)
3233
{
3334
return BadRequest("Invalid target specified.");
@@ -42,13 +43,15 @@ public async Task<IActionResult> RedirectToTrakt([FromQuery(Name = "target")] st
4243

4344
_database.Add(traktEntity);
4445
await _database.SaveChangesAsync();
45-
46-
return Redirect(_trakt.OAuth.CreateAuthorizationUrl(_trakt.ClientId, GetRedirectUri(), traktEntity.State.ToString()));
46+
47+
return Redirect(_trakt.OAuth.CreateAuthorizationUrl(_trakt.ClientId, GetRedirectUri(),
48+
traktEntity.State.ToString()));
4749
}
4850

4951
[Route("callback")]
5052
[HttpGet]
51-
public async Task<IActionResult> TraktCallback([FromQuery(Name = "code")] string code, [FromQuery(Name = "state")] string stateStr)
53+
public async Task<IActionResult> TraktCallback([FromQuery(Name = "code")] string code,
54+
[FromQuery(Name = "state")] string stateStr)
5255
{
5356
if (!Guid.TryParse(stateStr, out Guid state))
5457
{
@@ -64,7 +67,8 @@ public async Task<IActionResult> TraktCallback([FromQuery(Name = "code")] string
6467
_database.Remove(traktEntity);
6568
await _database.SaveChangesAsync();
6669

67-
var traktAuth = await _trakt.OAuth.GetAuthorizationAsync(code, _trakt.ClientId, _trakt.ClientSecret, GetRedirectUri());
70+
var traktAuth =
71+
await _trakt.OAuth.GetAuthorizationAsync(code, _trakt.ClientId, _trakt.ClientSecret, GetRedirectUri());
6872
if (!traktAuth.IsValid)
6973
{
7074
return BadRequest("Received trakt token was invalid.");
@@ -81,10 +85,11 @@ public async Task<IActionResult> TraktCallback([FromQuery(Name = "refresh")] str
8185
{
8286
return BadRequest("Invalid refresh code specified.");
8387
}
84-
88+
8589
try
8690
{
87-
var traktAuth = await _trakt.OAuth.RefreshAuthorizationAsync(refresh, _trakt.ClientId, _trakt.ClientSecret, GetRedirectUri());
91+
var traktAuth = await _trakt.OAuth.RefreshAuthorizationAsync(refresh, _trakt.ClientId,
92+
_trakt.ClientSecret, GetRedirectUri());
8893
if (!traktAuth.IsValid)
8994
{
9095
return BadRequest("Received trakt token was invalid.");
@@ -112,4 +117,4 @@ private string GetRedirectUri()
112117
return redirectUri.ToString();
113118
}
114119
}
115-
}
120+
}

RadarrAPI/Controllers/UpdateController.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using LidarrAPI.Database;
5+
using LidarrAPI.Update;
6+
using LidarrAPI.Update.Data;
47
using Microsoft.AspNetCore.Mvc;
58
using Microsoft.EntityFrameworkCore;
6-
using RadarrAPI.Database;
7-
using RadarrAPI.Update.Data;
89
using StatsdClient;
9-
using Branch = RadarrAPI.Update.Branch;
10-
using OperatingSystem = RadarrAPI.Update.OperatingSystem;
10+
using OperatingSystem = LidarrAPI.Update.OperatingSystem;
1111

12-
namespace RadarrAPI.Controllers
12+
namespace LidarrAPI.Controllers
1313
{
1414
[Route("v1/[controller]")]
1515
public class UpdateController : Controller
@@ -23,17 +23,19 @@ public UpdateController(DatabaseContext database)
2323

2424
[Route("{branch}/changes")]
2525
[HttpGet]
26-
public object GetChanges([FromRoute(Name = "branch")]Branch updateBranch, [FromQuery(Name = "version")]string urlVersion, [FromQuery(Name = "os")]OperatingSystem operatingSystem)
26+
public object GetChanges([FromRoute(Name = "branch")] Branch updateBranch,
27+
[FromQuery(Name = "version")] string urlVersion, [FromQuery(Name = "os")] OperatingSystem operatingSystem)
2728
{
2829
using (DogStatsd.StartTimer("controller.update.get_changes.time"))
2930
{
3031
DogStatsd.Increment("controller.update.get_changes.count");
3132

3233
var updates = _database.UpdateEntities
33-
.Include(x => x.UpdateFiles)
34-
.Where(x => x.Branch == updateBranch && x.UpdateFiles.Any(u => u.OperatingSystem == operatingSystem))
35-
.OrderByDescending(x => x.ReleaseDate)
36-
.Take(5);
34+
.Include(x => x.UpdateFiles)
35+
.Where(x => x.Branch == updateBranch &&
36+
x.UpdateFiles.Any(u => u.OperatingSystem == operatingSystem))
37+
.OrderByDescending(x => x.ReleaseDate)
38+
.Take(5);
3739

3840
var response = new List<UpdatePackage>();
3941

@@ -71,7 +73,8 @@ public object GetChanges([FromRoute(Name = "branch")]Branch updateBranch, [FromQ
7173

7274
[Route("{branch}")]
7375
[HttpGet]
74-
public object GetUpdates([FromRoute(Name = "branch")]Branch updateBranch, [FromQuery(Name = "version")]string urlVersion, [FromQuery(Name = "os")]OperatingSystem operatingSystem)
76+
public object GetUpdates([FromRoute(Name = "branch")] Branch updateBranch,
77+
[FromQuery(Name = "version")] string urlVersion, [FromQuery(Name = "os")] OperatingSystem operatingSystem)
7578
{
7679
// Check given version
7780
if (!Version.TryParse(urlVersion, out Version version))
@@ -85,11 +88,12 @@ public object GetUpdates([FromRoute(Name = "branch")]Branch updateBranch, [FromQ
8588
using (DogStatsd.StartTimer("controller.update.get_updates.time"))
8689
{
8790
DogStatsd.Increment("controller.update.get_updates.count");
88-
91+
8992
// Grab latest update based on branch and operatingsystem
9093
var update = _database.UpdateEntities
9194
.Include(x => x.UpdateFiles)
92-
.Where(x => x.Branch == updateBranch && x.UpdateFiles.Any(u => u.OperatingSystem == operatingSystem))
95+
.Where(x => x.Branch == updateBranch &&
96+
x.UpdateFiles.Any(u => u.OperatingSystem == operatingSystem))
9397
.OrderByDescending(x => x.ReleaseDate)
9498
.Take(1)
9599
.FirstOrDefault();
@@ -151,4 +155,4 @@ public object GetUpdates([FromRoute(Name = "branch")]Branch updateBranch, [FromQ
151155
}
152156
}
153157
}
154-
}
158+
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
using System.Threading.Tasks;
2+
using LidarrAPI.Release;
3+
using LidarrAPI.Update;
24
using Microsoft.AspNetCore.Mvc;
35
using Microsoft.Extensions.Options;
4-
using RadarrAPI.Release;
5-
using RadarrAPI.Update;
66

7-
namespace RadarrAPI.Controllers
7+
namespace LidarrAPI.Controllers
88
{
99
[Route("v1/[controller]")]
1010
public class WebhookController
1111
{
12-
private readonly ReleaseService _releaseService;
13-
1412
private readonly Config _config;
13+
private readonly ReleaseService _releaseService;
1514

1615
public WebhookController(ReleaseService releaseService, IOptions<Config> optionsConfig)
1716
{
@@ -20,7 +19,8 @@ public WebhookController(ReleaseService releaseService, IOptions<Config> options
2019
}
2120

2221
[Route("refresh")]
23-
[HttpGet, HttpPost]
22+
[HttpGet]
23+
[HttpPost]
2424
public async Task<string> Refresh([FromQuery] Branch branch, [FromQuery(Name = "api_key")] string apiKey)
2525
{
2626
if (!_config.ApiKey.Equals(apiKey))
@@ -33,4 +33,4 @@ public async Task<string> Refresh([FromQuery] Branch branch, [FromQuery(Name = "
3333
return "Thank you.";
3434
}
3535
}
36-
}
36+
}

RadarrAPI/Database/DatabaseContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using Microsoft.EntityFrameworkCore;
2-
using RadarrAPI.Database.Models;
1+
using LidarrAPI.Database.Models;
2+
using Microsoft.EntityFrameworkCore;
33

4-
namespace RadarrAPI.Database
4+
namespace LidarrAPI.Database
55
{
66
public class DatabaseContext : DbContext
77
{

RadarrAPI/Database/Migrations/20170113010120_Initial.Designer.cs

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RadarrAPI/Database/Migrations/20170113010120_Initial.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using Microsoft.EntityFrameworkCore.Migrations;
33

4-
namespace RadarrAPI.Database.Migrations
4+
namespace LidarrAPI.Database.Migrations
55
{
66
public partial class Initial : Migration
77
{

RadarrAPI/Database/Migrations/20170304204209_AddTraktEntity.Designer.cs

Lines changed: 6 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RadarrAPI/Database/Migrations/20170304204209_AddTraktEntity.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System;
2-
using System.Collections.Generic;
32
using Microsoft.EntityFrameworkCore.Migrations;
43

5-
namespace RadarrAPI.Database.Migrations
4+
namespace LidarrAPI.Database.Migrations
65
{
76
public partial class AddTraktEntity : Migration
87
{

0 commit comments

Comments
 (0)