diff --git a/Advanced-Topics-in-C-Sharp/Advanced-Topics-in-C-Sharp.csproj b/Advanced-Topics-in-C-Sharp/Advanced-Topics-in-C-Sharp.csproj index cee0337..f54ef2e 100644 --- a/Advanced-Topics-in-C-Sharp/Advanced-Topics-in-C-Sharp.csproj +++ b/Advanced-Topics-in-C-Sharp/Advanced-Topics-in-C-Sharp.csproj @@ -8,6 +8,15 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Advanced-Topics-in-C-Sharp_Lab03/Advanced-Topics-in-C-Sharp_Lab03.csproj b/Advanced-Topics-in-C-Sharp_Lab03/Advanced-Topics-in-C-Sharp_Lab03.csproj index 2db32e2..27ef646 100644 --- a/Advanced-Topics-in-C-Sharp_Lab03/Advanced-Topics-in-C-Sharp_Lab03.csproj +++ b/Advanced-Topics-in-C-Sharp_Lab03/Advanced-Topics-in-C-Sharp_Lab03.csproj @@ -8,6 +8,15 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Advanced-Topics-in-C-Sharp_Lab03/Models/Direction.cs b/Advanced-Topics-in-C-Sharp_Lab03/Models/Direction.cs new file mode 100644 index 0000000..afd4486 --- /dev/null +++ b/Advanced-Topics-in-C-Sharp_Lab03/Models/Direction.cs @@ -0,0 +1,14 @@ +namespace Advanced_Topics_in_C_Sharp_Lab03.Models +{ + public enum Direction + { + North, + South, + East, + West, + Northeast, + Northwest, + Southeast, + Southwest + } +} diff --git a/Advanced-Topics-in-C-Sharp_Lab03/Models/Route.cs b/Advanced-Topics-in-C-Sharp_Lab03/Models/Route.cs new file mode 100644 index 0000000..63d327a --- /dev/null +++ b/Advanced-Topics-in-C-Sharp_Lab03/Models/Route.cs @@ -0,0 +1,20 @@ +namespace Advanced_Topics_in_C_Sharp_Lab03.Models +{ + public class Route + { + public int Number { get; set; } + public string Name { get; set; } + public Direction Direction { get; set; } + public bool RampAccessible { get; set; } + public bool BicycleAccessible { get; set; } + public Route(int number, string name, Direction direction, bool rampAccessible, bool bicycleAccessible) + { + Number = number; + Name = name; + Direction = direction; + RampAccessible = rampAccessible; + BicycleAccessible = bicycleAccessible; + + } + } +} diff --git a/Advanced-Topics-in-C-Sharp_Lab03/Models/ScheduledStop.cs b/Advanced-Topics-in-C-Sharp_Lab03/Models/ScheduledStop.cs new file mode 100644 index 0000000..5833734 --- /dev/null +++ b/Advanced-Topics-in-C-Sharp_Lab03/Models/ScheduledStop.cs @@ -0,0 +1,17 @@ +namespace Advanced_Topics_in_C_Sharp_Lab03.Models +{ + public class ScheduledStop + { + public int Id { get; set; } + public Stop Stop { get; set; } + public Route Route { get; set; } + public DateTime ScheduledArrival { get; set; } + public ScheduledStop(int id, Stop stop, Route route, DateTime scheduledArrival) + { + Id = id; + Stop = stop; + Route = route; + ScheduledArrival = scheduledArrival; + } + } +} diff --git a/Advanced-Topics-in-C-Sharp_Lab03/Models/Stop.cs b/Advanced-Topics-in-C-Sharp_Lab03/Models/Stop.cs new file mode 100644 index 0000000..e0b4465 --- /dev/null +++ b/Advanced-Topics-in-C-Sharp_Lab03/Models/Stop.cs @@ -0,0 +1,18 @@ +namespace Advanced_Topics_in_C_Sharp_Lab03.Models +{ + public class Stop + { + public int Number { get; set; } + public string Street { get; set; } + public string Name { get; set; } + public Direction Direction { get; set; } + public Stop(int number, string street, string name, Direction direction) + { + Number = number; + Street = street; + Name = name; + Direction = direction; + + } + } +} diff --git a/Advanced-Topics-in-C-Sharp_Lab03/Program.cs b/Advanced-Topics-in-C-Sharp_Lab03/Program.cs index 6a7afb4..7972a65 100644 --- a/Advanced-Topics-in-C-Sharp_Lab03/Program.cs +++ b/Advanced-Topics-in-C-Sharp_Lab03/Program.cs @@ -1,41 +1,106 @@ +using Advanced_Topics_in_C_Sharp_Lab03.Models; +using Route = Advanced_Topics_in_C_Sharp_Lab03.Models.Route; + var builder = WebApplication.CreateBuilder(args); -// Add services to the container. -// 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()) +List routes = new List(); + +List stops = new List(); + +List scheduledStops = new List(); + +Route routeOne = new Route(1, "streetOne", Direction.North, true, false); +Route routeTwo = new Route(2, "streetTwo", Direction.East, true, true); +routes.Add(routeOne); +routes.Add(routeTwo); + +Stop stopOne = new Stop(1, "streetOne", "firstStop", Direction.South); +Stop stopTwo = new Stop(2, "streetOne", "secondStop", Direction.West); +Stop stopThree = new Stop(3, "streetOne", "thirdStop", Direction.Southeast); +Stop stopFour = new Stop(4, "streetTwo", "forthStop", Direction.North); +Stop stopFive = new Stop(5, "streetTwo", "fifthStop", Direction.Southwest); + +stops.Add(stopOne); +stops.Add(stopTwo); +stops.Add(stopThree); +stops.Add(stopFour); +stops.Add(stopFive); + +ScheduledStop scheduledStopOne = new ScheduledStop(1, stopOne, routeOne, DateTime.Now); +ScheduledStop scheduledStopTwo = new ScheduledStop(2, stopTwo, routeOne, DateTime.Now.AddMinutes(10)); +ScheduledStop scheduledStopThree = new ScheduledStop(3, stopThree, routeOne, DateTime.Now.AddMinutes(20)); +ScheduledStop scheduledStopFour = new ScheduledStop(4, stopFour, routeOne, DateTime.Now.AddMinutes(30)); +ScheduledStop scheduledStopFive = new ScheduledStop(5, stopFive, routeOne, DateTime.Now.AddMinutes(40)); + +ScheduledStop scheduledStopSix = new ScheduledStop(6, stopFive, routeTwo, DateTime.Now); +ScheduledStop scheduledStopSeven = new ScheduledStop(7, stopFour, routeTwo, DateTime.Now.AddMinutes(10)); +ScheduledStop scheduledStopEight = new ScheduledStop(8, stopThree, routeTwo, DateTime.Now.AddMinutes(20)); +ScheduledStop scheduledStopNine = new ScheduledStop(9, stopTwo, routeTwo, DateTime.Now.AddMinutes(30)); +ScheduledStop scheduledStopTen = new ScheduledStop(10, stopOne, routeTwo, DateTime.Now.AddMinutes(40)); + +scheduledStops.Add(scheduledStopOne); +scheduledStops.Add(scheduledStopTwo); +scheduledStops.Add(scheduledStopThree); +scheduledStops.Add(scheduledStopFour); +scheduledStops.Add(scheduledStopFive); +scheduledStops.Add(scheduledStopSix); +scheduledStops.Add(scheduledStopSeven); +scheduledStops.Add(scheduledStopEight); +scheduledStops.Add(scheduledStopNine); +scheduledStops.Add(scheduledStopTen); + + +app.MapGet("/routes", () => +{ + return routes; +}); + +IEnumerable GetScheduledStopsByRoute(Route route) { - app.UseSwagger(); - app.UseSwaggerUI(); + return scheduledStops.Where(s => s.Route == route).OrderBy(a => a.ScheduledArrival); } -var summaries = new[] +app.MapGet("/routes/{number}", (int number) => { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" -}; + Route route = routes.FirstOrDefault(a => a.Number == number); + + List scheduledStops = GetScheduledStopsByRoute(route).Take(5).ToList(); + + return Results.Ok(new + { + Route = route, + ScheduledStops = scheduledStops + }); + +}); -app.MapGet("/weatherforecast", () => +app.MapGet("/stops/{number}", (int number) => { - var forecast = Enumerable.Range(1, 5).Select(index => - new WeatherForecast - ( - DateTime.Now.AddDays(index), - Random.Shared.Next(-20, 55), - summaries[Random.Shared.Next(summaries.Length)] - )) - .ToArray(); - return forecast; -}) -.WithName("GetWeatherForecast"); - -app.Run(); - -internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary) + Stop stop = stops.FirstOrDefault(s => s.Number == number); + + return Results.Ok(stop); +}); + +app.MapGet("/stop/{number}/schedule", (int number, int top) => { - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); -} \ No newline at end of file + Stop stop = stops.FirstOrDefault(a => a.Number == number); + if (stop == null) + { + return Results.NotFound(); + } + + List scheduleds = scheduledStops.Where(b => b.Stop.Number == number) + .OrderBy(c => c.ScheduledArrival) + .Take(top) + .ToList(); + + return Results.Ok(scheduleds); +}); + +app.Run(); \ No newline at end of file