Skip to content

Commit

Permalink
Merge branch 'unidevs' of https://github.com/muqimjon/EcoLink into un…
Browse files Browse the repository at this point in the history
…idevs
  • Loading branch information
muqimjon committed Jan 23, 2024
2 parents 5d24d45 + ab9cfbe commit 7efba0d
Show file tree
Hide file tree
Showing 52 changed files with 390 additions and 505 deletions.

This file was deleted.

4 changes: 4 additions & 0 deletions src/backend/EcoLink.Application/Commons/Helpers/TimeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ public class TimeHelper
{
public static DateTimeOffset GetDateTime()
=> DateTimeOffset.UtcNow.AddHours(TimeConstants.UTC);

public static int GetAge(DateTimeOffset dateOfBirth)
=> DateTimeOffset.UtcNow.Year - dateOfBirth.Year - (DateTimeOffset.UtcNow < dateOfBirth.AddYears(
DateTimeOffset.UtcNow.Year - dateOfBirth.Year) ? 1 : 0);
}
2 changes: 0 additions & 2 deletions src/backend/EcoLink.Application/EcoLink.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjectionFixed" Version="5.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public record class CreateUserCommand : IRequest<int>
public CreateUserCommand(CreateUserCommand command)
{
Age = command.Age;
State = command.State;
Phone = command.Phone;
Email = command.Email;
IsBot = command.IsBot;
Expand Down Expand Up @@ -40,6 +41,7 @@ public CreateUserCommand(CreateUserCommand command)
public string LanguageCode { get; set; } = string.Empty;
public long ChatId { get; set; }
public bool IsBot { get; set; }
public State State { get; set; }
}

