Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
133 changes: 67 additions & 66 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,67 @@
name: AutoPile CI/CD Pipeline
on:
push:
branches:
- develop
- master
workflow_dispatch:

env:
AZURE_WEBAPP_NAME: autopile
AZURE_WEBAPP_PACKAGE_PATH: "./publish"

jobs:
ci:
name: Build and Test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Set up .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.x'

- name: Restore
run: dotnet restore ./AutoPile.sln

- name: Build
run: dotnet build ./AutoPile.sln --configuration Release --no-restore

- name: Test
run: dotnet test --no-build --configuration Release

- name: Publish
if: github.ref == 'refs/heads/master'
run: dotnet publish ./AutoPile.sln --configuration Release --no-build --output ${{env.AZURE_WEBAPP_PACKAGE_PATH}}

- name: Upload Artifact
if: github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: app-build
path: ${{env.AZURE_WEBAPP_PACKAGE_PATH}}

cd:
name: Deploy to Azure
needs: ci
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: app-build
path: ${{env.AZURE_WEBAPP_PACKAGE_PATH}}

- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v3
with:
app-name: ${{env.AZURE_WEBAPP_NAME}}
publish-profile: ${{secrets.AZURE_PUBLISH_PROFILE}}
package: "${{env.AZURE_WEBAPP_PACKAGE_PATH}}"
name: AutoPile CI/CD Pipeline
on:
push:
branches:
- develop
- master
workflow_dispatch:

env:
AZURE_WEBAPP_NAME: autopile
AZURE_WEBAPP_PACKAGE_PATH: "./publish"

jobs:
ci:
name: Build and Test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Set up .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.x'

- name: Restore
run: dotnet restore ./AutoPile.sln

- name: Build
run: dotnet build ./AutoPile.sln --configuration Release --no-restore

- name: Test
run: dotnet test --no-build --configuration Release

- name: Publish
if: github.ref == 'refs/heads/master'
run: dotnet publish ./AutoPile.sln --configuration Release --no-build --output ${{env.AZURE_WEBAPP_PACKAGE_PATH}}

- name: Upload Artifact
if: github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: app-build
path: ${{env.AZURE_WEBAPP_PACKAGE_PATH}}

cd:
name: Deploy to Azure
needs: ci
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: app-build
path: ${{env.AZURE_WEBAPP_PACKAGE_PATH}}

- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v3
with:
app-name: ${{env.AZURE_WEBAPP_NAME}}
publish-profile: ${{secrets.AZURE_PUBLISH_PROFILE}}
package: "${{env.AZURE_WEBAPP_PACKAGE_PATH}}"

