Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gallery frontend v2 #72

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions Src/Clients/PaintedProsthetics.Web.Api/Controllers/ImagesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PaintedProsthetics.Gallery.Models;
using PaintedProsthetics.Web.Api.Helpers;

namespace PaintedProsthetics.Web.Api.Controllers
{
[Route("api/Images")]
[ApiController]
public class ImagesController : ControllerBase
{
private readonly ImagesContext _context;

public ImagesController(ImagesContext context)
{
_context = context;
}

// GET: api/Images
[HttpGet]
public async Task<ActionResult<IEnumerable<Image>>> GetImages()
{
return await _context.Images.ToListAsync();
}

// GET: api/Images/5
[HttpGet("{id}")]
public async Task<ActionResult<Image>> GetImage(long id)
{
var image = await _context.Images.FindAsync(id);

if (image == null)
{
return NotFound();
}

return image;
}

// PUT: api/Images/5
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")]
public async Task<IActionResult> PutImage(long id, Image image)
{
if (id != image.Id)
{
return BadRequest();
}

_context.Entry(image).State = EntityState.Modified;

try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ImageExists(id))
{
return NotFound();
}
else
{
throw;
}
}

return NoContent();
}

// POST: api/Images
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPost]
public async Task<ActionResult<Image>> PostImage(Image image)
{
_context.Images.Add(image);
await _context.SaveChangesAsync();

//return CreatedAtAction("GetImage", new { id = image.Id }, image);
return CreatedAtAction(nameof(GetImage), new { id = image.Id }, image);
}

// DELETE: api/Images/5
[HttpDelete("{id}")]
public async Task<ActionResult<Image>> DeleteImage(long id)
{
var image = await _context.Images.FindAsync(id);
if (image == null)
{
return NotFound();
}

_context.Images.Remove(image);
await _context.SaveChangesAsync();

return image;
}

private bool ImageExists(long id)
{
return _context.Images.Any(e => e.Id == id);
}
}
}
15 changes: 15 additions & 0 deletions Src/Clients/PaintedProsthetics.Web.Api/Helpers/ImagesContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using PaintedProsthetics.Gallery.Models;

namespace PaintedProsthetics.Web.Api.Helpers
{
public class ImagesContext : DbContext
{
public ImagesContext(DbContextOptions<ImagesContext> options) : base(options)
{

}

public DbSet<Image> Images { 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,32 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace PaintedProsthetics.Web.Api.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Images",
columns: table => new
{
Id = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Title = table.Column<string>(nullable: true),
AltText = table.Column<string>(nullable: true),
ImageUrl = table.Column<string>(nullable: true),
Artist = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Images", x => x.Id);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Images");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using PaintedProsthetics.Web.Api.Helpers;

namespace PaintedProsthetics.Web.Api.Migrations
{
[DbContext(typeof(ImagesContext))]
partial class ImagesContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.8");

modelBuilder.Entity("PaintedProsthetics.Gallery.Models.Image", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");

b.Property<string>("AltText")
.HasColumnType("TEXT");

b.Property<string>("Artist")
.HasColumnType("TEXT");

b.Property<string>("ImageUrl")
.HasColumnType("TEXT");

b.Property<string>("Title")
.HasColumnType("TEXT");

b.HasKey("Id");

b.ToTable("Images");
});
#pragma warning restore 612, 618
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Domain\PaintedProsthetics.Amputee\PaintedProsthetics.Amputee.csproj" />
<ProjectReference Include="..\..\Domain\PaintedProsthetics.Artists\PaintedProsthetics.Artists.csproj" />
Expand All @@ -18,5 +34,9 @@
<ProjectReference Include="..\PaintedProsthetics.Web.Api.Client\PaintedProsthetics.Web.Api.Client.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Helpers\" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"PaintedProsthetics.Web.Api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"launchUrl": "api/Images",
"applicationUrl": "https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
20 changes: 20 additions & 0 deletions Src/Clients/PaintedProsthetics.Web.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.EntityFrameworkCore;
using PaintedProsthetics.Web.Api.Helpers;
using PaintedProsthetics.Web.Api.Controllers;
using Microsoft.AspNetCore.Cors;
using System.Web.Http;

namespace PaintedProsthetics.Web.Api
{
Expand All @@ -13,11 +18,24 @@ public Startup(IConfiguration configuration)
Configuration = configuration;
}


public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ImagesContext>(opt =>
opt.UseSqlServer(Configuration.GetConnectionString("ImagesContext")));

services.AddCors(options =>
{
options.AddDefaultPolicy(
builder =>
{
builder.WithOrigins("http://localhost:3000").AllowAnyHeader();
});
});

services.AddControllers();
}

Expand All @@ -32,6 +50,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseHttpsRedirection();

app.UseRouting();

app.UseCors();

app.UseAuthorization();

Expand Down
7 changes: 5 additions & 2 deletions Src/Clients/PaintedProsthetics.Web.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
"AllowedHosts": "*",
"ConnectionStrings": {
"ImagesContext": "Server=(localdb)\\mssqllocaldb;Database=ImagesContext-6f3de508-a343-4969-976c-1df4bc0604d5;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const config = {
apiUrl: 'https://localhost:5001'
};
Loading