Skip to content

Commit

Permalink
Gets an Ok!
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeLegendXIII committed Sep 28, 2019
1 parent 5109d70 commit d08716c
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 61 deletions.
3 changes: 2 additions & 1 deletion Conferences.Api/Conferences.Api/Conferences.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
Expand All @@ -11,6 +11,7 @@
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.12" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Conferences.Api.Controllers
{
[Route("api/v1/[controller]")]
[ApiController]
public class ConferencesController : ControllerBase
{
[HttpGet("")]
public async Task<IActionResult> GetConferences()
{
return Ok();
}
}
}
45 changes: 0 additions & 45 deletions Conferences.Api/Conferences.Api/Controllers/ValuesController.cs

This file was deleted.

35 changes: 35 additions & 0 deletions Conferences.Api/Conferences.Api/Domain/Conference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Conferences.Api.Domain
{
public class Conference
{
public int Id { get; set; }

public string Name { get; set; }

public string State { get; set; }

public string City { get; set; }

public DateTime StartDate { get; set; }

public DateTime EndDate { get; set; }

public bool Attending { get; set; }

public bool Speaking { get; set; }

public Topic FocusTopic { get; set; }
}

public class Topic
{
public int Id { get; set; }

public string Name { get; set; }
}
}
17 changes: 17 additions & 0 deletions Conferences.Api/Conferences.Api/Domain/ConferenceDataContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Conferences.Api.Domain
{
public class ConferenceDataContext : DbContext
{
public ConferenceDataContext(DbContextOptions<ConferenceDataContext> ctx) : base(ctx) { }

public virtual DbSet<Conference> Conferences { get; set; }

public virtual DbSet<Topic> Topics { get; set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Conferences.Api.Migrations
{
public partial class InitialMigration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Topics",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Topics", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Conferences",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(nullable: true),
State = table.Column<string>(nullable: true),
City = table.Column<string>(nullable: true),
StartDate = table.Column<DateTime>(nullable: false),
EndDate = table.Column<DateTime>(nullable: false),
Attending = table.Column<bool>(nullable: false),
Speaking = table.Column<bool>(nullable: false),
FocusTopicId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Conferences", x => x.Id);
table.ForeignKey(
name: "FK_Conferences_Topics_FocusTopicId",
column: x => x.FocusTopicId,
principalTable: "Topics",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});

migrationBuilder.CreateIndex(
name: "IX_Conferences_FocusTopicId",
table: "Conferences",
column: "FocusTopicId");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Conferences");

migrationBuilder.DropTable(
name: "Topics");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// <auto-generated />
using System;
using Conferences.Api.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace Conferences.Api.Migrations
{
[DbContext(typeof(ConferenceDataContext))]
partial class ConferenceDataContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

modelBuilder.Entity("Conferences.Api.Domain.Conference", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<bool>("Attending");
b.Property<string>("City");
b.Property<DateTime>("EndDate");
b.Property<int?>("FocusTopicId");
b.Property<string>("Name");
b.Property<bool>("Speaking");
b.Property<DateTime>("StartDate");
b.Property<string>("State");
b.HasKey("Id");
b.HasIndex("FocusTopicId");
b.ToTable("Conferences");
});

modelBuilder.Entity("Conferences.Api.Domain.Topic", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name");
b.HasKey("Id");
b.ToTable("Topics");
});

modelBuilder.Entity("Conferences.Api.Domain.Conference", b =>
{
b.HasOne("Conferences.Api.Domain.Topic", "FocusTopic")
.WithMany()
.HasForeignKey("FocusTopicId");
});
#pragma warning restore 612, 618
}
}
}
17 changes: 16 additions & 1 deletion Conferences.Api/Conferences.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Conferences.Api.Domain;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand All @@ -15,17 +17,30 @@ namespace Conferences.Api
{
public class Startup
{
public Startup(IConfiguration configuration)
public Startup(IConfiguration configuration, IHostingEnvironment environment)
{
Configuration = configuration;
Environment = environment;
}

public IConfiguration Configuration { get; }
public IHostingEnvironment Environment { get; set; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

if (Environment.IsEnvironment("testing"))
{
services.AddDbContext<ConferenceDataContext>(options => options.UseInMemoryDatabase("test"));
}
else
{
services.AddDbContext<ConferenceDataContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
Loading

0 comments on commit d08716c

Please sign in to comment.