Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better comments on APIs documentation #267

Merged
merged 4 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public async Task GetAllDeviceConcentrator_WithNoArgument_ReturnConcentratorList
var concentratorController = this.CreateController();

// Act
var result = await concentratorController.GetAllDeviceConcentrator();
var response = await concentratorController.GetAllDeviceConcentrator();

// Assert
Assert.IsNotNull(result);
Assert.IsAssignableFrom<OkObjectResult>(result);
var okObjectResult = result as ObjectResult;
Assert.IsNotNull(response);
Assert.IsAssignableFrom<OkObjectResult>(response.Result);
var okObjectResult = response.Result as ObjectResult;

Assert.IsNotNull(okObjectResult);
Assert.AreEqual(200, okObjectResult.StatusCode);
Expand Down Expand Up @@ -114,12 +114,12 @@ public async Task GetDeviceConcentrator_With_Valid_Argument_Should_Return_Concen
var concentratorController = this.CreateController();

// Act
var result = await concentratorController.GetDeviceConcentrator(twin.DeviceId);
var response = await concentratorController.GetDeviceConcentrator(twin.DeviceId);

// Assert
Assert.IsNotNull(result);
Assert.IsAssignableFrom<OkObjectResult>(result);
var okObjectResult = result as ObjectResult;
Assert.IsNotNull(response);
Assert.IsAssignableFrom<OkObjectResult>(response.Result);
var okObjectResult = response.Result as OkObjectResult;

