Skip to content

Commit

Permalink
daily
Browse files Browse the repository at this point in the history
  • Loading branch information
Recep Güneş committed Aug 31, 2023
1 parent 406d97e commit 7459fbb
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 20 deletions.
14 changes: 12 additions & 2 deletions internal-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ services:

apigateway:
image: ${DOCKER_REGISTRY-}apigateway
ports:
- 8083:80
build:
context: .
dockerfile: src/Gateway/Gateway.WebAPI/Dockerfile
Expand All @@ -48,3 +46,15 @@ services:
networks:
- backend
- fronted

webui:
image: ${DOCKER_REGISTRY-}webui
ports:
- 8080:8080
build:
context: .
dockerfile: src/Fronted/webui/Dockerfile
depends_on:
- apigateway
networks:
- fronted
2 changes: 1 addition & 1 deletion src/Fronted/webui/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VUE_APP_TITLE=Url Shortener App
VUE_APP_API_GATEWAY_URL=http://localhost:8083
VUE_APP_API_GATEWAY_URL=http://localhost:5043
2 changes: 2 additions & 0 deletions src/Fronted/webui/.env.Production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VUE_APP_TITLE=Url Shortener App
VUE_APP_API_GATEWAY_URL=http://apigateway:80
12 changes: 12 additions & 0 deletions src/Fronted/webui/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:lts-alpine
WORKDIR /app
# install vite globally
RUN npm install -g @vue/cli
# copy all filtes
COPY . .
# install all deps
RUN yarn install

# vite default port
EXPOSE 8080
CMD ["vue", "serve"]
41 changes: 41 additions & 0 deletions src/Fronted/webui/package-lock.json

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

1 change: 1 addition & 0 deletions src/Fronted/webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"@types/axios": "^0.14.0",
"axios": "^1.5.0",
"bootstrap": "^5.3.1",
"core-js": "^3.8.3",
"querystring-es3": "^0.2.1",
"vue": "^3.2.13",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Ocelot.DependencyInjection;
using Ocelot.Values;

namespace Gateway.Infrastructure.Extensions
{
Expand All @@ -20,7 +19,6 @@ public static IServiceCollection LoadInfrastructreLayer(this IServiceCollection
});
});


var tempConfiguration = new ConfigurationBuilder()
.AddConfiguration(configuration)
.SetBasePath(Directory.GetCurrentDirectory())
Expand Down
21 changes: 17 additions & 4 deletions src/Gateway/Gateway.WebAPI/ocelot.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
"UpstreamHttpMethod": [ "GET" ],
"Key": "GetUrl"
},
{
"DownstreamPathTemplate": "/api/buffer/get_all_urls",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5137
}
],
"UpstreamPathTemplate": "/get_all_urls",
"UpstreamHttpMethod": [ "GET" ],
"Key": "GetAllUrls"
},
{
"DownstreamPathTemplate": "/api/shortener/publish_url",
"DownstreamScheme": "http",
Expand All @@ -27,17 +40,17 @@
"Key": "PublishUrl"
},
{
"DownstreamPathTemplate": "/api/buffer/get_all_urls",
"DownstreamPathTemplate": "/api/shortener/redirect/{shortPath}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5137
"Port": 5202
}
],
"UpstreamPathTemplate": "/get_all_urls",
"UpstreamPathTemplate": "/redirect/{shortPath}",
"UpstreamHttpMethod": [ "GET" ],
"Key": "GetAllUrls"
"Key": "ReachUrl"
}
]
}
25 changes: 18 additions & 7 deletions src/Gateway/Gateway.WebAPI/ocelot.Production.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@
"UpstreamHttpMethod": [ "GET" ],
"Key": "GetUrl"
},

