Controllers>UserController.cs
[HttpGet]
public async Task<IActionResult> GetUser([FromQuery]GetUserDto getUser)
{
var result = await _userService.GetUser(getUser);
return result;
}
Dtos>UserDto.cs
public class GetUserDto
{
[EmailAddress]
[MaxLength(100)]
[DefaultValue("XXX@gmail.com")]
public string? Email { get; set; }
}
public class GetUserResponseDto
{
public string? Username { get; set; }
public string? Phone { get; set; }
}
Services>UserService.cs
public async Task<IActionResult> GetUser(GetUserDto getUser)
{
return new JsonResult(new { status = "0" });
}
public async Task<IActionResult> GetUser(GetUserDto getUser)
{
var result = _context.UserProfiles.Where(e => e.Email.Equals(getUser.Email))
.Select(e => new GetUserResponseDto
{
Username = e.Username,
Phone = e.Phone
});
return new JsonResult(new { status = "0", UserInfo = result });
}
點擊「開始」