Assert.IsNotNull(okObjectResult);
Assert.AreEqual(200, okObjectResult.StatusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10
using Microsoft.Extensions.Logging;

public abstract class DeviceModelsControllerBase<TListItemModel, TModel> : ControllerBase
where TModel: DeviceModel
where TModel : DeviceModel
where TListItemModel : DeviceModel
{
/// <summary>
Expand Down Expand Up @@ -71,7 +71,7 @@ public DeviceModelsControllerBase(
IDeviceModelImageManager deviceModelImageManager,
IDeviceModelMapper<TListItemModel, TModel> deviceModelMapper,
IDeviceService devicesService,
ITableClientFactory tableClientFactory,
ITableClientFactory tableClientFactory,
string filter)
{
this.log = log;
Expand All @@ -86,9 +86,7 @@ public DeviceModelsControllerBase(
/// Gets the device models.
/// </summary>
/// <returns>The list of device models.</returns>
[HttpGet()]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult<IEnumerable<TListItemModel>> Get()
public virtual ActionResult<IEnumerable<TListItemModel>> Get()
{
// PartitionKey 0 contains all device models
var entities = this.tableClientFactory
Expand All @@ -106,10 +104,7 @@ public ActionResult<IEnumerable<TListItemModel>> Get()
/// </summary>
/// <param name="id">The model identifier.</param>
/// <returns>The corresponding model.</returns>
[HttpGet("{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult<TModel> Get(string id)
public virtual ActionResult<TModel> Get(string id)
{
try
{
Expand Down Expand Up @@ -137,10 +132,7 @@ public ActionResult<TModel> Get(string id)
/// </summary>
/// <param name="id">The model identifier.</param>
/// <returns>The avatar.</returns>
[HttpGet("{id}/avatar")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult<string> GetAvatar(string id)
public virtual ActionResult<string> GetAvatar(string id)
{
try
{
Expand Down Expand Up @@ -169,10 +161,7 @@ public ActionResult<string> GetAvatar(string id)
/// <param name="id">The model identifier.</param>
/// <param name="file">The file.</param>
/// <returns>The avatar.</returns>
[HttpPost("{id}/avatar")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<string>> ChangeAvatar(string id, IFormFile file)
public virtual async Task<ActionResult<string>> ChangeAvatar(string id, IFormFile file)
{
try
{
Expand All @@ -199,10 +188,7 @@ public async Task<ActionResult<string>> ChangeAvatar(string id, IFormFile file)
/// Deletes the avatar.
/// </summary>
/// <param name="id">The model identifier.</param>
[HttpDelete("{id}/avatar")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> DeleteAvatar(string id)
public virtual async Task<IActionResult> DeleteAvatar(string id)
{
try
{
Expand Down Expand Up @@ -232,10 +218,7 @@ public async Task<IActionResult> DeleteAvatar(string id)
/// </summary>
/// <param name="deviceModel">The device model.</param>
/// <returns>The action result.</returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> Post(TModel deviceModel)
public virtual async Task<IActionResult> Post(TModel deviceModel)
{
if (!string.IsNullOrEmpty(deviceModel.ModelId))
{
Expand Down Expand Up @@ -274,11 +257,7 @@ public async Task<IActionResult> Post(TModel deviceModel)
/// </summary>
/// <param name="deviceModel">The device model.</param>
/// <returns>The action result.</returns>
[HttpPut("{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> Put(TModel deviceModel)
public virtual async Task<IActionResult> Put(TModel deviceModel)
{
if (string.IsNullOrEmpty(deviceModel.ModelId))
{
Expand Down Expand Up @@ -315,11 +294,7 @@ public async Task<IActionResult> Put(TModel deviceModel)
/// </summary>
/// <param name="id">The device model identifier.</param>
/// <returns>The action result.</returns>
[HttpDelete("{id}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> Delete(string id)
public virtual async Task<IActionResult> Delete(string id)
{
// we get all devices
var deviceList = await this.devicesService.GetAllDevice();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10
{
using AzureIoTHub.Portal.Server.Factories;
using AzureIoTHub.Portal.Server.Managers;
using AzureIoTHub.Portal.Server.Mappers;
using AzureIoTHub.Portal.Server.Services;
using AzureIoTHub.Portal.Shared.Models.V10.DeviceModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Threading.Tasks;

[ApiController]
[ApiVersion("1.0")]
Expand All @@ -33,5 +35,109 @@ public DeviceModelsController(ILogger<DeviceModelsControllerBase<DeviceModel, De
: base(log, deviceModelImageManager, deviceModelMapper, devicesService, tableClientFactory, $"")
{
}

/// <summary>
/// Gets the device model list.
/// </summary>
/// <returns>An array representing the device models.</returns>
[HttpGet(Name = "GET Device model list")]
[ProducesResponseType(StatusCodes.Status200OK)]
public override ActionResult<IEnumerable<DeviceModel>> Get()
{
return base.Get();
}

/// <summary>
/// Get the device model details.
/// </summary>
/// <param name="id">The devic emodel identifier.</param>
/// <returns>The device model details.</returns>
[HttpGet("{id}", Name = "GET Device model")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public override ActionResult<DeviceModel> Get(string id)
{
return base.Get(id);
}

/// <summary>
/// Gets the device model avatar.
/// </summary>
/// <param name="id">The device model identifier</param>
/// <returns></returns>
[HttpGet("{id}/avatar", Name = "GET Device model avatar URL")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public override ActionResult<string> GetAvatar(string id)
{
return base.GetAvatar(id);
}

/// <summary>
/// Changes the avatar.
/// </summary>
/// <param name="id">The model identifier.</param>
/// <param name="file">The file.</param>
/// <returns>The avatar.</returns>
[HttpPost("{id}/avatar", Name = "POST Update the device model avatar")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public override Task<ActionResult<string>> ChangeAvatar(string id, IFormFile file)
{
return base.ChangeAvatar(id, file);
}

/// <summary>
/// Deletes the avatar.
/// </summary>
/// <param name="id">The model identifier.</param>
[HttpDelete("{id}/avatar", Name = "DELETE Remove the device model avatar")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public override Task<IActionResult> DeleteAvatar(string id)
{
return base.DeleteAvatar(id);
}

/// <summary>
/// Creates the specified device model.
/// </summary>
/// <param name="deviceModel">The device model.</param>
/// <returns>The action result.</returns>
[HttpPost(Name = "POST Create a new device model")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public override Task<IActionResult> Post(DeviceModel deviceModel)
{
return base.Post(deviceModel);
}

/// <summary>
/// Updates the specified device model.
/// </summary>
/// <param name="deviceModel">The device model.</param>
/// <returns>The action result.</returns>
[HttpPut("{id}", Name = "PUT Update the device model")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public override Task<IActionResult> Put(DeviceModel deviceModel)
{
return base.Put(deviceModel);
}

/// <summary>
/// Deletes the specified device model.
/// </summary>
/// <param name="id">The device model identifier.</param>
/// <returns>The action result.</returns>
[HttpDelete("{id}", Name = "DELETE Remove the device model")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public override Task<IActionResult> Delete(string id)
{
return base.Delete(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10
using AzureIoTHub.Portal.Shared.Models.V10.Device;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Threading.Tasks;

[ApiController]
[ApiVersion("1.0")]
Expand All @@ -23,5 +25,59 @@ public DevicesController(
{

}

/// <summary>
/// Gets the device list.
/// </summary>
/// <returns></returns>
[HttpGet(Name = "GET Device list")]
public override Task<IEnumerable<DeviceListItem>> Get()
{
return base.Get();
}

/// <summary>
/// Gets the specified device.
/// </summary>
/// <param name="deviceID">The device identifier.</param>
/// <returns></returns>
[HttpGet("{deviceID}", Name = "GET Device details")]
public override Task<DeviceDetails> Get(string deviceID)
{
return base.Get(deviceID);
}

/// <summary>
/// Creates the device.
/// </summary>
/// <param name="device">The device.</param>
/// <returns></returns>
[HttpPost(Name = "POST Create device")]
public override Task<IActionResult> CreateDeviceAsync(DeviceDetails device)
{
return base.CreateDeviceAsync(device);
}

/// <summary>
/// Updates the device.
/// </summary>
/// <param name="device">The device.</param>
/// <returns></returns>
[HttpPut(Name = "PUT Update device")]
public override Task<IActionResult> UpdateDeviceAsync(DeviceDetails device)
{
return base.UpdateDeviceAsync(device);
}

/// <summary>
/// Deletes the specified device.
/// </summary>
/// <param name="deviceID">The device identifier.</param>
/// <returns></returns>
[HttpDelete("{deviceID}", Name = "DELETE Remove device")]
public override Task<IActionResult> Delete(string deviceID)
{
return base.Delete(deviceID);
}
}
}
Loading