Skip to content

Commit

Permalink
salom dunyo
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrohim-qosimov committed Sep 20, 2024
1 parent 88379f5 commit 9202919
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 10 deletions.
43 changes: 43 additions & 0 deletions UrphaCapital.API/Controllers/SelectController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using UrphaCapital.Application.UseCases.Selects.Queries;

namespace UrphaCapital.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SelectController : ControllerBase
{
private readonly IMediator _mediator;

public SelectController(IMediator mediator)
{
_mediator = mediator;
}

[HttpGet("get-mentors")]
public async Task<IActionResult> GetMentors()
{
var query = new SelectAllMentorsQuery();
var result = await _mediator.Send(query);
return Ok(result);
}

[HttpGet("get-students")]
public async Task<IActionResult> GetStudents()
{
var query = new SelectAllStudentsQuery();
var result = await _mediator.Send(query);
return Ok(result);
}

[HttpGet("get-courses")]
public async Task<IActionResult> GetCourses()
{
var query = new SelectAllCoursesQuery();
var result = await _mediator.Send(query);
return Ok(result);
}
}
}
10 changes: 0 additions & 10 deletions UrphaCapital.Application/AuthServices/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ public TokenModel GenerateToken(Student user)
{
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(DateTime.UtcNow).ToString(CultureInfo.InvariantCulture), ClaimValueTypes.Integer64),
new Claim("UserId", user.Id.ToString()),
new Claim("Title", user.FullName),
new Claim("Phone", user.PhoneNumber),
new Claim("Address", user.Address),
new Claim("Email", user.Email),
new Claim("Role", user.Role!),
};

Expand Down Expand Up @@ -65,10 +61,7 @@ public TokenModel GenerateToken(Admin user)
{
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(DateTime.UtcNow).ToString(CultureInfo.InvariantCulture), ClaimValueTypes.Integer64),
new Claim("Id", user.Id.ToString()),
new Claim("Title", user.Name),
new Claim("Phone", user.PhoneNumber),
new Claim("Email", user.Email),
new Claim("Role", user.Role!)
};

Expand Down Expand Up @@ -101,10 +94,7 @@ public TokenModel GenerateToken(Mentor user)
{
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(DateTime.UtcNow).ToString(CultureInfo.InvariantCulture), ClaimValueTypes.Integer64),
new Claim("Id", user.Id.ToString()),
new Claim("Title", user.Name),
new Claim("Phone", user.PhoneNumber),
new Claim("Email", user.Email),
new Claim("Role", user.Role!)
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UrphaCapital.Application.Abstractions;
using UrphaCapital.Application.UseCases.Selects.Queries;
using UrphaCapital.Application.ViewModels;

namespace UrphaCapital.Application.UseCases.Selects.Handlers
{
public class SelectAllCoursesQueryHandler : IRequestHandler<SelectAllCoursesQuery, IEnumerable<CourseSelectModel>>
{
private readonly IApplicationDbContext _context;

public SelectAllCoursesQueryHandler(IApplicationDbContext context)
{
_context = context;
}

public async Task<IEnumerable<CourseSelectModel>> Handle(SelectAllCoursesQuery request, CancellationToken cancellationToken)
{
return await _context.Courses.OrderBy(x => x.Name).Select(x => new CourseSelectModel()
{
Title = x.Name,
Id = x.Id,
}).ToListAsync(cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using UrphaCapital.Application.Abstractions;
using UrphaCapital.Application.UseCases.Selects.Queries;
using UrphaCapital.Application.ViewModels;

namespace UrphaCapital.Application.UseCases.Selects.Handlers
{
public class SelectAllMentorsQueryHandler : IRequestHandler<SelectAllMentorsQuery, IEnumerable<MentorSelectModel>>
{
private readonly IApplicationDbContext _context;

public SelectAllMentorsQueryHandler(IApplicationDbContext context)
{
_context = context;
}

public async Task<IEnumerable<MentorSelectModel>> Handle(SelectAllMentorsQuery request, CancellationToken cancellationToken)
{
return await _context.Mentors
.OrderBy(m => m.Name)
.Select(x => new MentorSelectModel
{
FullName = x.Name,
Id = x.Id
}).ToListAsync(cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UrphaCapital.Application.Abstractions;
using UrphaCapital.Application.UseCases.Selects.Queries;
using UrphaCapital.Application.ViewModels;

namespace UrphaCapital.Application.UseCases.Selects.Handlers
{
public class SelectAllStudentsQueryHandler : IRequestHandler<SelectAllStudentsQuery, IEnumerable<StudentSelectModel>>
{
private readonly IApplicationDbContext _context;

public SelectAllStudentsQueryHandler(IApplicationDbContext context)
{
_context = context;
}

public async Task<IEnumerable<StudentSelectModel>> Handle(SelectAllStudentsQuery request, CancellationToken cancellationToken)
{
return await _context.Students.OrderBy(x => x.FullName).Select(x => new StudentSelectModel()
{
FullName = x.FullName,
Id = x.Id,
}).ToListAsync(cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UrphaCapital.Application.ViewModels;

namespace UrphaCapital.Application.UseCases.Selects.Queries
{
public class SelectAllCoursesQuery : IRequest<IEnumerable<CourseSelectModel>>
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UrphaCapital.Application.ViewModels;
using UrphaCapital.Domain.Entities.Auth;

namespace UrphaCapital.Application.UseCases.Selects.Queries
{
public class SelectAllMentorsQuery : IRequest<IEnumerable<MentorSelectModel>>
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UrphaCapital.Application.ViewModels;
using UrphaCapital.Domain.Entities.Auth;

namespace UrphaCapital.Application.UseCases.Selects.Queries
{
public class SelectAllStudentsQuery : IRequest<IEnumerable<StudentSelectModel>>
{
}
}
8 changes: 8 additions & 0 deletions UrphaCapital.Application/ViewModels/CourseSelectModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UrphaCapital.Application.ViewModels
{
public class CourseSelectModel
{
public Guid Id { get; set; }
public string Title { get; set; }
}
}
8 changes: 8 additions & 0 deletions UrphaCapital.Application/ViewModels/MentorSelectModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UrphaCapital.Application.ViewModels
{
public class MentorSelectModel
{
public long Id { get; set; }
public string FullName { get; set; }
}
}
8 changes: 8 additions & 0 deletions UrphaCapital.Application/ViewModels/StudentSelectModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UrphaCapital.Application.ViewModels
{
public class StudentSelectModel
{
public long Id { get; set; }
public string FullName { get; set; }
}
}

0 comments on commit 9202919

Please sign in to comment.