diff --git a/API/API.csproj b/API/API.csproj new file mode 100644 index 0000000..37f96ad --- /dev/null +++ b/API/API.csproj @@ -0,0 +1,19 @@ + + + + net7.0 + enable + enable + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + diff --git a/API/Controllers/UserController.cs b/API/Controllers/UserController.cs new file mode 100644 index 0000000..a96fd5f --- /dev/null +++ b/API/Controllers/UserController.cs @@ -0,0 +1,38 @@ +using API.Data; +using API.Entities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace API.Controllers{ + +[ApiController] +public class UserController : ControllerBase +{ + + private readonly TestContext _dbContext; + public UserController( + TestContext dbContext + ) + { + _dbContext = dbContext; + } + + + [HttpGet] + [Route("test")] + public async Task> GetUsers() + { + return await _dbContext.User.ToListAsync(); + + } + + [HttpGet] + [Route("hey")] + public string Get() + { + return "hey"; + } + +} +} + diff --git a/API/Controllers/WeatherForecastController.cs b/API/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..68b3235 --- /dev/null +++ b/API/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace API.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + +} diff --git a/API/Data/Migrations/20240823185906_InitialCreate.Designer.cs b/API/Data/Migrations/20240823185906_InitialCreate.Designer.cs new file mode 100644 index 0000000..2bcbdc5 --- /dev/null +++ b/API/Data/Migrations/20240823185906_InitialCreate.Designer.cs @@ -0,0 +1,46 @@ +// +using API.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace API.Data.Migrations +{ + [DbContext(typeof(TestContext))] + [Migration("20240823185906_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.7"); + + modelBuilder.Entity("API.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Email") + .HasColumnType("TEXT"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("User"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/API/Data/Migrations/20240823185906_InitialCreate.cs b/API/Data/Migrations/20240823185906_InitialCreate.cs new file mode 100644 index 0000000..7e9dc71 --- /dev/null +++ b/API/Data/Migrations/20240823185906_InitialCreate.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace API.Data.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "User", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + FirstName = table.Column(type: "TEXT", nullable: false), + LastName = table.Column(type: "TEXT", nullable: false), + Email = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_User", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "User"); + } + } +} diff --git a/API/Data/Migrations/TestContextModelSnapshot.cs b/API/Data/Migrations/TestContextModelSnapshot.cs new file mode 100644 index 0000000..977a899 --- /dev/null +++ b/API/Data/Migrations/TestContextModelSnapshot.cs @@ -0,0 +1,43 @@ +// +using API.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace API.Data.Migrations +{ + [DbContext(typeof(TestContext))] + partial class TestContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.7"); + + modelBuilder.Entity("API.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Email") + .HasColumnType("TEXT"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("User"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/API/Data/TestContext.cs b/API/Data/TestContext.cs new file mode 100644 index 0000000..5655d63 --- /dev/null +++ b/API/Data/TestContext.cs @@ -0,0 +1,12 @@ +using API.Entities; +using Microsoft.EntityFrameworkCore; + +namespace API.Data +{ + public class TestContext : DbContext + { + public TestContext(DbContextOptions options) : base(options) {} + + public required DbSet User { get; set; } + } +} \ No newline at end of file diff --git a/API/Entities/User.cs b/API/Entities/User.cs new file mode 100644 index 0000000..6a3d96b --- /dev/null +++ b/API/Entities/User.cs @@ -0,0 +1,10 @@ +namespace API.Entities +{ + public class User + { + public required int Id { get; set; } + public required string FirstName { get; set; } + public required string LastName { get; set; } + public string? Email { get; set; } + } +} \ No newline at end of file diff --git a/API/Program.cs b/API/Program.cs new file mode 100644 index 0000000..65d2156 --- /dev/null +++ b/API/Program.cs @@ -0,0 +1,31 @@ +using API.Data; +using Microsoft.EntityFrameworkCore; + +var builder = WebApplication.CreateBuilder(args); + +// 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(); +builder.Services.AddDbContext(options => { + options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")); +}); + +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/API/Properties/launchSettings.json b/API/Properties/launchSettings.json new file mode 100644 index 0000000..77b21af --- /dev/null +++ b/API/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:42014", + "sslPort": 44378 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5074", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7250;http://localhost:5074", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/API/WeatherForecast.cs b/API/WeatherForecast.cs new file mode 100644 index 0000000..26424a0 --- /dev/null +++ b/API/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace API; + +public class WeatherForecast +{ + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +} diff --git a/API/appsettings.Development.json b/API/appsettings.Development.json new file mode 100644 index 0000000..bd853a4 --- /dev/null +++ b/API/appsettings.Development.json @@ -0,0 +1,11 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ConnectionStrings": { + "DefaultConnection": "Data source=test.db" + } +} diff --git a/API/appsettings.json b/API/appsettings.json new file mode 100644 index 0000000..4d56694 --- /dev/null +++ b/API/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/API/test.db b/API/test.db new file mode 100644 index 0000000..1fd9104 Binary files /dev/null and b/API/test.db differ diff --git a/TestSolution.sln b/TestSolution.sln new file mode 100644 index 0000000..62893c9 --- /dev/null +++ b/TestSolution.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{D35237DE-A277-4C26-AA84-DC9301922E23}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D35237DE-A277-4C26-AA84-DC9301922E23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D35237DE-A277-4C26-AA84-DC9301922E23}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D35237DE-A277-4C26-AA84-DC9301922E23}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D35237DE-A277-4C26-AA84-DC9301922E23}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal