Skip to content

Commit

Permalink
Merge pull request #50 from Learnathon-By-Geeky-Solutions/frontend/debug
Browse files Browse the repository at this point in the history
User module Controllers seperated
  • Loading branch information
SaiemAziz authored Feb 22, 2025
2 parents 013d3c7 + d337991 commit 4584cca
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MentorConnect.BuildingBlocks.SharedKernel.DTOs.Users;

public class CreateAdminDto
public class CreateUpdateAdminDto
{
public Guid Id { get; set; }
public string? Extra { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MentorConnect.BuildingBlocks.SharedKernel.DTOs.Users;

public class CreateMenteeDto
public class CreateUpdateMenteeDto
{
public Guid Id { get; set; }
public string? Extra { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MentorConnect.BuildingBlocks.SharedKernel.DTOs.Users;

public class CreateMentorDto
public class CreateUpdateMentorDto
{
public Guid Id { get; set; }
public string? Extra { get; set; }
Expand Down
1 change: 1 addition & 0 deletions backend/MentorConnect.API/MentorConnect.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Scalar.AspNetCore" Version="2.0.14" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using MentorConnect.BuildingBlocks.SharedKernel.DTOs.Users;
using MentorConnect.Users.Application.Contracts;
using Microsoft.AspNetCore.Mvc;

namespace MentorConnect.Users.API.Controllers;

[Route("api/admins")]
[ApiController]
public class AdminControllers(IUserServices userServices) : ControllerBase
{
private readonly IUserServices _userServices = userServices;
[HttpGet]
public async Task<ActionResult<List<GetAdminDto>>> GetAdmins()
{
return await _userServices.GetAllAdmins();
}
[HttpGet("{id:guid}")]
public async Task<ActionResult<GetAdminDto>> GetAdminById([FromRoute] Guid id)
{
var allAdmins = await _userServices.GetAllAdmins();
var result = allAdmins.FirstOrDefault(admin => admin.Id == id);
if (result == null)
{
return NotFound();
}
return result;
}
[HttpPost]
public async Task<ActionResult<GetAdminDto>> AddAdmin([FromBody] CreateUpdateAdminDto admin)
{
var result = await _userServices.AddAdmin(admin);
return result;
}
[HttpPut("{id:guid}")]
public async Task<ActionResult> UpdateAdmin([FromRoute] Guid id, [FromBody] CreateUpdateAdminDto admin)
{
if (id != admin.Id)
{
return BadRequest();
}
await _userServices.UpdateAdmin(admin);
return NoContent();
}
[HttpDelete("{id:guid}")]
public async Task<ActionResult> DeleteAdmin([FromRoute] Guid id)
{
await _userServices.DeleteAdmin(id);
return NoContent();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using MentorConnect.BuildingBlocks.SharedKernel.DTOs.Users;
using MentorConnect.Users.Application.Contracts;
using Microsoft.AspNetCore.Mvc;
namespace MentorConnect.Users.API.Controllers;

[Route("api/mentees")]
[ApiController]
public class MenteeControllers(IUserServices userServices) : ControllerBase
{
private readonly IUserServices _userServices = userServices;
[HttpGet]
public async Task<ActionResult<List<GetMenteeDto>>> GetMentees()
{
return await _userServices.GetAllMentees();
}
[HttpGet("{id:guid}")]
public async Task<ActionResult<GetMenteeDto>> GetMenteeById([FromRoute] Guid id)
{
var allMentees = await _userServices.GetAllMentees();
var result = allMentees.FirstOrDefault(mentee => mentee.Id == id);
if (result == null)
{
return NotFound();
}
return result;
}
[HttpPost]
public async Task<ActionResult<GetMenteeDto>> AddMentee([FromBody] CreateUpdateMenteeDto mentee)
{
var result = await _userServices.AddMentee(mentee);
return result;
}
[HttpPut("{id:guid}")]
public async Task<ActionResult> UpdateMentee([FromRoute] Guid id, [FromBody] CreateUpdateMenteeDto mentee)
{
if (id != mentee.Id)
{
return BadRequest();
}
await _userServices.UpdateMentee(mentee);
return NoContent();
}
[HttpDelete("{id:guid}")]
public async Task<ActionResult> DeleteMentee([FromRoute] Guid id)
{
await _userServices.DeleteMentee(id);
return NoContent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using MentorConnect.BuildingBlocks.SharedKernel.DTOs.Users;
using MentorConnect.Users.Application.Contracts;
using Microsoft.AspNetCore.Mvc;
namespace MentorConnect.Users.API.Controllers;
[Route("api/mentors")]
[ApiController]
public class MentorControllers(IUserServices userServices) : ControllerBase
{
private readonly IUserServices _userServices = userServices;
[HttpGet]
public async Task<ActionResult<List<GetMentorDto>>> GetMentors()
{
return await _userServices.GetAllMentors();
}
[HttpGet("{id:guid}")]
public async Task<ActionResult<GetMentorDto>> GetMentorById([FromRoute] Guid id)
{
var allMentors = await _userServices.GetAllMentors();
var result = allMentors.FirstOrDefault(mentor => mentor.Id == id);
if (result == null)
{
return NotFound();
}
return result;
}
[HttpPost]
public async Task<ActionResult<GetMentorDto>> AddMentor([FromBody] CreateUpdateMentorDto mentor)
{
var result = await _userServices.AddMentor(mentor);
return result;
}
[HttpPut("{id:guid}")]
public async Task<ActionResult> UpdateMentor([FromRoute] Guid id, [FromBody] CreateUpdateMentorDto mentor)
{
if (id != mentor.Id)
{
return BadRequest();
}
await _userServices.UpdateMentor(mentor);
return NoContent();
}
[HttpDelete("{id:guid}")]
public async Task<ActionResult> DeleteMentor([FromRoute] Guid id)
{
await _userServices.DeleteMentor(id);
return NoContent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using MentorConnect.BuildingBlocks.SharedKernel.DTOs.Users;
using MentorConnect.Users.Application.Contracts;
using Microsoft.AspNetCore.Mvc;

namespace MentorConnect.Users.API.Controllers;

[Route("api/users")]
[ApiController]
public class UserController(IUserServices userServices) : ControllerBase
{
private readonly IUserServices _userServices = userServices;
[HttpGet]
public async Task<ActionResult<List<GetUserDto>>> GetUsers()
{
return await _userServices.GetAllUsers();
}

[HttpGet("{id:guid}")]
public async Task<ActionResult<GetUserDto>> GetUserById([FromRoute] Guid id)
{
GetUserDto? user = await _userServices.GetUserById(id);
if (user == null)
{
return NotFound();
}
return user;
}
[HttpPost]
public async Task<ActionResult<GetUserDto>> AddUser([FromBody] CreateUserDto user)
{
var result = await _userServices.AddUser(user);
return result;
}
[HttpPut("{id:guid}")]
public async Task<ActionResult> UpdateUser([FromRoute] Guid id, [FromBody] UpdateUserDto user)
{
if (id != user.Id)
{
return BadRequest();
}
await _userServices.UpdateUser(user);
return NoContent();
}
[HttpDelete("{id:guid}")]
public async Task<ActionResult> DeleteUser([FromRoute] Guid id)
{
await _userServices.DeleteUser(id);
return NoContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ public interface IUserServices
Task<List<GetAdminDto>> GetAllAdmins();
Task<GetUserDto?> GetUserById(Guid id);
Task<GetUserDto> AddUser(CreateUserDto userInfo);
Task<GetAdminDto> AddAdmin(CreateAdminDto adminInfo);
Task<GetMenteeDto> AddMentee(CreateMenteeDto menteeInfo);
Task<GetMentorDto> AddMentor(CreateMentorDto mentorInfo);
Task<GetAdminDto> AddAdmin(CreateUpdateAdminDto adminInfo);
Task<GetMenteeDto> AddMentee(CreateUpdateMenteeDto menteeInfo);
Task<GetMentorDto> AddMentor(CreateUpdateMentorDto mentorInfo);
Task UpdateUser(UpdateUserDto userInfo);
Task DeleteUser(Guid id);
Task UpdateAdmin(CreateUpdateAdminDto adminInfo);
Task DeleteAdmin(Guid id);
Task UpdateMentor(CreateUpdateMentorDto mentorInfo);
Task DeleteMentor(Guid id);
Task UpdateMentee(CreateUpdateMenteeDto menteeInfo);
Task DeleteMentee(Guid id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public AdminProfile()
CreateMap<Admin, GetAdminDto>()
.ForMember(dest => dest.User, opt => opt.MapFrom(src => src.User));
CreateMap<Admin, AdminDto>();
CreateMap<CreateAdminDto, Admin>();
CreateMap<CreateUpdateAdminDto, Admin>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public MenteeProfile()
CreateMap<Mentee, GetMenteeDto>()
.ForMember(dest => dest.User, opt => opt.MapFrom(src => src.User));
CreateMap<Mentee, MenteeDto>();
CreateMap<CreateMenteeDto, Mentee>();
CreateMap<CreateUpdateMenteeDto, Mentee>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public MentorProfile()
CreateMap<Mentor, GetMentorDto>()
.ForMember(dest => dest.User, opt => opt.MapFrom(src => src.User));
CreateMap<Mentor, MentorDto>();
CreateMap<CreateMentorDto, Mentor>();
CreateMap<CreateUpdateMentorDto, Mentor>();
}
}
Loading

0 comments on commit 4584cca

Please sign in to comment.