add comments for swagger
This commit is contained in:
		
							parent
							
								
									88ccaea826
								
							
						
					
					
						commit
						0e1c464cc1
					
				| @ -6,6 +6,7 @@ using AB.Services.Abstractions; | |||||||
| using AB_API.Middleware; | using AB_API.Middleware; | ||||||
| using Microsoft.EntityFrameworkCore; | using Microsoft.EntityFrameworkCore; | ||||||
| using Microsoft.OpenApi.Models; | using Microsoft.OpenApi.Models; | ||||||
|  | using System.Reflection; | ||||||
| using System.Text.Json.Serialization; | using System.Text.Json.Serialization; | ||||||
| 
 | 
 | ||||||
| var builder = WebApplication.CreateBuilder(args); | var builder = WebApplication.CreateBuilder(args); | ||||||
| @ -17,7 +18,18 @@ builder.Services.AddControllers().AddApplicationPart(typeof(AB.API.AssemblyRefer | |||||||
| 
 | 
 | ||||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||||||
| builder.Services.AddEndpointsApiExplorer(); | builder.Services.AddEndpointsApiExplorer(); | ||||||
| builder.Services.AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApiInfo { Title = "AB-API", Version = "v1", Description = "An Api for the AB-Application" })); | builder.Services.AddSwaggerGen(c => | ||||||
|  | { | ||||||
|  |     c.SwaggerDoc("v1", new OpenApiInfo | ||||||
|  |     { | ||||||
|  |         Title = "AB-API", | ||||||
|  |         Version = "v1", | ||||||
|  |         Description = "An Api for the AB-Application" | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     var xmlFilename = $"{typeof(AB.API.AssemblyReference).Assembly.GetName().Name}.xml"; | ||||||
|  |     c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); | ||||||
|  | }); | ||||||
| 
 | 
 | ||||||
| builder.Services.AddScoped<ICustomerService, CustomerService>(); | builder.Services.AddScoped<ICustomerService, CustomerService>(); | ||||||
| builder.Services.AddScoped<ICustomerRepository, CustomerRepository>(); | builder.Services.AddScoped<ICustomerRepository, CustomerRepository>(); | ||||||
|  | |||||||
| @ -4,6 +4,7 @@ | |||||||
| 		<TargetFramework>net6.0</TargetFramework> | 		<TargetFramework>net6.0</TargetFramework> | ||||||
| 		<ImplicitUsings>enable</ImplicitUsings> | 		<ImplicitUsings>enable</ImplicitUsings> | ||||||
| 		<Nullable>enable</Nullable> | 		<Nullable>enable</Nullable> | ||||||
|  | 		<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||||||
| 	</PropertyGroup> | 	</PropertyGroup> | ||||||
| 
 | 
 | ||||||
| 	<ItemGroup> | 	<ItemGroup> | ||||||
|  | |||||||
| @ -1,11 +1,13 @@ | |||||||
| using AB.Contracts; | using AB.Contracts; | ||||||
| using AB.Services.Abstractions; | using AB.Services.Abstractions; | ||||||
|  | using Microsoft.AspNetCore.Http; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
| 
 | 
 | ||||||
| namespace AB.API.Controllers.BusinessPartner; | namespace AB.API.Controllers.BusinessPartner; | ||||||
| 
 | 
 | ||||||
| [ApiController] | [ApiController] | ||||||
| [Route("api/customers")] | [Route("api/customers")] | ||||||
|  | [Produces("application/json")] | ||||||
| public class CustomerController : ControllerBase | public class CustomerController : ControllerBase | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
| @ -16,6 +18,11 @@ public class CustomerController : ControllerBase | |||||||
|             _customerService = customerService; |             _customerService = customerService; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// Abrufen aller Kunden  | ||||||
|  |     /// </summary> | ||||||
|  |     /// <param name="cancellationToken"></param> | ||||||
|  |     /// <returns>Eine Liste aller Kunden</returns> | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     public async Task<ActionResult<IEnumerable<CustomerDto>>> GetCustomers(CancellationToken cancellationToken) |     public async Task<ActionResult<IEnumerable<CustomerDto>>> GetCustomers(CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
| @ -24,6 +31,12 @@ public class CustomerController : ControllerBase | |||||||
|         return Ok(customers); |         return Ok(customers); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// Abrufen eines Kunden anhand seiner Id | ||||||
|  |     /// </summary> | ||||||
|  |     /// <param name="customerId"></param> | ||||||
|  |     /// <param name="cancellationToken"></param> | ||||||
|  |     /// <returns>Den Kunden mit der angegeben Id</returns> | ||||||
|     [HttpGet("{customerId:guid}")] |     [HttpGet("{customerId:guid}")] | ||||||
|     public async Task<ActionResult<CustomerDto>> GetCustomerById(Guid customerId, CancellationToken cancellationToken) |     public async Task<ActionResult<CustomerDto>> GetCustomerById(Guid customerId, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
| @ -32,7 +45,14 @@ public class CustomerController : ControllerBase | |||||||
|         return Ok(customer); |         return Ok(customer); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// Anlegen eines neuen Kunden | ||||||
|  |     /// </summary> | ||||||
|  |     /// <param name="customerForCreation"></param> | ||||||
|  |     /// <returns>Einen neu erstellten Kunden</returns> | ||||||
|  |     /// <response code="201">Kunde wurde erstellt</response> | ||||||
|     [HttpPost] |     [HttpPost] | ||||||
|  |     [ProducesResponseType(StatusCodes.Status201Created)] | ||||||
|     public async Task<CreatedAtActionResult> CreateCustomer([FromBody] CustomerForCreationDto customerForCreation) |     public async Task<CreatedAtActionResult> CreateCustomer([FromBody] CustomerForCreationDto customerForCreation) | ||||||
|     { |     { | ||||||
|         var customerDto = await _customerService.CreateAsync(customerForCreation); |         var customerDto = await _customerService.CreateAsync(customerForCreation); | ||||||
| @ -40,7 +60,17 @@ public class CustomerController : ControllerBase | |||||||
|         return CreatedAtAction(nameof(CreateCustomer), new { customerId = customerDto.Id }, customerDto); |         return CreatedAtAction(nameof(CreateCustomer), new { customerId = customerDto.Id }, customerDto); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// Löschen eines vorhandenen Kunden | ||||||
|  |     /// </summary> | ||||||
|  |     /// <param name="customerId"></param> | ||||||
|  |     /// <param name="cancellationToken"></param> | ||||||
|  |     /// <returns></returns> | ||||||
|  |     /// <response code="204">Kunde wurde gelöscht</response> | ||||||
|  |     /// <response code="404">Kunde wurde nicht gefunden</response> | ||||||
|     [HttpDelete("{customerId:guid}")] |     [HttpDelete("{customerId:guid}")] | ||||||
|  |     [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||||
|  |     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|     public async Task<NoContentResult> DeleteCustomer(Guid customerId, CancellationToken cancellationToken) |     public async Task<NoContentResult> DeleteCustomer(Guid customerId, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
|         await _customerService.DeleteAsync(customerId, cancellationToken); |         await _customerService.DeleteAsync(customerId, cancellationToken); | ||||||
| @ -48,7 +78,19 @@ public class CustomerController : ControllerBase | |||||||
|         return NoContent(); |         return NoContent(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// Bearbeiten eines vorhanden Kunden | ||||||
|  |     /// </summary> | ||||||
|  |     /// <param name="customerId"></param> | ||||||
|  |     /// <param name="customerForUpdate"></param> | ||||||
|  |     /// <param name="cancellationToken"></param> | ||||||
|  |     /// <returns>Den veränderten Kunden | ||||||
|  |     /// </returns> | ||||||
|  |     /// <response code="200">Kunde wurde bearbeitet</response> | ||||||
|  |     /// <response code="404">Kunde wurde nicht gefunden</response> | ||||||
|     [HttpPut("{customerId:guid}")] |     [HttpPut("{customerId:guid}")] | ||||||
|  |     [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|     public async Task<ActionResult<CustomerDto>> UpdateCustomer(Guid customerId, CustomerForUpdateDto customerForUpdate, CancellationToken cancellationToken) |     public async Task<ActionResult<CustomerDto>> UpdateCustomer(Guid customerId, CustomerForUpdateDto customerForUpdate, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
|         var customerDto = await _customerService.UpdateAsync(customerId, customerForUpdate, cancellationToken); |         var customerDto = await _customerService.UpdateAsync(customerId, customerForUpdate, cancellationToken); | ||||||
|  | |||||||
| @ -1,11 +1,13 @@ | |||||||
| using AB.Contracts; | using AB.Contracts; | ||||||
| using AB.Services.Abstractions; | using AB.Services.Abstractions; | ||||||
|  | using Microsoft.AspNetCore.Http; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
| 
 | 
 | ||||||
| namespace AB.API.Controllers.BusinessPartner; | namespace AB.API.Controllers.BusinessPartner; | ||||||
| 
 | 
 | ||||||
| [ApiController] | [ApiController] | ||||||
| [Route("api/suppliers")] | [Route("api/suppliers")] | ||||||
|  | [Produces("application/json")] | ||||||
| public class SupplierController : ControllerBase | public class SupplierController : ControllerBase | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
| @ -16,6 +18,11 @@ public class SupplierController : ControllerBase | |||||||
|         _supplierService = supplierService; |         _supplierService = supplierService; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// Abrufen aller Lieferanten | ||||||
|  |     /// </summary> | ||||||
|  |     /// <param name="cancellationToken"></param> | ||||||
|  |     /// <returns></returns> | ||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     public async Task<ActionResult<IEnumerable<SupplierDto>>> GetSupplieres(CancellationToken cancellationToken) |     public async Task<ActionResult<IEnumerable<SupplierDto>>> GetSupplieres(CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
| @ -24,7 +31,16 @@ public class SupplierController : ControllerBase | |||||||
|         return Ok(suppliers); |         return Ok(suppliers); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// Abrufen eines Lieferanten anhand seiner Id | ||||||
|  |     /// </summary> | ||||||
|  |     /// <param name="supplierId"></param> | ||||||
|  |     /// <param name="cancellationToken"></param> | ||||||
|  |     /// <returns></returns> | ||||||
|  |     /// <response code="404">Lieferant wurde nicht gefunden</response> | ||||||
|     [HttpGet("{supplierId:guid}")] |     [HttpGet("{supplierId:guid}")] | ||||||
|  |     [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|     public async Task<ActionResult<SupplierDto>> GetSupplierById(Guid supplierId, CancellationToken cancellationToken) |     public async Task<ActionResult<SupplierDto>> GetSupplierById(Guid supplierId, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
|         var supplierDto = await _supplierService.GetSupplierByIdAsync(supplierId, cancellationToken); |         var supplierDto = await _supplierService.GetSupplierByIdAsync(supplierId, cancellationToken); | ||||||
| @ -32,7 +48,15 @@ public class SupplierController : ControllerBase | |||||||
|         return Ok(supplierDto); |         return Ok(supplierDto); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// Anlegen eines neuen Lieferanten | ||||||
|  |     /// </summary> | ||||||
|  |     /// <param name="supplierForCreation"></param> | ||||||
|  |     /// <param name="cancellationToken"></param> | ||||||
|  |     /// <returns>Einen neu erstellen Kunden</returns> | ||||||
|  |     /// <response code="201">Lieferant wurde erstellt</response> | ||||||
|     [HttpPost] |     [HttpPost] | ||||||
|  |     [ProducesResponseType(StatusCodes.Status201Created)] | ||||||
|     public async Task<CreatedAtActionResult> CreateSupplier([FromBody] SupplierForCreationDto supplierForCreation, CancellationToken cancellationToken) |     public async Task<CreatedAtActionResult> CreateSupplier([FromBody] SupplierForCreationDto supplierForCreation, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
|         var supplierDto = await _supplierService.CreateAsync(supplierForCreation, cancellationToken); |         var supplierDto = await _supplierService.CreateAsync(supplierForCreation, cancellationToken); | ||||||
| @ -40,7 +64,17 @@ public class SupplierController : ControllerBase | |||||||
|         return CreatedAtAction(nameof(CreateSupplier), new { id = supplierDto.Id }, supplierDto); |         return CreatedAtAction(nameof(CreateSupplier), new { id = supplierDto.Id }, supplierDto); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// Löschen eines vorhanden Lieferanten | ||||||
|  |     /// </summary> | ||||||
|  |     /// <param name="supplierId"></param> | ||||||
|  |     /// <param name="cancellationToken"></param> | ||||||
|  |     /// <returns></returns> | ||||||
|  |     /// <response code="204">Lieferant wurde gelöscht</response> | ||||||
|  |     /// <response code="404">Lieferant wurde nicht gefunden</response> | ||||||
|     [HttpDelete("{supplierId:guid}")] |     [HttpDelete("{supplierId:guid}")] | ||||||
|  |     [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||||
|  |     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||||
|     public async Task<NoContentResult> DeleteSupplier(Guid supplierId, CancellationToken cancellationToken) |     public async Task<NoContentResult> DeleteSupplier(Guid supplierId, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
|         await _supplierService.DeleteAsync(supplierId, cancellationToken); |         await _supplierService.DeleteAsync(supplierId, cancellationToken); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user