Table of Contents

Class NewsController

Namespace
GastroSky.Controllers.V1
Assembly
GastroSky.dll

Endpoints for reading and writing news articles.

[ApiController]
[Authorize]
[Route("api/v1/news")]
[Produces("application/json", new string[] { })]
public class NewsController : GastroSkyControllerBase
Inheritance
NewsController
Inherited Members

Constructors

NewsController(GastroSkyDatabaseContext, ISlugGenerator, IConfiguration, IRemoteFileStorage, IMapper, ILogger<NewsController>)

Endpoints for reading and writing news articles.

public NewsController(GastroSkyDatabaseContext db, ISlugGenerator slugGenerator, IConfiguration configuration, IRemoteFileStorage remoteFileStorage, IMapper mapper, ILogger<NewsController> logger)

Parameters

db GastroSkyDatabaseContext
slugGenerator ISlugGenerator
configuration IConfiguration
remoteFileStorage IRemoteFileStorage
mapper IMapper
logger ILogger<NewsController>

Methods

CreateNewsArticle(NewsCreationRequestDto)

Creates a news article draft.

[HttpPost]
[Authorize(Policy = "https://api.gastrosky.ch/identity/claims/resources/news:W")]
[Route("")]
[ProducesResponseType(400)]
[ProducesResponseType(403)]
[ProducesResponseType(500)]
[ProducesResponseType<ResponseBodyDto<NewsResponseDto>>(201)]
public Task<IActionResult> CreateNewsArticle(NewsCreationRequestDto dto)

Parameters

dto NewsCreationRequestDto

Request DTO containing the news article creation details. Check out the API DocFX documentation on NewsCreationRequestDto for more information.

Returns

Task<IActionResult>

IActionResult

Remarks

Sample request:

POST /api/v1/news
{
  "slug": "news01",
  "titleTranslationsJson": "JSON-string here",
  "subtitleTranslationsJson": "JSON-string here",
  "markdownTranslationsJson": "JSON-string here",
  "authorName": "Maria Bernasconi"
}

DeleteNewsArticle(string)

Deletes a news article.

[HttpDelete]
[Authorize(Policy = "https://api.gastrosky.ch/identity/claims/resources/news:R")]
[Authorize(Policy = "https://api.gastrosky.ch/identity/claims/resources/news:W")]
[Route("{slug}")]
[ProducesResponseType(204)]
[ProducesResponseType(404)]
[ProducesResponseType(500)]
public Task<IActionResult> DeleteNewsArticle(string slug)

Parameters

slug string

News article slug string.

Returns

Task<IActionResult>

IActionResult

GetHiddenNewsArticle(string)

Gets a specific news article (published or draft).

[HttpGet]
[Authorize(Policy = "https://api.gastrosky.ch/identity/claims/resources/news:R")]
[Route("hidden/{slug}")]
[ProducesResponseType(404)]
[ProducesResponseType<ResponseBodyDto<NewsResponseDto>>(200)]
public Task<IActionResult> GetHiddenNewsArticle(string slug)

Parameters

slug string

News article slug string.

Returns

Task<IActionResult>

IActionResult

GetHiddenNewsArticles(PaginationFilter?, SortingOrder)

Gets a list of news articles (published or drafts).

[HttpGet]
[Authorize(Policy = "https://api.gastrosky.ch/identity/claims/resources/news:R")]
[Route("hidden")]
[ProducesResponseType<ResponseBodyDto<NewsReducedResponseDto>>(200)]
public Task<IActionResult> GetHiddenNewsArticles(PaginationFilter? paginationFilter = null, SortingOrder sortingOrder = SortingOrder.Descending)

Parameters

paginationFilter PaginationFilter

Pagination filter. PaginationFilter

sortingOrder SortingOrder

Desired sorting order. Can be 0 for SortingOrder.Ascending or 1 for SortingOrder.Descending. SortingOrder

Returns

Task<IActionResult>

IActionResult

GetPublicNewsArticle(string)

Gets a specific public news article.

[HttpGet]
[AllowAnonymous]
[Route("{slug}")]
[ProducesResponseType(404)]
[ProducesResponseType<ResponseBodyDto<NewsResponseDto>>(200)]
public Task<IActionResult> GetPublicNewsArticle(string slug)

Parameters

slug string

News article slug string.

Returns

Task<IActionResult>

IActionResult

GetPublicNewsArticles(string?, PaginationFilter?, TimeRangeFilter?, SortingOrder)

Gets a list of public news articles with optional query filters applied.

[HttpGet]
[AllowAnonymous]
[Route("")]
[ProducesResponseType<ResponseBodyDto<NewsReducedResponseDto>>(200)]
public Task<IActionResult> GetPublicNewsArticles(string? titleFilter = null, PaginationFilter? paginationFilter = null, TimeRangeFilter? timeRangeFilter = null, SortingOrder sortingOrder = SortingOrder.Descending)

Parameters

titleFilter string

Case-insensitive article title filter.

paginationFilter PaginationFilter

Pagination filter. PaginationFilter

timeRangeFilter TimeRangeFilter

Time range filter for filtering based on the news article publication date. TimeRangeFilter

sortingOrder SortingOrder

Desired sorting order. Can be 0 for SortingOrder.Ascending or 1 for SortingOrder.Descending. SortingOrder

Returns

Task<IActionResult>

IActionResult

PublishNewsArticle(NewsPublicationRequestDto)

Publishes a news article draft.

[HttpPut]
[Authorize(Policy = "https://api.gastrosky.ch/identity/claims/resources/news:W")]
[Route("publish")]
[ProducesResponseType(400)]
[ProducesResponseType(403)]
[ProducesResponseType(500)]
[ProducesResponseType<ResponseBodyDto<NewsResponseDto>>(200)]
public Task<IActionResult> PublishNewsArticle(NewsPublicationRequestDto dto)

Parameters

dto NewsPublicationRequestDto

Request DTO containing the news article publication details. Check out the API DocFX documentation on NewsPublicationRequestDto for more information.

Returns

Task<IActionResult>

IActionResult

Remarks

Sample request:

PUT /api/v1/news/publish
{
  "slug": "news01",
  "publish": true
}

UpdateNewsArticle(NewsModificationRequestDto)

Modifies a news article draft.

[HttpPut]
[Authorize(Policy = "https://api.gastrosky.ch/identity/claims/resources/news:W")]
[Route("")]
[ProducesResponseType(400)]
[ProducesResponseType(403)]
[ProducesResponseType(500)]
[ProducesResponseType<ResponseBodyDto<NewsResponseDto>>(200)]
public Task<IActionResult> UpdateNewsArticle(NewsModificationRequestDto dto)

Parameters

dto NewsModificationRequestDto

Request DTO containing the news article modification details. Check out the API DocFX documentation on NewsModificationRequestDto for more information.

Returns

Task<IActionResult>

IActionResult

Remarks

Sample request:

PUT /api/v1/news
{
  "slug": "news01",
  "titleTranslationsJson": "JSON-string here",
  "subtitleTranslationsJson": "JSON-string here",
  "markdownTranslationsJson": "JSON-string here",
  "authorName": "Maria Bernasconi"
}