Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions exercise.wwwapi/DTOs/UserDTO.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
namespace exercise.wwwapi.DTOs
using exercise.wwwapi.Models;
using System.ComponentModel.DataAnnotations.Schema;

namespace exercise.wwwapi.DTOs
{
public class UserDTO
{
public int id { get; set; }
public string email { get; set; }
public string password { get; set; }
public string? firstName { get; set; }
public string? lastName { get; set; }
public string? bio { get; set; }
public string? githubUsername { get; set; }
public string? username { get; set; }
public string? Username { get; set; }
public string? Email { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? GithubUsername { get; set; }
public string? Mobile { get; set; }
public Roles? Role { get; set; }
public string? Specialism { get; set; }
public string? Bio { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public string? Photo { get; set; }
}
}
13 changes: 10 additions & 3 deletions exercise.wwwapi/Endpoints/UserEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static IResult Register(RegisterRequestDTO request, IRepository<User> se
Data = mapper.Map<UserDTO>(user)
};

return Results.Created($"/users/{response.Data.id}", response.Data);
return Results.Created($"/users/{user.Id}", response);
}

[ProducesResponseType(StatusCodes.Status200OK)]
Expand Down Expand Up @@ -132,11 +132,18 @@ private static IResult Login(LoginRequestDTO request, IRepository<User> service,
}
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public static async Task<IResult> GetUserById(IRepository<User> service, int id)
public static async Task<IResult> GetUserById(IRepository<User> service, int id, IMapper mapper)
{
var user = service.GetById(id);
if (user == null) return TypedResults.NotFound();
return TypedResults.Ok(user);

ResponseDTO<UserDTO> response = new ResponseDTO<UserDTO>
{
Message = "success",
Data = mapper.Map<UserDTO>(user)
};

return TypedResults.Ok(response);
}

[ProducesResponseType(StatusCodes.Status200OK)]
Expand Down
Loading