Skip to content

Commit

Permalink
FE components
Browse files Browse the repository at this point in the history
  • Loading branch information
Radoslav Radev committed Mar 17, 2024
1 parent 462dcc4 commit 284c60e
Show file tree
Hide file tree
Showing 52 changed files with 12,384 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# Mono auto generated files
mono_crash.*

DEVstorageBucket/
# Build results
[Dd]ebug/
[Dd]ebugPublic/
Expand Down
1 change: 1 addition & 0 deletions Backend/.idea/.idea.OpenVidStreamer/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Backend/APIGateway/APIGateway.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\OcelotSwagger\MMLib.SwaggerForOcelot\src\MMLib.SwaggerForOcelot\MMLib.SwaggerForOcelot.csproj" />
</ItemGroup>

</Project>
18 changes: 10 additions & 8 deletions Backend/APIGateway/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

//builder.Services.AddControllers();

builder.Configuration.AddJsonFile($"ocelot.{builder.Environment.EnvironmentName}.json", optional: false, reloadOnChange: true);
builder.Configuration.AddJsonFile($"ocelot.{builder.Environment.EnvironmentName}.json", optional: false,
reloadOnChange: true);

builder.Services.AddAuthentication(options =>
{
Expand All @@ -21,20 +22,17 @@
// swagger
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();


builder.Services.AddCors();

builder.Services.AddOcelot().AddConsul();
builder.Services.AddSwaggerForOcelot(builder.Configuration);

var app = builder.Build();



app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();
Expand All @@ -43,6 +41,10 @@
app.UseAuthorization();


app.UseSwaggerForOcelotUI(opt => { opt.PathToSwaggerGenerator = "/swagger/docs"; });


app.UseOcelot();

app.Run();

app.Run();
109 changes: 106 additions & 3 deletions Backend/APIGateway/ocelot.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,44 @@
"UpstreamPathTemplate": "/videolib/{everything}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ],
"ServiceName": "OpenVisStreamer.VideoLibrary",


"AuthenticationOptions": {
"AuthenticationProviderKey": "Bearer",
"AllowedScopes": []
},
"UseServiceDiscovery": true,
"LoadBalancerOptions": {
"Type": "LeastConnection"
},
"ServiceDiscoveryProvider": {
"Host": "localhost",
"Port": 8500,
"Type": "Consul"
}
},
{
"Priority": 1,
"DownstreamPathTemplate": "/login",
"DownstreamScheme": "https",
"UpstreamPathTemplate": "/account/login",
"UpstreamHttpMethod": ["Get", "Post"],
"ServiceName": "OpenVisStreamer.Account",
"UseServiceDiscovery": true,
"LoadBalancerOptions": {
"Type": "LeastConnection"
},
"ServiceDiscoveryProvider": {
"Host": "localhost",
"Port": 8500,
"Type": "Consul"
}
},
{
"Priority": 1,
"DownstreamPathTemplate": "/register",
"DownstreamScheme": "https",
"UpstreamPathTemplate": "/account/register",
"UpstreamHttpMethod": ["Get", "Post"],
"ServiceName": "OpenVisStreamer.Account",
"UseServiceDiscovery": true,
"LoadBalancerOptions": {
"Type": "LeastConnection"
Expand All @@ -19,13 +55,15 @@
}
},
{
"Priority": 0,
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "https",
"UpstreamPathTemplate": "/account/{everything}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ],
"ServiceName": "OpenVisStreamer.Account",
"AuthenticationOptions": {
"AuthenticationProviderKey": "Bearer",

"AllowedScopes": []
},
"UseServiceDiscovery": true,
Expand Down Expand Up @@ -125,5 +163,70 @@
"Port": 8500,
"Type": "Consul"
}
}
},
"SwaggerEndPoints": [
{
"Key": "videolib",
"Config": [
{
"Name": "Video Library",
"Version": "v1",
"Service": {
"Name": "OpenVisStreamer.VideoLibrary",
"Path": "/swagger/v1/swagger.json"
}
}
]
},
{
"Key": "account",
"Config": [
{
"Name": "Account Service",
"Version": "v1",
"Url": "https://localhost:7176/account/swagger/v1/swagger.json"
}
]
},
{
"Key": "recommendationAlgo",
"Config": [
{
"Name": "Recommendation Algorithm",
"Version": "v1",
"Url": "https://localhost:7176/recommendationAlgo/swagger/v1/swagger.json"
}
]
},
{
"Key": "render",
"Config": [
{
"Name": "Render Service",
"Version": "v1",
"Url": "https://localhost:7176/render/swagger/v1/swagger.json"
}
]
},
{
"Key": "upload",
"Config": [
{
"Name": "Upload Service",
"Version": "v1",
"Url": "https://localhost:7176/upload/swagger/v1/swagger.json"
}
]
},
{
"Key": "streamer",
"Config": [
{
"Name": "Streamer Service",
"Version": "v1",
"Url": "https://localhost:7176/streamer/swagger/v1/swagger.json"
}
]
}
]
}
2 changes: 1 addition & 1 deletion Backend/Account/Account.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="Riok.Mapperly" Version="3.4.0" />
<PackageReference Include="Stripe.net" Version="43.17.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.1.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 16 additions & 4 deletions Backend/Account/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Account.Model.DTO;
using Account.Services;
using Microsoft.AspNetCore.Mvc;
using OpenVisStreamer.VideoLibrary.Exceptions;

