13 changed files with 224 additions and 12 deletions
@ -0,0 +1,13 @@ |
|||||
|
namespace w230415_classes.Intf |
||||
|
{ |
||||
|
public interface IHall |
||||
|
{ |
||||
|
string Name { get; set; } |
||||
|
|
||||
|
bool AddPlace(int iRow, int iPosition); |
||||
|
bool BookPlace(int iRow, int iPosition); |
||||
|
bool DeletePlace(int iRow, int iPosition); |
||||
|
IEnumerable<IHallPlace> GetNotBookedPlaceList(); |
||||
|
IHallPlace? ReadPlace(int iRow, int iPosition); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
namespace w230415_classes.Intf |
||||
|
{ |
||||
|
public interface IHallPlace |
||||
|
{ |
||||
|
bool FlagBooked { get; set; } |
||||
|
int SeatPosition { get; set; } |
||||
|
int SeatRow { get; set; } |
||||
|
string Uid { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,78 @@ |
|||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using w230415_classes.Intf; |
||||
|
|
||||
|
namespace w230415_webapi.Controllers |
||||
|
{ |
||||
|
[ApiController] |
||||
|
[Route("v1/hall")] |
||||
|
public class HallController : ControllerBase |
||||
|
{ |
||||
|
private readonly IHall _hall; |
||||
|
|
||||
|
public HallController(IHall hall) |
||||
|
{ |
||||
|
_hall = hall; |
||||
|
} |
||||
|
|
||||
|
[HttpGet(Name = "GetNotBookedPlaces")] |
||||
|
public IEnumerable<IHallPlace> GetNotBooked() |
||||
|
{ |
||||
|
return _hall.GetNotBookedPlaceList(); |
||||
|
} |
||||
|
|
||||
|
[HttpGet("seat/{iRow}/{iPosition}", Name = "GetPlace")] |
||||
|
public IHallPlace GetHallPlace( |
||||
|
int iRow, |
||||
|
int iPosition) |
||||
|
{ |
||||
|
var place = _hall.ReadPlace(iRow, iPosition); |
||||
|
Response.StatusCode = place != null ? 200 : 404; |
||||
|
return place; |
||||
|
} |
||||
|
|
||||
|
[HttpGet("seat", Name = "GetPlace by query params")] |
||||
|
public IHallPlace GetHallPlace2( |
||||
|
int iRow, |
||||
|
int iPosition) |
||||
|
{ |
||||
|
var place = _hall.ReadPlace(iRow, iPosition); |
||||
|
Response.StatusCode = place != null ? 200 : 404; |
||||
|
return place; |
||||
|
} |
||||
|
|
||||
|
[HttpPost("seat", Name = "Add place by form params")] |
||||
|
public void AddHallPlace( |
||||
|
[FromForm] |
||||
|
int iRow, |
||||
|
[FromForm] |
||||
|
int iPosition) |
||||
|
{ |
||||
|
bool result = _hall.AddPlace(iRow, iPosition); |
||||
|
Response.StatusCode = result ? 200 : 500; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
[HttpDelete("seat", Name = "Remove place by form params")] |
||||
|
public void RemoveHallPlace( |
||||
|
[FromHeader] |
||||
|
int iRow, |
||||
|
[FromHeader] |
||||
|
int iPosition) |
||||
|
{ |
||||
|
bool result = _hall.DeletePlace(iRow, iPosition); |
||||
|
Response.StatusCode = result ? 200 : 500; |
||||
|
} |
||||
|
|
||||
|
[HttpPatch("seat/booking/{iRow}/{iPosition}", Name = "Set booking status by params")] |
||||
|
public void SetBooking( |
||||
|
int iRow, |
||||
|
int iPosition) |
||||
|
{ |
||||
|
bool result = _hall.BookPlace(iRow, iPosition); |
||||
|
Response.StatusCode = result ? 200 : 500; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
using w230415_classes; |
||||
|
using w230415_classes.Intf; |
||||
|
|
||||
|
namespace w230415_webapi |
||||
|
{ |
||||
|
public class Program |
||||
|
{ |
||||
|
public static void Main(string[] args) |
||||
|
{ |
||||
|
var builder = WebApplication.CreateBuilder(args); |
||||
|
|
||||
|
// Add services to the container.
|
||||
|
var pHall = new CinemaHall(); |
||||
|
builder.Services.AddSingleton<IHall>(pHall); |
||||
|
builder.Services.AddControllers(); |
||||
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
|
builder.Services.AddEndpointsApiExplorer(); |
||||
|
builder.Services.AddSwaggerGen(); |
||||
|
|
||||
|
var app = builder.Build(); |
||||
|
|
||||
|
// Configure the HTTP request pipeline.
|
||||
|
if (app.Environment.IsDevelopment()) |
||||
|
{ |
||||
|
app.UseSwagger(); |
||||
|
app.UseSwaggerUI(); |
||||
|
} |
||||
|
|
||||
|
app.MapControllers(); |
||||
|
|
||||
|
app.Run(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
{ |
||||
|
"$schema": "https://json.schemastore.org/launchsettings.json", |
||||
|
"iisSettings": { |
||||
|
"windowsAuthentication": false, |
||||
|
"anonymousAuthentication": true, |
||||
|
"iisExpress": { |
||||
|
"applicationUrl": "http://localhost:21569", |
||||
|
"sslPort": 0 |
||||
|
} |
||||
|
}, |
||||
|
"profiles": { |
||||
|
"w230415_webapi": { |
||||
|
"commandName": "Project", |
||||
|
"dotnetRunMessages": true, |
||||
|
"launchBrowser": true, |
||||
|
"launchUrl": "swagger", |
||||
|
"applicationUrl": "http://localhost:5095", |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
}, |
||||
|
"IIS Express": { |
||||
|
"commandName": "IISExpress", |
||||
|
"launchBrowser": true, |
||||
|
"launchUrl": "swagger", |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
{ |
||||
|
"Logging": { |
||||
|
"LogLevel": { |
||||
|
"Default": "Information", |
||||
|
"Microsoft.AspNetCore": "Warning" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
{ |
||||
|
"Logging": { |
||||
|
"LogLevel": { |
||||
|
"Default": "Information", |
||||
|
"Microsoft.AspNetCore": "Warning" |
||||
|
} |
||||
|
}, |
||||
|
"AllowedHosts": "*" |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>net6.0</TargetFramework> |
||||
|
<Nullable>enable</Nullable> |
||||
|
<ImplicitUsings>enable</ImplicitUsings> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\w230415\w230415_classes.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
Loading…
Reference in new issue