4 回答
TA贡献1810条经验 获得超5个赞
我会把它放在Teams
控制器中并使用类似路由的方式接收它/teams/1/users
- 其中 1 是团队 ID。这更像是“休息”:)。您需要使用注释您的 Teams 控制器操作[Route("{teamId}/users")].
但是,如果您想将其保留在用户控制器中,则使用注释团队操作[Route("some-action-name/{teamId}")]
并使用users/some-action-name/{teamId}
TA贡献1788条经验 获得超4个赞
你可以Attribute Routing试一试,这就是我的意思
[HttpGet("/{userId}")]
public async Task<IActionResult> GetByUserId(Guid userId)
[HttpGet("/{teamId}")]
public async Task<IActionResult> GetByTeamId(Guid teamId)
[HttpGet("/{teamId}")]route用参数定义一个新的teamId
TA贡献1794条经验 获得超7个赞
you need to provide action name in your url.which is unique path
像这样 https://localhost:5001/Users/GetByTeamId?teamId=4AF29C4A-282A-4FB8-8691-9D44398A97F2
TA贡献1848条经验 获得超10个赞
尝试向您的路由属性添加操作,不要忘记将操作名称添加到您的网址
namespace Sppd.TeamTuner.Controllers
{
[Authorize]
[ApiController]
[Route("[controller]/[Action]")]
public class UsersController : ControllerBase
{
private readonly ITeamTunerUserService _userService;
private readonly ITokenProvider _tokenProvider;
private readonly IAuthorizationService _authorizationService;
private readonly IMapper _mapper;
public UsersController(ITeamTunerUserService userService, ITokenProvider tokenProvider, IAuthorizationService authorizationService, IMapper mapper)
{
_userService = userService;
_tokenProvider = tokenProvider;
_authorizationService = authorizationService;
_mapper = mapper;
}
[HttpGet]
public async Task<IActionResult> GetByUserId(Guid userId)
{
// TODO: secure this call
var user = _userService.GetByIdAsync(userId);
return Ok(_mapper.Map<UserDto>(await user));
}
}
}
- 4 回答
- 0 关注
- 131 浏览
添加回答
举报