IntershipController changes
This commit is contained in:
parent
fd5d6b0f48
commit
66870cf7cd
@ -3,7 +3,9 @@ services:
|
||||
|
||||
internship.api:
|
||||
image: internship.api:latest
|
||||
build: ../src/Internship.Api
|
||||
build:
|
||||
context: ../src
|
||||
dockerfile: InternshipSystem.Api/Dockerfile
|
||||
ports:
|
||||
- 8080:80
|
||||
|
||||
|
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@ -9,9 +9,9 @@
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/src/Internship.Api/bin/Debug/netcoreapp3.1/Internship.Api.dll",
|
||||
"program": "${workspaceFolder}/src/InternshipSystem.Api/bin/Debug/netcoreapp3.1/InternshipSystem.Api.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/src/Internship.Api",
|
||||
"cwd": "${workspaceFolder}/src/InternshipSystem.Api",
|
||||
"stopAtEntry": false,
|
||||
"serverReadyAction": {
|
||||
"action": "openExternally",
|
||||
|
6
.vscode/tasks.json
vendored
6
.vscode/tasks.json
vendored
@ -7,7 +7,7 @@
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/src/Internship.Api/Internship.Api.csproj",
|
||||
"${workspaceFolder}/src/InternshipSystem.Api/InternshipSystem.Api.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
@ -19,7 +19,7 @@
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/src/Internship.Api/Internship.Api.csproj",
|
||||
"${workspaceFolder}/src/InternshipSystem.Api/InternshipSystem.Api.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
@ -32,7 +32,7 @@
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"${workspaceFolder}/src/Internship.Api/Internship.Api.csproj",
|
||||
"${workspaceFolder}/src/InternshipSystem.Api/InternshipSystem.Api.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
|
@ -1,26 +1,91 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using InternshipSystem.Core;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using InternshipSystem.Repository;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace InternshipSystem.Api.Controllers {
|
||||
namespace InternshipSystem.Api.Controllers
|
||||
{
|
||||
|
||||
[ApiController]
|
||||
//[Route("[internship]")]
|
||||
[Route("Internship")]
|
||||
public class InternshipController : ControllerBase {
|
||||
private readonly InternshipDbContext _context;
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetInternships() {
|
||||
//TODO: parse params
|
||||
//return JsonResult("");
|
||||
return Ok();
|
||||
public InternshipController(InternshipDbContext context)
|
||||
{
|
||||
this._context = context;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult CreateInternship(Internship internship) {
|
||||
//TODO: add internship
|
||||
return Ok();
|
||||
public async Task<ActionResult<Internship>> CreateInternship(Internship internship)
|
||||
{
|
||||
this._context.Internships.Add(internship);
|
||||
await this._context.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction(nameof(GetInternship), new { id = internship.Id }, internship);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<Internship>>> GetAllInternships() =>
|
||||
await this._context.Internships.ToListAsync();
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<Internship>> GetInternship(int id)
|
||||
{
|
||||
var internship = await this._context.Internships.FindAsync(id);
|
||||
|
||||
if(internship == null) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return internship;
|
||||
}
|
||||
|
||||
//TODO: Refactor
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdateInternship(int id, Internship internship)
|
||||
{
|
||||
if (id != internship.Id)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
var internshipItem = await this._context.Internships.FindAsync(id);
|
||||
if (internshipItem == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await this._context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException) when (!InternshipsExists(id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
private bool InternshipsExists(int id) =>
|
||||
this._context.Internships.Find(id) != null;
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteInternship(int id) {
|
||||
var internshipItem = await this._context.Internships.FindAsync(id);
|
||||
|
||||
if (internshipItem == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
this._context.Internships.Remove(internshipItem);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
@ -2,15 +2,18 @@ FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build-env
|
||||
WORKDIR /app
|
||||
|
||||
# Copy csproj and restore as distinct layers
|
||||
COPY *.csproj ./
|
||||
RUN dotnet restore
|
||||
# TODO: TODO
|
||||
# COPY */*.csproj ./
|
||||
# RUN ls
|
||||
# RUN dotnet restore InternshipSystem.Api.csproj
|
||||
|
||||
# Copy everything else and build
|
||||
COPY . ./
|
||||
WORKDIR /app/InternshipSystem.Api
|
||||
RUN dotnet publish -c Release -o out
|
||||
|
||||
# Build runtime image
|
||||
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine
|
||||
WORKDIR /app
|
||||
COPY --from=build-env /app/out .
|
||||
ENTRYPOINT ["dotnet", "./Internship.Api.dll"]
|
||||
ENTRYPOINT ["dotnet", "./InternshipSystem.Api.dll"]
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\InternshipSystem.Core\InternshipSystem.Core.csproj" />
|
||||
<ProjectReference Include="..\InternshipSystem.Repository\InternshipSystem.Repository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,5 +1,7 @@
|
||||
using InternshipSystem.Repository;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@ -18,6 +20,8 @@ namespace InternshipSystem.Api
|
||||
services
|
||||
.AddSwaggerGen(options =>
|
||||
options.SwaggerDoc("v1", new OpenApiInfo {Title = "InternshipSystem Api - TEST", Version = "v1"}))
|
||||
.AddDbContext<InternshipDbContext>(options =>
|
||||
options.UseNpgsql(Configuration.GetConnectionString("InternshipDbContext")))
|
||||
.AddControllers()
|
||||
;
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EFCore.NamingConventions" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.4">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
Loading…
Reference in New Issue
Block a user