Skip to content

Commit

Permalink
Remove ProducesSuccess and use RespondSuccessLegacy more
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Nov 8, 2024
1 parent abf40e7 commit 4304802
Show file tree
Hide file tree
Showing 39 changed files with 89 additions and 117 deletions.
3 changes: 2 additions & 1 deletion API/Controller/Account/Authenticated/ChangeEmail.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using OpenShock.API.Models.Requests;
using OpenShock.Common.Errors;
using OpenShock.Common.Models;
using OpenShock.Common.Problems;
using OpenShock.Common.Utils;

Expand All @@ -15,7 +16,7 @@ public sealed partial class AuthenticatedAccountController
/// <returns></returns>
/// <exception cref="Exception"></exception>
[HttpPost("email")]
[ProducesSuccess]
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status200OK)]
public async Task<IActionResult> ChangeEmail(ChangeEmailRequest data)
{
throw new NotImplementedException();
Expand Down
3 changes: 2 additions & 1 deletion API/Controller/Account/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OpenShock.Common.Errors;
using OpenShock.Common.Problems;
using OpenShock.Common.Utils;
using OpenShock.Common.Models;

namespace OpenShock.API.Controller.Account;

Expand All @@ -19,7 +20,7 @@ public sealed partial class AccountController
/// <response code="200">User successfully logged in</response>
/// <response code="401">Invalid username or password</response>
[HttpPost("login")]
[ProducesSuccess]
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.Unauthorized, "InvalidCredentials")]
[ProducesProblem(HttpStatusCode.Forbidden, "InvalidDomain")]
[MapToApiVersion("1")]
Expand Down
3 changes: 2 additions & 1 deletion API/Controller/Account/LoginV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using OpenShock.Common.Problems;
using OpenShock.Common.Services.Turnstile;
using OpenShock.Common.Utils;
using OpenShock.Common.Models;

namespace OpenShock.API.Controller.Account;

Expand All @@ -20,7 +21,7 @@ public sealed partial class AccountController
/// <response code="200">User successfully logged in</response>
/// <response code="401">Invalid username or password</response>
[HttpPost("login")]
[ProducesSuccess]
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.Unauthorized, "InvalidCredentials")]
[ProducesProblem(HttpStatusCode.Forbidden, "InvalidDomain")]
[MapToApiVersion("2")]
Expand Down
3 changes: 2 additions & 1 deletion API/Controller/Account/PasswordResetCheckValid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OpenShock.API.Services.Account;
using OpenShock.Common.Errors;
using OpenShock.Common.Problems;
using OpenShock.Common.Models;

namespace OpenShock.API.Controller.Account;

Expand All @@ -19,7 +20,7 @@ public sealed partial class AccountController
/// <response code="200">Valid password reset process</response>
/// <response code="404">Password reset process not found</response>
[HttpHead("recover/{passwordResetId}/{secret}")]
[ProducesSuccess]
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "PasswordResetNotFound")]
[MapToApiVersion("1")]
public async Task<IActionResult> PasswordResetCheckValid([FromRoute] Guid passwordResetId, [FromRoute] string secret, CancellationToken cancellationToken)
Expand Down
3 changes: 2 additions & 1 deletion API/Controller/Account/PasswordResetComplete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OpenShock.API.Services.Account;
using OpenShock.Common.Errors;
using OpenShock.Common.Problems;
using OpenShock.Common.Models;

namespace OpenShock.API.Controller.Account;

Expand All @@ -19,7 +20,7 @@ public sealed partial class AccountController
/// <response code="200">Password successfully changed</response>
/// <response code="404">Password reset process not found</response>
[HttpPost("recover/{passwordResetId}/{secret}")]
[ProducesSuccess]
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "PasswordResetNotFound")]
[MapToApiVersion("1")]
public async Task<IActionResult> PasswordResetComplete([FromRoute] Guid passwordResetId,
Expand Down
2 changes: 1 addition & 1 deletion API/Controller/Account/PasswordResetInitiate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed partial class AccountController
/// </summary>
/// <response code="200">Password reset email sent if the email is associated to an registered account</response>
[HttpPost("reset")]
[ProducesSuccess]
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status200OK)]
[MapToApiVersion("1")]
public async Task<BaseResponse<object>> PasswordResetInitiate([FromBody] ResetRequest body)
{
Expand Down
3 changes: 2 additions & 1 deletion API/Controller/Account/Signup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using OpenShock.API.Services.Account;
using OpenShock.Common.Errors;
using OpenShock.Common.Problems;
using OpenShock.Common.Models;

namespace OpenShock.API.Controller.Account;

Expand All @@ -18,7 +19,7 @@ public sealed partial class AccountController
/// <response code="200">User successfully signed up</response>
/// <response code="409">Username or email already exists</response>
[HttpPost("signup")]
[ProducesSuccess]
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.Conflict, "EmailOrUsernameAlreadyExists")]
[MapToApiVersion("1")]
public async Task<IActionResult> SignUp([FromBody] SignUp body)
Expand Down
3 changes: 2 additions & 1 deletion API/Controller/Account/SignupV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using OpenShock.Common.Problems;
using OpenShock.Common.Services.Turnstile;
using OpenShock.Common.Utils;
using OpenShock.Common.Models;

