@@ -12,25 +12,25 @@ namespace OpenShock.API.Controller.Shares;
1212
1313public sealed partial class SharesController
1414{
15- [ HttpPost ( "requests " ) ]
15+ [ HttpPost ( "invites " ) ]
1616 [ ProducesResponseType < Guid > ( StatusCodes . Status200OK , MediaTypeNames . Text . Plain ) ]
1717 [ ProducesResponseType < OpenShockProblem > ( StatusCodes . Status404NotFound , MediaTypeNames . Application . ProblemJson ) ] // UserNotFound, ShareCreateShockerNotFound
1818 [ ProducesResponseType < OpenShockProblem > ( StatusCodes . Status400BadRequest , MediaTypeNames . Application . ProblemJson ) ] // ShareCreateCannotShareWithSelf
1919 [ ApiVersion ( "2" ) ]
20- public async Task < IActionResult > CreateShare ( [ FromBody ] CreateShareRequest data )
20+ public async Task < IActionResult > CreateShareInvite ( [ FromBody ] CreateShareRequest body )
2121 {
22- if ( data . User == CurrentUser . Id )
22+ if ( body . User == CurrentUser . Id )
2323 {
2424 return Problem ( ShareError . ShareRequestCreateCannotShareWithSelf ) ;
2525 }
2626
27- var providedShockerIds = data . Shockers . Select ( x => x . Id ) . ToArray ( ) ;
27+ var providedShockerIds = body . Shockers . Select ( x => x . Id ) . ToArray ( ) ;
2828 var belongsToUsFuture = _db . Shockers . AsNoTracking ( ) . Where ( x =>
2929 x . Device . OwnerId == CurrentUser . Id && providedShockerIds . Contains ( x . Id ) ) . Select ( x => x . Id ) . Future ( ) ;
3030
31- if ( data . User != null )
31+ if ( body . User != null )
3232 {
33- var existsFuture = _db . Users . AsNoTracking ( ) . DeferredAny ( x => x . Id == data . User ) . FutureValue ( ) ;
33+ var existsFuture = _db . Users . AsNoTracking ( ) . DeferredAny ( x => x . Id == body . User ) . FutureValue ( ) ;
3434
3535 // We can already resolve the futures here since this is the last future query
3636 if ( ! await existsFuture . ValueAsync ( ) ) return Problem ( UserError . UserNotFound ) ;
@@ -47,26 +47,26 @@ public async Task<IActionResult> CreateShare([FromBody] CreateShareRequest data)
4747
4848 await using var transaction = await _db . Database . BeginTransactionAsync ( ) ;
4949
50- var shareRequest = new ShareRequest
50+ var shareInvite = new UserShareInvite
5151 {
5252 Id = Guid . CreateVersion7 ( ) ,
5353 OwnerId = CurrentUser . Id ,
54- UserId = data . User
54+ RecipientUserId = body . User
5555 } ;
56- _db . ShareRequests . Add ( shareRequest ) ;
56+ _db . UserShareInvites . Add ( shareInvite ) ;
5757
58- foreach ( var createShockerShare in data . Shockers )
58+ foreach ( var createUserShare in body . Shockers )
5959 {
60- _db . ShareRequestShockerMappings . Add ( new ShareRequestShocker
60+ _db . UserShareInviteShockers . Add ( new UserShareInviteShocker
6161 {
62- ShareRequestId = shareRequest . Id ,
63- ShockerId = createShockerShare . Id ,
64- AllowShock = createShockerShare . Permissions . Shock ,
65- AllowVibrate = createShockerShare . Permissions . Vibrate ,
66- AllowSound = createShockerShare . Permissions . Sound ,
67- AllowLiveControl = createShockerShare . Permissions . Live ,
68- MaxIntensity = createShockerShare . Limits . Intensity ,
69- MaxDuration = createShockerShare . Limits . Duration ,
62+ InviteId = shareInvite . Id ,
63+ ShockerId = createUserShare . Id ,
64+ AllowShock = createUserShare . Permissions . Shock ,
65+ AllowVibrate = createUserShare . Permissions . Vibrate ,
66+ AllowSound = createUserShare . Permissions . Sound ,
67+ AllowLiveControl = createUserShare . Permissions . Live ,
68+ MaxIntensity = createUserShare . Limits . Intensity ,
69+ MaxDuration = createUserShare . Limits . Duration ,
7070 IsPaused = false
7171 } ) ;
7272 }
@@ -75,6 +75,6 @@ public async Task<IActionResult> CreateShare([FromBody] CreateShareRequest data)
7575
7676 await transaction . CommitAsync ( ) ;
7777
78- return Ok ( shareRequest . Id ) ;
78+ return Ok ( shareInvite . Id ) ;
7979 }
8080}
0 commit comments