Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions DigiLearn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Transaction", "Transaction"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransactionModule", "src\Modules\Transaction\TransactionModule.csproj", "{7855A4BE-AF70-4196-BE58-661EF9BB7AF9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigiLearn.WebApi", "src\EndPoints\DigiLearn.WebApi\DigiLearn.WebApi.csproj", "{71B252BB-9EBA-4853-BDE3-6A9FC3CD5017}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -143,6 +145,10 @@ Global
{7855A4BE-AF70-4196-BE58-661EF9BB7AF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7855A4BE-AF70-4196-BE58-661EF9BB7AF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7855A4BE-AF70-4196-BE58-661EF9BB7AF9}.Release|Any CPU.Build.0 = Release|Any CPU
{71B252BB-9EBA-4853-BDE3-6A9FC3CD5017}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71B252BB-9EBA-4853-BDE3-6A9FC3CD5017}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71B252BB-9EBA-4853-BDE3-6A9FC3CD5017}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71B252BB-9EBA-4853-BDE3-6A9FC3CD5017}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -175,6 +181,7 @@ Global
{9C2E7E12-AC2A-413E-B7DB-12BEC6450A38} = {F4DF9E24-BE80-4499-8986-C615759BEDB3}
{4BA50B18-2ACF-4A17-9F72-9E125B9B6CBE} = {B3BD9597-3591-48AF-A287-50339FC5F23A}
{7855A4BE-AF70-4196-BE58-661EF9BB7AF9} = {4BA50B18-2ACF-4A17-9F72-9E125B9B6CBE}
{71B252BB-9EBA-4853-BDE3-6A9FC3CD5017} = {CDAFBBC7-33A5-4FE0-BA9D-564B07E2478E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0E3590F8-90D4-4262-8345-AACE391D9339}
Expand Down
112 changes: 112 additions & 0 deletions src/EndPoints/DigiLearn.WebApi/Controllers/BlogController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using BlogModule.Services;
using BlogModule.Services.DTOs.Command;
using BlogModule.Services.DTOs.Query;
using DigiLearn.WebApi.Infrastructure;
using DigiLearn.WebApi.Infrastructure.Security;
using DigiLearn.WebApi.Models.Blog;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Permissions;