public class CreateUserCommandHandler(IRepository<User> repository, IMapper mapper) : IRequestHandler<CreateUserCommand, int>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public CreateUserWithReturnCommand(CreateUserWithReturnCommand command)
Address = command.Address;
Username = command.Username;
LastName = command.LastName;
FirstName = command.FirstName;
Languages = command.Languages;
FirstName = command.FirstName;
TelegramId = command.TelegramId;
Patronomyc = command.Patronomyc;
Profession = command.Profession;
Experience = command.Experience;
Profession = command.Profession;
DateOfBirth = command.DateOfBirth;
LanguageCode = command.LanguageCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public UpdateUserCommand(UpdateUserCommand command)
Phone = command.Phone;
Email = command.Email;
IsBot = command.IsBot;
State = command.State;
Degree = command.Degree;
ChatId = command.ChatId;
Address = command.Address;
Expand Down Expand Up @@ -39,7 +38,6 @@ public UpdateUserCommand(UpdateUserCommand command)
public string Languages { get; set; } = string.Empty;
public string Experience { get; set; } = string.Empty;
public UserProfession Profession { get; set; }
public State State { get; set; }
public long TelegramId { get; set; }
public string UserName { get; set; } = string.Empty;
public string LanguageCode { get; set; } = string.Empty;
Expand Down
3 changes: 1 addition & 2 deletions src/backend/EcoLink.Application/Users/DTOs/UserResultDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ public class UserResultDto
public string Languages { get; set; } = string.Empty;
public string Experience { get; set; } = string.Empty;
public UserProfession Profession { get; set; }
public State State { get; set; }
public long TelegramId { get; set; }
public string Username { get; set; } = string.Empty;
public string UserName { get; set; } = string.Empty;
public string LanguageCode { get; set; } = string.Empty;
public long ChatId { get; set; }
public bool IsBot { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ public record GetAllUsersQuery : IRequest<IEnumerable<UserResultDto>>
public class GetAllUsersQueryHandler(IRepository<User> repository, IMapper mapper) : IRequestHandler<GetAllUsersQuery, IEnumerable<UserResultDto>>
{
public async Task<IEnumerable<UserResultDto>> Handle(GetAllUsersQuery request, CancellationToken cancellationToken)
=> mapper.Map<IEnumerable<UserResultDto>>(await Task.Run(() => repository.SelectAll()))
?? throw new NotFoundException($"User is not found with ID = {request.Id}");
=> mapper.Map<IEnumerable<UserResultDto>>(await Task.Run(() => repository.SelectAll()));
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,13 @@
using EcoLink.Application.Investors.DTOs;
using EcoLink.Application.Entrepreneurs.DTOs;
using EcoLink.Application.ProjectManagers.DTOs;
using EcoLink.Application.Representatives.DTOs;

namespace EcoLink.Application.Users.Queries.GetUsers;
namespace EcoLink.Application.Users.Queries.GetUsers;

public record GetUserByTelegramIdQuery : IRequest<UserResultDto>
{
public GetUserByTelegramIdQuery(long telegramId) { TelegramId = telegramId; }
public long TelegramId { get; set; }
}

public class GetUserByTelegramIdQueryHandler(IMapper mapper,
IRepository<User> repository,
IRepository<Investor> investorRepository,
IRepository<Entrepreneur> entrepreneurRepository,
IRepository<Representative> representativeRepository,
IRepository<ProjectManager> projectManagerRepository) :
IRequestHandler<GetUserByTelegramIdQuery, UserResultDto>
public class GetUserByTelegramIdQueryHandler(IRepository<User> repository, IMapper mapper) : IRequestHandler<GetUserByTelegramIdQuery, UserResultDto>
{
public async Task<UserResultDto> Handle(GetUserByTelegramIdQuery request, CancellationToken cancellationToken)
{
var resultDto = mapper.Map<UserResultDto>(await repository.SelectAsync(i => i.TelegramId == request.TelegramId))
?? throw new NotFoundException($"User is not found with Telegram ID = {request.TelegramId}");

switch(resultDto.Profession)
{
case UserProfession.Investor:
resultDto.Application = mapper.Map<InvestorResultDto>(await investorRepository.SelectAsync(i => i.UserId == resultDto.Id));
break;
case UserProfession.Entrepreneur:
resultDto.Application = mapper.Map<EntrepreneurResultDto>(await entrepreneurRepository.SelectAsync(i => i.UserId == resultDto.Id));
break;
case UserProfession.Representative:
resultDto.Application = mapper.Map<RepresentativeResultDto>(await representativeRepository.SelectAsync(i => i.UserId == resultDto.Id));
break;
case UserProfession.ProjectManager:
resultDto.Application = mapper.Map<ProjectManagerResultDto>(await projectManagerRepository.SelectAsync(i => i.UserId == resultDto.Id));
break;
};
return resultDto;
}
=> mapper.Map<UserResultDto>(await repository.SelectAsync(i => i.TelegramId == request.TelegramId));
}
7 changes: 0 additions & 7 deletions src/backend/EcoLink.Domain/Configurations/Filter.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/backend/EcoLink.Domain/Configurations/PaginationMetaData.cs

This file was deleted.

13 changes: 0 additions & 13 deletions src/backend/EcoLink.Domain/Configurations/PaginationParams.cs

This file was deleted.

5 changes: 2 additions & 3 deletions src/backend/EcoLink.Domain/Enums/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public enum State
{
NewUser,
None,
WaitingForSubmitApplication,
WaitingForSelectLanguage,
Expand All @@ -12,7 +11,6 @@ public enum State
WaitingForSelectProfession,
WaitingForEnterPatronomyc,
WaitingForEnterDateOfBirth,
WaitingForEnterAge,
WaitingForEnterDegree,
WaitingForEnterSector,
WaitingForEnterInvestmentAmount,
Expand All @@ -32,11 +30,12 @@ public enum State
WaitingForEnterProjectDirection,
WaitingForSelectSettings,
WaitingForSelectForFeedback,
WaitingForSelectForEditPersonalInfo,
WaitingForSelectPersonalInfo,
WaitingForFeedbackForOrganization,
WaitingForFeedbackForTelegramBot,
WaitingForSelectEntrepreneurshipMenu,
WaitingForSelectInvestmentMenu,
WaitingForSelectProjectManagementMenu,
WaitingForSelectRepresentationMenu,
WaitingForEnterAge,
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ public class EntrepreneursController(IMediator mediator) : BaseController
{
[HttpPost("create")]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
public async Task<IActionResult> Create(CreateEntrepreneurCommand command, CancellationToken cancellationToken = default)
=> Ok(await mediator.Send(new CreateEntrepreneurCommand(command), cancellationToken));
public async Task<IActionResult> Create(CreateEntrepreneurCommand command)
=> Ok(await mediator.Send(new CreateEntrepreneurCommand(command)));

[HttpPost("create-with-return")]
[ProducesResponseType(typeof(EntrepreneurResultDto), StatusCodes.Status200OK)]
public async Task<IActionResult> Create(CreateEntrepreneurshipAppWithReturnCommand command, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new CreateEntrepreneurshipAppWithReturnCommand(command), cancellationToken) });
public async Task<IActionResult> Create(CreateEntrepreneurshipAppWithReturnCommand command)
=> Ok(await mediator.Send(new CreateEntrepreneurshipAppWithReturnCommand(command)));

[HttpPut("update")]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
public async Task<IActionResult> Update(UpdateEntrepreneurCommand command, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new UpdateEntrepreneurCommand(command), cancellationToken) });
public async Task<IActionResult> Update(UpdateEntrepreneurCommand command)
=> Ok(await mediator.Send(new UpdateEntrepreneurCommand(command)));