namespace OpenShock.API.Controller.Account;

Expand All @@ -23,7 +24,7 @@ public sealed partial class AccountController
/// <response code="200">User successfully signed up</response>
/// <response code="400">Username or email already exists</response>
[HttpPost("signup")]
[ProducesSuccess]
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.Conflict, "EmailOrUsernameAlreadyExists")]
[ProducesProblem(HttpStatusCode.Forbidden, "InvalidTurnstileResponse")]
[MapToApiVersion("2")]
Expand Down
10 changes: 4 additions & 6 deletions API/Controller/Admin/GetOnlineDevices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public sealed partial class AdminController
/// <response code="200">All online devices</response>
/// <response code="401">Unauthorized</response>
[HttpGet("monitoring/onlineDevices")]
[ProducesSuccess<IEnumerable<AdminOnlineDeviceResponse>>]
public async Task<BaseResponse<IEnumerable<AdminOnlineDeviceResponse>>> GetOnlineDevices()
[ProducesResponseType<BaseResponse<IEnumerable<AdminOnlineDeviceResponse>>>(StatusCodes.Status200OK)]
public async Task<IActionResult> GetOnlineDevices()
{
var devicesOnline = _redis.RedisCollection<DeviceOnline>(false);

Expand All @@ -39,9 +39,7 @@ public async Task<BaseResponse<IEnumerable<AdminOnlineDeviceResponse>>> GetOnlin
}
}).ToListAsync();

return new BaseResponse<IEnumerable<AdminOnlineDeviceResponse>>
{
Data = allOnlineDevices.Select(x =>
return RespondSuccessLegacy(allOnlineDevices.Select(x =>
{
var dbItem = dbLookup.First(y => y.Id == x.Id);
return new AdminOnlineDeviceResponse
Expand All @@ -57,7 +55,7 @@ public async Task<BaseResponse<IEnumerable<AdminOnlineDeviceResponse>>> GetOnlin
Uptime = x.Uptime
};
})
};
);
}

public sealed class AdminOnlineDeviceResponse
Expand Down
3 changes: 2 additions & 1 deletion API/Controller/Device/AssignLCG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using OpenShock.Common.Problems;
using OpenShock.Common.Services.LCGNodeProvisioner;
using OpenShock.Common.Utils;
using OpenShock.Common.Models;

namespace OpenShock.API.Controller.Device;

Expand All @@ -17,7 +18,7 @@ public sealed partial class DeviceController
/// <response code="200">Successfully assigned LCG node</response>
/// <response code="503">Unable to find suitable LCG node</response>
[HttpGet("assignLCG")]
[ProducesSuccess<LcgNodeResponse>]
[ProducesResponseType<BaseResponse<LcgNodeResponse>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.ServiceUnavailable, "NoLcgNodesAvailable")]
public async Task<IActionResult> GetLiveControlGateway([FromServices] ILCGNodeProvisioner geoLocation,
[FromServices] IWebHostEnvironment env)
Expand Down
10 changes: 4 additions & 6 deletions API/Controller/Device/GetSelf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public sealed partial class DeviceController
/// </summary>
/// <response code="200">The device information was successfully retrieved.</response>
[HttpGet("self")]
[ProducesSuccess<DeviceSelfResponse>]
public async Task<BaseResponse<DeviceSelfResponse>> GetSelf()
[ProducesResponseType<BaseResponse<DeviceSelfResponse>>(StatusCodes.Status200OK)]
public async Task<IActionResult> GetSelf()
{
var shockers = await _db.Shockers.Where(x => x.Device == CurrentDevice.Id).Select(x => new MinimalShocker
{
Expand All @@ -23,14 +23,12 @@ public async Task<BaseResponse<DeviceSelfResponse>> GetSelf()
Model = x.Model
}).ToArrayAsync();

return new BaseResponse<DeviceSelfResponse>
{
Data = new DeviceSelfResponse
return RespondSuccessLegacy(new DeviceSelfResponse
{
Id = CurrentDevice.Id,
Name = CurrentDevice.Name,
Shockers = shockers
}
};
);
}
}
3 changes: 2 additions & 1 deletion API/Controller/Device/Pair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net;
using OpenShock.Common.Errors;
using OpenShock.Common.Problems;
using OpenShock.Common.Models;

