Table of Contents

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 nameof operator to always get this right 100% of the times) and the second item the desired error message to return.

Returns

IActionResult

IActionResult

EnvelopeBadRequest(string)

protected IActionResult EnvelopeBadRequest(string error)

Parameters

error string

Returns

IActionResult

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

uri string

The URI under which the created resource is now accessible.

totalItems long

Total amount of items that were created.

items ICollection<T>

Response DTOs for the created items.

Returns

IActionResult

IActionResult

Type Parameters

T

The 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

uri string

The URI under which the created resource is now accessible.

totalItems long

Total amount of items that were created.

items T[]

Response DTOs for the created items.

Returns

IActionResult

IActionResult

Type Parameters

T

The type of DTO associated with the created resource.

EnvelopeError(int, string)

protected IActionResult EnvelopeError(int httpCode, string error)

Parameters

httpCode int
error string

Returns

IActionResult

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

totalItems long

Total amount of potentially "fetchable" items, given the passed query parameters, with any filters applied etc....

items ICollection<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

IActionResult

IActionResult

Type Parameters

T

The 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

totalItems long

Total amount of potentially "fetchable" items, given the passed query parameters, with any filters applied etc....

items 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

IActionResult

IActionResult

Type Parameters

T

The 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

configuration IConfiguration
remoteFileStorage IRemoteFileStorage
company Company

Returns

Task<byte[]>

FilterPosts(IQueryable<Post>, Dictionary<string, Dictionary<string, string>>)

protected IQueryable<Post> FilterPosts(IQueryable<Post> query, Dictionary<string, Dictionary<string, string>> filters)

Parameters

query IQueryable<Post>
filters Dictionary<string, Dictionary<string, string>>

Returns

IQueryable<Post>

Forbidden()

Returns status code

403
in an RFC 7807 compliant way.
protected IActionResult Forbidden()

Returns

IActionResult

IActionResult

GetCompany(GastroSkyDatabaseContext, string, bool)

protected Task<Company?> GetCompany(GastroSkyDatabaseContext db, string companySlug, bool asNoTracking = true)

Parameters

db GastroSkyDatabaseContext
companySlug string
asNoTracking bool

Returns

Task<Company>

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

db GastroSkyDatabaseContext

GastroSkyDatabaseContext

asNoTracking bool

Should the query be executed "as no tracking"? Set this to true if you're 100% sure that it will be exclusively read-only access.

Returns

Task<User>

null if user wasn't found; otherwise User

SortPosts(IQueryable<Post>, Dictionary<string, SortingOrder>)

protected IQueryable<Post> SortPosts(IQueryable<Post> query, Dictionary<string, SortingOrder> sortBy)

Parameters

query IQueryable<Post>
sortBy Dictionary<string, SortingOrder>

Returns

IQueryable<Post>

TryUpdateDb(GastroSkyDatabaseContext, IActionResult)

protected Task<IActionResult> TryUpdateDb(GastroSkyDatabaseContext db, IActionResult onSuccess)

Parameters

db GastroSkyDatabaseContext
onSuccess IActionResult

Returns

Task<IActionResult>