namespace Account.Controllers;

Expand All @@ -12,9 +13,18 @@ public class AccountController(AccountService _accountService):ControllerBase


[HttpPost("register")]
public async Task<OkObjectResult> Register([FromBody] RegisterRequestDTO request)
public async Task<IActionResult> Register([FromBody] RegisterRequestDTO request)
{
var accountNtoken = await _accountService.Register(request);
Tuple<AccountDTO, string> accountNtoken;
try
{
accountNtoken = await _accountService.Register(request);

}
catch (EmailAlreadyInUseException e)
{
return StatusCode(442);
}

return Ok(accountNtoken);
}
Expand All @@ -29,7 +39,8 @@ public async Task<OkObjectResult> Login([FromBody] LoginRequestDTO request)
[HttpGet("balance")]
public async Task<ActionResult<decimal>> GetBalance()
{
var accId= Common.AccIdExtractorFromHttpContext.GetAccId(HttpContext);
HttpContext.Request.Headers.TryGetValue("Authorization", out var token);
var accId = Common.AccIdExtractorFromHttpContext.ExtractAccIdUpnFromJwtToken(token);
var balance = await _accountService.GetBalance(new Guid(accId));
return Ok(balance);
}
Expand All @@ -38,7 +49,8 @@ public async Task<ActionResult<decimal>> GetBalance()
[HttpPost("activateSubscription")]
public async Task<ActionResult<AccountDTO>> ActivateSubscription()
{
var accId= Common.AccIdExtractorFromHttpContext.GetAccId(HttpContext);
HttpContext.Request.Headers.TryGetValue("Authorization", out var token);
var accId = Common.AccIdExtractorFromHttpContext.ExtractAccIdUpnFromJwtToken(token);
var account = await _accountService.ActivateSubscription(new Guid(accId));
return Ok(account);
}
Expand Down
3 changes: 2 additions & 1 deletion Backend/Account/Controllers/PaymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public PaymentController(StripePaymentService paymentService)
[HttpPost("processPayment")]
public async Task<IActionResult> ProcessPayment([FromBody] IncomingPaymentDTO incomingPayment)
{
var accId = Common.AccIdExtractorFromHttpContext.GetAccId(HttpContext);
HttpContext.Request.Headers.TryGetValue("Authorization", out var token);
var accId = Common.AccIdExtractorFromHttpContext.ExtractAccIdUpnFromJwtToken(token);
var charge = await _paymentService.ProcessPaymentAsync(incomingPayment, accId);
if (charge.Status == "succeeded")
{
Expand Down
6 changes: 6 additions & 0 deletions Backend/Account/Exceptions/EmailAlreadyInUseException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace OpenVisStreamer.VideoLibrary.Exceptions;

public class EmailAlreadyInUseException(string message) :Exception(message)
{

}
3 changes: 3 additions & 0 deletions Backend/Account/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
builder.Services.AddHealthChecks();

var app = builder.Build();

app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());

if (app.Environment.IsDevelopment())
{
app.UseSwagger();
Expand Down
10 changes: 9 additions & 1 deletion Backend/Account/Services/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Account.Model.Mappers;
using Account.Repository.EFC;
using Microsoft.EntityFrameworkCore;
using OpenVisStreamer.VideoLibrary.Exceptions;
using Polly;
using Polly.Retry;

Expand All @@ -15,12 +16,18 @@ public class AccountService(DatabaseContext _accountDbContext, IConfiguration co
{
var account = await _accountDbContext.Accounts.FirstOrDefaultAsync(x => x.Email == request.email);
if (account is null) return null;
if (!BCrypt.Net.BCrypt.Verify(request.passwordUnhashed, account.PasswordHashed)) return null;
var authToken = AuthTokenGenerator.GenerateOwnAuthToken(account.AccId.ToString(),configuration);
return new Tuple<AccountDTO, string>(AccountMapper.AccountToAccountDto(account), authToken);
}

public async Task<Tuple<AccountDTO,string>> Register(RegisterRequestDTO request)
{

//check if email is already in use
var accountWithEmail = await _accountDbContext.Accounts.FirstOrDefaultAsync(x => x.Email == request.email);
if (accountWithEmail != null) throw new EmailAlreadyInUseException("Email already in use");

var account = new Repository.Entities.Account()
{
Email = request.email,
Expand All @@ -31,7 +38,8 @@ public async Task<Tuple<AccountDTO,string>> Register(RegisterRequestDTO request)
var authToken = AuthTokenGenerator.GenerateOwnAuthToken(account.AccId.ToString(),configuration);
var accountDto = AccountMapper.AccountToAccountDto(account);

Task.Run(() => _dbRetryPolicy.ExecuteAsync(async () => await _accountDbContext.SaveChangesAsync()));
await _accountDbContext.SaveChangesAsync();
// Task.Run(() => _dbRetryPolicy.ExecuteAsync(async () => await _accountDbContext.SaveChangesAsync()));

return new Tuple<AccountDTO, string>(accountDto, authToken);
}
Expand Down
Loading

0 comments on commit 284c60e

Please sign in to comment.