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

cleaning unneeded things #2

Open
wants to merge 2 commits into
base: master
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
16 changes: 7 additions & 9 deletions Shared.Models/Ticket.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Shared.Models
{
public class Ticket
{
public string UserName { get; set; }
public DateTime BookedOn { get; set; }
public string Boarding { get; set; }
public string Destination { get; set; }
}
public class Ticket
{
public string UserName { get; set; }
public DateTime BookedOn { get; set; }
public string Boarding { get; set; }
public string Destination { get; set; }
}
}
32 changes: 13 additions & 19 deletions TicketProcessor.Microservice/Program.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace TicketProcessor.Microservice
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
2 changes: 0 additions & 2 deletions TicketProcessor.Microservice/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public Startup(IConfiguration 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.AddMassTransit(x =>
Expand All @@ -45,7 +44,6 @@ public void ConfigureServices(IServiceCollection services)
services.AddControllers();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
Expand Down
11 changes: 7 additions & 4 deletions TicketProcessor.Microservice/TicketProcessor.Microservice.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Controllers\**" />
<Content Remove="Controllers\**" />
<EmbeddedResource Remove="Controllers\**" />
<None Remove="Controllers\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="MassTransit" Version="7.0.3" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.0.3" />
<PackageReference Include="MassTransit.RabbitMQ" Version="7.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
</ItemGroup>

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

<ItemGroup>
<ProjectReference Include="..\Shared.Models\Shared.Models.csproj" />
</ItemGroup>
Expand Down
46 changes: 23 additions & 23 deletions Ticketing.Microservice/Controllers/TicketController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@

namespace Ticketing.Microservice.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TicketController : ControllerBase
{
private readonly IBus _bus;
[Route("api/[controller]")]
[ApiController]
public class TicketController : ControllerBase
{
private readonly IBus _bus;

public TicketController(IBus bus)
{
_bus = bus;
}
[HttpPost]
public async Task<IActionResult> CreateTicket(Ticket ticket)
{
if (ticket != null)
{
ticket.BookedOn = DateTime.Now;
Uri uri = new Uri("rabbitmq://localhost/ticketQueue");
var endPoint = await _bus.GetSendEndpoint(uri);
await endPoint.Send(ticket);
return Ok();
}
return BadRequest();
}
}
public TicketController(IBus bus)
{
_bus = bus;
}
[HttpPost]
public async Task<IActionResult> CreateTicket(Ticket ticket)
{
if (ticket != null)
{
ticket.BookedOn = DateTime.Now;
Uri uri = new Uri("rabbitmq://localhost/ticketQueue");
var endPoint = await _bus.GetSendEndpoint(uri);
await endPoint.Send(ticket);
return Ok();
}
return BadRequest();
}
}
}
6 changes: 0 additions & 6 deletions Ticketing.Microservice/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Ticketing.Microservice
{
Expand Down
94 changes: 46 additions & 48 deletions Ticketing.Microservice/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,50 @@

namespace Ticketing.Microservice
{
public class Startup
{
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.AddMassTransit(x =>
{
x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(config =>
{
config.UseHealthCheck(provider);
config.Host(new Uri("rabbitmq://localhost"), h =>
{
h.Username("guest");
h.Password("guest");
});
}));
});
services.AddMassTransitHostedService();
services.AddControllers();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
services.AddMassTransit(x =>
{
x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(config =>
{
config.UseHealthCheck(provider);
config.Host(new Uri("rabbitmq://localhost"), h =>
{
h.Username("guest");
h.Password("guest");
});
}));
});
services.AddMassTransitHostedService();
services.AddControllers();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}