[HttpDelete("delete/{id:long}")]
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
public async Task<IActionResult> Delete(long id, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new DeleteEntrepreneurCommand(id), cancellationToken) });
public async Task<IActionResult> Delete(long id)
=> Ok(await mediator.Send(new DeleteEntrepreneurCommand(id)));

[HttpGet("get/{id:long}")]
[ProducesResponseType(typeof(EntrepreneurResultDto), StatusCodes.Status200OK)]
public async Task<IActionResult> Get(long id, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new GetEntrepreneurQuery(id), cancellationToken) });
public async Task<IActionResult> Get(long id)
=> Ok(await mediator.Send(new GetEntrepreneurQuery(id)));

[HttpGet("get-by-userId/{userId:long}")]
[ProducesResponseType(typeof(EntrepreneurResultDto), StatusCodes.Status200OK)]
public async Task<IActionResult> GetByUserId(long userId, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new GetEntrepreneurByUserIdQuery(userId), cancellationToken) });
public async Task<IActionResult> GetByUserId(long userId)
=> Ok(await mediator.Send(new GetEntrepreneurByUserIdQuery(userId)));

[HttpGet("get-all")]
[ProducesResponseType(typeof(IEnumerable<EntrepreneurResultDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> GetAll(CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new GetAllEntrepreneursQuery(), cancellationToken) });
public async Task<IActionResult> GetAll()
=> Ok(await mediator.Send(new GetAllEntrepreneursQuery()));
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using EcoLink.Application.Entrepreneurs.Commands.CreateEntrepreneurs;
using EcoLink.Application.EntrepreneurshipApps.Queries.GetEntrepreneurshipApp;


namespace EcoLink.WebApi.Controllers.Entrepreneurship;

public class EntrepreneurshipAppsController(IMediator mediator) : BaseController
{
[HttpPost("create")]
public async Task<IActionResult> Create(CreateEntrepreneurshipAppWithReturnCommand command, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new CreateEntrepreneurshipAppWithReturnCommand(command), cancellationToken) });
public async Task<IActionResult> Create(CreateEntrepreneurshipAppWithReturnCommand command)
=> Ok(await mediator.Send(new CreateEntrepreneurshipAppWithReturnCommand(command)));

[HttpGet("get-all-by-user-id/{userId:long}")]
public async Task<IActionResult> GetAllByUserId(long userId, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new GetAllEntrepreneurshipAppsByUserIdQuery(userId), cancellationToken) });
public async Task<IActionResult> GetAllByUserId(long userId)
=> Ok(await mediator.Send(new GetAllEntrepreneurshipAppsByUserIdQuery(userId)));

