mirror of
https://github.com/D4M13N-D3V/comissions-app-core-api.git
synced 2025-06-16 05:09:09 +00:00
fix: added more notifications
This commit is contained in:
parent
de95f333aa
commit
80502aa2d6
@ -5,6 +5,8 @@ using comissions.app.database.Entities;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Novu;
|
||||||
|
using Novu.DTO.Events;
|
||||||
|
|
||||||
namespace comissions.app.api.Controllers;
|
namespace comissions.app.api.Controllers;
|
||||||
|
|
||||||
@ -15,9 +17,10 @@ public class AdminArtistRequestsController : Controller
|
|||||||
{
|
{
|
||||||
private readonly ApplicationDbContext _dbContext;
|
private readonly ApplicationDbContext _dbContext;
|
||||||
private readonly IPaymentService _paymentService;
|
private readonly IPaymentService _paymentService;
|
||||||
|
private readonly NovuClient _client;
|
||||||
public AdminArtistRequestsController(ApplicationDbContext dbContext, IPaymentService paymentService)
|
public AdminArtistRequestsController(NovuClient client, ApplicationDbContext dbContext, IPaymentService paymentService)
|
||||||
{
|
{
|
||||||
|
_client = client;
|
||||||
_paymentService = paymentService;
|
_paymentService = paymentService;
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
}
|
}
|
||||||
@ -126,6 +129,16 @@ public class AdminArtistRequestsController : Controller
|
|||||||
request = _dbContext.ArtistRequests.Update(request).Entity;
|
request = _dbContext.ArtistRequests.Update(request).Entity;
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
var result = request.ToModel();
|
var result = request.ToModel();
|
||||||
|
var newTriggerModel = new EventCreateData()
|
||||||
|
{
|
||||||
|
EventName = "artistrequestaccepted",
|
||||||
|
To =
|
||||||
|
{
|
||||||
|
SubscriberId = userId,
|
||||||
|
},
|
||||||
|
Payload = { }
|
||||||
|
};
|
||||||
|
await _client.Event.Trigger(newTriggerModel);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +156,16 @@ public class AdminArtistRequestsController : Controller
|
|||||||
|
|
||||||
_dbContext.ArtistRequests.Remove(request);
|
_dbContext.ArtistRequests.Remove(request);
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
|
var newTriggerModel = new EventCreateData()
|
||||||
|
{
|
||||||
|
EventName = "artistrequestdenied",
|
||||||
|
To =
|
||||||
|
{
|
||||||
|
SubscriberId = userId,
|
||||||
|
},
|
||||||
|
Payload = { }
|
||||||
|
};
|
||||||
|
await _client.Event.Trigger(newTriggerModel);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,6 +9,8 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Stripe;
|
using Stripe;
|
||||||
|
using Novu;
|
||||||
|
using Novu.DTO.Events;
|
||||||
using Stripe.Checkout;
|
using Stripe.Checkout;
|
||||||
|
|
||||||
namespace comissions.app.api.Controllers;
|
namespace comissions.app.api.Controllers;
|
||||||
@ -20,11 +22,12 @@ public class RequestsController : Controller
|
|||||||
private readonly ApplicationDbContext _dbContext;
|
private readonly ApplicationDbContext _dbContext;
|
||||||
private readonly IStorageService _storageService;
|
private readonly IStorageService _storageService;
|
||||||
private readonly IPaymentService _paymentService;
|
private readonly IPaymentService _paymentService;
|
||||||
|
private readonly NovuClient _client;
|
||||||
private readonly string _webHookSecret;
|
private readonly string _webHookSecret;
|
||||||
|
|
||||||
public RequestsController(ApplicationDbContext dbContext, IPaymentService paymentService, IStorageService storageService, IConfiguration configuration)
|
public RequestsController(ApplicationDbContext dbContext, NovuClient client, IPaymentService paymentService, IStorageService storageService, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
|
_client = client;
|
||||||
_webHookSecret = configuration.GetValue<string>("Stripe:WebHookSecret");
|
_webHookSecret = configuration.GetValue<string>("Stripe:WebHookSecret");
|
||||||
_paymentService = paymentService;
|
_paymentService = paymentService;
|
||||||
_storageService = storageService;
|
_storageService = storageService;
|
||||||
@ -746,6 +749,16 @@ public class RequestsController : Controller
|
|||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
var result = request.ToModel();
|
var result = request.ToModel();
|
||||||
|
var newTriggerModel = new EventCreateData()
|
||||||
|
{
|
||||||
|
EventName = "requestcompleted",
|
||||||
|
To =
|
||||||
|
{
|
||||||
|
SubscriberId = request.UserId
|
||||||
|
},
|
||||||
|
Payload = { }
|
||||||
|
};
|
||||||
|
await _client.Event.Trigger(newTriggerModel);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -777,6 +790,26 @@ public class RequestsController : Controller
|
|||||||
request.AcceptedDate = DateTime.UtcNow;
|
request.AcceptedDate = DateTime.UtcNow;
|
||||||
_dbContext.Entry(request).State = EntityState.Modified;
|
_dbContext.Entry(request).State = EntityState.Modified;
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
|
var newTriggerModel = new EventCreateData()
|
||||||
|
{
|
||||||
|
EventName = "requestacceptedbuyer",
|
||||||
|
To =
|
||||||
|
{
|
||||||
|
SubscriberId = request.UserId
|
||||||
|
},
|
||||||
|
Payload = { }
|
||||||
|
};
|
||||||
|
await _client.Event.Trigger(newTriggerModel);
|
||||||
|
var newTriggerArtistModel = new EventCreateData()
|
||||||
|
{
|
||||||
|
EventName = "requestacceptedartist",
|
||||||
|
To =
|
||||||
|
{
|
||||||
|
SubscriberId = request.Artist.UserId
|
||||||
|
},
|
||||||
|
Payload = { }
|
||||||
|
};
|
||||||
|
await _client.Event.Trigger(newTriggerModel);
|
||||||
|
|
||||||
var result = request.ToModel();
|
var result = request.ToModel();
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
@ -809,6 +842,16 @@ public class RequestsController : Controller
|
|||||||
_dbContext.Entry(request).State = EntityState.Modified;
|
_dbContext.Entry(request).State = EntityState.Modified;
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
var result = request.ToModel();
|
var result = request.ToModel();
|
||||||
|
var newTriggerModel = new EventCreateData()
|
||||||
|
{
|
||||||
|
EventName = "requestdenied",
|
||||||
|
To =
|
||||||
|
{
|
||||||
|
SubscriberId = request.UserId
|
||||||
|
},
|
||||||
|
Payload = { }
|
||||||
|
};
|
||||||
|
await _client.Event.Trigger(newTriggerModel);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,15 +864,19 @@ public class RequestsController : Controller
|
|||||||
.Where(x=>x.UserId==User.GetUserId())
|
.Where(x=>x.UserId==User.GetUserId())
|
||||||
.CountAsync();
|
.CountAsync();
|
||||||
|
|
||||||
|
var artist = await _dbContext.UserArtists.FirstOrDefaultAsync(x=>x.Id==model.ArtistId);
|
||||||
|
if(artist==null)
|
||||||
|
return NotFound("Artist not found.");
|
||||||
|
|
||||||
if(openRequests>3)
|
if(openRequests>3)
|
||||||
return BadRequest("You can only have 3 open requests at a time.");
|
return BadRequest("You can only have 3 open requests at a time.");
|
||||||
|
var userId = User.GetUserId();
|
||||||
var request = new Request()
|
var request = new Request()
|
||||||
{
|
{
|
||||||
Amount = model.Amount,
|
Amount = model.Amount,
|
||||||
Message = model.Message,
|
Message = model.Message,
|
||||||
RequestDate = DateTime.UtcNow,
|
RequestDate = DateTime.UtcNow,
|
||||||
UserId = User.GetUserId(),
|
UserId = userId,
|
||||||
ArtistId = model.ArtistId,
|
ArtistId = model.ArtistId,
|
||||||
Accepted = false,
|
Accepted = false,
|
||||||
AcceptedDate = null,
|
AcceptedDate = null,
|
||||||
@ -840,6 +887,26 @@ public class RequestsController : Controller
|
|||||||
};
|
};
|
||||||
_dbContext.Requests.Add(request);
|
_dbContext.Requests.Add(request);
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
|
var newArtistTriggerModel = new EventCreateData()
|
||||||
|
{
|
||||||
|
EventName = "requestcreatedbuyer",
|
||||||
|
To =
|
||||||
|
{
|
||||||
|
SubscriberId = userId,
|
||||||
|
},
|
||||||
|
Payload = { }
|
||||||
|
};
|
||||||
|
await _client.Event.Trigger(newArtistTriggerModel);
|
||||||
|
var newTriggerModel = new EventCreateData()
|
||||||
|
{
|
||||||
|
EventName = "requestcreatedartist",
|
||||||
|
To =
|
||||||
|
{
|
||||||
|
SubscriberId = artist.UserId,
|
||||||
|
},
|
||||||
|
Payload = { }
|
||||||
|
};
|
||||||
|
await _client.Event.Trigger(newTriggerModel);
|
||||||
return Ok(request.ToModel());
|
return Ok(request.ToModel());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user