namespace OpenShock.API.Controller.Device;

Expand All @@ -20,7 +21,7 @@ public sealed partial class DeviceController
[AllowAnonymous]
[HttpGet("pair/{pairCode}", Name = "Pair")]
[HttpGet("~/{version:apiVersion}/pair/{pairCode}", Name = "Pair_DEPRECATED")] // Backwards compatibility
[ProducesSuccess<string>]
[ProducesResponseType<BaseResponse<string>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "PairCodeNotFound")]
public async Task<IActionResult> Pair([FromRoute] string pairCode)
{
Expand Down
3 changes: 2 additions & 1 deletion API/Controller/Devices/DeviceOtaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.EntityFrameworkCore;
using OpenShock.Common.Authentication.Attributes;
using OpenShock.Common.Errors;
using OpenShock.Common.Models;
using OpenShock.Common.Models.Services.Ota;
using OpenShock.Common.Problems;
using OpenShock.Common.Services.Ota;
Expand All @@ -21,7 +22,7 @@ public sealed partial class DevicesController
/// <response code="404">Could not find device or you do not have access to it</response>
[HttpGet("{deviceId}/ota")]
[UserSessionOnly]
[ProducesSuccess<IReadOnlyCollection<OtaItem>>]
[ProducesResponseType<BaseResponse<IReadOnlyCollection<OtaItem>>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "DeviceNotFound")]
[MapToApiVersion("1")]
public async Task<IActionResult> GetOtaUpdateHistory([FromRoute] Guid deviceId, [FromServices] IOtaService otaService)
Expand Down
16 changes: 7 additions & 9 deletions API/Controller/Devices/DevicesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public sealed partial class DevicesController
/// </summary>
/// <response code="200">All devices for the current user</response>
[HttpGet]
[ProducesSuccess<IEnumerable<Models.Response.ResponseDevice>>]
[ProducesResponseType<BaseResponse<IEnumerable<Models.Response.ResponseDevice>>>(StatusCodes.Status200OK)]
[MapToApiVersion("1")]
public async Task<BaseResponse<IEnumerable<Models.Response.ResponseDevice>>> ListDevices()
public async Task<IActionResult> ListDevices()
{
var devices = await _db.Devices.Where(x => x.Owner == CurrentUser.DbUser.Id)
.Select(x => new Models.Response.ResponseDevice
Expand All @@ -33,10 +33,8 @@ public sealed partial class DevicesController
Name = x.Name,
CreatedOn = x.CreatedOn
}).ToListAsync();
return new BaseResponse<IEnumerable<Models.Response.ResponseDevice>>
{
Data = devices
};

return RespondSuccessLegacy(devices);
}

/// <summary>
Expand All @@ -45,7 +43,7 @@ public sealed partial class DevicesController
/// <param name="deviceId"></param>
/// <response code="200">The device</response>
[HttpGet("{deviceId}")]
[ProducesSuccess<Models.Response.ResponseDeviceWithToken>]
[ProducesResponseType<BaseResponse<Models.Response.ResponseDeviceWithToken>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "DeviceNotFound")]
[MapToApiVersion("1")]
public async Task<IActionResult> GetDeviceById([FromRoute] Guid deviceId)
Expand Down Expand Up @@ -190,7 +188,7 @@ public async Task<Guid> CreateDeviceV2([FromBody] HubCreateRequest data, [FromSe
/// <response code="404">Device does not exist or does not belong to you</response>
[HttpGet("{deviceId}/pair")]
[TokenPermission(PermissionType.Devices_Edit)]
[ProducesSuccess<string>]
[ProducesResponseType<BaseResponse<string>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "DeviceNotFound")]
[MapToApiVersion("1")]
public async Task<IActionResult> GetPairCode([FromRoute] Guid deviceId)
Expand Down Expand Up @@ -225,7 +223,7 @@ public async Task<IActionResult> GetPairCode([FromRoute] Guid deviceId)
/// <response code="412">Device is online but not connected to a LCG node, you might need to upgrade your firmware to use this feature</response>
/// <response code="500">Internal server error, lcg node could not be found</response>
[HttpGet("{deviceId}/lcg")]
[ProducesSuccess<LcgResponse>]
[ProducesResponseType<BaseResponse<LcgResponse>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "DeviceNotFound")]
[ProducesProblem(HttpStatusCode.NotFound, "DeviceIsNotOnline")]
[ProducesProblem(HttpStatusCode.PreconditionFailed, "DeviceNotConnectedToGateway")]
Expand Down
3 changes: 2 additions & 1 deletion API/Controller/Devices/ShockersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Asp.Versioning;
using OpenShock.Common.Errors;
using OpenShock.Common.Problems;
using OpenShock.Common.Models;

