Skip to content

Commit

Permalink
Start with delete blog endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
oveldman committed Aug 23, 2023
1 parent d0afb37 commit eef33d8
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Net;
using LanguageExt;
using LanguageExt.Common;
using MadWorld.Backend.API.Shared.Authorization;
using MadWorld.Backend.API.Shared.OpenAPI;
using MadWorld.Shared.Contracts.Anonymous.Blog;
using MadWorld.Shared.Contracts.Authorized.Account;
using MadWorld.Shared.Contracts.Authorized.Blog;
using MadWorld.Shared.Contracts.Shared.Authorization;
using MadWorld.Shared.Contracts.Shared.Functions;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
using Microsoft.OpenApi.Models;

namespace MadWorld.Backend.API.Authorized.Functions.Blog;

public class DeleteBlog
{
public DeleteBlog()
{
}


[Authorize(RoleTypes.Admin)]
[Function("DeleteBlog")]
[OpenApiSecurity(Security.SchemeName, SecuritySchemeType.ApiKey, Name = Security.HeaderName, In = OpenApiSecurityLocationType.Header)]
[OpenApiOperation(operationId: "DeleteBlog", tags: new[] { "Blog" })]
[OpenApiParameter("id", Required = true)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(OkResponse), Description = "The OK response")]
public Result<OkResponse> Run([HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "Blog/{id}")] HttpRequestData request,
FunctionContext executionContext,
string id)
{
var deleteBlogRequest = new DeleteBlogRequest()
{
Id = id
};

return new OkResponse()
{
Message = $"Blog {deleteBlogRequest.Id} has been deleted"
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public GetBlog(IGetBlogUseCase useCase)
[OpenApiSecurity(Security.SchemeName, SecuritySchemeType.ApiKey, Name = Security.HeaderName, In = OpenApiSecurityLocationType.Header)]
[OpenApiOperation(operationId: "GetBlog", tags: new[] { "Blog" })]
[OpenApiParameter("id", Required = true)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(GetAccountResponse), Description = "The OK response")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(GetBlogResponse), Description = "The OK response")]
public Result<Option<GetBlogResponse>> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Blog/{id}")] HttpRequestData request,
FunctionContext executionContext,
string id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public GetBlogs(IGetBlogsUseCase useCase)
[OpenApiSecurity(Security.SchemeName, SecuritySchemeType.ApiKey, Name = Security.HeaderName, In = OpenApiSecurityLocationType.Header)]
[OpenApiOperation(operationId: "GetBlogs", tags: new[] { "Blog" })]
[OpenApiParameter("page", Type = typeof(int))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(GetAccountResponse), Description = "The OK response")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(GetBlogsResponse), Description = "The OK response")]
public Result<GetBlogsResponse> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Blogs/page/{page}")] HttpRequestData request,
FunctionContext executionContext,
string page)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace MadWorld.Shared.Contracts.Authorized.Blog;

public class DeleteBlogRequest
{
public string Id { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace MadWorld.Shared.Contracts.Shared.Functions;

public class OkResponse : IResponse
{
public bool IsSuccess { get; } = true;
public string Message { get; set; } = string.Empty;
}

0 comments on commit eef33d8

Please sign in to comment.