Skip to content

Commit 5ecfd40

Browse files
author
Mehmet Ozkaya
committed
initial
1 parent a3cc426 commit 5ecfd40

File tree

115 files changed

+42050
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+42050
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Order.Core.Entities.Base
6+
{
7+
public abstract class Entity : EntityBase<int>
8+
{
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Order.Core.Entities.Base
6+
{
7+
public abstract class EntityBase<TId> : IEntityBase<TId>
8+
{
9+
public virtual TId Id { get; protected set; }
10+
11+
int? _requestedHashCode;
12+
13+
public bool IsTransient()
14+
{
15+
return Id.Equals(default(TId));
16+
}
17+
18+
public override bool Equals(object obj)
19+
{
20+
if (obj == null || !(obj is EntityBase<TId>))
21+
return false;
22+
23+
if (ReferenceEquals(this, obj))
24+
return true;
25+
26+
if (GetType() != obj.GetType())
27+
return false;
28+
29+
var item = (EntityBase<TId>)obj;
30+
31+
if (item.IsTransient() || IsTransient())
32+
return false;
33+
else
34+
return item == this;
35+
}
36+
37+
public override int GetHashCode()
38+
{
39+
if (!IsTransient())
40+
{
41+
if (!_requestedHashCode.HasValue)
42+
_requestedHashCode = Id.GetHashCode() ^ 31; // XOR for random distribution (http://blogs.msdn.com/b/ericlippert/archive/2011/02/28/guidelines-and-rules-for-gethashcode.aspx)
43+
44+
return _requestedHashCode.Value;
45+
}
46+
else
47+
return base.GetHashCode();
48+
}
49+
50+
public static bool operator ==(EntityBase<TId> left, EntityBase<TId> right)
51+
{
52+
if (Equals(left, null))
53+
return Equals(right, null) ? true : false;
54+
else
55+
return left.Equals(right);
56+
}
57+
58+
public static bool operator !=(EntityBase<TId> left, EntityBase<TId> right)
59+
{
60+
return !(left == right);
61+
}
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Order.Core.Entities.Base
6+
{
7+
public interface IEntityBase<TId>
8+
{
9+
TId Id { get; }
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Order.Core.Entities.Base;
2+
3+
namespace Order.Core.Entities
4+
{
5+
public class Order : Entity
6+
{
7+
public string UserName { get; set; }
8+
public decimal TotalPrice { get; set; }
9+
10+
// BillingAddress
11+
public string FirstName { get; set; }
12+
public string LastName { get; set; }
13+
public string EmailAddress { get; set; }
14+
public string AddressLine { get; set; }
15+
public string Country { get; set; }
16+
public string State { get; set; }
17+
public string ZipCode { get; set; }
18+
19+
// Payment
20+
public string CardName { get; set; }
21+
public string CardNumber { get; set; }
22+
public string Expiration { get; set; }
23+
public string CVV { get; set; }
24+
public PaymentMethod PaymentMethod { get; set; }
25+
}
26+
27+
public enum PaymentMethod
28+
{
29+
CreditCard = 1,
30+
DebitCard = 2,
31+
Paypal = 3
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Order.Core.Entities.Base;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Linq.Expressions;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Order.Core.Repositories.Base
10+
{
11+
public interface IRepository<T> where T : Entity
12+
{
13+
Task<IReadOnlyList<T>> GetAllAsync();
14+
Task<IReadOnlyList<T>> GetAsync(Expression<Func<T, bool>> predicate);
15+
Task<IReadOnlyList<T>> GetAsync(Expression<Func<T, bool>> predicate = null,
16+
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
17+
string includeString = null,
18+
bool disableTracking = true);
19+
Task<IReadOnlyList<T>> GetAsync(Expression<Func<T, bool>> predicate = null,
20+
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
21+
List<Expression<Func<T, object>>> includes = null,
22+
bool disableTracking = true);
23+
Task<T> GetByIdAsync(int id);
24+
Task<T> AddAsync(T entity);
25+
Task UpdateAsync(T entity);
26+
Task DeleteAsync(T entity);
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Order.Core.Repositories.Base;
2+
using Order.Core.Entities;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Order.Core.Repositories
9+
{
10+
public interface IOrderRepository : IRepository<Entities.Order>
11+
{
12+
Task<IEnumerable<Entities.Order>> GetOrderListAsync();
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace Order.Infrastructure
4+
{
5+
public class Class1
6+
{
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29806.167
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B1F80D21-7738-4DA6-B3D1-C5E77F7146E4}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{5AFB00CF-8E6E-4402-8870-05CF483F43BC}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Catalog", "Catalog", "{4F4FB78C-17C7-4726-A65D-C5CA1E40A806}"
11+
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Basket", "Basket", "{D6F43D19-A527-4BDB-9CF7-2ABB731C1014}"
13+
EndProject
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Order", "Order", "{ED7226E2-4D3C-4164-A88C-436845332BC1}"
15+
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Catalog.API", "src\Catalog\Catalog.API\Catalog.API.csproj", "{C81249E2-63E5-41EC-9A29-C66D622AF86D}"
17+
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebUI", "WebUI", "{A620B284-D093-4BB9-92B2-8E0FE0B7B24C}"
19+
EndProject
20+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ApiGateway", "ApiGateway", "{652564FB-14BE-4016-BB38-57039BB73B2A}"
21+
EndProject
22+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShopApp", "src\webui\ShopApp\ShopApp.csproj", "{B445668C-7C71-469D-9A6A-27C87043EF60}"
23+
EndProject
24+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Order.API", "src\Order\Order.API\Order.API.csproj", "{981A5534-0E42-4DC9-B99C-2A95EAF97ADF}"
25+
EndProject
26+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Basket.API", "src\Basket\Basket.API\Basket.API.csproj", "{A80C8D6B-E128-4ABD-996B-DE9872845A91}"
27+
EndProject
28+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Order.Core", "Order.Core\Order.Core.csproj", "{268069EA-D298-4F9A-9C9E-1A823815124B}"
29+
EndProject
30+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Order.Infrastructure", "src\order\Order.Infrastructure\Order.Infrastructure.csproj", "{F8A541D6-36C6-4CC2-8FE2-804FC7FF4A4B}"
31+
EndProject
32+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shipment", "Shipment", "{97A43AA5-C1D3-4CB0-B0EB-501A71422A35}"
33+
EndProject
34+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shipment.API", "src\shipment\Shipment.API\Shipment.API.csproj", "{3F0400B9-666C-4E0F-9CAD-58C3ED760C76}"
35+
EndProject
36+
Global
37+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
38+
Debug|Any CPU = Debug|Any CPU
39+
Release|Any CPU = Release|Any CPU
40+
EndGlobalSection
41+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
42+
{C81249E2-63E5-41EC-9A29-C66D622AF86D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43+
{C81249E2-63E5-41EC-9A29-C66D622AF86D}.Debug|Any CPU.Build.0 = Debug|Any CPU
44+
{C81249E2-63E5-41EC-9A29-C66D622AF86D}.Release|Any CPU.ActiveCfg = Release|Any CPU
45+
{C81249E2-63E5-41EC-9A29-C66D622AF86D}.Release|Any CPU.Build.0 = Release|Any CPU
46+
{B445668C-7C71-469D-9A6A-27C87043EF60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47+
{B445668C-7C71-469D-9A6A-27C87043EF60}.Debug|Any CPU.Build.0 = Debug|Any CPU
48+
{B445668C-7C71-469D-9A6A-27C87043EF60}.Release|Any CPU.ActiveCfg = Release|Any CPU
49+
{B445668C-7C71-469D-9A6A-27C87043EF60}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{981A5534-0E42-4DC9-B99C-2A95EAF97ADF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{981A5534-0E42-4DC9-B99C-2A95EAF97ADF}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{981A5534-0E42-4DC9-B99C-2A95EAF97ADF}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{981A5534-0E42-4DC9-B99C-2A95EAF97ADF}.Release|Any CPU.Build.0 = Release|Any CPU
54+
{A80C8D6B-E128-4ABD-996B-DE9872845A91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
55+
{A80C8D6B-E128-4ABD-996B-DE9872845A91}.Debug|Any CPU.Build.0 = Debug|Any CPU
56+
{A80C8D6B-E128-4ABD-996B-DE9872845A91}.Release|Any CPU.ActiveCfg = Release|Any CPU
57+
{A80C8D6B-E128-4ABD-996B-DE9872845A91}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{268069EA-D298-4F9A-9C9E-1A823815124B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59+
{268069EA-D298-4F9A-9C9E-1A823815124B}.Debug|Any CPU.Build.0 = Debug|Any CPU
60+
{268069EA-D298-4F9A-9C9E-1A823815124B}.Release|Any CPU.ActiveCfg = Release|Any CPU
61+
{268069EA-D298-4F9A-9C9E-1A823815124B}.Release|Any CPU.Build.0 = Release|Any CPU
62+
{F8A541D6-36C6-4CC2-8FE2-804FC7FF4A4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63+
{F8A541D6-36C6-4CC2-8FE2-804FC7FF4A4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
64+
{F8A541D6-36C6-4CC2-8FE2-804FC7FF4A4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
65+
{F8A541D6-36C6-4CC2-8FE2-804FC7FF4A4B}.Release|Any CPU.Build.0 = Release|Any CPU
66+
{3F0400B9-666C-4E0F-9CAD-58C3ED760C76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
67+
{3F0400B9-666C-4E0F-9CAD-58C3ED760C76}.Debug|Any CPU.Build.0 = Debug|Any CPU
68+
{3F0400B9-666C-4E0F-9CAD-58C3ED760C76}.Release|Any CPU.ActiveCfg = Release|Any CPU
69+
{3F0400B9-666C-4E0F-9CAD-58C3ED760C76}.Release|Any CPU.Build.0 = Release|Any CPU
70+
EndGlobalSection
71+
GlobalSection(SolutionProperties) = preSolution
72+
HideSolutionNode = FALSE
73+
EndGlobalSection
74+
GlobalSection(NestedProjects) = preSolution
75+
{4F4FB78C-17C7-4726-A65D-C5CA1E40A806} = {B1F80D21-7738-4DA6-B3D1-C5E77F7146E4}
76+
{D6F43D19-A527-4BDB-9CF7-2ABB731C1014} = {B1F80D21-7738-4DA6-B3D1-C5E77F7146E4}
77+
{ED7226E2-4D3C-4164-A88C-436845332BC1} = {B1F80D21-7738-4DA6-B3D1-C5E77F7146E4}
78+
{C81249E2-63E5-41EC-9A29-C66D622AF86D} = {4F4FB78C-17C7-4726-A65D-C5CA1E40A806}
79+
{A620B284-D093-4BB9-92B2-8E0FE0B7B24C} = {B1F80D21-7738-4DA6-B3D1-C5E77F7146E4}
80+
{652564FB-14BE-4016-BB38-57039BB73B2A} = {B1F80D21-7738-4DA6-B3D1-C5E77F7146E4}
81+
{B445668C-7C71-469D-9A6A-27C87043EF60} = {A620B284-D093-4BB9-92B2-8E0FE0B7B24C}
82+
{981A5534-0E42-4DC9-B99C-2A95EAF97ADF} = {ED7226E2-4D3C-4164-A88C-436845332BC1}
83+
{A80C8D6B-E128-4ABD-996B-DE9872845A91} = {D6F43D19-A527-4BDB-9CF7-2ABB731C1014}
84+
{268069EA-D298-4F9A-9C9E-1A823815124B} = {ED7226E2-4D3C-4164-A88C-436845332BC1}
85+
{F8A541D6-36C6-4CC2-8FE2-804FC7FF4A4B} = {ED7226E2-4D3C-4164-A88C-436845332BC1}
86+
{97A43AA5-C1D3-4CB0-B0EB-501A71422A35} = {B1F80D21-7738-4DA6-B3D1-C5E77F7146E4}
87+
{3F0400B9-666C-4E0F-9CAD-58C3ED760C76} = {97A43AA5-C1D3-4CB0-B0EB-501A71422A35}
88+
EndGlobalSection
89+
GlobalSection(ExtensibilityGlobals) = postSolution
90+
SolutionGuid = {84204196-8211-4BEA-8688-10C3584CADB2}
91+
EndGlobalSection
92+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
9+
<PackageReference Include="RabbitMQ.Client" Version="5.1.2" />
10+
<PackageReference Include="StackExchange.Redis" Version="2.1.28" />
11+
</ItemGroup>
12+
13+
14+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using Basket.API.Entities;
2+
using Basket.API.RabbitMq;
3+
using Basket.API.Repositories.Interface;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.Extensions.Logging;
6+
using System;
7+
using System.Net;
8+
using System.Security.Claims;
9+
using System.Threading.Tasks;
10+
11+
namespace Basket.API.Controllers
12+
{
13+
[Route("api/v1/[controller]")]
14+
[ApiController]
15+
public class BasketController : ControllerBase
16+
{
17+
private readonly IBasketRepository _repository;
18+
private readonly EventBusRabbitMQPublisher _eventBus;
19+
private readonly ILogger<BasketController> _logger;
20+
21+
public BasketController(IBasketRepository repository, EventBusRabbitMQPublisher eventBus, ILogger<BasketController> logger)
22+
{
23+
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
24+
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
25+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
26+
}
27+
28+
[HttpGet("{id}")]
29+
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)]
30+
public async Task<ActionResult<CustomerBasket>> GetBasketByIdAsync(string id)
31+
{
32+
var basket = await _repository.GetBasketAsync(id);
33+
return Ok(basket ?? new CustomerBasket(id));
34+
}
35+
36+
[HttpPost]
37+
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)]
38+
public async Task<ActionResult<CustomerBasket>> UpdateBasketAsync([FromBody]CustomerBasket value)
39+
{
40+
return Ok(await _repository.UpdateBasketAsync(value));
41+
}
42+
43+
// DELETE api/values/5
44+
[HttpDelete("{id}")]
45+
[ProducesResponseType(typeof(void), (int)HttpStatusCode.OK)]
46+
public async Task DeleteBasketByIdAsync(string id)
47+
{
48+
await _repository.DeleteBasketAsync(id);
49+
}
50+
51+
[Route("checkout")]
52+
[HttpPost]
53+
[ProducesResponseType((int)HttpStatusCode.Accepted)]
54+
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
55+
public async Task<ActionResult> CheckoutAsync([FromBody]BasketCheckout basketCheckout)
56+
{
57+
// remove the basket
58+
// send checkout event to rabbitMq
59+
60+
var userId = "swn"; // _identityService.GetUserIdentity();
61+
62+
var basketRemoved = await _repository.DeleteBasketAsync(userId);
63+
if (!basketRemoved)
64+
{
65+
return BadRequest();
66+
}
67+
68+
basketCheckout.RequestId = Guid.NewGuid();
69+
basketCheckout.Buyer = userId;
70+
basketCheckout.City = "asd";
71+
basketCheckout.Country = "asd";
72+
73+
_eventBus.PublishBasketCheckout("basketCheckoutQueue", basketCheckout);
74+
75+
// TODO : burayı alttaki gibi yapılacak -- rabbitMQ kısmı ayrı bir class library yapılıp BasketCheckoutAcceptedIntegrationEvent class ı yapılıp 2 tarafta onu kullanacak
76+
77+
//var userName = this.HttpContext.User.FindFirst(x => x.Type == ClaimTypes.Name).Value;
78+
79+
//var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, userName, basketCheckout.City, basketCheckout.Street,
80+
// basketCheckout.State, basketCheckout.Country, basketCheckout.ZipCode, basketCheckout.CardNumber, basketCheckout.CardHolderName,
81+
// basketCheckout.CardExpiration, basketCheckout.CardSecurityNumber, basketCheckout.CardTypeId, basketCheckout.Buyer, basketCheckout.RequestId, basket);
82+
83+
//// Once basket is checkout, sends an integration event to
84+
//// ordering.api to convert basket to order and proceeds with
85+
//// order creation process
86+
//try
87+
//{
88+
// _eventBus.Publish(eventMessage);
89+
//}
90+
//catch (Exception ex)
91+
//{
92+
// _logger.LogError(ex, "ERROR Publishing integration event: {IntegrationEventId} from {AppName}", eventMessage.Id, "asd");
93+
// throw;
94+
//}
95+
96+
return Accepted();
97+
}
98+
99+
}
100+
}

0 commit comments

Comments
 (0)