Skip to content

Commit

Permalink
Merge branch 'Dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddxkalin committed Jan 28, 2024
2 parents 1a42559 + 8893cee commit ba713fc
Show file tree
Hide file tree
Showing 70 changed files with 2,865 additions and 208 deletions.
4 changes: 2 additions & 2 deletions API/Controllers/AnimalController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
using static Application.Animal.DeleteAnimal;
using static Application.Animal.ShowAnimalToEdit;
using static Application.AnimalCategory.AllAnimalCategories;
using static Common.GeneralApplicationConstants;
using static Application.Animal.AnimalProfile;
using static Common.GeneralApplicationConstants;

//[Authorize(Roles = MatchingRoleName)]
[Authorize(Roles = MatchingRoleName)]
[ApiController]
[Route("api/[controller]")]
public class AnimalController : ControllerBase
Expand Down
64 changes: 0 additions & 64 deletions API/Controllers/BaseApiController.cs

This file was deleted.

2 changes: 1 addition & 1 deletion API/Controllers/MarketplaceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using static Application.Marketplace.AllAnimalsForSale;
using static Common.GeneralApplicationConstants;

// [Authorize(Roles = MarketplaceRoleName)]
[Authorize(Roles = MarketplaceRoleName)]
[ApiController]
[Route("api/[controller]")]
public class MarketplaceController : ControllerBase
Expand Down
2 changes: 1 addition & 1 deletion API/Controllers/MatchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace API.Controllers

using static Common.GeneralApplicationConstants;

//[Authorize(Roles = MatchingRoleName)]
[Authorize(Roles = MatchingRoleName)]
[Route("api/[controller]")]
[ApiController]
public class MatchController : ControllerBase
Expand Down
4 changes: 2 additions & 2 deletions API/Controllers/PhotoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public async Task<IActionResult> DeleteUserPhoto()
}

[HttpPost("AddAnimalPhoto/{animalId}")]
public async Task<IActionResult> AddAnimalPhoto(IFormFile[] files, [FromRoute] string animalId)
public async Task<IActionResult> AddAnimalPhoto(IFormFile file, [FromRoute] string animalId)
{
AddAnimalPhotoCommand command = new AddAnimalPhotoCommand()
{
Files = files,
File = file,
AnimalId = animalId
};

Expand Down
21 changes: 19 additions & 2 deletions API/Controllers/ProfileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;

using API.Infrastructure;
using Infrastructure;
using Application.DTOs.User;
using Application.Service.Interfaces;
using Application.Response;
using Domain;

[Authorize]
[Route("api/[controller]")]
[ApiController]
public class ProfileController : ControllerBase
{
private readonly IProfileService profileService;
private readonly UserManager<User> userManager;

public ProfileController(IProfileService profileService)
public ProfileController(IProfileService profileService,
UserManager<User> userManager)
{
this.profileService = profileService;
this.userManager = userManager;
}

[Route("")]
Expand Down Expand Up @@ -59,5 +64,17 @@ public async Task<ActionResult> DeleteRole([FromQuery] string roleName)

return Ok(result);
}

[Route("changePassword")]
[HttpPost]
public async Task<IActionResult> ChangePassword(
[FromBody] ChangePasswordDto dto)
{
var user = await userManager.GetUserAsync(User);

Result<Unit> result = await profileService.ChangePassword(dto, user!);

return Ok(result);
}
}
}
2 changes: 1 addition & 1 deletion API/Controllers/SwipeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

using static Common.GeneralApplicationConstants;

//[Authorize(Roles = MatchingRoleName)]
[Authorize(Roles = MatchingRoleName)]
[Route("api/[controller]")]
[ApiController]
public class SwipeController : ControllerBase
Expand Down
22 changes: 22 additions & 0 deletions Application/DTOs/User/ChangePasswordDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Application.DTOs.User
{
using System.ComponentModel.DataAnnotations;

using static Common.ExceptionMessages.User;
using static Common.EntityValidationConstants.User;

public class ChangePasswordDto
{
[Required]
[DataType(DataType.Password, ErrorMessage = InvalidPassword)]
public string OldPassword { get; set; } = null!;

[Required]
[DataType(DataType.Password, ErrorMessage = InvalidPassword)]
[MinLength(PasswordMinLength, ErrorMessage = InvalidPasswordLength)]
public string NewPassword { get; set; } = null!;

[Compare(nameof(NewPassword), ErrorMessage = PasswordsDoNotMatch)]
public string ConfirmPassword { get; set; } = null!;
}
}
3 changes: 2 additions & 1 deletion Application/Marketplace/ShowAnimalMarketplaceToEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using DTOs.Photo;
using Persistence.Repositories;
using Application.DTOs.Marketplace;

