Skip to content

Commit

Permalink
New Methods
Browse files Browse the repository at this point in the history
(AddCourse, RemoveCourse) ,
Bug fixed
  • Loading branch information
Novr_wz05 authored and Novr_wz05 committed May 10, 2024
1 parent ed84067 commit 0828d41
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
26 changes: 26 additions & 0 deletions Api/Controllers/HostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ public async Task<ActionResult<bool>> AddNewBook(AddBookRequest request)
}
}

[HttpPost("AddNewCourse")]
public async Task<ActionResult<bool>> AddNewCourse(AddCourseRequest request)
{
try
{
return Ok(await _hostService.AddCourseAsync(request));
}
catch (Exception exception)
{
return BadRequest(exception.Message);
}
}

[HttpDelete("RemoveBook")]
public async Task<ActionResult<bool>> RemoveBook(string bookId)
{
Expand All @@ -40,5 +53,18 @@ public async Task<ActionResult<bool>> RemoveBook(string bookId)
return BadRequest(exception.Message);
}
}

[HttpDelete("RemoveCourse")]
public async Task<ActionResult<bool>> RemoveCourse(string courseId)
{
try
{
return Ok(await _hostService.RemoveCourseAsync(courseId));
}
catch (Exception exception)
{
return BadRequest(exception.Message);
}
}
}
}
11 changes: 8 additions & 3 deletions Infrastructure/Infrastructure/Services/HostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Application.Repositories;
using Application.Services;
using Domain.Models;
using System.Net;

namespace Infrastructure.Services;

Expand Down Expand Up @@ -51,7 +52,9 @@ public async Task<bool> AddCourseAsync(AddCourseRequest request)
Tags = request.Tags,
};

var result = await
var result = await _unitOfWork.WriteCourseRepository.AddAsync(newCourse);
await _unitOfWork.WriteCourseRepository.SaveChangesAsync();
return result;
}

public async Task<bool> BanUser(string userId)
Expand Down Expand Up @@ -80,8 +83,10 @@ public async Task<bool> RemoveBookAsync(string bookId)
return result;
}

public Task<bool> RemoveCourseAsync(string courseId)
public async Task<bool> RemoveCourseAsync(string courseId)
{
throw new NotImplementedException();
var result = await _unitOfWork.WriteCourseRepository.RemoveAsync(courseId);
await _unitOfWork.WriteCourseRepository.SaveChangesAsync();
return result;
}
}
4 changes: 3 additions & 1 deletion Infrastructure/Persistence/Repositories/UnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ namespace Persistence.Repositories;

public class UnitOfWork : IUnitOfWork
{
public UnitOfWork(IReadBookRepository readBookRepository, IWriteBookRepository writeBookRepository, IReadUserRepository readUserRepository, IWriteUserRepository writeUserRepository)
public UnitOfWork(IReadBookRepository readBookRepository, IWriteBookRepository writeBookRepository, IReadUserRepository readUserRepository, IWriteUserRepository writeUserRepository, IReadCourseRepository readCourseRepository, IWriteCourseRepository writeCourseRepository)
{
ReadBookRepository = readBookRepository;
WriteBookRepository = writeBookRepository;
ReadUserRepository = readUserRepository;
WriteUserRepository = writeUserRepository;
ReadCourseRepository = readCourseRepository;
WriteCourseRepository = writeCourseRepository;
}

public IReadBookRepository ReadBookRepository { get; }
Expand Down

0 comments on commit 0828d41

Please sign in to comment.