Skip to content

Commit

Permalink
Map shocker functions to versions
Browse files Browse the repository at this point in the history
  • Loading branch information
LucHeart committed Dec 11, 2023
1 parent 4421fd7 commit 0c1e34d
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 59 deletions.
2 changes: 1 addition & 1 deletion API/API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>OpenShock.API</AssemblyName>
<RootNamespace>OpenShock.API</RootNamespace>
<AssemblyVersion>1.8.0</AssemblyVersion>
<AssemblyVersion>1.8.1</AssemblyVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Company>OpenShock</Company>
<Product>API</Product>
Expand Down
12 changes: 7 additions & 5 deletions API/Controller/Shockers/ControlLogController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.Net;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OpenShock.API.Models.Response;
Expand All @@ -10,17 +11,18 @@ namespace OpenShock.API.Controller.Shockers;

public sealed partial class ShockerController
{
/// <summary>
/// Gets the logs for a shocker.
/// </summary>
/// <param name="id"></param>
/// <param name="offset"></param>
/// <summary>
/// Gets the logs for a shocker.
/// </summary>
/// <param name="id"></param>
/// <param name="offset"></param>
/// <param name="limit"></param>
/// <response code="200">The logs</response>
/// <response code="404">Shocker does not exist</response>
[HttpGet("{id}/logs", Name = "GetShockerLogs")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<IEnumerable<LogEntry>>> GetShockerLogs([FromRoute] Guid id, [FromQuery] uint offset = 0,
[FromQuery] [Range(1, 500)] uint limit = 100)
{
Expand Down
8 changes: 5 additions & 3 deletions API/Controller/Shockers/CreateShockerController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OpenShock.API.Models.Requests;
Expand All @@ -9,9 +10,9 @@ namespace OpenShock.API.Controller.Shockers;

public sealed partial class ShockerController
{
/// <summary>
/// Creates a new Shocker.
/// </summary>
/// <summary>
/// Creates a new Shocker.
/// </summary>
/// <param name="data"></param>
/// <response code="201">Successfully created shocker</response>
/// <response code="400">You can have a maximum of 11 Shockers per Device.</response>
Expand All @@ -20,6 +21,7 @@ public sealed partial class ShockerController
[ProducesResponseType((int)HttpStatusCode.Created)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<Guid>> CreateShocker([FromBody] NewShocker data)
{
var device = await _db.Devices.AnyAsync(x => x.Owner == CurrentUser.DbUser.Id && x.Id == data.Device);
Expand Down
8 changes: 5 additions & 3 deletions API/Controller/Shockers/DeleteShockerController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OpenShock.Common.Models;
Expand All @@ -7,15 +8,16 @@ namespace OpenShock.API.Controller.Shockers;

public sealed partial class ShockerController
{
/// <summary>
/// Deletes a shocker
/// </summary>
/// <summary>
/// Deletes a shocker
/// </summary>
/// <param name="id"></param>
/// <response code="200">Successfully deleted shocker</response>
/// <response code="404">Shocker does not exist</response>
[HttpDelete("{id}", Name = "DeleteShocker")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<object>> DeleteShocker([FromRoute] Guid id)
{
var affected = await _db.Shockers.Where(x => x.DeviceNavigation.Owner == CurrentUser.DbUser.Id && x.Id == id).ExecuteDeleteAsync();
Expand Down
8 changes: 5 additions & 3 deletions API/Controller/Shockers/GetShockerController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OpenShock.API.Models.Response;
Expand All @@ -8,15 +9,16 @@ namespace OpenShock.API.Controller.Shockers;

public sealed partial class ShockerController
{
/// <summary>
/// Gets information about a shocker.
/// </summary>
/// <summary>
/// Gets information about a shocker.
/// </summary>
/// <param name="id"></param>
/// <response code="200">The shocker information was successfully retrieved.</response>
/// <response code="404">The shocker does not exist or you do not have access to it.</response>
[HttpGet("{id}", Name = "GetShocker")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<ShockerWithDevice>> GetShocker([FromRoute] Guid id)
{
var shocker = await _db.Shockers.Where(x => x.DeviceNavigation.Owner == CurrentUser.DbUser.Id && x.Id == id).Select(x => new ShockerWithDevice
Expand Down
10 changes: 6 additions & 4 deletions API/Controller/Shockers/OwnShockerController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OpenShock.API.Models.Response;
using OpenShock.Common.Models;
Expand All @@ -7,12 +8,13 @@ namespace OpenShock.API.Controller.Shockers;

public sealed partial class ShockerController
{
/// <summary>
/// Gets all shockers owned by the authenticated user.
/// </summary>
/// <summary>
/// Gets all shockers owned by the authenticated user.
/// </summary>
/// <response code="200">The shockers were successfully retrieved.</response>
[HttpGet("own", Name = "GetOwnShockers")]
[ProducesResponseType(StatusCodes.Status200OK)]
[MapToApiVersion("1")]
public async Task<BaseResponse<IEnumerable<ResponseDeviceWithShockers>>> GetOwnShockers()
{
var shockers = await _db.Devices.Where(x => x.Owner == CurrentUser.DbUser.Id).OrderBy(x => x.CreatedOn).Select(
Expand Down
10 changes: 6 additions & 4 deletions API/Controller/Shockers/PatchShockerController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OpenShock.API.Models.Requests;
Expand All @@ -8,16 +9,17 @@ namespace OpenShock.API.Controller.Shockers;

public sealed partial class ShockerController
{
/// <summary>
/// Edits a shocker
/// </summary>
/// <param name="id"></param>
/// <summary>
/// Edits a shocker
/// </summary>
/// <param name="id"></param>
/// <param name="data"></param>
/// <response code="200">Successfully updated shocker</response>
/// <response code="404">Shocker does not exist</response>
[HttpPatch("{id}", Name = "EditShocker")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<object>> EditShocker([FromRoute] Guid id, [FromBody] NewShocker data)
{
var device = await _db.Devices.AnyAsync(x => x.Owner == CurrentUser.DbUser.Id && x.Id == data.Device);
Expand Down
10 changes: 6 additions & 4 deletions API/Controller/Shockers/PauseShockerController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OpenShock.API.Models.Requests;
Expand All @@ -8,16 +9,17 @@ namespace OpenShock.API.Controller.Shockers;

public sealed partial class ShockerController
{
/// <summary>
/// Pauses or unpauses a shocker
/// </summary>
/// <param name="id"></param>
/// <summary>
/// Pauses or unpauses a shocker
/// </summary>
/// <param name="id"></param>
/// <param name="data"></param>
/// <response code="200">Successfully set pause state</response>
/// <response code="404">Shocker not found or does not belong to you</response>
[HttpPost("{id}/pause", Name = "PauseShocker")]
[ProducesResponseType((int) HttpStatusCode.OK)]
[ProducesResponseType((int) HttpStatusCode.NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<bool?>> Pause([FromRoute] Guid id, [FromBody] PauseRequest data)
{
var shocker = await _db.Shockers.Where(x => x.Id == id && x.DeviceNavigation.Owner == CurrentUser.DbUser.Id)
Expand Down
63 changes: 35 additions & 28 deletions API/Controller/Shockers/ShareShockerController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OpenShock.API.Models.Requests;
Expand All @@ -11,15 +12,16 @@ namespace OpenShock.API.Controller.Shockers;

public sealed partial class ShockerController
{
/// <summary>
/// Gets information about the authenticated device.
/// </summary>
/// <param name="id"></param>
/// <summary>
/// Gets information about the authenticated device.
/// </summary>
/// <param name="id"></param>
/// <response code="200">The device information was successfully retrieved.</response>
/// <response code="404">Device does not exists or you do not have access to it.</response>
[HttpGet("{id}/shares", Name = "GetShares")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<IEnumerable<ShareInfo>>> GetShares([FromRoute] Guid id)
{
var owns = await _db.Shockers.AnyAsync(x => x.DeviceNavigation.Owner == CurrentUser.DbUser.Id && x.Id == id);
Expand Down Expand Up @@ -57,15 +59,16 @@ public async Task<BaseResponse<IEnumerable<ShareInfo>>> GetShares([FromRoute] Gu
};
}

/// <summary>
/// Gets share codes for a shocker
/// </summary>
/// <summary>
/// Gets share codes for a shocker
/// </summary>
/// <param name="id"></param>
/// <response code="200">The device information was successfully retrieved.</response>
/// <response code="404">Device does not exists or you do not have access to it.</response>
[HttpGet("{id}/shareCodes", Name = "GetShareCodes")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<IEnumerable<ShareCodeInfo>>> GetShareCodes([FromRoute] Guid id)
{
var owns = await _db.Shockers.AnyAsync(x => x.DeviceNavigation.Owner == CurrentUser.DbUser.Id && x.Id == id);
Expand All @@ -92,17 +95,18 @@ public class ShareCodeInfo
public required DateTime CreatedOn { get; set; }
}

/// <summary>
/// Creates a share code for a shocker
/// </summary>
/// <param name="id"></param>
/// <param name="data"></param>
/// <response code="200">The device information was successfully retrieved.</response>
/// <response code="404">Device does not exists or you do not have access to it.</response>
/// <summary>
/// Creates a share code for a shocker
/// </summary>
/// <param name="id"></param>
/// <param name="data"></param>
/// <response code="200">The device information was successfully retrieved.</response>
/// <response code="404">Device does not exists or you do not have access to it.</response>
/// <returns></returns>
[HttpPost("{id}/shares", Name = "CreateShare")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<Guid>> CreateShareCode([FromRoute] Guid id, [FromBody] CreateShareCode data)
{
var device = await _db.Shockers.Where(x => x.DeviceNavigation.Owner == CurrentUser.DbUser.Id && x.Id == id).AnyAsync();
Expand All @@ -128,16 +132,17 @@ public async Task<BaseResponse<Guid>> CreateShareCode([FromRoute] Guid id, [From
};
}

/// <summary>
/// Deletes a share code for a shocker
/// </summary>
/// <param name="id"></param>
/// <summary>
/// Deletes a share code for a shocker
/// </summary>
/// <param name="id"></param>
/// <param name="sharedWith"></param>
/// <response code="200">The device information was successfully retrieved.</response>
/// <response code="404">Device does not exists or you do not have access to it.</response>
[HttpDelete("{id}/shares/{sharedWith}", Name = "DeleteShare")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<object>> DeleteShare([FromRoute] Guid id, [FromRoute] Guid sharedWith)
{
var affected = await _db.ShockerShares.Where(x =>
Expand All @@ -149,17 +154,18 @@ public async Task<BaseResponse<object>> DeleteShare([FromRoute] Guid id, [FromRo
return new BaseResponse<object>("Successfully deleted share");
}

/// <summary>
/// Updates a share code for a shocker
/// </summary>
/// <param name="id"></param>
/// <param name="sharedWith"></param>
/// <summary>
/// Updates a share code for a shocker
/// </summary>
/// <param name="id"></param>
/// <param name="sharedWith"></param>
/// <param name="data"></param>
/// <response code="200">The device information was successfully retrieved.</response>
/// <response code="404">Device does not exists or you do not have access to it.</response>
[HttpPatch("{id}/shares/{sharedWith}", Name = "UpdateShare")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<object>> UpdateShare([FromRoute] Guid id, [FromRoute] Guid sharedWith, [FromBody] CreateShareCode data)
{
var affected = await _db.ShockerShares.Where(x =>
Expand All @@ -179,17 +185,18 @@ public async Task<BaseResponse<object>> UpdateShare([FromRoute] Guid id, [FromRo
return new BaseResponse<object>("Successfully updated share");
}

/// <summary>
/// Pauses a share code for a shocker
/// </summary>
/// <param name="id"></param>
/// <param name="sharedWith"></param>
/// <summary>
/// Pauses a share code for a shocker
/// </summary>
/// <param name="id"></param>
/// <param name="sharedWith"></param>
/// <param name="data"></param>
/// <response code="200">The device information was successfully retrieved.</response>
/// <response code="404">Device does not exists or you do not have access to it.</response>
[HttpPost("{id}/shares/{sharedWith}/pause", Name = "PauseShare")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[MapToApiVersion("1")]
public async Task<BaseResponse<object>> UpdatePauseShare([FromRoute] Guid id, [FromRoute] Guid sharedWith, [FromBody] PauseRequest data)
{
var affected = await _db.ShockerShares.Where(x =>
Expand Down
8 changes: 5 additions & 3 deletions API/Controller/Shockers/SharedShockersController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using OpenShock.API.Models.Response;
using OpenShock.Common.Models;
Expand All @@ -7,12 +8,13 @@ namespace OpenShock.API.Controller.Shockers;

public partial class ShockerController
{
/// <summary>
/// Gets all shockers shared with the authenticated user.
/// <summary>
/// Gets all shockers shared with the authenticated user.
/// </summary>
/// <response code="200">The shockers were successfully retrieved.</response>
[HttpGet("shared", Name = "GetSharedShockers")]
[ProducesResponseType(StatusCodes.Status200OK)]
[MapToApiVersion("1")]
public async Task<BaseResponse<IEnumerable<OwnerShockerResponse>>> GetSharedShockers()
{
var sharedShockersRaw = await _db.ShockerShares.Where(x => x.SharedWith == CurrentUser.DbUser.Id).Select(x =>
Expand Down
2 changes: 1 addition & 1 deletion LiveControlGateway/LiveControlGateway.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<AssemblyName>OpenShock.LiveControlGateway</AssemblyName>
<RootNamespace>OpenShock.LiveControlGateway</RootNamespace>
<Company>OpenShock</Company>
<AssemblyVersion>1.8.0</AssemblyVersion>
<AssemblyVersion>1.8.1</AssemblyVersion>
<Product>LiveControlGateway</Product>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>12</LangVersion>
Expand Down

0 comments on commit 0c1e34d

Please sign in to comment.