namespace OpenShock.API.Controller.Devices;

Expand All @@ -17,7 +18,7 @@ public sealed partial class DevicesController
/// <response code="200">All shockers for the device</response>
/// <response code="404">Device does not exists or you do not have access to it.</response>
[HttpGet("{deviceId}/shockers")]
[ProducesSuccess<IEnumerable<ShockerResponse>>]
[ProducesResponseType<BaseResponse<IEnumerable<ShockerResponse>>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "DeviceNotFound")]
[MapToApiVersion("1")]
public async Task<IActionResult> GetShockers([FromRoute] Guid deviceId)
Expand Down
13 changes: 5 additions & 8 deletions API/Controller/Public/GetStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ public sealed partial class PublicController
/// </summary>
/// <response code="200">The statistics were successfully retrieved.</response>
[HttpGet("stats")]
[ProducesSuccess<StatsResponse>]
public async Task<BaseResponse<StatsResponse>> GetOnlineDevicesStatistics(
[ProducesResponseType<BaseResponse<StatsResponse>>(StatusCodes.Status200OK)]
public async Task<IActionResult> GetOnlineDevicesStatistics(
[FromServices] IRedisConnectionProvider redisConnectionProvider)
{
var deviceOnlines = redisConnectionProvider.RedisCollection<DeviceOnline>(false);

return new BaseResponse<StatsResponse>
return RespondSuccessLegacy(new StatsResponse
{
Data = new StatsResponse
{
DevicesOnline = await deviceOnlines.CountAsync()
}
};
DevicesOnline = await deviceOnlines.CountAsync()
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion API/Controller/Public/PublicShareController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed partial class PublicController
/// <response code="200">The share link information was successfully retrieved.</response>
/// <response code="404">The share link does not exist.</response>
[HttpGet("shares/links/{shareLinkId}")]
[ProducesSuccess<PublicShareLinkResponse>]
[ProducesResponseType<BaseResponse<PublicShareLinkResponse>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "ShareLinkNotFound")]
public async Task<IActionResult> GetShareLink([FromRoute] Guid shareLinkId)
{
Expand Down
3 changes: 2 additions & 1 deletion API/Controller/Shares/DeleteShareCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.EntityFrameworkCore;
using OpenShock.Common;
using OpenShock.Common.Errors;
using OpenShock.Common.Models;
using OpenShock.Common.Problems;

namespace OpenShock.API.Controller.Shares;
Expand All @@ -17,7 +18,7 @@ public sealed partial class SharesController
/// <response code="200">Deleted share code</response>
/// <response code="404">Share code not found or does not belong to you</response>
[HttpDelete("code/{shareCodeId}")]
[ProducesSuccess]
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "ShareCodeNotFound")]
[MapToApiVersion("1")]
public async Task<IActionResult> DeleteShareCode([FromRoute] Guid shareCodeId)
Expand Down
2 changes: 1 addition & 1 deletion API/Controller/Shares/LinkShareCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed partial class SharesController
/// <response code="400">You cannot link your own shocker code / You already have this shocker linked to your account</response>
/// <response code="500">Error while linking share code to your account</response>
[HttpPost("code/{shareCodeId}")]
[ProducesSuccess]
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "ShareCodeNotFound")]
[ProducesProblem(HttpStatusCode.BadRequest, "CantLinkOwnShareCode")]
[ProducesProblem(HttpStatusCode.BadRequest, "ShockerAlreadyLinked")]
Expand Down
3 changes: 2 additions & 1 deletion API/Controller/Shares/Links/AddShocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net;
using OpenShock.Common.Errors;
using OpenShock.Common.Problems;
using OpenShock.Common.Models;

namespace OpenShock.API.Controller.Shares.Links;

Expand All @@ -18,7 +19,7 @@ public sealed partial class ShareLinksController
/// <response code="404">Share link or shocker does not exist</response>
/// <response code="409">Shocker already exists in share link</response>
[HttpPost("{shareLinkId}/{shockerId}")]
[ProducesSuccess]
[ProducesResponseType<BaseResponse<object>>(StatusCodes.Status200OK)]
[ProducesProblem(HttpStatusCode.NotFound, "ShareLinkNotFound")]
[ProducesProblem(HttpStatusCode.NotFound, "ShockerNotFound")]
[ProducesProblem(HttpStatusCode.Conflict, "ShockerAlreadyInShareLink")]
Expand Down
Loading

0 comments on commit 4304802

Please sign in to comment.