Skip to content

Commit bd032d0

Browse files
committed
return type with relevant shares on invite accept
1 parent 6865644 commit bd032d0

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

API/Controller/Devices/DevicesController.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using OpenShock.Common.Redis;
1313
using OpenShock.Common.Utils;
1414
using System.Net.Mime;
15+
using Redis.OM;
1516

1617
namespace OpenShock.API.Controller.Devices;
1718

@@ -201,9 +202,7 @@ public async Task<IActionResult> GetPairCode([FromRoute] Guid deviceId)
201202

202203
var deviceExists = await _db.Devices.AnyAsync(x => x.Id == deviceId && x.OwnerId == CurrentUser.Id);
203204
if (!deviceExists) return Problem(HubError.HubNotFound);
204-
// replace with unlink?
205-
var existing = await devicePairs.FindByIdAsync(deviceId.ToString());
206-
if (existing is not null) await devicePairs.DeleteAsync(existing);
205+
await _redis.Connection.UnlinkAsync($"{typeof(DevicePair).FullName}:{deviceId}");
207206

208207
string pairCode = CryptoUtils.RandomNumericString(6);
209208

API/Controller/Shares/V2GetShares.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace OpenShock.API.Controller.Shares;
1010

11-
file sealed class V2UserSharesListItemDto
11+
internal sealed class V2UserSharesListItemDto
1212
{
1313

1414
public required Guid Id { get; set; }

API/Controller/Shares/V2Invites.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ public async Task<IActionResult> DenyIncomingInvite(Guid id)
110110
/// <param name="deviceUpdateService"></param>
111111
/// <returns></returns>
112112
[HttpPost("invites/incoming/{id:guid}")]
113-
[ProducesResponseType(StatusCodes.Status200OK)]
113+
[ProducesResponseType<V2UserSharesListItem>(StatusCodes.Status200OK)]
114114
[ProducesResponseType<OpenShockProblem>(StatusCodes.Status404NotFound, MediaTypeNames.Application.ProblemJson)] // ShareRequestNotFound
115115
[ApiVersion("2")]
116116
public async Task<IActionResult> RedeemInvite(Guid id, [FromServices] IDeviceUpdateService deviceUpdateService)
117117
{
118118
var shareRequest = await _db.UserShareInvites
119-
.Include(x => x.ShockerMappings)
119+
.Include(x => x.ShockerMappings).Include(x => x.Owner)
120120
.FirstOrDefaultAsync(x => x.Id == id && (x.RecipientUserId == null || x.RecipientUserId == CurrentUser.Id));
121121

122122
if (shareRequest is null) return Problem(ShareError.ShareRequestNotFound);
@@ -164,8 +164,37 @@ public async Task<IActionResult> RedeemInvite(Guid id, [FromServices] IDeviceUpd
164164
{
165165
await deviceUpdateService.UpdateDevice(shareRequest.OwnerId, affectedHub, DeviceUpdateType.ShockerUpdated, CurrentUser.Id);
166166
}
167+
168+
169+
var returnObject = new V2UserSharesListItemDto()
170+
{
171+
Id = shareRequest.OwnerId,
172+
Email = shareRequest.Owner.Email,
173+
Name = shareRequest.Owner.Name,
174+
Shares = shareRequest.ShockerMappings.Select(y => new UserShareInfo
175+
{
176+
Id = y.Shocker.Id,
177+
Name = y.Shocker.Name,
178+
CreatedOn = DateTime.UtcNow,
179+
Permissions = new ShockerPermissions
180+
{
181+
Sound = y.AllowSound,
182+
Vibrate = y.AllowVibrate,
183+
Shock = y.AllowShock,
184+
Live = y.AllowLiveControl
185+
},
186+
Limits = new ShockerLimits
187+
{
188+
Duration = y.MaxDuration,
189+
Intensity = y.MaxIntensity
190+
},
191+
Paused = y.IsPaused
192+
})
193+
};
194+
167195

168-
return Ok();
196+
197+
return Ok(returnObject.ToV2UserSharesListItem());
169198
}
170199
}
171200

API/Controller/Shockers/ShockerShares.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ [FromServices] IDeviceUpdateService deviceUpdateService
140140
}
141141

142142
/// <summary>
143-
/// Remove a share code for a shocker
143+
/// Remove a share for a shocker
144144
/// </summary>
145145
/// <param name="shockerId"></param>
146146
/// <param name="sharedWithUserId"></param>
@@ -152,7 +152,7 @@ [FromServices] IDeviceUpdateService deviceUpdateService
152152
[ProducesResponseType(StatusCodes.Status200OK)]
153153
[ProducesResponseType<OpenShockProblem>(StatusCodes.Status404NotFound, MediaTypeNames.Application.ProblemJson)] // ShockerNotFound
154154
[MapToApiVersion("1")]
155-
public async Task<IActionResult> ShockerShareCodeRemove(
155+
public async Task<IActionResult> ShockerShareRemove(
156156
[FromRoute] Guid shockerId,
157157
[FromRoute] Guid sharedWithUserId,
158158
[FromServices] IDeviceUpdateService deviceUpdateService)

0 commit comments

Comments
 (0)