Skip to content

Commit

Permalink
Merge pull request #4 from jaickler/Feature/Finish-Implementation-of-War
Browse files Browse the repository at this point in the history
Feature: Finish Implementation of War Model and Methods
Fix: #1
  • Loading branch information
jaickler authored Mar 9, 2024
2 parents 055d7af + b32ef64 commit 87fcc3d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
24 changes: 24 additions & 0 deletions HellDiversDotNet/Models/HomeWorld.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace HellDiversDotNet.Models
{
public class HomeWorld
{
[JsonPropertyName("planets")]
public List<Planet> Planets { get; set; }

[JsonPropertyName("race")]
public string Race { get; set; }

public HomeWorld? FromJson(string json)
{
return JsonSerializer.Deserialize<HomeWorld>(json);
}
}
}
20 changes: 20 additions & 0 deletions HellDiversDotNet/Models/War.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ public class War
[JsonPropertyName("end_date")]
public DateTime EndDate { get; set; }

[JsonPropertyName("home_worlds")]
public List<HomeWorld?> HomeWorlds { get; set; }

Check warning on line 20 in HellDiversDotNet/Models/War.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'HomeWorlds' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.


[JsonPropertyName("minimum_client_version")]
public string MinimumClientVersion { get; set; }

Check warning on line 24 in HellDiversDotNet/Models/War.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'MinimumClientVersion' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[JsonPropertyName("planet_permanent_effects")]
public List<uint?> PlanetPermanentEffectIds { get; set; }

Check warning on line 27 in HellDiversDotNet/Models/War.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'PlanetPermanentEffectIds' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[JsonPropertyName("planets")]
public List<Planet> Planets { get; set; }

[JsonPropertyName("start_date")]
public DateTime StartDate { get; set; }

[JsonPropertyName("war_id")]
public uint WarId { get; set; }


public War FromJson(string json)
{
return JsonSerializer.Deserialize<War>(json);

Check warning on line 41 in HellDiversDotNet/Models/War.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
Expand Down
15 changes: 15 additions & 0 deletions HellDiversDotNet/Services/SuperEarthConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ private HttpClient BaseClient { get
return response;
}

public async Task<War?> GetWarAsync(uint? warId = null)
{
if (warId == null)
{
warId = (await GetBaseContentAsync()).CurrentSeason;
}

HttpClient client = BaseClient;
var response = await client.GetFromJsonAsync<War>
(new Uri(string.Join('/',
client.BaseAddress, warId, "info")));

return response;
}

public async Task<Planet?> GetPlanetAsync(uint planetId, uint? warId = null)
{
if (warId == null)
Expand Down
10 changes: 10 additions & 0 deletions HellDiversDotNetTests/SuperEarthConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public async Task GetLatestEventReturnsEvent()
because: "the function should return an event.");
}

[TestMethod]
public async Task GetWarReturnsWar()
{
var war = await superEarthConnection.GetWarAsync();

war.Should().NotBeNull();
war.Should().BeOfType<War>(
because: "the function should return a war(For Super Earth).");
}

[TestMethod]
public async Task GetPlanetReturnsPlanet()
{
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
## Our Mission
At Hell Divers Command Center, our unwavering mission is to rally the courageous souls of our Hell Divers in a relentless pursuit of victory against the despicable scourges of the Automatons and the Terminids. With steely determination and unyielding resolve, we shall provide our valiant warriors with the tools and intelligence necessary to seize every strategic advantage on the battlefield. Our sacred duty is to thwart the nefarious schemes of J.O.E.L. (Joint Offensive Extraterrestrial Liaison) and ensure the triumph of humanity over the forces of darkness. United under the banner of liberty and justice, we stand as guardians of our cherished world, ready to sacrifice all in defense of freedom and the future of our civilization.
To do this we have compiled all information from across Super Earth's various scouts and sensors to determine when and where you need to be to help spread freedom.

### Dedication
1. To My Beloved Spouse <3
2. [dealloc's Api](https://github.com/dealloc/helldivers2-api)
3. The Devs Behind HellDivers 2

0 comments on commit 87fcc3d

Please sign in to comment.