From 706c897160e5f1573facaf50b0cdbda81e34982a Mon Sep 17 00:00:00 2001 From: Christian Schou Date: Sat, 22 Jan 2022 13:20:52 +0100 Subject: [PATCH] Add project files. --- .dockerignore | 25 ++ .editorconfig | 4 + SuperHeroApi.sln | 30 ++ SuperHeroApi/Data/ApplicationDbContext.cs | 31 ++ .../MovieContextConfiguration.cs | 85 ++++++ .../SuperheroContextConfiguration.cs | 43 +++ .../SuperpowerContextConfiguration.cs | 71 +++++ SuperHeroApi/Dockerfile | 22 ++ SuperHeroApi/Interfaces/IMovieRepository.cs | 6 + .../Interfaces/ISuperheroRepository.cs | 7 + .../Interfaces/ISuperpowerRepository.cs | 7 + .../20220122115234_Initial.Designer.cs | 274 ++++++++++++++++++ .../Migrations/20220122115234_Initial.cs | 134 +++++++++ .../ApplicationDbContextModelSnapshot.cs | 272 +++++++++++++++++ SuperHeroApi/Models/Movie.cs | 21 ++ SuperHeroApi/Models/Superhero.cs | 18 ++ SuperHeroApi/Models/Superpower.cs | 19 ++ SuperHeroApi/Program.cs | 40 +++ SuperHeroApi/Properties/launchSettings.json | 38 +++ SuperHeroApi/Repositories/MovieRepository.cs | 15 + .../Repositories/SuperheroRepository.cs | 15 + .../Repositories/SuperpowerRepository.cs | 15 + SuperHeroApi/SuperHeroApi.csproj | 31 ++ SuperHeroApi/appsettings.Development.json | 8 + SuperHeroApi/appsettings.json | 12 + 25 files changed, 1243 insertions(+) create mode 100644 .dockerignore create mode 100644 .editorconfig create mode 100644 SuperHeroApi.sln create mode 100644 SuperHeroApi/Data/ApplicationDbContext.cs create mode 100644 SuperHeroApi/Data/ContextConfigurations/MovieContextConfiguration.cs create mode 100644 SuperHeroApi/Data/ContextConfigurations/SuperheroContextConfiguration.cs create mode 100644 SuperHeroApi/Data/ContextConfigurations/SuperpowerContextConfiguration.cs create mode 100644 SuperHeroApi/Dockerfile create mode 100644 SuperHeroApi/Interfaces/IMovieRepository.cs create mode 100644 SuperHeroApi/Interfaces/ISuperheroRepository.cs create mode 100644 SuperHeroApi/Interfaces/ISuperpowerRepository.cs create mode 100644 SuperHeroApi/Migrations/20220122115234_Initial.Designer.cs create mode 100644 SuperHeroApi/Migrations/20220122115234_Initial.cs create mode 100644 SuperHeroApi/Migrations/ApplicationDbContextModelSnapshot.cs create mode 100644 SuperHeroApi/Models/Movie.cs create mode 100644 SuperHeroApi/Models/Superhero.cs create mode 100644 SuperHeroApi/Models/Superpower.cs create mode 100644 SuperHeroApi/Program.cs create mode 100644 SuperHeroApi/Properties/launchSettings.json create mode 100644 SuperHeroApi/Repositories/MovieRepository.cs create mode 100644 SuperHeroApi/Repositories/SuperheroRepository.cs create mode 100644 SuperHeroApi/Repositories/SuperpowerRepository.cs create mode 100644 SuperHeroApi/SuperHeroApi.csproj create mode 100644 SuperHeroApi/appsettings.Development.json create mode 100644 SuperHeroApi/appsettings.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3729ff0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6d8f727 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# CS8618: Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. +dotnet_diagnostic.CS8618.severity = silent diff --git a/SuperHeroApi.sln b/SuperHeroApi.sln new file mode 100644 index 0000000..5328d13 --- /dev/null +++ b/SuperHeroApi.sln @@ -0,0 +1,30 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32014.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperHeroApi", "SuperHeroApi\SuperHeroApi.csproj", "{0B4520C5-2D35-4D48-A908-25DBCA897E39}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{75DC658F-A708-4674-AEE6-483FB21BCB3D}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0B4520C5-2D35-4D48-A908-25DBCA897E39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B4520C5-2D35-4D48-A908-25DBCA897E39}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B4520C5-2D35-4D48-A908-25DBCA897E39}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0B4520C5-2D35-4D48-A908-25DBCA897E39}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A6DB8171-D299-465B-8EDA-61B35E4686A5} + EndGlobalSection +EndGlobal diff --git a/SuperHeroApi/Data/ApplicationDbContext.cs b/SuperHeroApi/Data/ApplicationDbContext.cs new file mode 100644 index 0000000..adf48de --- /dev/null +++ b/SuperHeroApi/Data/ApplicationDbContext.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore; +using SuperHeroApi.Data.ContextConfigurations; +using SuperHeroApi.Models; + +namespace SuperHeroApi.Data +{ + public class ApplicationDbContext : DbContext + { + public ApplicationDbContext(DbContextOptions options) : base(options) + { + + } + + protected override void OnModelCreating(ModelBuilder builder) + { + // Generate three GUIDS and place them in an arrays + var ids = new Guid[] {Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; + + // Apply configuration for the three contexts in our application + // This will create the demo data for our GraphQL endpoint. + builder.ApplyConfiguration(new SuperheroContextConfiguration(ids)); + builder.ApplyConfiguration(new SuperpowerContextConfiguration(ids)); + builder.ApplyConfiguration(new MovieContextConfiguration(ids)); + } + + // Add the DbSets for each of our models we would like at our database + public DbSet Superheroes { get; set; } + public DbSet Superpowers { get; set; } + public DbSet Movies { get; set; } + } +} diff --git a/SuperHeroApi/Data/ContextConfigurations/MovieContextConfiguration.cs b/SuperHeroApi/Data/ContextConfigurations/MovieContextConfiguration.cs new file mode 100644 index 0000000..8eec634 --- /dev/null +++ b/SuperHeroApi/Data/ContextConfigurations/MovieContextConfiguration.cs @@ -0,0 +1,85 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using SuperHeroApi.Models; + +namespace SuperHeroApi.Data.ContextConfigurations +{ + public class MovieContextConfiguration : IEntityTypeConfiguration + { + private Guid[] _ids; + + public MovieContextConfiguration(Guid[] ids) + { + _ids = ids; + } + + public void Configure(EntityTypeBuilder builder) + { + builder + .HasData( + new Movie + { + Id = Guid.NewGuid(), + Title = "Batman Begins", + Description = "Batman Begins is a 2005 superhero film directed by Christopher Nolan and written by Nolan and David S. Goyer. Based on the DC Comics character Batman, it stars Christian Bale as Bruce Wayne / Batman, with Michael Caine, Liam Neeson, Katie Holmes, Gary Oldman,", + Instructor = "Christopher Nolan", + ReleaseDate = new DateTime(2005, 06, 25), + SuperheroId = _ids[0] + }, + new Movie + { + Id= Guid.NewGuid(), + Title = "The Dark Knight", + Description = "The Dark Knight is a 2008 superhero film directed, produced, and co-written by Christopher Nolan. Based on the DC Comics character Batman, the film is the second installment of Nolan's The Dark Knight Trilogy and a sequel to 2005's Batman Begins, starring Christian Bale and supported by Michael Caine, Heath Ledger, Gary Oldman, Aaron Eckhart, Maggie Gyllenhaal, and Morgan Freeman.", + Instructor = "Christopher Nolan", + ReleaseDate = new DateTime(2008, 07, 18), + SuperheroId = _ids[0] + }, + new Movie + { + Id = Guid.NewGuid(), + Title = "The Dark Knight Rises", + Description = "The Dark Knight Rises is a 2012 superhero film directed by Christopher Nolan, who co-wrote the screenplay with his brother Jonathan Nolan, and the story with David S. Goyer.", + Instructor = "Christopher Nolan", + ReleaseDate = new DateTime(2012, 07, 20), + SuperheroId = _ids[0] + }, + new Movie + { + Id = Guid.NewGuid(), + Title = "Star Wars: Episode IV – A New Hope", + Description = "Star Wars (retroactively titled Star Wars: Episode IV – A New Hope) is a 1977 American epic space opera film written and directed by George Lucas, produced by Lucasfilm and distributed by 20th Century Fox.", + Instructor = "George Lucas", + ReleaseDate = new DateTime(1977, 05, 25), + SuperheroId = _ids[1] + }, + new Movie + { + Id = Guid.NewGuid(), + Title = "Star Wars: Episode V – The Empire Strikes Back", + Description = "The Empire Strikes Back (also known as Star Wars: Episode V – The Empire Strikes Back) is a 1980 American epic space opera film directed by Irvin Kershner and written by Leigh Brackett and Lawrence Kasdan, based on a story by George Lucas.", + Instructor = "Irvin Kershner", + ReleaseDate = new DateTime(1980, 05, 21), + SuperheroId = _ids[1] + }, + new Movie + { + Id = Guid.NewGuid(), + Title = "Star Wars: Episode VI – Return of the Jedi", + Description = "Return of the Jedi (also known as Star Wars: Episode VI – Return of the Jedi) is a 1983 American epic space opera film directed by Richard Marquand. The screenplay is by Lawrence Kasdan and George Lucas from a story by Lucas, who was also the executive producer.", + Instructor = "Richard Marquand", + ReleaseDate = new DateTime(1983, 05, 25), + SuperheroId = _ids[1] + }, + new Movie + { + Id = Guid.NewGuid(), + Title = "Black Widow", + Description = "Black Widow is a 2021 American superhero film based on Marvel Comics featuring the character of the same name. Produced by Marvel Studios and distributed by Walt Disney Studios Motion Pictures, it is the 24th film in the Marvel Cinematic Universe (MCU).", + Instructor = "Cate Shortland", + ReleaseDate = new DateTime(2021, 06, 29), + SuperheroId= _ids[2] + }); + } + } +} diff --git a/SuperHeroApi/Data/ContextConfigurations/SuperheroContextConfiguration.cs b/SuperHeroApi/Data/ContextConfigurations/SuperheroContextConfiguration.cs new file mode 100644 index 0000000..7a17f00 --- /dev/null +++ b/SuperHeroApi/Data/ContextConfigurations/SuperheroContextConfiguration.cs @@ -0,0 +1,43 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using SuperHeroApi.Models; + +namespace SuperHeroApi.Data.ContextConfigurations +{ + public class SuperheroContextConfiguration : IEntityTypeConfiguration + { + private Guid[] _ids; + + public SuperheroContextConfiguration(Guid[] ids) + { + _ids = ids; + } + + public void Configure(EntityTypeBuilder builder) + { + builder + .HasData( + new Superhero + { + Id = _ids[0], + Name = "Batman", + Description = "Batman was originally introduced as a ruthless vigilante who frequently killed or maimed criminals, but evolved into a character with a stringent moral code and strong sense of justice. Unlike most superheroes, Batman does not possess any superpowers, instead relying on his intellect, fighting skills, and wealth.", + Height = 1.93 + }, + new Superhero + { + Id = _ids[1], + Name = "Luke Skywalker", + Description = "Luke Skywalker was a Tatooine farmboy who rose from humble beginnings to become one of the greatest Jedi the galaxy has ever known. Along with his friends Princess Leia and Han Solo, Luke battled the evil Empire, discovered the truth of his parentage, and ended the tyranny of the Sith.", + Height = 1.70 + }, + new Superhero + { + Id = _ids[2], + Name = "Black Widow", + Description = "Black Widow, real name Natasha Romanoff, is a trained female secret agent and superhero that appears in Marvel Comics. Associated with the superhero teams S.H.I.E.L.D. and the Avengers, Black Widow makes up for her lack of superpowers with world class training as an athlete, acrobat, and expert martial artist and weapon specialist.", + Height = 1.70 + }); + } + } +} diff --git a/SuperHeroApi/Data/ContextConfigurations/SuperpowerContextConfiguration.cs b/SuperHeroApi/Data/ContextConfigurations/SuperpowerContextConfiguration.cs new file mode 100644 index 0000000..d3c77be --- /dev/null +++ b/SuperHeroApi/Data/ContextConfigurations/SuperpowerContextConfiguration.cs @@ -0,0 +1,71 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using SuperHeroApi.Models; + +namespace SuperHeroApi.Data.ContextConfigurations +{ + public class SuperpowerContextConfiguration : IEntityTypeConfiguration + { + private Guid[] _ids; + + public SuperpowerContextConfiguration(Guid[] ids) + { + _ids = ids; + } + + public void Configure(EntityTypeBuilder builder) + { + builder + .HasData( + new Superpower + { + Id = Guid.NewGuid(), + SuperPower = "Intellect.", + Description = "He's always a step ahead.", + SuperheroId = _ids[0] + }, + new Superpower + { + Id = Guid.NewGuid(), + SuperPower = "Fighting", + Description = "Sublime fighting skills.", + SuperheroId = _ids[0] + }, + new Superpower + { + Id = Guid.NewGuid(), + SuperPower = "Wealth.", + Description = "He got a lot of money", + SuperheroId = _ids[0] + }, + new Superpower + { + Id = Guid.NewGuid(), + SuperPower = "Deflect blaster power.", + Description = "Skywalker is able to deflect fire from a blaster back at the opponent firing. This enables Luke to turn someone else's weapon against them.", + SuperheroId = _ids[1] + }, + new Superpower + { + Id = Guid.NewGuid(), + SuperPower = "Espionage", + Description = "She's good at spying at people.", + SuperheroId = _ids[2] + }, + new Superpower + { + Id = Guid.NewGuid(), + SuperPower = "Infiltration", + Description = "She knows how to infiltrate the enemy.", + SuperheroId = _ids[2] + }, + new Superpower + { + Id = Guid.NewGuid(), + SuperPower = "Subterfuge", + Description = "The knowledge of how to undermine others.", + SuperheroId = _ids[2] + }); + } + } +} diff --git a/SuperHeroApi/Dockerfile b/SuperHeroApi/Dockerfile new file mode 100644 index 0000000..eb3ac42 --- /dev/null +++ b/SuperHeroApi/Dockerfile @@ -0,0 +1,22 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /src +COPY ["SuperHeroApi/SuperHeroApi.csproj", "SuperHeroApi/"] +RUN dotnet restore "SuperHeroApi/SuperHeroApi.csproj" +COPY . . +WORKDIR "/src/SuperHeroApi" +RUN dotnet build "SuperHeroApi.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "SuperHeroApi.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "SuperHeroApi.dll"] \ No newline at end of file diff --git a/SuperHeroApi/Interfaces/IMovieRepository.cs b/SuperHeroApi/Interfaces/IMovieRepository.cs new file mode 100644 index 0000000..b6beef6 --- /dev/null +++ b/SuperHeroApi/Interfaces/IMovieRepository.cs @@ -0,0 +1,6 @@ +namespace SuperHeroApi.Interfaces +{ + public interface IMovieRepository + { + } +} diff --git a/SuperHeroApi/Interfaces/ISuperheroRepository.cs b/SuperHeroApi/Interfaces/ISuperheroRepository.cs new file mode 100644 index 0000000..34d2746 --- /dev/null +++ b/SuperHeroApi/Interfaces/ISuperheroRepository.cs @@ -0,0 +1,7 @@ +namespace SuperHeroApi.Interfaces +{ + public interface ISuperheroRepository + { + + } +} diff --git a/SuperHeroApi/Interfaces/ISuperpowerRepository.cs b/SuperHeroApi/Interfaces/ISuperpowerRepository.cs new file mode 100644 index 0000000..f7847e2 --- /dev/null +++ b/SuperHeroApi/Interfaces/ISuperpowerRepository.cs @@ -0,0 +1,7 @@ +namespace SuperHeroApi.Interfaces +{ + public interface ISuperpowerRepository + { + + } +} diff --git a/SuperHeroApi/Migrations/20220122115234_Initial.Designer.cs b/SuperHeroApi/Migrations/20220122115234_Initial.Designer.cs new file mode 100644 index 0000000..458b102 --- /dev/null +++ b/SuperHeroApi/Migrations/20220122115234_Initial.Designer.cs @@ -0,0 +1,274 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SuperHeroApi.Data; + +#nullable disable + +namespace SuperHeroApi.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220122115234_Initial")] + partial class Initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("SuperHeroApi.Models.Movie", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Instructor") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReleaseDate") + .HasColumnType("datetime2"); + + b.Property("SuperheroId") + .HasColumnType("uniqueidentifier"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("SuperheroId"); + + b.ToTable("Movies"); + + b.HasData( + new + { + Id = new Guid("191895b4-7207-40a2-9203-24d1e65b3991"), + Description = "Batman Begins is a 2005 superhero film directed by Christopher Nolan and written by Nolan and David S. Goyer. Based on the DC Comics character Batman, it stars Christian Bale as Bruce Wayne / Batman, with Michael Caine, Liam Neeson, Katie Holmes, Gary Oldman,", + Instructor = "Christopher Nolan", + ReleaseDate = new DateTime(2005, 6, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), + Title = "Batman Begins" + }, + new + { + Id = new Guid("da5d6fc6-a958-4892-b243-f1ec229456cc"), + Description = "The Dark Knight is a 2008 superhero film directed, produced, and co-written by Christopher Nolan. Based on the DC Comics character Batman, the film is the second installment of Nolan's The Dark Knight Trilogy and a sequel to 2005's Batman Begins, starring Christian Bale and supported by Michael Caine, Heath Ledger, Gary Oldman, Aaron Eckhart, Maggie Gyllenhaal, and Morgan Freeman.", + Instructor = "Christopher Nolan", + ReleaseDate = new DateTime(2008, 7, 18, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), + Title = "The Dark Knight" + }, + new + { + Id = new Guid("1f9119bf-e246-4d7e-b5b5-a88749baf24a"), + Description = "The Dark Knight Rises is a 2012 superhero film directed by Christopher Nolan, who co-wrote the screenplay with his brother Jonathan Nolan, and the story with David S. Goyer.", + Instructor = "Christopher Nolan", + ReleaseDate = new DateTime(2012, 7, 20, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), + Title = "The Dark Knight Rises" + }, + new + { + Id = new Guid("73b5e8fb-4735-48cd-ae70-ec89618d77a8"), + Description = "Star Wars (retroactively titled Star Wars: Episode IV – A New Hope) is a 1977 American epic space opera film written and directed by George Lucas, produced by Lucasfilm and distributed by 20th Century Fox.", + Instructor = "George Lucas", + ReleaseDate = new DateTime(1977, 5, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), + Title = "Star Wars: Episode IV – A New Hope" + }, + new + { + Id = new Guid("ee989106-2bf5-48b1-840d-350c3d26b34b"), + Description = "The Empire Strikes Back (also known as Star Wars: Episode V – The Empire Strikes Back) is a 1980 American epic space opera film directed by Irvin Kershner and written by Leigh Brackett and Lawrence Kasdan, based on a story by George Lucas.", + Instructor = "Irvin Kershner", + ReleaseDate = new DateTime(1980, 5, 21, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), + Title = "Star Wars: Episode V – The Empire Strikes Back" + }, + new + { + Id = new Guid("e500d81b-6785-46fa-aa14-1d64f9abc8c0"), + Description = "Return of the Jedi (also known as Star Wars: Episode VI – Return of the Jedi) is a 1983 American epic space opera film directed by Richard Marquand. The screenplay is by Lawrence Kasdan and George Lucas from a story by Lucas, who was also the executive producer.", + Instructor = "Richard Marquand", + ReleaseDate = new DateTime(1983, 5, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), + Title = "Star Wars: Episode VI – Return of the Jedi" + }, + new + { + Id = new Guid("14ad1d2f-852e-469e-94c2-7d969702eef5"), + Description = "Black Widow is a 2021 American superhero film based on Marvel Comics featuring the character of the same name. Produced by Marvel Studios and distributed by Walt Disney Studios Motion Pictures, it is the 24th film in the Marvel Cinematic Universe (MCU).", + Instructor = "Cate Shortland", + ReleaseDate = new DateTime(2021, 6, 29, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2"), + Title = "Black Widow" + }); + }); + + modelBuilder.Entity("SuperHeroApi.Models.Superhero", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Height") + .HasColumnType("float"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Superheroes"); + + b.HasData( + new + { + Id = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), + Description = "Batman was originally introduced as a ruthless vigilante who frequently killed or maimed criminals, but evolved into a character with a stringent moral code and strong sense of justice. Unlike most superheroes, Batman does not possess any superpowers, instead relying on his intellect, fighting skills, and wealth.", + Height = 1.9299999999999999, + Name = "Batman" + }, + new + { + Id = new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), + Description = "Luke Skywalker was a Tatooine farmboy who rose from humble beginnings to become one of the greatest Jedi the galaxy has ever known. Along with his friends Princess Leia and Han Solo, Luke battled the evil Empire, discovered the truth of his parentage, and ended the tyranny of the Sith.", + Height = 1.7, + Name = "Luke Skywalker" + }, + new + { + Id = new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2"), + Description = "Black Widow, real name Natasha Romanoff, is a trained female secret agent and superhero that appears in Marvel Comics. Associated with the superhero teams S.H.I.E.L.D. and the Avengers, Black Widow makes up for her lack of superpowers with world class training as an athlete, acrobat, and expert martial artist and weapon specialist.", + Height = 1.7, + Name = "Black Widow" + }); + }); + + modelBuilder.Entity("SuperHeroApi.Models.Superpower", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SuperPower") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SuperheroId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("SuperheroId"); + + b.ToTable("Superpowers"); + + b.HasData( + new + { + Id = new Guid("6248fae6-f98a-4775-b534-d12c96da8b12"), + Description = "He's always a step ahead.", + SuperPower = "Intellect.", + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4") + }, + new + { + Id = new Guid("107f699d-7bb4-489d-8694-f3017727284e"), + Description = "Sublime fighting skills.", + SuperPower = "Fighting", + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4") + }, + new + { + Id = new Guid("cafd071d-9f9a-4cf4-af20-894d5af75ab5"), + Description = "He got a lot of money", + SuperPower = "Wealth.", + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4") + }, + new + { + Id = new Guid("c6618c14-929b-4568-b12f-ea7f7ebb748b"), + Description = "Skywalker is able to deflect fire from a blaster back at the opponent firing. This enables Luke to turn someone else's weapon against them.", + SuperPower = "Deflect blaster power.", + SuperheroId = new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe") + }, + new + { + Id = new Guid("987eef1c-e372-4b6a-8e6f-1dafe6e1c3ad"), + Description = "She's good at spying at people.", + SuperPower = "Espionage", + SuperheroId = new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2") + }, + new + { + Id = new Guid("57b1e4bf-3818-4bd1-a854-8c61070d057c"), + Description = "She knows how to infiltrate the enemy.", + SuperPower = "Infiltration", + SuperheroId = new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2") + }, + new + { + Id = new Guid("9b17d0d5-8eba-4075-9d91-bc281ef3ac4b"), + Description = "The knowledge of how to undermine others.", + SuperPower = "Subterfuge", + SuperheroId = new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2") + }); + }); + + modelBuilder.Entity("SuperHeroApi.Models.Movie", b => + { + b.HasOne("SuperHeroApi.Models.Superhero", "Superhero") + .WithMany("Movies") + .HasForeignKey("SuperheroId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Superhero"); + }); + + modelBuilder.Entity("SuperHeroApi.Models.Superpower", b => + { + b.HasOne("SuperHeroApi.Models.Superhero", "Superhero") + .WithMany("Superpowers") + .HasForeignKey("SuperheroId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Superhero"); + }); + + modelBuilder.Entity("SuperHeroApi.Models.Superhero", b => + { + b.Navigation("Movies"); + + b.Navigation("Superpowers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SuperHeroApi/Migrations/20220122115234_Initial.cs b/SuperHeroApi/Migrations/20220122115234_Initial.cs new file mode 100644 index 0000000..8c61556 --- /dev/null +++ b/SuperHeroApi/Migrations/20220122115234_Initial.cs @@ -0,0 +1,134 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SuperHeroApi.Migrations +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Superheroes", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + Height = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Superheroes", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Movies", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Title = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + Instructor = table.Column(type: "nvarchar(max)", nullable: false), + ReleaseDate = table.Column(type: "datetime2", nullable: false), + SuperheroId = table.Column(type: "uniqueidentifier", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Movies", x => x.Id); + table.ForeignKey( + name: "FK_Movies_Superheroes_SuperheroId", + column: x => x.SuperheroId, + principalTable: "Superheroes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Superpowers", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + SuperPower = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + SuperheroId = table.Column(type: "uniqueidentifier", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Superpowers", x => x.Id); + table.ForeignKey( + name: "FK_Superpowers_Superheroes_SuperheroId", + column: x => x.SuperheroId, + principalTable: "Superheroes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "Superheroes", + columns: new[] { "Id", "Description", "Height", "Name" }, + values: new object[] { new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2"), "Black Widow, real name Natasha Romanoff, is a trained female secret agent and superhero that appears in Marvel Comics. Associated with the superhero teams S.H.I.E.L.D. and the Avengers, Black Widow makes up for her lack of superpowers with world class training as an athlete, acrobat, and expert martial artist and weapon specialist.", 1.7, "Black Widow" }); + + migrationBuilder.InsertData( + table: "Superheroes", + columns: new[] { "Id", "Description", "Height", "Name" }, + values: new object[] { new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), "Luke Skywalker was a Tatooine farmboy who rose from humble beginnings to become one of the greatest Jedi the galaxy has ever known. Along with his friends Princess Leia and Han Solo, Luke battled the evil Empire, discovered the truth of his parentage, and ended the tyranny of the Sith.", 1.7, "Luke Skywalker" }); + + migrationBuilder.InsertData( + table: "Superheroes", + columns: new[] { "Id", "Description", "Height", "Name" }, + values: new object[] { new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), "Batman was originally introduced as a ruthless vigilante who frequently killed or maimed criminals, but evolved into a character with a stringent moral code and strong sense of justice. Unlike most superheroes, Batman does not possess any superpowers, instead relying on his intellect, fighting skills, and wealth.", 1.9299999999999999, "Batman" }); + + migrationBuilder.InsertData( + table: "Movies", + columns: new[] { "Id", "Description", "Instructor", "ReleaseDate", "SuperheroId", "Title" }, + values: new object[,] + { + { new Guid("14ad1d2f-852e-469e-94c2-7d969702eef5"), "Black Widow is a 2021 American superhero film based on Marvel Comics featuring the character of the same name. Produced by Marvel Studios and distributed by Walt Disney Studios Motion Pictures, it is the 24th film in the Marvel Cinematic Universe (MCU).", "Cate Shortland", new DateTime(2021, 6, 29, 0, 0, 0, 0, DateTimeKind.Unspecified), new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2"), "Black Widow" }, + { new Guid("191895b4-7207-40a2-9203-24d1e65b3991"), "Batman Begins is a 2005 superhero film directed by Christopher Nolan and written by Nolan and David S. Goyer. Based on the DC Comics character Batman, it stars Christian Bale as Bruce Wayne / Batman, with Michael Caine, Liam Neeson, Katie Holmes, Gary Oldman,", "Christopher Nolan", new DateTime(2005, 6, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), "Batman Begins" }, + { new Guid("1f9119bf-e246-4d7e-b5b5-a88749baf24a"), "The Dark Knight Rises is a 2012 superhero film directed by Christopher Nolan, who co-wrote the screenplay with his brother Jonathan Nolan, and the story with David S. Goyer.", "Christopher Nolan", new DateTime(2012, 7, 20, 0, 0, 0, 0, DateTimeKind.Unspecified), new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), "The Dark Knight Rises" }, + { new Guid("73b5e8fb-4735-48cd-ae70-ec89618d77a8"), "Star Wars (retroactively titled Star Wars: Episode IV – A New Hope) is a 1977 American epic space opera film written and directed by George Lucas, produced by Lucasfilm and distributed by 20th Century Fox.", "George Lucas", new DateTime(1977, 5, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), "Star Wars: Episode IV – A New Hope" }, + { new Guid("da5d6fc6-a958-4892-b243-f1ec229456cc"), "The Dark Knight is a 2008 superhero film directed, produced, and co-written by Christopher Nolan. Based on the DC Comics character Batman, the film is the second installment of Nolan's The Dark Knight Trilogy and a sequel to 2005's Batman Begins, starring Christian Bale and supported by Michael Caine, Heath Ledger, Gary Oldman, Aaron Eckhart, Maggie Gyllenhaal, and Morgan Freeman.", "Christopher Nolan", new DateTime(2008, 7, 18, 0, 0, 0, 0, DateTimeKind.Unspecified), new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), "The Dark Knight" }, + { new Guid("e500d81b-6785-46fa-aa14-1d64f9abc8c0"), "Return of the Jedi (also known as Star Wars: Episode VI – Return of the Jedi) is a 1983 American epic space opera film directed by Richard Marquand. The screenplay is by Lawrence Kasdan and George Lucas from a story by Lucas, who was also the executive producer.", "Richard Marquand", new DateTime(1983, 5, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), "Star Wars: Episode VI – Return of the Jedi" }, + { new Guid("ee989106-2bf5-48b1-840d-350c3d26b34b"), "The Empire Strikes Back (also known as Star Wars: Episode V – The Empire Strikes Back) is a 1980 American epic space opera film directed by Irvin Kershner and written by Leigh Brackett and Lawrence Kasdan, based on a story by George Lucas.", "Irvin Kershner", new DateTime(1980, 5, 21, 0, 0, 0, 0, DateTimeKind.Unspecified), new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), "Star Wars: Episode V – The Empire Strikes Back" } + }); + + migrationBuilder.InsertData( + table: "Superpowers", + columns: new[] { "Id", "Description", "SuperPower", "SuperheroId" }, + values: new object[,] + { + { new Guid("107f699d-7bb4-489d-8694-f3017727284e"), "Sublime fighting skills.", "Fighting", new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4") }, + { new Guid("57b1e4bf-3818-4bd1-a854-8c61070d057c"), "She knows how to infiltrate the enemy.", "Infiltration", new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2") }, + { new Guid("6248fae6-f98a-4775-b534-d12c96da8b12"), "He's always a step ahead.", "Intellect.", new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4") }, + { new Guid("987eef1c-e372-4b6a-8e6f-1dafe6e1c3ad"), "She's good at spying at people.", "Espionage", new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2") }, + { new Guid("9b17d0d5-8eba-4075-9d91-bc281ef3ac4b"), "The knowledge of how to undermine others.", "Subterfuge", new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2") }, + { new Guid("c6618c14-929b-4568-b12f-ea7f7ebb748b"), "Skywalker is able to deflect fire from a blaster back at the opponent firing. This enables Luke to turn someone else's weapon against them.", "Deflect blaster power.", new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe") }, + { new Guid("cafd071d-9f9a-4cf4-af20-894d5af75ab5"), "He got a lot of money", "Wealth.", new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4") } + }); + + migrationBuilder.CreateIndex( + name: "IX_Movies_SuperheroId", + table: "Movies", + column: "SuperheroId"); + + migrationBuilder.CreateIndex( + name: "IX_Superpowers_SuperheroId", + table: "Superpowers", + column: "SuperheroId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Movies"); + + migrationBuilder.DropTable( + name: "Superpowers"); + + migrationBuilder.DropTable( + name: "Superheroes"); + } + } +} diff --git a/SuperHeroApi/Migrations/ApplicationDbContextModelSnapshot.cs b/SuperHeroApi/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..1218b0d --- /dev/null +++ b/SuperHeroApi/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,272 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SuperHeroApi.Data; + +#nullable disable + +namespace SuperHeroApi.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("SuperHeroApi.Models.Movie", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Instructor") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReleaseDate") + .HasColumnType("datetime2"); + + b.Property("SuperheroId") + .HasColumnType("uniqueidentifier"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("SuperheroId"); + + b.ToTable("Movies"); + + b.HasData( + new + { + Id = new Guid("191895b4-7207-40a2-9203-24d1e65b3991"), + Description = "Batman Begins is a 2005 superhero film directed by Christopher Nolan and written by Nolan and David S. Goyer. Based on the DC Comics character Batman, it stars Christian Bale as Bruce Wayne / Batman, with Michael Caine, Liam Neeson, Katie Holmes, Gary Oldman,", + Instructor = "Christopher Nolan", + ReleaseDate = new DateTime(2005, 6, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), + Title = "Batman Begins" + }, + new + { + Id = new Guid("da5d6fc6-a958-4892-b243-f1ec229456cc"), + Description = "The Dark Knight is a 2008 superhero film directed, produced, and co-written by Christopher Nolan. Based on the DC Comics character Batman, the film is the second installment of Nolan's The Dark Knight Trilogy and a sequel to 2005's Batman Begins, starring Christian Bale and supported by Michael Caine, Heath Ledger, Gary Oldman, Aaron Eckhart, Maggie Gyllenhaal, and Morgan Freeman.", + Instructor = "Christopher Nolan", + ReleaseDate = new DateTime(2008, 7, 18, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), + Title = "The Dark Knight" + }, + new + { + Id = new Guid("1f9119bf-e246-4d7e-b5b5-a88749baf24a"), + Description = "The Dark Knight Rises is a 2012 superhero film directed by Christopher Nolan, who co-wrote the screenplay with his brother Jonathan Nolan, and the story with David S. Goyer.", + Instructor = "Christopher Nolan", + ReleaseDate = new DateTime(2012, 7, 20, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), + Title = "The Dark Knight Rises" + }, + new + { + Id = new Guid("73b5e8fb-4735-48cd-ae70-ec89618d77a8"), + Description = "Star Wars (retroactively titled Star Wars: Episode IV – A New Hope) is a 1977 American epic space opera film written and directed by George Lucas, produced by Lucasfilm and distributed by 20th Century Fox.", + Instructor = "George Lucas", + ReleaseDate = new DateTime(1977, 5, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), + Title = "Star Wars: Episode IV – A New Hope" + }, + new + { + Id = new Guid("ee989106-2bf5-48b1-840d-350c3d26b34b"), + Description = "The Empire Strikes Back (also known as Star Wars: Episode V – The Empire Strikes Back) is a 1980 American epic space opera film directed by Irvin Kershner and written by Leigh Brackett and Lawrence Kasdan, based on a story by George Lucas.", + Instructor = "Irvin Kershner", + ReleaseDate = new DateTime(1980, 5, 21, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), + Title = "Star Wars: Episode V – The Empire Strikes Back" + }, + new + { + Id = new Guid("e500d81b-6785-46fa-aa14-1d64f9abc8c0"), + Description = "Return of the Jedi (also known as Star Wars: Episode VI – Return of the Jedi) is a 1983 American epic space opera film directed by Richard Marquand. The screenplay is by Lawrence Kasdan and George Lucas from a story by Lucas, who was also the executive producer.", + Instructor = "Richard Marquand", + ReleaseDate = new DateTime(1983, 5, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), + Title = "Star Wars: Episode VI – Return of the Jedi" + }, + new + { + Id = new Guid("14ad1d2f-852e-469e-94c2-7d969702eef5"), + Description = "Black Widow is a 2021 American superhero film based on Marvel Comics featuring the character of the same name. Produced by Marvel Studios and distributed by Walt Disney Studios Motion Pictures, it is the 24th film in the Marvel Cinematic Universe (MCU).", + Instructor = "Cate Shortland", + ReleaseDate = new DateTime(2021, 6, 29, 0, 0, 0, 0, DateTimeKind.Unspecified), + SuperheroId = new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2"), + Title = "Black Widow" + }); + }); + + modelBuilder.Entity("SuperHeroApi.Models.Superhero", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Height") + .HasColumnType("float"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Superheroes"); + + b.HasData( + new + { + Id = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4"), + Description = "Batman was originally introduced as a ruthless vigilante who frequently killed or maimed criminals, but evolved into a character with a stringent moral code and strong sense of justice. Unlike most superheroes, Batman does not possess any superpowers, instead relying on his intellect, fighting skills, and wealth.", + Height = 1.9299999999999999, + Name = "Batman" + }, + new + { + Id = new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe"), + Description = "Luke Skywalker was a Tatooine farmboy who rose from humble beginnings to become one of the greatest Jedi the galaxy has ever known. Along with his friends Princess Leia and Han Solo, Luke battled the evil Empire, discovered the truth of his parentage, and ended the tyranny of the Sith.", + Height = 1.7, + Name = "Luke Skywalker" + }, + new + { + Id = new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2"), + Description = "Black Widow, real name Natasha Romanoff, is a trained female secret agent and superhero that appears in Marvel Comics. Associated with the superhero teams S.H.I.E.L.D. and the Avengers, Black Widow makes up for her lack of superpowers with world class training as an athlete, acrobat, and expert martial artist and weapon specialist.", + Height = 1.7, + Name = "Black Widow" + }); + }); + + modelBuilder.Entity("SuperHeroApi.Models.Superpower", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SuperPower") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SuperheroId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("SuperheroId"); + + b.ToTable("Superpowers"); + + b.HasData( + new + { + Id = new Guid("6248fae6-f98a-4775-b534-d12c96da8b12"), + Description = "He's always a step ahead.", + SuperPower = "Intellect.", + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4") + }, + new + { + Id = new Guid("107f699d-7bb4-489d-8694-f3017727284e"), + Description = "Sublime fighting skills.", + SuperPower = "Fighting", + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4") + }, + new + { + Id = new Guid("cafd071d-9f9a-4cf4-af20-894d5af75ab5"), + Description = "He got a lot of money", + SuperPower = "Wealth.", + SuperheroId = new Guid("bc9b3642-25cd-4b33-af7c-4861519bd7d4") + }, + new + { + Id = new Guid("c6618c14-929b-4568-b12f-ea7f7ebb748b"), + Description = "Skywalker is able to deflect fire from a blaster back at the opponent firing. This enables Luke to turn someone else's weapon against them.", + SuperPower = "Deflect blaster power.", + SuperheroId = new Guid("aed332fe-d264-4f9f-9a54-ecf8a878dbbe") + }, + new + { + Id = new Guid("987eef1c-e372-4b6a-8e6f-1dafe6e1c3ad"), + Description = "She's good at spying at people.", + SuperPower = "Espionage", + SuperheroId = new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2") + }, + new + { + Id = new Guid("57b1e4bf-3818-4bd1-a854-8c61070d057c"), + Description = "She knows how to infiltrate the enemy.", + SuperPower = "Infiltration", + SuperheroId = new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2") + }, + new + { + Id = new Guid("9b17d0d5-8eba-4075-9d91-bc281ef3ac4b"), + Description = "The knowledge of how to undermine others.", + SuperPower = "Subterfuge", + SuperheroId = new Guid("619b7fee-9dfc-424a-b2af-e9dc2f89f0a2") + }); + }); + + modelBuilder.Entity("SuperHeroApi.Models.Movie", b => + { + b.HasOne("SuperHeroApi.Models.Superhero", "Superhero") + .WithMany("Movies") + .HasForeignKey("SuperheroId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Superhero"); + }); + + modelBuilder.Entity("SuperHeroApi.Models.Superpower", b => + { + b.HasOne("SuperHeroApi.Models.Superhero", "Superhero") + .WithMany("Superpowers") + .HasForeignKey("SuperheroId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Superhero"); + }); + + modelBuilder.Entity("SuperHeroApi.Models.Superhero", b => + { + b.Navigation("Movies"); + + b.Navigation("Superpowers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SuperHeroApi/Models/Movie.cs b/SuperHeroApi/Models/Movie.cs new file mode 100644 index 0000000..e172824 --- /dev/null +++ b/SuperHeroApi/Models/Movie.cs @@ -0,0 +1,21 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace SuperHeroApi.Models +{ + public class Movie + { + [Key] + public Guid Id { get; set; } + + [Required(ErrorMessage = "The movie title is required")] + public string Title { get; set; } + public string Description { get; set; } + public string Instructor { get; set; } + public DateTime ReleaseDate { get; set; } + + [ForeignKey("SuperheroId")] + public Guid SuperheroId { get; set; } + public Superhero Superhero { get; set; } + } +} diff --git a/SuperHeroApi/Models/Superhero.cs b/SuperHeroApi/Models/Superhero.cs new file mode 100644 index 0000000..dee0b6d --- /dev/null +++ b/SuperHeroApi/Models/Superhero.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; + +namespace SuperHeroApi.Models +{ + public class Superhero + { + [Key] + public Guid Id { get; set; } + + [Required(ErrorMessage = "Please specify a name for the superhero")] + public string Name { get; set; } + public string Description { get; set; } + public double Height { get; set; } + + public ICollection Superpowers { get; set; } + public ICollection Movies { get; set; } + } +} diff --git a/SuperHeroApi/Models/Superpower.cs b/SuperHeroApi/Models/Superpower.cs new file mode 100644 index 0000000..49f394a --- /dev/null +++ b/SuperHeroApi/Models/Superpower.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace SuperHeroApi.Models +{ + public class Superpower + { + [Key] + public Guid Id { get; set; } + + [Required(ErrorMessage = "The superpower is required")] + public string SuperPower { get; set; } + public string Description { get; set; } + + [ForeignKey("SuperheroId")] + public Guid SuperheroId { get; set; } + public Superhero Superhero { get; set; } + } +} diff --git a/SuperHeroApi/Program.cs b/SuperHeroApi/Program.cs new file mode 100644 index 0000000..f64f79c --- /dev/null +++ b/SuperHeroApi/Program.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore; +using SuperHeroApi.Data; +using SuperHeroApi.Interfaces; +using SuperHeroApi.Repositories; + +var builder = WebApplication.CreateBuilder(args); +ConfigurationManager configuration = builder.Configuration; + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +// Register custom services for the superheroes +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); + +// Add Application Db Context options +builder.Services.AddDbContext(options => +options.UseSqlServer(configuration.GetConnectionString("SqlServer"))); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/SuperHeroApi/Properties/launchSettings.json b/SuperHeroApi/Properties/launchSettings.json new file mode 100644 index 0000000..e5f690c --- /dev/null +++ b/SuperHeroApi/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:26045", + "sslPort": 44338 + } + }, + "profiles": { + "SuperHeroApi": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:7116;http://localhost:5116", + "dotnetRunMessages": true + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "publishAllPorts": true, + "useSSL": true + } + } +} \ No newline at end of file diff --git a/SuperHeroApi/Repositories/MovieRepository.cs b/SuperHeroApi/Repositories/MovieRepository.cs new file mode 100644 index 0000000..d78db1e --- /dev/null +++ b/SuperHeroApi/Repositories/MovieRepository.cs @@ -0,0 +1,15 @@ +using SuperHeroApi.Data; +using SuperHeroApi.Interfaces; + +namespace SuperHeroApi.Repositories +{ + public class MovieRepository : IMovieRepository + { + private readonly ApplicationDbContext _appDbContext; + + public MovieRepository(ApplicationDbContext appDbContext) + { + _appDbContext = appDbContext; + } + } +} diff --git a/SuperHeroApi/Repositories/SuperheroRepository.cs b/SuperHeroApi/Repositories/SuperheroRepository.cs new file mode 100644 index 0000000..6e99504 --- /dev/null +++ b/SuperHeroApi/Repositories/SuperheroRepository.cs @@ -0,0 +1,15 @@ +using SuperHeroApi.Data; +using SuperHeroApi.Interfaces; + +namespace SuperHeroApi.Repositories +{ + public class SuperheroRepository : ISuperheroRepository + { + private readonly ApplicationDbContext _appDbContext; + + public SuperheroRepository(ApplicationDbContext appDbContext) + { + _appDbContext = appDbContext; + } + } +} diff --git a/SuperHeroApi/Repositories/SuperpowerRepository.cs b/SuperHeroApi/Repositories/SuperpowerRepository.cs new file mode 100644 index 0000000..65ff3c0 --- /dev/null +++ b/SuperHeroApi/Repositories/SuperpowerRepository.cs @@ -0,0 +1,15 @@ +using SuperHeroApi.Data; +using SuperHeroApi.Interfaces; + +namespace SuperHeroApi.Repositories +{ + public class SuperpowerRepository : ISuperpowerRepository + { + private readonly ApplicationDbContext _appDbContext; + + public SuperpowerRepository(ApplicationDbContext appDbContext) + { + _appDbContext = appDbContext; + } + } +} diff --git a/SuperHeroApi/SuperHeroApi.csproj b/SuperHeroApi/SuperHeroApi.csproj new file mode 100644 index 0000000..39753c6 --- /dev/null +++ b/SuperHeroApi/SuperHeroApi.csproj @@ -0,0 +1,31 @@ + + + + net6.0 + enable + enable + 73833193-9918-4fe2-ac47-288df42c47fc + Linux + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + diff --git a/SuperHeroApi/appsettings.Development.json b/SuperHeroApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/SuperHeroApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/SuperHeroApi/appsettings.json b/SuperHeroApi/appsettings.json new file mode 100644 index 0000000..0684dd3 --- /dev/null +++ b/SuperHeroApi/appsettings.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "SqlServer": "Server=DESKTOP-BD1F2DF;Database=SuperheroesApi;Trusted_Connection=True;" + } +}