Skip to content
55 changes: 12 additions & 43 deletions .github/workflows/develop_autopile.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy ASP.Net Core app to Azure Web App - autopile

on:
Expand All @@ -11,7 +8,9 @@ on:

jobs:
build:
runs-on: windows-latest
runs-on: ubuntu-latest
permissions:
contents: read #This is required for actions/checkout

steps:
- uses: actions/checkout@v4
Expand All @@ -21,45 +20,15 @@ jobs:
with:
dotnet-version: '9.x'

- name: Build with dotnet
run: dotnet build --configuration Release

- name: dotnet publish
run: dotnet publish -c Release -o "${{env.DOTNET_ROOT}}/myapp"
- name: Restore
run: dotnet restore ./AutoPile.sln

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
- name: Build
run: dotnet build ./AutoPile.sln --configuration Release --no-restore

deploy:
runs-on: windows-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
permissions:
id-token: write #This is required for requesting the JWT
- name: Test
run: dotnet test --no-build --configuration Release

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: .net-app

- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_8D7D3ADE3F6945FDB842D69367CCC0A2 }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_D560FBBA60F5467B96310A66546941E1 }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_7B5512553F074DD889236ED335B0C6F2 }}

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: 'autopile'
slot-name: 'Production'
package: .




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