Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/TheOfficeAPI/Common/Data/OfficeEpisodesData.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
using TheOfficeAPI.Common.Models;
using System.Collections.ObjectModel;
using TheOfficeAPI.Common.Models;

namespace TheOfficeAPI.Common.Data
{
public static class OfficeEpisodesData
{
public static readonly List<Episode> Episodes = new List<Episode>()
.Concat(Season1Episodes.Episodes)
.Concat(Season2Episodes.Episodes)
.Concat(Season3Episodes.Episodes)
.Concat(Season4Episodes.Episodes)
.Concat(Season5Episodes.Episodes)
.Concat(Season6Episodes.Episodes)
.Concat(Season7Episodes.Episodes)
.Concat(Season8Episodes.Episodes)
.Concat(Season9Episodes.Episodes)
.ToList();
public static readonly ReadOnlyCollection<Episode> Episodes = new(
new List<Episode>()
.Concat(Season1Episodes.Episodes)
.Concat(Season2Episodes.Episodes)
.Concat(Season3Episodes.Episodes)
.Concat(Season4Episodes.Episodes)
.Concat(Season5Episodes.Episodes)
.Concat(Season6Episodes.Episodes)
.Concat(Season7Episodes.Episodes)
.Concat(Season8Episodes.Episodes)
.Concat(Season9Episodes.Episodes)
.ToList());
}
}
9 changes: 6 additions & 3 deletions src/TheOfficeAPI/Common/Data/Season3EpisodesData.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System.Collections.ObjectModel;
using TheOfficeAPI.Common.Models;

namespace TheOfficeAPI.Common.Data;

public static class Season3Episodes
{
private const int SeasonNumber = 3;
public static readonly List<Episode> Episodes = new List<Episode>

public static readonly ReadOnlyCollection<Episode> Episodes = new(new List<Episode>
{
new Episode { Season = SeasonNumber, EpisodeNumber = 1, Title = "Gay Witch Hunt", ReleasedDate = "2006-09-21" },
new Episode { Season = SeasonNumber, EpisodeNumber = 2, Title = "The Convention", ReleasedDate = "2006-09-28" },
Expand All @@ -29,5 +32,5 @@ public static class Season3Episodes
new Episode { Season = SeasonNumber, EpisodeNumber = 21, Title = "Women's Appreciation", ReleasedDate = "2007-05-03" },
new Episode { Season = SeasonNumber, EpisodeNumber = 22, Title = "Beach Games", ReleasedDate = "2007-05-10" },
new Episode { Season = SeasonNumber, EpisodeNumber = 23, Title = "The Job", ReleasedDate = "2007-05-17" }
};
});
}
1 change: 1 addition & 0 deletions src/TheOfficeAPI/Level0/Controllers/HealthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public class HealthController : ControllerBase
{
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult Get()

Check warning on line 11 in src/TheOfficeAPI/Level0/Controllers/HealthController.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Use the ProducesResponseType overload containing the return type for successful responses. (https://rules.sonarsource.com/csharp/RSPEC-6968)

Check warning on line 11 in src/TheOfficeAPI/Level0/Controllers/HealthController.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Use the ProducesResponseType overload containing the return type for successful responses. (https://rules.sonarsource.com/csharp/RSPEC-6968)
{
return Ok(new { status = "Healthy", timestamp = DateTime.UtcNow });
}
Expand Down
10 changes: 6 additions & 4 deletions src/TheOfficeAPI/Level0/Controllers/OfficeApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[Route("api")]
public class Level0Controller : ControllerBase
{
private const string InvalidRequestMessage = "Invalid request";
private readonly TheOfficeService _theOfficeService;

public Level0Controller(TheOfficeService theOfficeService)
Expand Down Expand Up @@ -116,7 +117,8 @@
/// </code>
/// </example>
[HttpPost("theOffice")]
[ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult HandleRequest([FromBody] ApiRequest request)

Check warning on line 121 in src/TheOfficeAPI/Level0/Controllers/OfficeApiController.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Use the ProducesResponseType overload containing the return type for successful responses. (https://rules.sonarsource.com/csharp/RSPEC-6968)

Check warning on line 121 in src/TheOfficeAPI/Level0/Controllers/OfficeApiController.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Use the ProducesResponseType overload containing the return type for successful responses. (https://rules.sonarsource.com/csharp/RSPEC-6968)
{
// Level 0: Always return 200 OK, put actual status in response body
try
Expand Down Expand Up @@ -165,7 +167,7 @@
{
Success = false,
Error = "Season parameter is required",
Message = "Invalid request"
Message = InvalidRequestMessage
});

return null;
Expand All @@ -178,7 +180,7 @@
{
Success = false,
Error = "Both season and episode parameters are required",
Message = "Invalid request"
Message = InvalidRequestMessage
});

return null;
Expand All @@ -193,7 +195,7 @@
{
Success = false,
Error = $"Season parameter is outside of the scope. Please select the season number between 1 and {seasonsCount} (inclusive).",
Message = "Invalid request"
Message = InvalidRequestMessage
});
}
return null;
Expand All @@ -208,7 +210,7 @@
{
Success = false,
Error = $"Episode parameter is outside of the scope. Please select the episode number between 1 and {episodesCountFromSpecificSeason} (inclusive).",
Message = "Invalid request"
Message = InvalidRequestMessage
});
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/TheOfficeAPI/Level0/Services/TheOfficeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TheOfficeService

public TheOfficeService()
{
_episodes = OfficeEpisodesData.Episodes;
_episodes = OfficeEpisodesData.Episodes.ToList();
_seasons = InitializeSeasons();
}

Expand Down
10 changes: 9 additions & 1 deletion src/TheOfficeAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

public class Program
{
// Protected constructor to satisfy S1118 (utility class should not have public constructor)
// while keeping the class non-static for WebApplicationFactory<Program> compatibility
protected Program()
{
}

public static void Main(string[] args)
{
CreateWebApplication(args).Run();
Expand All @@ -28,10 +34,12 @@
// RAILWAY: Use Railway's PORT environment variable and bind to 0.0.0.0
var port = Environment.GetEnvironmentVariable("PORT");
string url;

if (port != null)
{
#pragma warning disable S5332 // HTTP is required for Railway deployment behind reverse proxy
url = $"http://0.0.0.0:{port}";
#pragma warning restore S5332
Console.WriteLine($"=== RAILWAY/PRODUCTION MODE ===");
Console.WriteLine($"PORT from environment: {port}");
Console.WriteLine($"Binding to: {url}");
Expand All @@ -39,7 +47,7 @@
}
else
{
url = serverOptions?.DefaultUrl ?? "http://localhost:5000";

Check warning on line 50 in src/TheOfficeAPI/Program.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Refactor your code not to use hardcoded absolute paths or URIs. (https://rules.sonarsource.com/csharp/RSPEC-1075)

Check warning on line 50 in src/TheOfficeAPI/Program.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Refactor your code not to use hardcoded absolute paths or URIs. (https://rules.sonarsource.com/csharp/RSPEC-1075)
Console.WriteLine($"=== LOCAL DEVELOPMENT MODE ===");
Console.WriteLine($"Using config URL: {url}");
Console.WriteLine($"================================");
Expand Down
Loading