Class GastroSkyControllerBase
- Namespace
- GastroSky.Controllers
- Assembly
- GastroSky.dll
Base class for all API controllers throughout the GastroSky project.
public class GastroSkyControllerBase : ControllerBase
- Inheritance
-
GastroSkyControllerBase
- Derived
- Inherited Members
Methods
BadRequest(params (string, string)[])
Adds one or more errors about the ModelState to an RFC 7807 compliant response body. Check out RFC 7807 for more details about this standardized error response body format.
protected IActionResult BadRequest(params (string, string)[] errors)
Parameters
errors(string, string)[]One or more error tuples, where the first tuple item is the name of the problematic query parameter in question (ideally, this is the exact name of the request body's DTO field; you can use C#'s
nameofoperator to always get this right 100% of the times) and the second item the desired error message to return.
Returns
EnvelopeBadRequest(string)
protected IActionResult EnvelopeBadRequest(string error)
Parameters
errorstring
Returns
EnvelopeCreated<T>(string, long, ICollection<T>)
Wraps one or more successfully created items into the ResponseBodyDto<T> envelope response body DTO to return alongside the 201 status code.
protected IActionResult EnvelopeCreated<T>(string uri, long totalItems, ICollection<T> items)
Parameters
uristringThe URI under which the created resource is now accessible.
totalItemslongTotal amount of items that were created.
itemsICollection<T>Response DTOs for the created items.
Returns
Type Parameters
TThe type of DTO associated with the created resource.
EnvelopeCreated<T>(string, long, params T[])
Wraps one or more successfully created items into the ResponseBodyDto<T> envelope response body DTO to return alongside the 201 status code.
protected IActionResult EnvelopeCreated<T>(string uri, long totalItems, params T[] items)
Parameters
uristringThe URI under which the created resource is now accessible.
totalItemslongTotal amount of items that were created.
itemsT[]Response DTOs for the created items.
Returns
Type Parameters
TThe type of DTO associated with the created resource.
EnvelopeError(int, string)
protected IActionResult EnvelopeError(int httpCode, string error)
Parameters
Returns
EnvelopeOk<T>(long, ICollection<T>)
Wraps one or more result items into the ResponseBodyDto<T> envelope response body DTO.
protected IActionResult EnvelopeOk<T>(long totalItems, ICollection<T> items)
Parameters
totalItemslongTotal amount of potentially "fetchable" items, given the passed query parameters, with any filters applied etc....
itemsICollection<T>Items returned for this query (could be a page of 10 items, or could be all of them) with filters and query params applied and all...
Returns
Type Parameters
TThe type of item to wrap into the envelope response body.
EnvelopeOk<T>(long, params T[])
Wraps one or more result items into the ResponseBodyDto<T> envelope response body DTO.
protected IActionResult EnvelopeOk<T>(long totalItems, params T[] items)
Parameters
totalItemslongTotal amount of potentially "fetchable" items, given the passed query parameters, with any filters applied etc....
itemsT[]Items returned for this query (could be a page of 10 items, or could be all of them) with filters and query params applied and all...
Returns
Type Parameters
TThe type of item to wrap into the envelope response body.
FetchCompanyProfilePicture(IConfiguration, IRemoteFileStorage, Company)
protected Task<byte[]?> FetchCompanyProfilePicture(IConfiguration configuration, IRemoteFileStorage remoteFileStorage, Company company)
Parameters
configurationIConfigurationremoteFileStorageIRemoteFileStoragecompanyCompany
Returns
FilterPosts(IQueryable<Post>, Dictionary<string, Dictionary<string, string>>)
protected IQueryable<Post> FilterPosts(IQueryable<Post> query, Dictionary<string, Dictionary<string, string>> filters)
Parameters
queryIQueryable<Post>filtersDictionary<string, Dictionary<string, string>>
Returns
Forbidden()
protected IActionResult Forbidden()
Returns
GetCompany(GastroSkyDatabaseContext, string, bool)
protected Task<Company?> GetCompany(GastroSkyDatabaseContext db, string companySlug, bool asNoTracking = true)
Parameters
dbGastroSkyDatabaseContextcompanySlugstringasNoTrackingbool
Returns
GetUser(GastroSkyDatabaseContext, bool)
Queries the db to get the user specified in the auth token.
protected Task<User?> GetUser(GastroSkyDatabaseContext db, bool asNoTracking = true)
Parameters
dbGastroSkyDatabaseContextasNoTrackingboolShould the query be executed "as no tracking"? Set this to
trueif you're 100% sure that it will be exclusively read-only access.
Returns
SortPosts(IQueryable<Post>, Dictionary<string, SortingOrder>)
protected IQueryable<Post> SortPosts(IQueryable<Post> query, Dictionary<string, SortingOrder> sortBy)
Parameters
queryIQueryable<Post>sortByDictionary<string, SortingOrder>
Returns
TryUpdateDb(GastroSkyDatabaseContext, IActionResult)
protected Task<IActionResult> TryUpdateDb(GastroSkyDatabaseContext db, IActionResult onSuccess)
Parameters
dbGastroSkyDatabaseContextonSuccessIActionResult