namespace DigiLearn.WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class BlogController : ApiController
{
private readonly IBlogService _service;

public BlogController(IBlogService service)
{
_service = service;
}

#region Blog
[Authorize]
[HttpPost("CreatePost")]
public async Task<ApiResult> CreatePost([FromForm] CreatePostViewModel command)
{
return CommandResult(await _service.CreatePost(new CreatePostCommand
{
CategoryId = command.CategoryId,
ImageFile = command.ImageFile,
Description = command.Description,
Slug = command.Slug,
OwnerName = command.OwnerName,
Title = command.Title,
UserId = User.GetUserId()
}));
}

[HttpPatch("EditPost")]
public async Task<ApiResult> EditPost([FromForm] EditPostCommand command)
{
return CommandResult(await _service.EditPost(command));
}

/// <summary>
/// این متد کار حذف پست رو انجام میده
/// </summary>
/// <param name="postId"></param>
/// <example>
/// نمونه ریکوئست => api/Blog/DeletePost?{id}
/// </example>
/// <returns></returns>
[HttpDelete("DeletePost")]
public async Task<ApiResult> DeletePost(Guid postId)
{
return CommandResult(await _service.DeletePost(postId));
}

[HttpGet("GetPostById")]
public async Task<ApiResult<BlogPostDto?>> GetPostById(Guid postId)
{
return QueryResult(await _service.GetPostById(postId));
}
[HttpGet("GetPostBySlug")]
public async Task<ApiResult<BlogPostFilterItemDto?>> GetPostBySlug(string slug)
{
return QueryResult(await _service.GetPostBySlug(slug));
}
[HttpGet("GetPostsByFilter")]
public async Task<ApiResult<BlogPostFilterResult>> GetPostsByFilter(
[FromQuery] BlogPostFilterParams filterParams)
{
return QueryResult(await _service.GetPostsByFilter(filterParams));
}
#endregion

//PostCategory
#region Category
[HttpPost("CreateCategory")]
public async Task<ApiResult> CreateCategory
(CreateBlogCategoryCommand command)
{
return CommandResult(await _service.CreateCategory(command));
}
[HttpPatch("EditCategory")]
public async Task<ApiResult> EditCategory
(EditBlogCategoryCommand command)
{
return CommandResult(await _service.EditCategory(command));
}
[HttpDelete("DeleteCategory")]
public async Task<ApiResult> DeleteCategory
(Guid categoryId)
{
return CommandResult(await _service.DeleteCategory(categoryId));
}
[HttpGet("GetCategoryById")]
public async Task<ApiResult<BlogCategoryDto>> GetCategoryById(Guid categoryId)
{
return QueryResult(await _service.GetCategoryById(categoryId));
}
[HttpGet("GetAllCategories")]
public async Task<ApiResult<List<BlogCategoryDto>>> GetAllCategories()
{
return QueryResult(await _service.GetAllCategories());
}
#endregion
}
}
61 changes: 61 additions & 0 deletions src/EndPoints/DigiLearn.WebApi/Controllers/CommentController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using BlogModule.Services.DTOs.Command;
using BlogModule.Services.DTOs.Query;
using CommentModule.Services;
using CommentModule.Services.DTOs;
using DigiLearn.WebApi.Infrastructure;
using DigiLearn.WebApi.Models.Comment;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace DigiLearn.WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class CommentController : ApiController
{
private readonly ICommentService _service;

public CommentController(ICommentService service)
{
_service = service;
}


[HttpPost("CreateComment")]
public async Task<ApiResult> CreateComment(CreateCommentViewModel command)
{
return CommandResult(await _service.CreateComment(new CreateCommentCommand
{
CommentType = command.CommentType,
ParentId = command.ParentId,
EntityId = command.EntityId,
Text = command.Text,
UserId = User.GetUserId(),
}));
}

[HttpDelete("DeleteComment")]
public async Task<ApiResult> DeleteComment(Guid commentId)
{
return CommandResult(await _service.DeleteComment(commentId));
}

[HttpGet("GetCommentById")]
public async Task<ApiResult<CommentDto?>> GetCommentById(Guid commentId)
{
return QueryResult(await _service.GetCommentById(commentId));
}
[HttpGet("GetCommentByFilter")]
public async Task<ApiResult<CommentFilterResult>> GetCommentByFilter
([FromQuery] CommentFilterParams filterParams)
{
return QueryResult(await _service.GetCommentByFilter(filterParams));
}
[HttpGet("GetAllComments")]
public async Task<ApiResult<AllCommentFilterResult>> GetAllComments
([FromQuery] CommentFilterParams filterParams)
{
return QueryResult(await _service.GetAllComments(filterParams));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using CoreModule.Application.Category.AddChild;
using CoreModule.Application.Category.Create;
using CoreModule.Application.Category.Edit;
using CoreModule.Application.Course.Edit;
using CoreModule.Facade.Category;
using CoreModule.Query.Category._DTOs;
using DigiLearn.WebApi.Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace DigiLearn.WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class CourseCategoryController : ApiController
{
private readonly ICourseCategoryFacade _facade;

public CourseCategoryController(ICourseCategoryFacade facade)
{
_facade = facade;
}

#region Commands
[HttpPost("CreateCourseCategory")]
[Authorize]
public async Task<ApiResult> CreateCourseCategory(CreateCategoryCommand command)
{
return CommandResult(await _facade.Create(command));
}

[HttpPatch("EditCourseCategory")]
[Authorize]
public async Task<ApiResult> EditCourseCategory(EditCategoryCommand command)
{
return CommandResult(await _facade.Edit(command));
}

[HttpDelete("DeleteCourseCategory")]
[Authorize]
public async Task<ApiResult> DeleteCourseCategory(Guid CourseCategoryId)
{
return CommandResult(await _facade.Delete(CourseCategoryId));
}

[HttpPost("AddChildeCourseCategory")]
[Authorize]
public async Task<ApiResult> AddChildeCourseCategory(AddChildCategoryCommand command)
{
return CommandResult(await _facade.AddChild(command));
}
#endregion

#region Queries
[HttpGet("GetMainCourseCategories")]
public async Task<ApiResult<List<CourseCategoryDto>>> GetMainChildeCourseCategories()
{
return QueryResult(await _facade.GetMainCategories());
}

[HttpGet("GetByIdCourseCategory")]
public async Task<ApiResult<CourseCategoryDto?>> GetByIdChildeCourseCategory(Guid categoryId)
{
return QueryResult(await _facade.GetById(categoryId));
}

[HttpGet("GetChildrenCourseCategory")]
public async Task<ApiResult<List<CourseCategoryDto>>> GetChildrenCourseCategory(Guid parentId)
{
return QueryResult(await _facade.GetChildren(parentId));
}
#endregion
}
}
82 changes: 82 additions & 0 deletions src/EndPoints/DigiLearn.WebApi/Controllers/CourseController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using CoreModule.Application.Course.Create;
using CoreModule.Application.Course.Edit;
using CoreModule.Application.Course.Episodes.Add;
using CoreModule.Application.Course.Episodes.Delete;
using CoreModule.Application.Course.Episodes.Edit;
using CoreModule.Application.Course.Sections.AddSection;
using CoreModule.Facade.Course;
using DigiLearn.WebApi.Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace DigiLearn.WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class CourseController : ApiController
{
private readonly ICourseFacade _facade;

public CourseController(ICourseFacade facade)
{
_facade = facade;
}

[HttpPost("CreateCourse")]
[Authorize]
public async Task<ApiResult> CreateCourse(CreateCourseCommand command)
{
return CommandResult(await _facade.Create(command));
}

[HttpPatch("EditCourse")]
[Authorize]
public async Task<ApiResult> EditCourse(EditCourseCommand command)
{
return CommandResult(await _facade.Edit(command));
}

[HttpPost("AddCourseSection")]
[Authorize]
public async Task<ApiResult> AddCourseSection(AddCourseSectionCommand command)
{
return CommandResult(await _facade.AddSection(command));
}

[HttpPost("AddCourseEpisode")]
[Authorize]
public async Task<ApiResult> AddCourseEpisode(AddCourseEpisodeCommand command)
{
return CommandResult(await _facade.AddEpisode(command));
}

[HttpDelete("DeleteCourseEpisode")]
[Authorize]
public async Task<ApiResult> DeleteCourse(DeleteCourseEpisodeCommand command)
{
return CommandResult(await _facade.DeleteEpisode(command));
}

[HttpPatch("EditCourseEpisode")]
[Authorize]
public async Task<ApiResult> EditCourseEpisode(EditEpisodeCommand command)
{
return CommandResult(await _facade.EditEpisode(command));
}

[HttpPost("AddStudent")]
[Authorize]
public async Task<ApiResult> AddStudent(Guid courseId)
{
return CommandResult(await _facade.AddStudent(courseId, User.GetUserId()));
}

[HttpDelete("DeleteStudent")]
[Authorize]
public async Task<ApiResult> DeleteStudent(Guid courseId)
{
return CommandResult(await _facade.DeleteStudent(courseId, User.GetUserId()));
}
}
}
Loading