4 回答

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊
我會(huì)把它放在Teams
控制器中并使用類(lèi)似路由的方式接收它/teams/1/users
- 其中 1 是團(tuán)隊(duì) ID。這更像是“休息”:)。您需要使用注釋您的 Teams 控制器操作[Route("{teamId}/users")].
但是,如果您想將其保留在用戶(hù)控制器中,則使用注釋團(tuán)隊(duì)操作[Route("some-action-name/{teamId}")]
并使用users/some-action-name/{teamId}

TA貢獻(xiàn)1788條經(jīng)驗(yàn) 獲得超4個(gè)贊
你可以Attribute Routing試一試,這就是我的意思
[HttpGet("/{userId}")]
public async Task<IActionResult> GetByUserId(Guid userId)
[HttpGet("/{teamId}")]
public async Task<IActionResult> GetByTeamId(Guid teamId)
[HttpGet("/{teamId}")]route用參數(shù)定義一個(gè)新的teamId

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊
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貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊
嘗試向您的路由屬性添加操作,不要忘記將操作名稱(chēng)添加到您的網(wǎng)址
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 關(guān)注
- 183 瀏覽
添加回答
舉報(bào)