1 change: 1 addition & 0 deletions AutoPile.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
builder.Services.AddScoped<IReviewsCache, ReviewsCache>();
builder.Services.AddScoped<IUserInfoCache, UserInfoCache>();
builder.Services.AddScoped<IOrderCache, OrderCache>();
builder.Services.AddScoped<IStripeService, StripeService>();
// Add this to the service configuration section in Program.cs
// Register both QueueClients
// Register QueueClient for Email Queue
Expand Down
4 changes: 2 additions & 2 deletions AutoPile.DATA/Data/AutoPileMongoDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace AutoPile.DATA.Data
{
public class AutoPileMongoDbContext : DbContext
{
public DbSet<Product> Products { get; set; }
public DbSet<Review> Reviews { get; set; }
public virtual DbSet<Product> Products { get; set; }
public virtual DbSet<Review> Reviews { get; set; }

public static AutoPileMongoDbContext Create(IMongoDatabase database) =>
new(new DbContextOptionsBuilder<AutoPileMongoDbContext>()
Expand Down
9 changes: 9 additions & 0 deletions AutoPile.DOMAIN/Interface/IStripeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Stripe;

namespace AutoPile.SERVICE.Services
{
public interface IStripeService
{
Task<PaymentIntent> CreatePaymentIntentAsync(long amount, string currency);
}
}
24 changes: 6 additions & 18 deletions AutoPile.SERVICE/Services/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,13 @@ public AuthService(UserManager<ApplicationUser> userManager, ILogger<IAuthServic
throw new BadRequestException("Email already registered");
}

var existUserWithPhone = await _userManager.Users.AnyAsync(u => u.PhoneNumber == userSignupDTO.PhoneNumber);
var existUserWithPhone = _userManager.Users.Any(u => u.PhoneNumber == userSignupDTO.PhoneNumber);
if (existUserWithPhone)
{
throw new BadRequestException("Phone number already registered");
}

var user = new ApplicationUser
{
UserName = userSignupDTO.UserName,
Email = userSignupDTO.Email,
FirstName = userSignupDTO.FirstName,
LastName = userSignupDTO.LastName,
PhoneNumber = userSignupDTO.PhoneNumber
};
var user = _mapper.Map<ApplicationUser>(userSignupDTO);

var result = await _userManager.CreateAsync(user, userSignupDTO.Password);
if (!result.Succeeded)
Expand All @@ -148,13 +141,8 @@ public AuthService(UserManager<ApplicationUser> userManager, ILogger<IAuthServic
var refreshToken = RefreshTokenGenerator.GenerateRefreshToken();
await UpdateUserRefreshTokenAsync(user, refreshToken);

var responseDTO = new UserResponseDTO
{
Id = user.Id,
UserName = user.UserName,
Email = user.Email,
Roles = await _userManager.GetRolesAsync(user)
};
var responseDTO = _mapper.Map<UserResponseDTO>(user);
responseDTO.Roles = await _userManager.GetRolesAsync(user);

return (responseDTO, accessToken, refreshToken);
}
Expand All @@ -172,8 +160,8 @@ public AuthService(UserManager<ApplicationUser> userManager, ILogger<IAuthServic
UserResponseDTO userResponseDTO = _mapper.Map<UserResponseDTO>(user);

userResponseDTO.Roles = await _userManager.GetRolesAsync(user);
var userResponseInfoDTO = _mapper.Map<UserInfoResponseDTO>(user);
userResponseInfoDTO.Roles = userResponseDTO.Roles;
//var userResponseInfoDTO = _mapper.Map<UserInfoResponseDTO>(user);
//userResponseInfoDTO.Roles = userResponseDTO.Roles;
//await _userInfoCache.SetUserAsync(user.Id, userResponseInfoDTO);
_logger.LogInformation("Successfully cached user info for user {UserId}", user.Id);
return (userResponseDTO, accessToken, refreshToken);
Expand Down
27 changes: 5 additions & 22 deletions AutoPile.SERVICE/Services/PaymentService.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
using AutoMapper;
using AutoPile.DATA.Data;
using AutoPile.DATA.Data;
using AutoPile.DATA.Exceptions;
using AutoPile.DOMAIN.DTOs.Requests;
using MongoDB.Bson;
using Stripe;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoPile.SERVICE.Services
{
public class PaymentService : IPaymentService
{
private readonly AutoPileManagementDbContext _autoPileManagementDbContext;
private readonly AutoPileMongoDbContext _autoPileMongoDbContext;
private readonly IMapper _mapper;
private readonly IStripeService _stripeService;

public PaymentService(AutoPileManagementDbContext autoPileManagementDbContext, AutoPileMongoDbContext autoPileMongoDbContext, IMapper mapper)
public PaymentService(AutoPileMongoDbContext autoPileMongoDbContext, IStripeService stripeService)
{
_autoPileManagementDbContext = autoPileManagementDbContext;
_autoPileMongoDbContext = autoPileMongoDbContext;
_mapper = mapper;
_stripeService = stripeService;
}

public async Task<PaymentIntent> PaymentIntentCreateAsync(PaymentIntentCreate paymentIntentCreate)
Expand All @@ -32,19 +27,7 @@ public async Task<PaymentIntent> PaymentIntentCreateAsync(PaymentIntentCreate pa
}

var totalAmount = await CalculateTotalAmountAsync(paymentIntentCreate.Items);

var options = new PaymentIntentCreateOptions
{
Amount = (long)(totalAmount * 100),
Currency = "aud",
AutomaticPaymentMethods = new PaymentIntentAutomaticPaymentMethodsOptions
{
Enabled = true,
},
};

var service = new PaymentIntentService();
return await service.CreateAsync(options);
return await _stripeService.CreatePaymentIntentAsync((long)(totalAmount * 100), "aud");
}

private async Task<decimal> CalculateTotalAmountAsync(Item[] items)
Expand Down
27 changes: 27 additions & 0 deletions AutoPile.SERVICE/Services/StripeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Stripe;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoPile.SERVICE.Services
{
public class StripeService : IStripeService
{
public async Task<PaymentIntent> CreatePaymentIntentAsync(long amount, string currency)
{
var options = new PaymentIntentCreateOptions
{
Amount = amount,
Currency = currency,
AutomaticPaymentMethods = new PaymentIntentAutomaticPaymentMethodsOptions
{
Enabled = true,
},
};
var service = new PaymentIntentService();
return await service.CreateAsync(options);
}
}
}
Loading
Loading