diff --git a/.docker/docker-compose.yaml b/.docker/docker-compose.yaml index 463fd71..4514f2f 100644 --- a/.docker/docker-compose.yaml +++ b/.docker/docker-compose.yaml @@ -3,6 +3,9 @@ services: internship.api: image: internship.api:latest + environment: + CONNECTIONSTRINGS__INTERNSHIPDATABASE: "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=szwoniu" + ASPNETCORE_ENVIRONMENT: Development ports: - 8080:80 diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 12ed2af..75464ba 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -10,10 +10,6 @@ "context": "src" }, "problemMatcher": [], - "group": { - "kind": "build", - "isDefault": true - } }, { "label": "down: api", @@ -40,6 +36,10 @@ "down: api", "build: api" ], + "group": { + "kind": "build", + "isDefault": true + }, "problemMatcher": [] }, { diff --git a/src/InternshipSystem.Api/Controllers/CompaniesController.cs b/src/InternshipSystem.Api/Controllers/CompaniesController.cs new file mode 100644 index 0000000..b3da8c3 --- /dev/null +++ b/src/InternshipSystem.Api/Controllers/CompaniesController.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using InternshipSystem.Api.Queries; +using InternshipSystem.Core; +using InternshipSystem.Repository; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace InternshipSystem.Api.Controllers +{ + [ApiController] + [Route("companies")] + public class CompaniesController : ControllerBase + { + public CompaniesController(InternshipDbContext context) + { + Context = context; + } + private InternshipDbContext Context { get; } + + /// + /// Get companies matching provided paginated query + /// + /// Paginated query description + /// Part of companies collection + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task> SearchByNameAsync([FromQuery]SearchQuery query, CancellationToken cancellationToken) => + await Context.Companies + .Where(c => c.Name.Contains(query.Query ?? "")) + .OrderBy(o => o.Name) + .Skip(query.Page * query.PerPage) + .Take(query.PerPage) + .ToListAsync(cancellationToken); + } + +} \ No newline at end of file diff --git a/src/InternshipSystem.Api/InternshipSystem.Api.csproj b/src/InternshipSystem.Api/InternshipSystem.Api.csproj index 5ccb212..a5a067d 100644 --- a/src/InternshipSystem.Api/InternshipSystem.Api.csproj +++ b/src/InternshipSystem.Api/InternshipSystem.Api.csproj @@ -2,7 +2,8 @@ netcoreapp3.1 - + true + latest diff --git a/src/InternshipSystem.Api/Queries/SearchQuery.cs b/src/InternshipSystem.Api/Queries/SearchQuery.cs new file mode 100644 index 0000000..58d12df --- /dev/null +++ b/src/InternshipSystem.Api/Queries/SearchQuery.cs @@ -0,0 +1,20 @@ +namespace InternshipSystem.Api.Queries +{ + public class SearchQuery + { + /// + /// Value against which collection will be queried + /// + public string Query { get; set; } + + /// + /// Which part of the collections to retrieve + /// + public int Page { get; set; } + + /// + /// Size of the retrieved part + /// + public int PerPage { get; set; } + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Api/Startup.cs b/src/InternshipSystem.Api/Startup.cs index 5186330..3e2d92f 100644 --- a/src/InternshipSystem.Api/Startup.cs +++ b/src/InternshipSystem.Api/Startup.cs @@ -1,5 +1,10 @@ +using System; +using System.IO; +using System.Reflection; +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; @@ -16,8 +21,14 @@ namespace InternshipSystem.Api public void ConfigureServices(IServiceCollection services) => services + .AddDbContext(o => o.UseNpgsql(Configuration.GetConnectionString("InternshipDatabase"))) .AddSwaggerGen(options => - options.SwaggerDoc("v1", new OpenApiInfo {Title = "InternshipSystem Api - TEST", Version = "v1"})) + { + options.SwaggerDoc("v1", new OpenApiInfo {Title = "InternshipSystem Api - TEST", Version = "v1"}); + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + options.IncludeXmlComments(xmlPath); + }) .AddControllers() ; diff --git a/src/InternshipSystem.Core/InternshipSystem.Core.csproj b/src/InternshipSystem.Core/InternshipSystem.Core.csproj index 8642d92..6de04cb 100644 --- a/src/InternshipSystem.Core/InternshipSystem.Core.csproj +++ b/src/InternshipSystem.Core/InternshipSystem.Core.csproj @@ -2,6 +2,7 @@ netcoreapp3.1 + latest diff --git a/src/InternshipSystem.Core/InternshipType.cs b/src/InternshipSystem.Core/InternshipType.cs index 826e4f8..22eff95 100644 --- a/src/InternshipSystem.Core/InternshipType.cs +++ b/src/InternshipSystem.Core/InternshipType.cs @@ -1,15 +1,9 @@ namespace InternshipSystem.Core { - public enum InternshipType + public class InternshipType { - Other, - FreeInternship, - GraduateInternship, - FreeApprenticeship, - PaidApprenticeship, - EmploymentContract, - MandateContract, - ContractWork, - ForeignInternship + public int Id { get; set; } + public string Type { get; set; } + public string Description { get; set; } } } \ No newline at end of file diff --git a/src/InternshipSystem.Repository/InternshipDbContext.cs b/src/InternshipSystem.Repository/InternshipDbContext.cs index 4ddc481..7391851 100644 --- a/src/InternshipSystem.Repository/InternshipDbContext.cs +++ b/src/InternshipSystem.Repository/InternshipDbContext.cs @@ -10,9 +10,15 @@ namespace InternshipSystem.Repository public DbSet Editions { get; set; } public DbSet Reports { get; set; } public DbSet Interns { get; set; } + public DbSet InternshipTypes { get; set; } + + public InternshipDbContext(DbContextOptions options) + : base(options) + { + } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder - .UseNpgsql("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=szwoniu") .UseSnakeCaseNamingConvention(); protected override void OnModelCreating(ModelBuilder modelBuilder) { diff --git a/src/InternshipSystem.Repository/InternshipSystem.Repository.csproj b/src/InternshipSystem.Repository/InternshipSystem.Repository.csproj index 7be0990..ac1ea48 100644 --- a/src/InternshipSystem.Repository/InternshipSystem.Repository.csproj +++ b/src/InternshipSystem.Repository/InternshipSystem.Repository.csproj @@ -2,6 +2,7 @@ netcoreapp3.1 + latest