[HttpGet("get/{id:long}")]
public async Task<IActionResult> Get(long id, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new GetEntrepreneurshipAppByIdCommand(id), cancellationToken) });
public async Task<IActionResult> Get(long id)
=> Ok(await mediator.Send(new GetEntrepreneurshipAppByIdCommand(id)));

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ public class InvestmentAppsController(IMediator mediator) : BaseController
{
[HttpPost("create")]
[ProducesResponseType(typeof(InvestmentAppResultDto), StatusCodes.Status200OK)]
public async Task<IActionResult> Create(CreateInvestmentAppWithReturnCommand command, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new CreateInvestmentAppWithReturnCommand(command), cancellationToken) });
public async Task<IActionResult> Create(CreateInvestmentAppWithReturnCommand command)
=> Ok(await mediator.Send(new CreateInvestmentAppWithReturnCommand(command)));

[HttpGet("get-all-by-user-userId/{userId:long}")]
[ProducesResponseType(typeof(IEnumerable<InvestmentAppResultDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> GetAllByUserId(long userId, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new GetAllInvestmentAppsByUserIdQuery(userId), cancellationToken) });
public async Task<IActionResult> GetAllByUserId(long userId)
=> Ok(await mediator.Send(new GetAllInvestmentAppsByUserIdQuery(userId)));

[HttpGet("get/{userId:long}")]
[ProducesResponseType(typeof(InvestmentAppResultDto), StatusCodes.Status200OK)]
public async Task<IActionResult> Get(long id, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new GetInvestmentAppQuery(id), cancellationToken) });
public async Task<IActionResult> Get(long id)
=> Ok(await mediator.Send(new GetInvestmentAppQuery(id)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ public class InvestorsController(IMediator mediator) : BaseController
{
[HttpPost("create")]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
public async Task<IActionResult> Create(CreateInvestorCommand command, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new CreateInvestorCommand(command), cancellationToken) });
public async Task<IActionResult> Create(CreateInvestorCommand command)
=> Ok(await mediator.Send(new CreateInvestorCommand(command)));

[HttpPost("create-with-return")]
[ProducesResponseType(typeof(InvestorResultDto), StatusCodes.Status200OK)]
public async Task<IActionResult> CreateWithReturn(CreateInvestorWithReturnCommand command, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new CreateInvestorWithReturnCommand(command), cancellationToken) });
public async Task<IActionResult> CreateWithReturn(CreateInvestorWithReturnCommand command)
=> Ok(await mediator.Send(new CreateInvestorWithReturnCommand(command)));

[HttpPut("update")]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
public async Task<IActionResult> Update(UpdateInvestorCommand command, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new UpdateInvestorCommand(command), cancellationToken) });
public async Task<IActionResult> Update(UpdateInvestorCommand command)
=> Ok(await mediator.Send(new UpdateInvestorCommand(command)));

[HttpDelete("delete/{id:long}")]
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
public async Task<IActionResult> Delete(long id, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new DeleteInvestorCommand(id), cancellationToken) });
public async Task<IActionResult> Delete(long id)
=> Ok(await mediator.Send(new DeleteInvestorCommand(id)));

[HttpGet("get/{id:long}")]
[ProducesResponseType(typeof(InvestorResultDto), StatusCodes.Status200OK)]
public async Task<IActionResult> Get(long id, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new GetInvestorQuery(id), cancellationToken) });
public async Task<IActionResult> Get(long id)
=> Ok(await mediator.Send(new GetInvestorQuery(id)));

[HttpGet("get-by-user-id/{userId:long:}")]
[ProducesResponseType(typeof(InvestorResultDto), StatusCodes.Status200OK)]
public async Task<IActionResult> GetByUserId(long userId, CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new GetInvestorByUserIdQuery(userId), cancellationToken) });
public async Task<IActionResult> GetByUserId(long userId)
=> Ok(await mediator.Send(new GetInvestorByUserIdQuery(userId)));

[HttpGet("get-all")]
[ProducesResponseType(typeof(IEnumerable<InvestorResultDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> GetAll(CancellationToken cancellationToken = default)
=> Ok(new Response { Data = await mediator.Send(new GetAllInvestorsQuery(), cancellationToken) });
public async Task<IActionResult> GetAll()
=> Ok(await mediator.Send(new GetAllInvestorsQuery()));
}
Loading

0 comments on commit 7efba0d

Please sign in to comment.