using static Common.ExceptionMessages.Animal;

public class ShowAnimalMarketplaceToEdit
Expand Down Expand Up @@ -37,7 +38,7 @@ public async Task<Result<ShowAnimalMarketplaceToEditDto>> Handle(ShowAnimalMarke
await repository.All<Animal>().
Include(a => a.Photos).
Include(a => a.Breed).
FirstOrDefaultAsync(a => a.AnimalId.ToString() == request.AnimalId);
FirstOrDefaultAsync();

if (animal == null)
{
Expand Down
17 changes: 9 additions & 8 deletions Application/Photo/AddAnimalPhoto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using Domain;
using Response;
using DTOs.Photo;
using Service.Interfaces;
using Persistence.Repositories;

Expand All @@ -14,14 +15,14 @@

public class AddAnimalPhoto
{
public class AddAnimalPhotoCommand : IRequest<Result<Unit>>
public class AddAnimalPhotoCommand : IRequest<Result<PhotoDto>>
{
public string AnimalId { get; set; } = null!;
public IFormFile[] Files { get; set; } = null!;
public IFormFile File { get; set; } = null!;
}

public class AddAnimalPhotoCommandHandler :
IRequestHandler<AddAnimalPhotoCommand, Result<Unit>>
IRequestHandler<AddAnimalPhotoCommand, Result<PhotoDto>>
{
private readonly IPhotoService photoService;
private readonly IRepository repository;
Expand All @@ -33,15 +34,15 @@ public AddAnimalPhotoCommandHandler(IPhotoService photoService,
this.repository = repository;
}

public async Task<Result<Unit>> Handle(AddAnimalPhotoCommand request, CancellationToken cancellationToken)
public async Task<Result<PhotoDto>> Handle(AddAnimalPhotoCommand request, CancellationToken cancellationToken)
{
IFormFile[] files = request.Files;
IFormFile files = request.File;
string animalId = request.AnimalId;

if (files == null || files.Length == 0)
{
return
Result<Unit>.Failure(EmptyPhoto);
Result<PhotoDto>.Failure(EmptyPhoto);
}

Animal? animal = await repository.
Expand All @@ -51,11 +52,11 @@ public async Task<Result<Unit>> Handle(AddAnimalPhotoCommand request, Cancellati

if (animal == null)
{
return Result<Unit>.Failure(AnimalNotFound);
return Result<PhotoDto>.Failure(AnimalNotFound);
}

var result = await photoService.
AddAnimalPhotosAsync(files, animal);
AddAnimalPhotoAsync(files, animal);

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion Application/Service/Interfaces/IPhotoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface IPhotoService
{
Task<Result<Unit>> AddUserPhotoAsync(IFormFile file, string userId);
Task<Result<Unit>> AddAnimalPhotosAsync(IFormFile[] file, Animal animal);
Task<Result<PhotoDto>> AddAnimalPhotoAsync(IFormFile file, Animal animal);
Task<Result<Unit>> DeleteAnimalPhotoAsync(Photo photo);
Task<Result<Unit>> DeleteUserPhotoAsync(Photo photo, string userId);
Task<Result<Unit>> SetAnimalMainPhotoAsync(Photo photo);
Expand Down
7 changes: 5 additions & 2 deletions Application/Service/Interfaces/IProfileService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Application.Service.Interfaces
{
using Application.DTOs.User;
using Application.Response;
using MediatR;
using Response;
using DTOs.User;
using Domain;

public interface IProfileService
{
Expand All @@ -13,5 +14,7 @@ public interface IProfileService
Task<Result<Unit>> DeleteUser(string userId);

Task<Result<Unit>> DeleteRole(string userId, string roleName);

Task<Result<Unit>> ChangePassword(ChangePasswordDto dto, User user);
}
}
Loading

0 comments on commit ba713fc

Please sign in to comment.