diff --git a/StarWarsKb.Infrastructure/Model/Character.cs b/StarWarsKb.Infrastructure/Model/Character.cs index c95ef36..e2c5293 100644 --- a/StarWarsKb.Infrastructure/Model/Character.cs +++ b/StarWarsKb.Infrastructure/Model/Character.cs @@ -1,27 +1,42 @@ -namespace StarWars.Infrastructure.Model; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using StarWars.Infrastructure.Model; -public class Character : IDataItem +namespace StarWarsKb.Infrastructure.Model { - public Character() + public class Character : IStarWarsEntity { - Films = new List(); - Species = new List(); - Startships = new List(); - Vehicles = new List(); + public Character() + { + Films = new List(); + Species = new List(); + Vehicles = new List(); + Starships = new List(); + } + + [NotMapped] + public List Starships { get; set; } + + public string Name { get; set; } + public int Height { get; set; } + public double Mass { get; set; } + public string HairColor { get; set; } + public string SkinColor { get; set; } + public string EyeColor { get; set; } + public string BirthYear { get; set; } + public string Gender { get; set; } + public Planet HomeWorld { get; set; } + public int HomeWorldId { get; set; } + + [NotMapped] + public List Films { get; set; } + + [NotMapped] + public List Species { get; set; } + + [NotMapped] + public List Vehicles { get; set; } + public int StarWarId { get; set; } + public IList StarshipCharacters { get; set; } } - - public string Name { get; set; } - public int Height { get; set; } - public double Mass { get; set; } - public string HairColor { get; set; } - public string SkinColor { get; set; } - public string EyeColor { get; set; } - public string BirthYear { get; set; } - public string Gender { get; set; } - public Planet HomeWorld { get; set; } - public List Films { get; set; } - public List Species { get; set; } - public List Vehicles { get; set; } - public List Startships { get; set; } - public int Id { get; set; } } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Model/Film.cs b/StarWarsKb.Infrastructure/Model/Film.cs index a2224bc..c477930 100644 --- a/StarWarsKb.Infrastructure/Model/Film.cs +++ b/StarWarsKb.Infrastructure/Model/Film.cs @@ -1,7 +1,11 @@ -namespace StarWars.Infrastructure.Model; +using StarWars.Infrastructure.Model; -public class Film +namespace StarWarsKb.Infrastructure.Model { - public string Title { get; set; } - public int EpisodeId { get; set; } + public class Film : IStarWarsEntity + { + public string Title { get; set; } + public int EpisodeId { get; set; } + public int StarWarId { get; set; } + } } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Model/IDataItem.cs b/StarWarsKb.Infrastructure/Model/IDataItem.cs deleted file mode 100644 index 7c2d43a..0000000 --- a/StarWarsKb.Infrastructure/Model/IDataItem.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace StarWars.Infrastructure.Model; - -public interface IDataItem -{ - public int Id { get; set; } -} \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Model/IStarWarEntity.cs b/StarWarsKb.Infrastructure/Model/IStarWarEntity.cs deleted file mode 100644 index 23fd403..0000000 --- a/StarWarsKb.Infrastructure/Model/IStarWarEntity.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace StarWars.Infrastructure.Model; - -public interface IStarWarEntity -{ - public int StarWarId { get; set; } -} \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Model/IStarWarsEntity.cs b/StarWarsKb.Infrastructure/Model/IStarWarsEntity.cs new file mode 100644 index 0000000..989b5d7 --- /dev/null +++ b/StarWarsKb.Infrastructure/Model/IStarWarsEntity.cs @@ -0,0 +1,7 @@ +namespace StarWars.Infrastructure.Model +{ + public interface IStarWarsEntity + { + public int StarWarId { get; set; } + } +} \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Model/Planet.cs b/StarWarsKb.Infrastructure/Model/Planet.cs index b6b33de..eb82dac 100644 --- a/StarWarsKb.Infrastructure/Model/Planet.cs +++ b/StarWarsKb.Infrastructure/Model/Planet.cs @@ -1,6 +1,12 @@ -namespace StarWars.Infrastructure.Model; +using System.Collections.Generic; +using StarWars.Infrastructure.Model; -public class Planet +namespace StarWarsKb.Infrastructure.Model { - public string Name { get; set; } + public class Planet : IStarWarsEntity + { + public string Name { get; set; } + public IList Residents { get; set; } + public int StarWarId { get; set; } + } } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Model/Spec.cs b/StarWarsKb.Infrastructure/Model/Spec.cs index fdbddd2..499ddc2 100644 --- a/StarWarsKb.Infrastructure/Model/Spec.cs +++ b/StarWarsKb.Infrastructure/Model/Spec.cs @@ -1,7 +1,11 @@ -namespace StarWars.Infrastructure.Model; +using StarWars.Infrastructure.Model; -public class Spec +namespace StarWarsKb.Infrastructure.Model { - public string Name { get; set; } - public string Classification { get; set; } + public class Spec : IStarWarsEntity + { + public string Name { get; set; } + public string Classification { get; set; } + public int StarWarId { get; set; } + } } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Model/Starship.cs b/StarWarsKb.Infrastructure/Model/Starship.cs index de54cf6..0025d64 100644 --- a/StarWarsKb.Infrastructure/Model/Starship.cs +++ b/StarWarsKb.Infrastructure/Model/Starship.cs @@ -1,7 +1,24 @@ -namespace StarWars.Infrastructure.Model; +using System.Collections.Generic; +using StarWars.Infrastructure.Model; -public class Starship +namespace StarWarsKb.Infrastructure.Model { - public string Name { get; set; } - public string Model { get; set; } + public class Starship : IStarWarsEntity + { + public string Name { get; set; } + public string Model { get; set; } + public string Manufacturer { get; set; } + public long CostInCredits { get; set; } + public int Lenght { get; set; } + public string MaxAtmospheringSpeed { get; set; } + public int CrewCount { get; set; } + public int PassengersCount { get; set; } + public long CargoCapacity { get; set; } + public string Consumables { get; set; } + public string HyperdriveRating { get; set; } + public string MGLT { get; set; } + public string StarshipClass { get; set; } + public int StarWarId { get; set; } + public IList StarshipsCharacters { get; set; } + } } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Model/StarshipsCharacters.cs b/StarWarsKb.Infrastructure/Model/StarshipsCharacters.cs new file mode 100644 index 0000000..22f1c82 --- /dev/null +++ b/StarWarsKb.Infrastructure/Model/StarshipsCharacters.cs @@ -0,0 +1,10 @@ +namespace StarWarsKb.Infrastructure.Model +{ + public class StarshipsCharacters + { + public int StarshipId { get; set; } + public Starship Starship { get; set; } + public int CharacterId { get; set; } + public Character Character { get; set; } + } +} \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Model/Vehicle.cs b/StarWarsKb.Infrastructure/Model/Vehicle.cs index 5fcb4fc..0589dc6 100644 --- a/StarWarsKb.Infrastructure/Model/Vehicle.cs +++ b/StarWarsKb.Infrastructure/Model/Vehicle.cs @@ -1,7 +1,11 @@ -namespace StarWars.Infrastructure.Model; +using StarWars.Infrastructure.Model; -public class Vehicle +namespace StarWarsKb.Infrastructure.Model { - public string Name { get; set; } - public string Model { get; set; } + public class Vehicle : IStarWarsEntity + { + public string Name { get; set; } + public string Model { get; set; } + public int StarWarId { get; set; } + } } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Services/IWebReader.cs b/StarWarsKb.Infrastructure/Services/IWebReader.cs index 389d3e4..5d514f1 100644 --- a/StarWarsKb.Infrastructure/Services/IWebReader.cs +++ b/StarWarsKb.Infrastructure/Services/IWebReader.cs @@ -1,8 +1,9 @@ -using StarWars.Infrastructure.Services.POCO; +using StarWarsKb.Infrastructure.Services.POCO; -namespace StarWars.Infrastructure.Services; - -public interface IWebReader where T: IStarWarPOCOEntity +namespace StarWarsKb.Infrastructure.Services { - T? ReadEntityWithId(int id); + public interface IWebReader where T : IStarWarPOCOEntity + { + T ReadEntityWithId(int id); + } } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Services/POCO/CharacterPOCO.cs b/StarWarsKb.Infrastructure/Services/POCO/CharacterPOCO.cs index 2c25829..8754aee 100644 --- a/StarWarsKb.Infrastructure/Services/POCO/CharacterPOCO.cs +++ b/StarWarsKb.Infrastructure/Services/POCO/CharacterPOCO.cs @@ -1,21 +1,25 @@ -namespace StarWars.Infrastructure.Services.POCO; +using System; +using System.Collections.Generic; -public class CharacterPOCO : IStarWarPOCOEntity +namespace StarWarsKb.Infrastructure.Services.POCO { - public string name { get; set; } - public string height { get; set; } - public string mass { get; set; } - public string hair_color { get; set; } - public string skin_color { get; set; } - public string eye_color { get; set; } - public string birth_year { get; set; } - public string gender { get; set; } - public string homeworld { get; set; } - public List films { get; set; } - public List species { get; set; } - public List vehicles { get; set; } - public List starships { get; set; } - public DateTime created { get; set; } - public DateTime edited { get; set; } - public string url { get; set; } + public class CharacterPOCO : IStarWarPOCOEntity + { + public string name { get; set; } + public string height { get; set; } + public string mass { get; set; } + public string hair_color { get; set; } + public string skin_color { get; set; } + public string eye_color { get; set; } + public string birth_year { get; set; } + public string gender { get; set; } + public string homeworld { get; set; } + public List films { get; set; } + public List species { get; set; } + public List vehicles { get; set; } + public List starships { get; set; } + public DateTime created { get; set; } + public DateTime edited { get; set; } + public string url { get; set; } + } } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Services/POCO/IStarWarPOCOEntity.cs b/StarWarsKb.Infrastructure/Services/POCO/IStarWarPOCOEntity.cs index 876d6b5..f4c6e2c 100644 --- a/StarWarsKb.Infrastructure/Services/POCO/IStarWarPOCOEntity.cs +++ b/StarWarsKb.Infrastructure/Services/POCO/IStarWarPOCOEntity.cs @@ -1,6 +1,7 @@ -namespace StarWars.Infrastructure.Services.POCO; - -public interface IStarWarPOCOEntity +namespace StarWarsKb.Infrastructure.Services.POCO { - public string url { get; set; } + public interface IStarWarPOCOEntity + { + public string url { get; set; } + } } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Services/POCO/StarshipPOCO.cs b/StarWarsKb.Infrastructure/Services/POCO/StarshipPOCO.cs index 0d049f3..b92a50f 100644 --- a/StarWarsKb.Infrastructure/Services/POCO/StarshipPOCO.cs +++ b/StarWarsKb.Infrastructure/Services/POCO/StarshipPOCO.cs @@ -1,23 +1,27 @@ -namespace StarWars.Infrastructure.Services.POCO; +using System; +using System.Collections.Generic; -public class StarshipPOCO : IStarWarPOCOEntity +namespace StarWarsKb.Infrastructure.Services.POCO { - public string name { get; set; } - public string model { get; set; } - public string manufacturer { get; set; } - public string cost_in_credits { get; set; } - public string lenght { get; set; } - public string max_atmosphering_speed { get; set; } - public string crew { get; set; } - public string passengers { get; set; } - public string cargo_capacity { get; set; } - public string consumables { get; set; } - public string hyperdrive_rating { get; set; } - public string MGLT { get; set; } - public string starship_class { get; set; } - public List pilots { get; set; } - public List films { get; set; } - public DateTime created { get; set; } - public DateTime edited { get; set; } - public string url { get; set; } + public class StarshipPOCO : IStarWarPOCOEntity + { + public string name { get; set; } + public string model { get; set; } + public string manufacturer { get; set; } + public string cost_in_credits { get; set; } + public string lenght { get; set; } + public string max_atmosphering_speed { get; set; } + public string crew { get; set; } + public string passengers { get; set; } + public string cargo_capacity { get; set; } + public string consumables { get; set; } + public string hyperdrive_rating { get; set; } + public string MGLT { get; set; } + public string starship_class { get; set; } + public List pilots { get; set; } + public List films { get; set; } + public DateTime created { get; set; } + public DateTime edited { get; set; } + public string url { get; set; } + } } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Services/WebCharacterPOCOReader.cs b/StarWarsKb.Infrastructure/Services/WebCharacterPOCOReader.cs index d150294..d94b426 100644 --- a/StarWarsKb.Infrastructure/Services/WebCharacterPOCOReader.cs +++ b/StarWarsKb.Infrastructure/Services/WebCharacterPOCOReader.cs @@ -1,13 +1,15 @@ -using StarWars.Infrastructure.Services.POCO; +using StarWarsKb.Infrastructure.Services; +using StarWarsKb.Infrastructure.Services.POCO; -namespace StarWars.Infrastructure.Services; - -public class WebCharacterPOCOReader : WebPOCOReader, IWebReader +namespace StarWars.Infrastructure.Services { - public WebCharacterPOCOReader() : base("people") + public class WebCharacterPOCOReader : WebPOCOReader, IWebReader { - + public WebCharacterPOCOReader() : base("people") + { + + } + + } - - } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Services/WebPOCOReader.cs b/StarWarsKb.Infrastructure/Services/WebPOCOReader.cs index 57fdb45..1be81ba 100644 --- a/StarWarsKb.Infrastructure/Services/WebPOCOReader.cs +++ b/StarWarsKb.Infrastructure/Services/WebPOCOReader.cs @@ -1,26 +1,28 @@ +using System.Net.Http; using System.Text.Json; -using StarWars.Infrastructure.Services.POCO; +using StarWarsKb.Infrastructure.Services.POCO; -namespace StarWars.Infrastructure.Services; - -public abstract class WebPOCOReader where T: IStarWarPOCOEntity +namespace StarWarsKb.Infrastructure.Services { - private HttpClient _client; - private const string BaseUrl = @"https://swapi.dev/api/"; - private string subURL { get; } - - protected WebPOCOReader(string sub) + public abstract class WebPOCOReader where T : IStarWarPOCOEntity { - _client = new HttpClient(); - subURL = sub; - } + private HttpClient _client; + private const string BaseUrl = @"https://swapi.dev/api/"; + private string subURL { get; } - public T? ReadEntityWithId(int id) - { - var task = _client.GetStringAsync($"{BaseUrl}{subURL}/{id}/"); + protected WebPOCOReader(string sub) + { + _client = new HttpClient(); + subURL = sub; + } + + public T ReadEntityWithId(int id) + { + var task = _client.GetStringAsync($"{BaseUrl}{subURL}/{id}/"); - var poco = JsonSerializer.Deserialize(task.Result); + var poco = JsonSerializer.Deserialize(task.Result); - return poco; + return poco; + } } } \ No newline at end of file diff --git a/StarWarsKb.Infrastructure/Services/WebStarshipPOCOReader.cs b/StarWarsKb.Infrastructure/Services/WebStarshipPOCOReader.cs index 17c7fde..a0f004e 100644 --- a/StarWarsKb.Infrastructure/Services/WebStarshipPOCOReader.cs +++ b/StarWarsKb.Infrastructure/Services/WebStarshipPOCOReader.cs @@ -1,11 +1,11 @@ -using StarWars.Infrastructure.Services.POCO; +using StarWarsKb.Infrastructure.Services.POCO; -namespace StarWars.Infrastructure.Services; - -public class WebStarshipPOCOReader : WebPOCOReader, IWebReader +namespace StarWarsKb.Infrastructure.Services { - public WebStarshipPOCOReader() : base("starships") + public class WebStarshipPOCOReader : WebPOCOReader, IWebReader { - + public WebStarshipPOCOReader() : base("starships") + { + } } } \ No newline at end of file diff --git a/StarWarsKb.sln b/StarWarsKb.sln index a55ff74..f5fa72f 100644 --- a/StarWarsKb.sln +++ b/StarWarsKb.sln @@ -1,8 +1,34 @@  Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StarWarsKb.Back", "StarWarsKb.Back\StarWarsKb.Back.csproj", "{D64B15F1-073D-4C63-9CFB-C20CD34C4670}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StarWarsKb.Front", "StarWarsKb.Front\StarWarsKb.Front.csproj", "{87F2168B-742C-4EBC-B231-3A8D3436C301}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StarWarsKb.UnitTests", "StarWarsKb.UnitTests\StarWarsKb.UnitTests.csproj", "{E5779146-3178-47BC-BF24-CF5743CD66B9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StarWarsKb.Infrastructure", "StarWarsKb.Infrastructure\StarWarsKb.Infrastructure.csproj", "{6BE24F33-7F52-4EB9-9988-E3A13BBF711F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D64B15F1-073D-4C63-9CFB-C20CD34C4670}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D64B15F1-073D-4C63-9CFB-C20CD34C4670}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D64B15F1-073D-4C63-9CFB-C20CD34C4670}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D64B15F1-073D-4C63-9CFB-C20CD34C4670}.Release|Any CPU.Build.0 = Release|Any CPU + {87F2168B-742C-4EBC-B231-3A8D3436C301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {87F2168B-742C-4EBC-B231-3A8D3436C301}.Debug|Any CPU.Build.0 = Debug|Any CPU + {87F2168B-742C-4EBC-B231-3A8D3436C301}.Release|Any CPU.ActiveCfg = Release|Any CPU + {87F2168B-742C-4EBC-B231-3A8D3436C301}.Release|Any CPU.Build.0 = Release|Any CPU + {E5779146-3178-47BC-BF24-CF5743CD66B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E5779146-3178-47BC-BF24-CF5743CD66B9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E5779146-3178-47BC-BF24-CF5743CD66B9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E5779146-3178-47BC-BF24-CF5743CD66B9}.Release|Any CPU.Build.0 = Release|Any CPU + {6BE24F33-7F52-4EB9-9988-E3A13BBF711F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6BE24F33-7F52-4EB9-9988-E3A13BBF711F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6BE24F33-7F52-4EB9-9988-E3A13BBF711F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6BE24F33-7F52-4EB9-9988-E3A13BBF711F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection EndGlobal