{
"DownstreamPathTemplate": "/api/buffer/get_all_urls",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "buffer_api",
"Port": 80
}
],
"UpstreamPathTemplate": "/get_all_urls",
"UpstreamHttpMethod": [ "GET" ],
"Key": "GetAllUrls"
},
{
"DownstreamPathTemplate": "/api/shortener/publish_url",
"DownstreamScheme": "http",
Expand All @@ -27,19 +39,18 @@
"UpstreamHttpMethod": [ "POST" ],
"Key": "PublishUrl"
},

{
"DownstreamPathTemplate": "/api/buffer/get_all_urls",
"DownstreamPathTemplate": "/api/shortener/redirect/{shortPath}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "buffer_api",
"Host": "shortener_api",
"Port": 80
}
],
"UpstreamPathTemplate": "/get_all_urls",
"UpstreamHttpMethod": [ "GET" ]
"UpstreamPathTemplate": "/redirect/{shortPath}",
"UpstreamHttpMethod": [ "GET" ],
"Key": "ReachUrl"
}

]
}
41 changes: 41 additions & 0 deletions src/Shortener/Infrastructure/Commands/ReachUrlCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Shortener.Infrastructure.Context;

namespace Shortener.Infrastructure.Commands
{
public class ReachUrlDto
{
public string Message { get; set; } = string.Empty;
}

public class ReachUrlCommand : IRequest<ReachUrlDto>
{
public string ShortPath { get; set; }
public ReachUrlCommand(string shortPath)
{
ShortPath = shortPath;
}
}

public class ReachUrlCommandHandler : IRequestHandler<ReachUrlCommand, ReachUrlDto>
{
private readonly AppDbContext dbContext;
public ReachUrlCommandHandler(AppDbContext _dbContext)
{
dbContext = _dbContext;
}
public async Task<ReachUrlDto> Handle(ReachUrlCommand request, CancellationToken cancellationToken)
{
var url = await dbContext.Urls.FirstOrDefaultAsync(p => p.ShortPath == request.ShortPath);
if (url == null)
{
return new() { Message = "an error occurred" };
}
url.RequestCounter++;
url.LastRequestedDate = DateTime.UtcNow;
await dbContext.SaveChangesAsync();
return new() { Message = "it is okay" };
}
}
}
18 changes: 17 additions & 1 deletion src/Shortener/WebAPI/Controllers/ShortenerController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using MassTransit;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
using Shared.Extensions;
using Shortener.Infrastructure.Commands;
using Shortener.Infrastructure.Context;
using Shortener.Infrastructure.Models;
using System.Text.Json;


namespace WebAPI.Controllers
{
[Route("api/[controller]")]
Expand All @@ -14,11 +17,13 @@ public class ShortenerController : ControllerBase
{
private readonly ILogger logger;
private readonly AppDbContext appDbContext;
private readonly IMediator mediator;

public ShortenerController(ILogger<ShortenerController> _logger, AppDbContext _appDbContext)
public ShortenerController(ILogger<ShortenerController> _logger, AppDbContext _appDbContext, IMediator _mediator)
{
logger = _logger;
appDbContext = _appDbContext;
mediator = _mediator;
}

[HttpPost]
Expand Down Expand Up @@ -48,6 +53,17 @@ public async Task<IActionResult> PublishUrlToCreateShortPath([FromBody] ShortUrl
logger.LogWarning(ex.ToJsonString());
return BadRequest();
}

}


[HttpGet]
[Route("redirect/{shortPath}")]
public async Task<IActionResult> ReachUrl(string shortPath)
{
logger.LogInformation($"{shortPath} was send to command");
return Ok(await mediator.Send(new ReachUrlCommand(shortPath)));
}

}
}
4 changes: 2 additions & 2 deletions tests/Buffer/UnitTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
global using Xunit;
global using Microsoft.Extensions.Logging;
global using Moq;
global using Moq;
global using Xunit;
1 change: 0 additions & 1 deletion tests/Shortener/Shortener.UnitTests/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Moq;
using Shared.ConfigModels;
using Shortener.Infrastructure.Commands;
using Shortener.Infrastructure.Context;

Expand Down

0 comments on commit 7459fbb

Please sign in to comment.