@@ -19,34 +19,90 @@ public PlayOfferController(IMediator mediator)
19
19
}
20
20
21
21
///<summary>
22
- ///Retrieve all Play Offers matching the query params
22
+ ///Retrieve all Play Offers of a club with a matching id
23
23
///</summary>
24
- ///<param name="playOfferId">The id of the play offer</param>
25
- ///<param name="creatorId">The id of the creator of the play offer</param>
26
24
///<param name="clubId">The id of the club of the play offer</param>
27
- ///<returns>Play offer with a matching id</returns>
28
- ///<response code="200">Returns a Play offer matching the query params</response>
25
+ ///<returns>Play offers with a matching club id</returns>
26
+ ///<response code="200">Returns a list of Play offers matching the query params</response>
29
27
///<response code="204">No Play offer with matching properties was found</response>
30
28
[ HttpGet ]
29
+ [ Route ( "club" ) ]
30
+ [ ProducesResponseType ( typeof ( IEnumerable < PlayOfferDto > ) , StatusCodes . Status200OK ) ]
31
+ [ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status204NoContent ) ]
32
+ [ Consumes ( "application/json" ) ]
33
+ [ Produces ( "application/json" ) ]
34
+ public async Task < ActionResult < IEnumerable < PlayOfferDto > > > GetByClubIdAsync ( [ FromQuery ] Guid clubId )
35
+ {
36
+ //TODO: refactor after jwt implementation to get clubId from token
37
+ var result = await _mediator . Send ( new GetPlayOffersByClubIdQuery ( clubId ) ) ;
38
+
39
+ if ( result . Count ( ) == 0 )
40
+ return NoContent ( ) ;
41
+
42
+ return Ok ( result ) ;
43
+ }
44
+
45
+ ///<summary>
46
+ ///Retrieve all Play Offers of a participating member
47
+ ///</summary>
48
+ ///<param name="participantId">The id of the member participating in the play offer</param>
49
+ ///<returns>List of Play offers with where given member is creator or opponent</returns>
50
+ ///<response code="200">Returns a list of Play offers matching the query params</response>
51
+ ///<response code="204">No Play offer with matching properties was found</response>
52
+ [ HttpGet ]
53
+ [ Route ( "participant" ) ]
54
+ [ ProducesResponseType ( typeof ( IEnumerable < PlayOffer > ) , StatusCodes . Status200OK ) ]
55
+ [ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status204NoContent ) ]
56
+ [ Consumes ( "application/json" ) ]
57
+ [ Produces ( "application/json" ) ]
58
+ public async Task < ActionResult < IEnumerable < PlayOfferDto > > > GetByParticipantIdAsync ( [ FromQuery ] Guid participantId )
59
+ {
60
+ //TODO: refactor after jwt implementation to get participantId from token
61
+ var result = await _mediator . Send ( new GetPlayOffersByParticipantIdQuery ( participantId ) ) ;
62
+
63
+ if ( result . Count ( ) == 0 )
64
+ return NoContent ( ) ;
65
+
66
+ return Ok ( result ) ;
67
+ }
68
+
69
+ ///<summary>
70
+ ///Get all Play offers created by a member with a matching name
71
+ ///</summary>
72
+ ///<param name="creatorName">Name of the creator in the format '[FirstName] [LastName]', '[FirstName]' or '[LastName]'</param>
73
+ ///<returns>A list of Play offers with a matching id</returns>
74
+ ///<response code="200">Returns a List of Play offers with creator matching the query params</response>
75
+ ///<response code="204">No Play offers with matching creator was found</response>
76
+ [ HttpGet ]
77
+ [ Route ( "search" ) ]
31
78
[ ProducesResponseType ( typeof ( IEnumerable < PlayOffer > ) , StatusCodes . Status200OK ) ]
32
79
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status204NoContent ) ]
33
80
[ Consumes ( "application/json" ) ]
34
81
[ Produces ( "application/json" ) ]
35
- public async Task < ActionResult < IEnumerable < PlayOffer > > > GetByIdAsync ( [ FromQuery ] Guid ? playOfferId , [ FromQuery ] Guid ? creatorId , [ FromQuery ] Guid ? clubId )
82
+ public async Task < ActionResult < IEnumerable < PlayOfferDto > > > GetByCreatorNameAsync ( [ FromQuery ] string creatorName )
36
83
{
37
- var result = await _mediator . Send ( new GetPlayOffersByIdQuery ( playOfferId , creatorId , clubId ) ) ;
84
+ IEnumerable < PlayOfferDto > result ;
85
+ try
86
+ {
87
+ result = await _mediator . Send ( new GetPlayOffersByCreatorNameQuery ( creatorName ) ) ;
88
+ }
89
+ catch ( Exception e )
90
+ {
91
+ return BadRequest ( e . Message ) ;
92
+ }
38
93
39
94
if ( result . Count ( ) == 0 )
40
95
return NoContent ( ) ;
41
96
42
97
return Ok ( result ) ;
43
98
}
99
+
44
100
45
101
46
102
///<summary>
47
103
///Create a new Play Offer
48
104
///</summary>
49
- ///<param name="playOfferDto ">The Play Offer to create</param>
105
+ ///<param name="createPlayOfferDto ">The Play Offer to create</param>
50
106
///<returns>The newly created Play offer</returns>
51
107
///<response code="200">Returns the id of the created Play Offer</response>
52
108
///<response code="400">Invalid Play Offer structure</response>
@@ -55,12 +111,12 @@ public async Task<ActionResult<IEnumerable<PlayOffer>>> GetByIdAsync([FromQuery]
55
111
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status400BadRequest ) ]
56
112
[ Consumes ( "application/json" ) ]
57
113
[ Produces ( "application/json" ) ]
58
- public async Task < ActionResult < PlayOffer > > Create ( PlayOfferDto playOfferDto )
114
+ public async Task < ActionResult < PlayOffer > > Create ( CreatePlayOfferDto createPlayOfferDto )
59
115
{
60
116
Guid result ;
61
117
try
62
118
{
63
- result = await _mediator . Send ( new CreatePlayOfferCommand ( playOfferDto ) ) ;
119
+ result = await _mediator . Send ( new CreatePlayOfferCommand ( createPlayOfferDto ) ) ;
64
120
}
65
121
catch ( Exception e )
66
122
{
@@ -104,7 +160,7 @@ public async Task<ActionResult> Delete(Guid playOfferId)
104
160
///<response code="200">The opponentId was added to the Play Offer with the matching playOfferId</response>
105
161
///<response code="400">No playOffer with a matching playOfferId found</response>
106
162
[ HttpPost ]
107
- [ Route ( "/ join" ) ]
163
+ [ Route ( "join" ) ]
108
164
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status200OK ) ]
109
165
[ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status400BadRequest ) ]
110
166
[ Consumes ( "application/json" ) ]
0 commit comments