Compare commits
No commits in common. "87a2250852d5836ca52f8374bca0436eba855437" and "e3a188814654cd297c3ea4940ecb59e0c9cc6ac6" have entirely different histories.
87a2250852
...
e3a1888146
6 changed files with 14 additions and 62 deletions
|
@ -4,5 +4,4 @@ public class ProductTableGet
|
|||
{
|
||||
public string ProductTableName { get; set; }
|
||||
public string ProductTableId { get; set; }
|
||||
public string CompanyTableId { get; set; }
|
||||
}
|
|
@ -35,7 +35,7 @@ public class AdminOnlyHandler : AuthorizationHandler<AdminOnlyRequirement>
|
|||
}
|
||||
catch (NotFoundException _)
|
||||
{
|
||||
throw new ForbiddenException("You need to be logged in to do this action.");
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
if (_userProfileService.IsUserProfileAdmin(userProfile))
|
||||
|
|
|
@ -1,70 +1,38 @@
|
|||
namespace DrinkRateAPI.Exceptions;
|
||||
|
||||
public class DrinkRateException : Exception
|
||||
{
|
||||
public DrinkRateException() : base() { }
|
||||
public DrinkRateException(string message) : base(message) { }
|
||||
}
|
||||
public abstract class DrinkRateException : Exception;
|
||||
|
||||
/// <summary>
|
||||
/// 400 - Bad request
|
||||
/// </summary>
|
||||
public class BadRequestException : DrinkRateException
|
||||
{
|
||||
public BadRequestException() : base() { }
|
||||
public BadRequestException(string message) : base(message) { }
|
||||
}
|
||||
public class BadRequestException : DrinkRateException;
|
||||
|
||||
/// <summary>
|
||||
/// 401 - Unauthenticated
|
||||
/// </summary>
|
||||
public class UnauthenticatedException : DrinkRateException
|
||||
{
|
||||
public UnauthenticatedException() : base() { }
|
||||
public UnauthenticatedException(string message) : base(message) { }
|
||||
}
|
||||
public class UnauthenticatedException : DrinkRateException;
|
||||
|
||||
/// <summary>
|
||||
/// 402 - Payment required
|
||||
/// </summary>
|
||||
public class PaymentRequiredException : DrinkRateException
|
||||
{
|
||||
public PaymentRequiredException() : base() { }
|
||||
public PaymentRequiredException(string message) : base(message) { }
|
||||
}
|
||||
public class PaymentRequiredException : DrinkRateException;
|
||||
|
||||
/// <summary>
|
||||
/// 403 - Forbidden
|
||||
/// </summary>
|
||||
public class ForbiddenException : DrinkRateException
|
||||
{
|
||||
public ForbiddenException() : base() { }
|
||||
public ForbiddenException(string message) : base(message) { }
|
||||
}
|
||||
public class ForbiddenException : DrinkRateException;
|
||||
|
||||
/// <summary>
|
||||
/// 404 - Not found
|
||||
/// </summary>
|
||||
public class NotFoundException : DrinkRateException
|
||||
{
|
||||
public NotFoundException() : base() { }
|
||||
public NotFoundException(string message) : base(message) { }
|
||||
}
|
||||
public class NotFoundException : DrinkRateException;
|
||||
|
||||
/// <summary>
|
||||
/// 418 - I'm a teapot
|
||||
/// </summary>
|
||||
public class IamATeapotException : DrinkRateException
|
||||
{
|
||||
public IamATeapotException() : base() { }
|
||||
public IamATeapotException(string message) : base(message) { }
|
||||
}
|
||||
public class IamATeapotException : DrinkRateException;
|
||||
|
||||
/// <summary>
|
||||
/// 451 - Unavailable for lagal reasons
|
||||
/// </summary>
|
||||
public class UnavailableForLagalReasonsException : DrinkRateException
|
||||
{
|
||||
public UnavailableForLagalReasonsException() : base() { }
|
||||
public UnavailableForLagalReasonsException(string message) : base(message) { }
|
||||
}
|
||||
public class UnavailableForLagalReasonsException : DrinkRateException;
|
|
@ -13,7 +13,7 @@ public class ApplicationUserService(ApplicationDbContext context)
|
|||
{
|
||||
var appUserId = identity.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
var profile = await _context.UserProfiles
|
||||
.FirstOrDefaultAsync(x => x.ApplicationUserId.ToString() == appUserId && !x.IsDeleted)
|
||||
.FirstOrDefaultAsync(x => x.ApplicationUserId.ToString() == appUserId)
|
||||
?? throw new NotFoundException();
|
||||
|
||||
return profile;
|
||||
|
|
|
@ -4,7 +4,6 @@ using DrinkRateAPI.Contexts;
|
|||
using DrinkRateAPI.DbEntities;
|
||||
using DrinkRateAPI.Exceptions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
|
||||
namespace DrinkRateAPI.Services;
|
||||
|
||||
|
@ -25,20 +24,7 @@ public class ProductCompanyTableCoupleService(ApplicationDbContext context)
|
|||
};
|
||||
|
||||
_context.CompanyTable.Add(companyTable);
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateException ex) when
|
||||
(ex.InnerException is PostgresException
|
||||
{
|
||||
SqlState: PostgresErrorCodes.UniqueViolation
|
||||
}
|
||||
)
|
||||
{
|
||||
throw new BadRequestException("Product table or company table with the same name already exists.");
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return await GetProductCompanyTableCouplePostResponse(
|
||||
productCompanyTableCouplePost.ProductTableName,
|
||||
|
|
|
@ -15,13 +15,12 @@ public class ProductTableService(ApplicationDbContext context)
|
|||
{
|
||||
var productTable =
|
||||
await _context.ProductTable.FirstOrDefaultAsync(x => x.ProductTableName == productTableName) ??
|
||||
throw new NotFoundException($"Product table with the name {productTableName} not found.");
|
||||
throw new NotFoundException();
|
||||
|
||||
return new ProductTableGet
|
||||
{
|
||||
ProductTableName = productTable.ProductTableName,
|
||||
ProductTableId = productTable.Id.ToString(),
|
||||
CompanyTableId = productTable.CompanyTableId.ToString(),
|
||||
ProductTableId = productTable.Id.ToString()
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue