@@ -19,34 +19,90 @@ public PlayOfferController(IMediator mediator)
1919 }
2020
2121 ///<summary>
22- ///Retrieve all Play Offers matching the query params
22+ ///Retrieve all Play Offers of a club with a matching id
2323 ///</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>
2624 ///<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>
2927 ///<response code="204">No Play offer with matching properties was found</response>
3028 [ 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" ) ]
3178 [ ProducesResponseType ( typeof ( IEnumerable < PlayOffer > ) , StatusCodes . Status200OK ) ]
3279 [ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status204NoContent ) ]
3380 [ Consumes ( "application/json" ) ]
3481 [ 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 )
3683 {
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+ }
3893
3994 if ( result . Count ( ) == 0 )
4095 return NoContent ( ) ;
4196
4297 return Ok ( result ) ;
4398 }
99+
44100
45101
46102 ///<summary>
47103 ///Create a new Play Offer
48104 ///</summary>
49- ///<param name="playOfferDto ">The Play Offer to create</param>
105+ ///<param name="createPlayOfferDto ">The Play Offer to create</param>
50106 ///<returns>The newly created Play offer</returns>
51107 ///<response code="200">Returns the id of the created Play Offer</response>
52108 ///<response code="400">Invalid Play Offer structure</response>
@@ -55,12 +111,12 @@ public async Task<ActionResult<IEnumerable<PlayOffer>>> GetByIdAsync([FromQuery]
55111 [ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status400BadRequest ) ]
56112 [ Consumes ( "application/json" ) ]
57113 [ Produces ( "application/json" ) ]
58- public async Task < ActionResult < PlayOffer > > Create ( PlayOfferDto playOfferDto )
114+ public async Task < ActionResult < PlayOffer > > Create ( CreatePlayOfferDto createPlayOfferDto )
59115 {
60116 Guid result ;
61117 try
62118 {
63- result = await _mediator . Send ( new CreatePlayOfferCommand ( playOfferDto ) ) ;
119+ result = await _mediator . Send ( new CreatePlayOfferCommand ( createPlayOfferDto ) ) ;
64120 }
65121 catch ( Exception e )
66122 {
@@ -104,7 +160,7 @@ public async Task<ActionResult> Delete(Guid playOfferId)
104160 ///<response code="200">The opponentId was added to the Play Offer with the matching playOfferId</response>
105161 ///<response code="400">No playOffer with a matching playOfferId found</response>
106162 [ HttpPost ]
107- [ Route ( "/ join" ) ]
163+ [ Route ( "join" ) ]
108164 [ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status200OK ) ]
109165 [ ProducesResponseType ( typeof ( ActionResult ) , StatusCodes . Status400BadRequest ) ]
110166 [ Consumes ( "application/json" ) ]
0 commit comments