@@ -28,7 +28,7 @@ public PlayOfferController(IMediator mediator)
28
28
/// <response code="200">Returns a list of Play offers matching the query params</response>
29
29
/// <response code="204">No Play offer with matching properties was found</response>
30
30
[ HttpGet ]
31
- [ Authorize ]
31
+ [ Authorize ( Roles = "MEMBER,ADMIN" ) ]
32
32
[ Route ( "club" ) ]
33
33
[ ProducesResponseType ( typeof ( IEnumerable < PlayOfferDto > ) , StatusCodes . Status200OK ) ]
34
34
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status204NoContent ) ]
@@ -52,15 +52,15 @@ public async Task<ActionResult<IEnumerable<PlayOfferDto>>> GetByClubIdAsync()
52
52
///<response code="200">Returns a list of Play offers matching the query params</response>
53
53
///<response code="204">No Play offer with matching properties was found</response>
54
54
[ HttpGet ]
55
- [ Authorize ]
55
+ [ Authorize ( Roles = "MEMBER,ADMIN" ) ]
56
56
[ Route ( "participant" ) ]
57
57
[ ProducesResponseType ( typeof ( IEnumerable < PlayOffer > ) , StatusCodes . Status200OK ) ]
58
58
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status204NoContent ) ]
59
59
[ Consumes ( "application/json" ) ]
60
60
[ Produces ( "application/json" ) ]
61
61
public async Task < ActionResult < IEnumerable < PlayOfferDto > > > GetByParticipantIdAsync ( )
62
62
{
63
- var participantId = Guid . Parse ( User . FindFirst ( ClaimTypes . NameIdentifier ) . Value ) ;
63
+ var participantId = Guid . Parse ( User . FindFirst ( "sub" ) ! . Value ) ;
64
64
var result = await _mediator . Send ( new GetPlayOffersByParticipantIdQuery ( participantId ) ) ;
65
65
66
66
if ( result . Count ( ) == 0 )
@@ -77,7 +77,7 @@ public async Task<ActionResult<IEnumerable<PlayOfferDto>>> GetByParticipantIdAsy
77
77
///<response code="200">Returns a List of Play offers with creator matching the query params</response>
78
78
///<response code="204">No Play offers with matching creator was found</response>
79
79
[ HttpGet ]
80
- [ Authorize ]
80
+ [ Authorize ( Roles = "MEMBER,ADMIN" ) ]
81
81
[ Route ( "search" ) ]
82
82
[ ProducesResponseType ( typeof ( IEnumerable < PlayOffer > ) , StatusCodes . Status200OK ) ]
83
83
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status204NoContent ) ]
@@ -112,17 +112,14 @@ public async Task<ActionResult<IEnumerable<PlayOfferDto>>> GetByCreatorNameAsync
112
112
///<response code="400">Invalid Play Offer structure</response>
113
113
///<response code="401">Only members can create Play Offers</response>
114
114
[ HttpPost ]
115
- [ Authorize ]
115
+ [ Authorize ( Roles = "MEMBER" ) ]
116
116
[ ProducesResponseType ( typeof ( PlayOffer ) , StatusCodes . Status201Created ) ]
117
117
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status400BadRequest ) ]
118
118
[ Consumes ( "application/json" ) ]
119
119
[ Produces ( "application/json" ) ]
120
120
public async Task < ActionResult < PlayOffer > > Create ( CreatePlayOfferDto createPlayOfferDto )
121
121
{
122
- if ( User . Claims . First ( c => c . Type == "groups" ) . Value != "MEMBER" )
123
- return Unauthorized ( "Only members can create Play Offers!" ) ;
124
-
125
- var creatorId = Guid . Parse ( User . FindFirst ( ClaimTypes . NameIdentifier ) ! . Value ) ;
122
+ var creatorId = Guid . Parse ( User . FindFirst ( "sub" ) ! . Value ) ;
126
123
var clubId = Guid . Parse ( User . FindFirst ( "tennisClubId" ) ! . Value ) ;
127
124
128
125
Guid result ;
@@ -147,17 +144,14 @@ public async Task<ActionResult<PlayOffer>> Create(CreatePlayOfferDto createPlayO
147
144
///<response code="400">No Play Offer with matching id found</response>
148
145
///<response code="401">Only creator can cancel Play Offers</response>
149
146
[ HttpDelete ]
150
- [ Authorize ]
147
+ [ Authorize ( Roles = "MEMBER" ) ]
151
148
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status200OK ) ]
152
149
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status400BadRequest ) ]
153
150
[ Consumes ( "application/json" ) ]
154
151
[ Produces ( "application/json" ) ]
155
152
public async Task < ActionResult > Delete ( Guid playOfferId )
156
153
{
157
- if ( User . Claims . First ( c => c . Type == "groups" ) . Value != "MEMBER" )
158
- return Unauthorized ( "Only members can cancel Play Offers!" ) ;
159
-
160
- var memberId = Guid . Parse ( User . FindFirst ( ClaimTypes . NameIdentifier ) ! . Value ) ;
154
+ var memberId = Guid . Parse ( User . FindFirst ( "sub" ) ! . Value ) ;
161
155
162
156
try
163
157
{
@@ -184,18 +178,15 @@ public async Task<ActionResult> Delete(Guid playOfferId)
184
178
///<response code="400">No playOffer with a matching playOfferId found</response>
185
179
///<response code="401">Only members can join Play Offers</response>
186
180
[ HttpPost ]
187
- [ Authorize ]
181
+ [ Authorize ( Roles = "MEMBER" ) ]
188
182
[ Route ( "join" ) ]
189
183
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status200OK ) ]
190
184
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status400BadRequest ) ]
191
185
[ Consumes ( "application/json" ) ]
192
186
[ Produces ( "application/json" ) ]
193
187
public async Task < ActionResult > Join ( JoinPlayOfferDto joinPlayOfferDto )
194
188
{
195
- if ( User . Claims . First ( c => c . Type == "groups" ) . Value != "MEMBER" )
196
- return Unauthorized ( "Only members can join Play Offers!" ) ;
197
-
198
- var memberId = Guid . Parse ( User . FindFirst ( ClaimTypes . NameIdentifier ) ! . Value ) ;
189
+ var memberId = Guid . Parse ( User . FindFirst ( "sub" ) ! . Value ) ;
199
190
try
200
191
{
201
192
await _mediator . Send ( new JoinPlayOfferCommand ( joinPlayOfferDto , memberId ) ) ;
0 commit comments