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 19, 2024
2 parents 15b4cd9 + 588ad11 commit 1a42559
Show file tree
Hide file tree
Showing 88 changed files with 5,105 additions and 235 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,5 @@ $RECYCLE.BIN/
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/extensions.json
/*.lutconfig
10 changes: 5 additions & 5 deletions API/Controllers/MarketplaceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
using Application.DTOs.Marketplace;

using static Application.Marketplace.GetAnimal;
using static Application.Marketplace.MyAnimalForSale;
using static Application.Marketplace.AllAnimalsForSale;
using static Application.Marketplace.MyAnimalsForSale;
using static Application.Marketplace.MyAnimalsForAdoption;
using static Application.Marketplace.AddAnimalMarketplace;
using static Application.Marketplace.EditAnimalMarketplace;
using static Application.Marketplace.AllAnimalsForAdoption;
using static Application.Marketplace.DeleteAnimalMarketplace;
using static Application.Marketplace.ShowAnimalMarketplaceToEdit;
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 Expand Up @@ -129,8 +129,8 @@ public async Task<IActionResult> GetMyAnimalsForAdoption()
[HttpGet("MyAnimalsForSale")]
public async Task<IActionResult> GetMyAnimalsForSale()
{
MyAnimalForSaleQuery query =
new MyAnimalForSaleQuery()
MyAnimalsForSaleQuery query =
new MyAnimalsForSaleQuery()
{
UserId = this.User.GetById()
};
Expand Down
3 changes: 2 additions & 1 deletion API/Controllers/PhotoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Authorization;

using Infrastructure;

using static Application.Photo.AddUserPhoto;
using static Application.Photo.AddAnimalPhoto;
using static Application.Photo.DeleteAnimalPhoto;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task<IActionResult> DeleteAnimalPhoto([FromRoute]string photoId)
{
DeleteAnimalPhotoCommand command = new DeleteAnimalPhotoCommand()
{
PublicId = photoId
PhotoId = photoId
};

var result = await mediator.Send(command);
Expand Down
10 changes: 10 additions & 0 deletions API/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,15 @@ public async Task<IActionResult> Logout()

return Ok(result);
}

[Authorize]
[Route("AllTowns")]
[HttpGet]
public async Task<IActionResult> GetAllTowns()
{
var result = await this.userService.GetAllTownsAsync();

return Ok(result);
}
}
}
2 changes: 1 addition & 1 deletion Application/Animal/AddAnimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class AddAnimal
{
public class AddAnimalCommand : IRequest<Result<Unit>>
public class AddAnimalCommand : IRequest<Result<Unit>>
{
public AddAnimalDto AnimalDto { get; set; } = null!;

Expand Down
36 changes: 18 additions & 18 deletions Application/Animal/AllAnimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,54 @@
using Microsoft.EntityFrameworkCore;

using Domain;
using Domain.Enum;
using Response;
using Persistence;
using Application.DTOs.Animal;
using Persistence.Repositories;

using static Common.ExceptionMessages.Animal;

public class AllAnimal
{
public class AllAnimalQuery : IRequest<Result<IEnumerable<AllAnimalDto>>>
public class AllAnimalQuery : IRequest<Result<IEnumerable<AllAnimalsDto>>>
{
public string OwnerId { get; set; } = null!;
}

public class AllAnimalQueryHandler :
IRequestHandler<AllAnimalQuery, Result<IEnumerable<AllAnimalDto>>>
IRequestHandler<AllAnimalQuery, Result<IEnumerable<AllAnimalsDto>>>
{
private readonly IRepository repository;
private readonly DataContext dataContext;

public AllAnimalQueryHandler(IRepository repository, DataContext dataContext)
public AllAnimalQueryHandler(IRepository repository)
{
this.repository = repository;
this.dataContext = dataContext;
}

public async Task<Result<IEnumerable<AllAnimalDto>>> Handle(AllAnimalQuery request, CancellationToken cancellationToken)
public async Task<Result<IEnumerable<AllAnimalsDto>>> Handle(AllAnimalQuery request, CancellationToken cancellationToken)
{
string userId = request.OwnerId;
User? user = await repository.
All<User>(u => u.Id.ToString() == userId).
Include(u => u.Animals).FirstOrDefaultAsync();
Include(u => u.Animals).
ThenInclude(a => a.Photos).
FirstOrDefaultAsync();

if (!(user!.Animals.Any()))
{
return Result<IEnumerable<AllAnimalDto>>.Failure(NoPets);
}

var userAnimals = await repository.
AllReadonly<Animal>(a => a.OwnerId.ToString() == userId).
Select(a => new AllAnimalDto()
var userAnimals = user!.Animals.
Where(a => a.AnimalStatus == AnimalStatus.ForSwiping).
Select(a => new AllAnimalsDto()
{
Id = a.AnimalId.ToString(),
Name = a.Name,
MainPhoto = a.Photos.First(p => p.IsMain).Url
}).ToListAsync();
}).ToList();

if (!userAnimals.Any())
{
return Result<IEnumerable<AllAnimalsDto>>.Failure(NoPets);
}

return Result<IEnumerable<AllAnimalDto>>.Success(userAnimals);
return Result<IEnumerable<AllAnimalsDto>>.Success(userAnimals);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Application/Animal/DeleteAnimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ await repository.

foreach (AnimalMatch match in animalMatch)
{
AnimalMatch[] animalMatches = await repository.All<AnimalMatch>(am => am.MatchId == match.MatchId).ToArrayAsync();
AnimalMatch[] animalMatches = repository.All<AnimalMatch>(am => am.MatchId == match.MatchId).ToArray();

Guid[] matchesIds = animalMatches.
Select(am => am.MatchId)
Expand All @@ -95,7 +95,7 @@ await repository.
try
{
await repository.SaveChangesAsync();
return Result<Unit>.Success(Unit.Value,String.Format(SuccessfullyDeleteAnimal,animal.Name));
return Result<Unit>.Success(Unit.Value, String.Format(SuccessfullyDeleteAnimal, animal.Name));
}
catch (Exception)
{
Expand Down
2 changes: 1 addition & 1 deletion Application/Animal/ShowAnimalToEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ShowAnimalToEditQueryHandler(IRepository repository)
public async Task<Result<ShowAnimalToEditDto>> Handle(ShowAnimalToEditQuery request, CancellationToken cancellationToken)
{
Animal? animal =
await repository.
await repository.
All<Animal>(a => a.AnimalId.ToString()
== request.AnimalId).
Include(a => a.Photos).
Expand Down
12 changes: 7 additions & 5 deletions Application/Breed/AllBreeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ public async Task<Result<IEnumerable<BreedDto>>> Handle(AllBreedsQuery request,
{
int categoryId = request.CategoryId;

AnimalCategory? category = await repository.GetById<AnimalCategory>(categoryId);
AnimalCategory? category = await repository.
All<AnimalCategory>(c => c.AnimalCategoryId == categoryId).Include(c => c.Breeds).
FirstOrDefaultAsync();

if (category == null)
{
return Result<IEnumerable<BreedDto>>.Failure(CategoryNotExist);
return Result<IEnumerable<BreedDto>>.
Failure(CategoryNotExist);
}

BreedDto[] breeds = await repository.
All<Breed>().Where(b => b.CategoryId == categoryId).
BreedDto[] breeds = category.Breeds.
Select(b => new BreedDto()
{
BreedId = b.BreedId,
Name = b.Name,
}).ToArrayAsync();
}).ToArray();

return Result<IEnumerable<BreedDto>>.Success(breeds);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Application.DTOs.Animal
{
public class AllAnimalDto
public class AllAnimalsDto
{
public required string Id { get; set; }

Expand Down
6 changes: 3 additions & 3 deletions Application/DTOs/Marketplace/AddAnimalMarketplaceDto.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.DTOs.Animal;

namespace Application.DTOs.Marketplace
namespace Application.DTOs.Marketplace
{
using Animal;

public class AddAnimalMarketplaceDto : AddAnimalDto
{
public bool IsForSale { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Application/DTOs/Marketplace/AllAnimalForSaleDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
using Animal;

public class AllAnimalForSaleDto : AllAnimalDto
public class AllAnimalsForSaleDto : AllAnimalsMarketplaceDto
{
public decimal? Price { get; set; }
}
Expand Down
15 changes: 15 additions & 0 deletions Application/DTOs/Marketplace/AllAnimalMarketplaceDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Application.DTOs.Marketplace
{
using Application.DTOs.Animal;

public class AllAnimalsMarketplaceDto : AllAnimalsDto
{
public string Category { get; set; } = null!;

public string Breed { get; set; } = null!;

public string Gender { get; set; } = null!;

public string City { get; set; } = null!;
}
}
2 changes: 2 additions & 0 deletions Application/DTOs/User/UserDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ public class UserDto
public string? Gender { get; set; }

public string? JobTitle { get; set; }

public string[] Roles { get; set; } = null!;
}
}
4 changes: 4 additions & 0 deletions Application/DTOs/User/UserProfileDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class UserProfileDto

public string? Photo { get; set; } = null!;

public string? Description { get; set; }

public string Token { get; set; } = null!;

public IEnumerable<string> Roles { get; set; } = null!;
}
}
4 changes: 3 additions & 1 deletion Application/Marketplace/AddAnimalMarketplace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Service.Interfaces;
using Persistence.Repositories;
using Application.DTOs.Marketplace;

using static Common.ExceptionMessages.Animal;
using static Common.SuccessMessages.Animal;

Expand Down Expand Up @@ -93,7 +94,8 @@ public async Task<Result<Unit>> Handle(AddAnimalMarketplaceCommand request, Canc
}
catch (Exception)
{
return Result<Unit>.Failure(FailedToCreate);
return Result<Unit>.
Failure(string.Format(FailedToCreate,animal.Name));
}
}
}
Expand Down
23 changes: 14 additions & 9 deletions Application/Marketplace/AllAnimalsForAdoption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@

using Domain;
using Response;
using DTOs.Animal;
using Domain.Enum;
using Persistence.Repositories;
using Application.DTOs.Marketplace;

using static Common.ExceptionMessages.Marketplace;

public class AllAnimalsForAdoption
{
public class AllAnimalsForAdoptionQuery : IRequest<Result<IEnumerable<AllAnimalDto>>>
public class AllAnimalsForAdoptionQuery : IRequest<Result<IEnumerable<AllAnimalsMarketplaceDto>>>
{
public string UserId { get; set; } = null!;
}

public class AllAnimalsForAdoptionQueryHandler : IRequestHandler<AllAnimalsForAdoptionQuery, Result<IEnumerable<AllAnimalDto>>>
public class AllAnimalsForAdoptionQueryHandler : IRequestHandler<AllAnimalsForAdoptionQuery, Result<IEnumerable<AllAnimalsMarketplaceDto>>>
{
private readonly IRepository repository;

Expand All @@ -29,25 +30,29 @@ public AllAnimalsForAdoptionQueryHandler(IRepository repository)
this.repository = repository;
}

public async Task<Result<IEnumerable<AllAnimalDto>>> Handle(AllAnimalsForAdoptionQuery request, CancellationToken cancellationToken)
public async Task<Result<IEnumerable<AllAnimalsMarketplaceDto>>> Handle(AllAnimalsForAdoptionQuery request, CancellationToken cancellationToken)
{
string userId = request.UserId;

var allAnimals = await repository
.AllReadonly<Animal>(a => a.OwnerId.ToString() != userId && a.AnimalStatus == AnimalStatus.ForAdoption).
Select(a => new AllAnimalDto()
var allAnimals = await repository.
AllReadonly<Animal>(a => a.OwnerId.ToString() != userId && a.AnimalStatus == AnimalStatus.ForAdoption).
Select(a => new AllAnimalsMarketplaceDto()
{
Id = a.AnimalId.ToString(),
MainPhoto = a.Photos.First(a => a.IsMain).Url,
Name = a.Name,
Breed = a.Breed.Name,
Category = a.Breed.Category.Name,
City = a.Owner.City!,
Gender = a.Gender.ToString(),
}).ToArrayAsync();

if (!allAnimals.Any())
{
return Result<IEnumerable<AllAnimalDto>>.Failure(NoAnimalsForAdoption);
return Result<IEnumerable<AllAnimalsMarketplaceDto>>.Failure(NoAnimalsForAdoption);
}

return Result<IEnumerable<AllAnimalDto>>.Success(allAnimals);
return Result<IEnumerable<AllAnimalsMarketplaceDto>>.Success(allAnimals);
}
}
}
Expand Down
Loading

0 comments on commit 1a42559

Please sign in to comment.