Skip to content

Commit

Permalink
try to fix josn map typ
Browse files Browse the repository at this point in the history
  • Loading branch information
iAmBipinPaul committed Apr 19, 2024
1 parent cd23c1e commit 8ba8c2b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using UAParser;
using UrlShortener.Core;

namespace UrlShortener.Applications.Implementations
{
Expand All @@ -28,7 +29,7 @@ public async Task InsertShortUrlClick(InsertShortUrlClickInput input, Cancellati
IpAddress = input.IpAddress,
ClientInfo = JsonConvert.SerializeObject(input.ClientInfo),
PartitionValue = partitionValue,
IpInfo = input.IpInfo,
IpInfo = JsonConvert.SerializeObject(input.IpInfo) ,
Id = Guid.NewGuid().ToString()
};
_urlShortenerContext.ShortUrlClicks.Add(shortUrlClick);
Expand Down Expand Up @@ -57,13 +58,14 @@ public async Task<GetShortUrlClicksResponse> GetShortUrlClicks(GetShortUrlClicks
Items = res.Select(c =>
{
var clientInfo= c.ClientInfo is null ?null:JsonConvert.DeserializeObject<ClientInfo>(c.ClientInfo);
var ipInfo= c.IpInfo is null ?null:JsonConvert.DeserializeObject<IpInfo>(c.IpInfo);
return new ShortUrlClickResponse()
{
Id = c.Id,
ShortUrlId = c.ShortUrlId,
CreationDateTime = c.CreationDateTime,
IpAddress = c.IpAddress,
IpInfo = $"{c.IpInfo?.City},{c.IpInfo?.Region},{c.IpInfo?.Country} ({c.IpInfo?.Org})",
IpInfo = $"{ipInfo?.City},{ipInfo?.Region},{ipInfo?.Country} ({ipInfo?.Org})",
ClientInfo =
$"{clientInfo?.OS?.Family} {clientInfo?.OS?.Major} , {clientInfo?.Device?.Brand} {clientInfo?.Device?.Family},{clientInfo?.UA?.Family} {clientInfo?.UA?.Major}"
};
Expand Down
2 changes: 1 addition & 1 deletion src/API/UrlShortener.Domain/ShortUrlClick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ShortUrlClick
public string PartitionValue { get; set; }
public string? IpAddress { get; set; }
[Column(TypeName = "jsonb")]
public IpInfo? IpInfo { get; set; }
public string? IpInfo { get; set; }
[Column(TypeName = "jsonb")]
public string? ClientInfo { get; set; }
public int? ttl { get; set; } = 7889238; //3 month
Expand Down

0 comments on commit 8ba8c2b

Please sign in to comment.