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

Rey de la Torre #266

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ad815f3
project setup with a simple first request test
reydelatorre Jan 13, 2025
58ea660
second test: second request for same client id should be blocked with…
reydelatorre Jan 13, 2025
ef22121
third test: second request but from different client
reydelatorre Jan 13, 2025
2213899
clarify language
reydelatorre Jan 13, 2025
5066e0e
3rd request within the same window, from the same client who already …
reydelatorre Jan 13, 2025
15ee05a
tests for the InMemoryUsageRepository to ensure default usage for new…
reydelatorre Jan 13, 2025
f70ebad
cleanup: client token var
reydelatorre Jan 13, 2025
a657ee2
account for two requests by same client within time window
reydelatorre Jan 13, 2025
e822d6e
language
reydelatorre Jan 13, 2025
2cfa0eb
new cooldown rule strategies w/ corresponding tests
reydelatorre Jan 13, 2025
4de21ac
composite rate limiting strategy pattern
reydelatorre Jan 14, 2025
5a84aee
sample core webapi service to demonstrate rate limiter class lib
reydelatorre Jan 14, 2025
001b4ca
utilized attribute for sample webapi project to demonstrate rate limi…
reydelatorre Jan 14, 2025
8acf124
region-based rules
reydelatorre Jan 14, 2025
23f6c38
region based tests
reydelatorre Jan 14, 2025
4447233
composite attribute type
reydelatorre Jan 14, 2025
392f3ae
Update InMemoryUsageRepository.cs
reydelatorre Jan 14, 2025
64e872b
global rate limit
reydelatorre Jan 14, 2025
6435fd5
update readme
reydelatorre Jan 14, 2025
33a2094
Merge pull request #1 from reydelatorre/crexi-interview
reydelatorre Jan 14, 2025
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
129 changes: 129 additions & 0 deletions CrexiService/Controllers/ListingsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using CrexiService.Attributes;
using CrexiService.Models;
using Microsoft.AspNetCore.Mvc;
using RateLimiter.Attributes;

namespace CrexiService.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ListingsController : ControllerBase
{
[HttpGet("listings")]
[RateLimit(1, 5)]
public IEnumerable<CommercialListing> GetListings()
{
return new List<CommercialListing>()
{
new CommercialListing
{
ListingId = 101,
Title = "Downtown Retail Space",
Price = 2500000,
City = "Los Angeles",
State = "CA",
BrokerName = "Alice Realty"
},
new CommercialListing
{
ListingId = 102,
Title = "Midtown Office Suite",
Price = 1500000,
City = "New York",
State = "NY",
BrokerName = "Spongebob & Associates"
}
};
}

[HttpGet("regional-listings")]
[RegionRateLimit(usLimit: 5, usWindowSeconds: 10, euCooldownSeconds: 10)]
public IEnumerable<CommercialListing> GetRegionalListings()
{
return new List<CommercialListing>()
{
new CommercialListing
{
ListingId = 201,
Title = "Pasadena Commercial Space",
Price = 2300000,
City = "Pasadena",
State = "CA",
BrokerName = "Bingo Realty"
},
new CommercialListing
{
ListingId = 202,
Title = "Bronx Office Suite",
Price = 1500000,
City = "New York",
State = "NY",
BrokerName = "Fred Realty Corp"
},
new CommercialListing
{
ListingId = 203,
Title = "Cloud Space",
Price = 5500000,
City = "New York",
State = "NY",
BrokerName = "Fred Realty Corp"
}
};
}

[HttpGet("composite-listings")]
[CompositeRateLimit]
public IEnumerable<CommercialListing> GetCompositeListings()
{
return new List<CommercialListing>
{
new CommercialListing
{
ListingId = 101,
Title = "Office Retail",
Price = 2500000,
City = "Los Angeles",
State = "CA",
BrokerName = "Alice Realty"
},
new CommercialListing
{
ListingId = 102,
Title = "Concrete Office Suite",
Price = 1500000,
City = "Miami",
State = "FL",
BrokerName = "Magic Realty"
}
};
}

[HttpGet("global-listings")]
[GlobalRateLimit(1, 5)]
public IEnumerable<CommercialListing> GetGlobalListings()
{
return new List<CommercialListing>
{
new CommercialListing
{
ListingId = 101,
Title = "Global Offices",
Price = 12000000,
City = "Los Angeles",
State = "CA",
BrokerName = "Alice Realty"
},
new CommercialListing
{
ListingId = 102,
Title = "Enterprise Realty Suite",
Price = 51500000,
City = "Chicago",
State = "IL",
BrokerName = "Magic Realty"
}
};
}
}
}
17 changes: 17 additions & 0 deletions CrexiService/CrexiService.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RateLimiter\RateLimiter.csproj" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions CrexiService/CrexiService.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>http</ActiveDebugProfile>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions CrexiService/CrexiService.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@CrexiService_HostAddress = http://localhost:5232

GET {{CrexiService_HostAddress}}/weatherforecast/
Accept: application/json

###
12 changes: 12 additions & 0 deletions CrexiService/Models/CommercialListing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace CrexiService.Models
{
public class CommercialListing
{
public int ListingId { get; set; }
public required string Title { get; set; }
public int Price { get; set; }
public required string City { get; set; }
public required string State { get; set; }
public string? BrokerName { get; set; }
}
}
25 changes: 25 additions & 0 deletions CrexiService/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

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.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
41 changes: 41 additions & 0 deletions CrexiService/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8320",
"sslPort": 44332
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5232",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7031;http://localhost:5232",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
13 changes: 13 additions & 0 deletions CrexiService/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace CrexiService
{
public class WeatherForecast
{
public DateOnly Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string? Summary { get; set; }
}
}
8 changes: 8 additions & 0 deletions CrexiService/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions CrexiService/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Loading
Loading