mirror of
https://github.com/D4M13N-D3V/comissions-app-core-api.git
synced 2025-03-14 10:04:55 +00:00
fix: changed the request endpoint to take a artistname and unique displaynames
This commit is contained in:
parent
0229fb6270
commit
3767bbd6a9
@ -919,7 +919,7 @@ 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);
|
var artist = await _dbContext.UserArtists.Include(x=>x.User).FirstOrDefaultAsync(x=>x.User.DisplayName==model.ArtistDisplayName);
|
||||||
if(artist==null)
|
if(artist==null)
|
||||||
return NotFound("Artist not found.");
|
return NotFound("Artist not found.");
|
||||||
|
|
||||||
@ -932,7 +932,7 @@ public class RequestsController : Controller
|
|||||||
Message = model.Message,
|
Message = model.Message,
|
||||||
RequestDate = DateTime.UtcNow,
|
RequestDate = DateTime.UtcNow,
|
||||||
UserId = userId,
|
UserId = userId,
|
||||||
ArtistId = model.ArtistId,
|
ArtistId = artist.Id,
|
||||||
Accepted = false,
|
Accepted = false,
|
||||||
AcceptedDate = null,
|
AcceptedDate = null,
|
||||||
Declined = false,
|
Declined = false,
|
||||||
|
@ -35,6 +35,10 @@ public class UserController : Controller
|
|||||||
{
|
{
|
||||||
var userId = User.GetUserId();
|
var userId = User.GetUserId();
|
||||||
var existingUser = await _dbContext.Users.FirstAsync(user=>user.Id==userId);
|
var existingUser = await _dbContext.Users.FirstAsync(user=>user.Id==userId);
|
||||||
|
|
||||||
|
if(_dbContext.Users.Any(x=>x.DisplayName==model.DisplayName && x.Id!=userId))
|
||||||
|
return BadRequest("Display name is already in use.");
|
||||||
|
|
||||||
var updatedUser = model.ToEntity(existingUser);
|
var updatedUser = model.ToEntity(existingUser);
|
||||||
updatedUser = _dbContext.Users.Update(updatedUser).Entity;
|
updatedUser = _dbContext.Users.Update(updatedUser).Entity;
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
|
@ -31,10 +31,12 @@ public class UserMiddleware
|
|||||||
|
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
|
var displayName = context.User.Claims.FirstOrDefault(x=>x.Type==ClaimTypes.Name)?.Value ?? "Anonymous";
|
||||||
|
displayName = $"{displayName}#{Guid.NewGuid().ToString().Substring(0, 4)}";
|
||||||
user = new User
|
user = new User
|
||||||
{
|
{
|
||||||
Id = userId,
|
Id = userId,
|
||||||
DisplayName = context.User.Claims.FirstOrDefault(x=>x.Type==ClaimTypes.Name)?.Value ?? "Anonymous",
|
DisplayName = displayName,
|
||||||
Biography = string.Empty,
|
Biography = string.Empty,
|
||||||
Email = context.User.Claims.FirstOrDefault(x=>x.Type==ClaimTypes.Email)?.Value ?? string.Empty,
|
Email = context.User.Claims.FirstOrDefault(x=>x.Type==ClaimTypes.Email)?.Value ?? string.Empty,
|
||||||
};
|
};
|
||||||
|
@ -2,7 +2,7 @@ namespace comissions.app.database.Models.Request;
|
|||||||
|
|
||||||
public class RequestCreateModel
|
public class RequestCreateModel
|
||||||
{
|
{
|
||||||
public int ArtistId { get; set; }
|
public string ArtistDisplayName { get; set; }
|
||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
public decimal Amount { get; set; }
|
public decimal Amount { get; set; }
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user