Note Onion - 4 - API - NoteTypeController

Here is the source code for NoteTypeController.cs This is placed in the Controllers folder of the Note.Api class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Note.Application.DTOs;
using Note.Application.Services;
using Note.Shared;
using Notes.API;
using Swashbuckle.AspNetCore.Annotations;
using Swashbuckle.AspNetCore.Filters;

namespace Notes.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class NoteTypeController : ControllerBase
{
private readonly INoteTypeService _noteTypeService;

public NoteTypeController(INoteTypeService noteTypeService)
{
_noteTypeService = noteTypeService;
}

/// <summary>
/// Returns a list of all note types
/// </summary>
/// <returns>
/// A result(NoteTypeVM) object containing a collection of
/// note type objects.
/// </returns>
/// <param name="companyKey">Code given to you to help identify your company</param>
/// <param name="applicationKey">A filter representing an application integrated into this microservice</param>
/// <remarks>Get: api/noteTypes</remarks>
[HttpGet("{companyKey}/{applicationKey}")]
[SwaggerResponse(
StatusCodes.Status200OK,
"HTTP 200 means a model is being returned. Check the WasSuccessfulTrue to determine if it worked properly",
typeof(IResult<List<NoteTypeDto>>))]
[SwaggerResponseExample(
StatusCodes.Status200OK,
typeof(NoteTypeControllerSwashbuckleExamples.NoteTypeGetAllExample))]
public async Task<IActionResult> GetNoteTypesAsync(
string companyKey,
string applicationKey)
{
var result = await _noteTypeService.GetNoteTypes(companyKey, applicationKey);
return Ok(result);
}

/// <summary>
/// Returns one NoteType object based on an ID provided
/// </summary>
/// <param name="companyKey">This is a code given to your agency</param>
/// <param name="id">
/// This is the ID of the notetype object you are looking for
/// </param>
/// <returns></returns>
// Get: api/noteType/x
[HttpGet("{companyKey}/app{id}")]
[SwaggerResponse(
StatusCodes.Status200OK,
type: typeof(BaseResult<NoteTypeDto>))]
[SwaggerResponseExample(
StatusCodes.Status200OK,
typeof(NoteTypeControllerSwashbuckleExamples.NoteTypeGetOneExample))]
public async Task<IActionResult> GetNoteTypeById(
string companyKey,
long id)
{
var result = await _noteTypeService.GetNoteTypeById(companyKey, id);
return Ok(result);
}

///// <summary>
///// Returns a result(NoteTypeVM) object. A new object
///// </summary>
///// <returns></returns>
//[HttpGet("null")]
////[SwaggerResponse(StatusCodes.Status200OK, null, typeof(IResult<NoteTypeViewModel>))]
////[SwaggerResponseExample(StatusCodes.Status200OK, typeof(NoteTypeControllerSwashbuckleExamples.NoteTypeGetOneExampleNull))]
//public Task<IActionResult> GetOne()
//{
// return ReturnResult(new Result<List<NoteTypeDto>>());
// //var result = await _noteTypeService.GetNoteById(companyKey, id);
// //return Ok(result);
//}


/// <summary>
/// Adds a NoteTypeVM object to the database
/// </summary>
/// <param name="noteTypeVm"></param>
/// <returns></returns>
[HttpPost]
[SwaggerRequestExample(typeof(NoteTypeDto), typeof(NoteTypeControllerSwashbuckleExamples.NoteTypePostExample))]
[SwaggerResponse(
StatusCodes.Status200OK,
"HTTP 200 means a model is being returned. Check the WasSuccessfulTrue to determine if it worked properly",
typeof(IResult<NoteTypeDto>))]
[SwaggerResponseExample(
StatusCodes.Status200OK,
typeof(NoteTypeControllerSwashbuckleExamples.NoteTypePostResultsExampleSuccess))]
public async Task<IActionResult> CreateNoteType(
[FromBody] NoteTypeDto noteTypeDto)
{
var result = await _noteTypeService.CreateNoteType(noteTypeDto);
return Ok(result);
}

//[SwaggerResponse(StatusCodes.Status200OK, type: typeof(BaseResult<bool>))]
/// <summary>
/// Update the database with the NoteTypeVM object being provided.
/// </summary>
/// <param name="id">ID of the notetype code being updated</param>
/// <returns></returns>
[HttpPut("{id}")]
[SwaggerRequestExample(
typeof(NoteTypeDto),
typeof(NoteTypeControllerSwashbuckleExamples.NoteTypePutExample))]
[SwaggerResponseExample(
StatusCodes.Status200OK,
typeof(NoteTypeControllerSwashbuckleExamples.NoteTypePostResultsExampleSuccess))]
public async Task<IActionResult> UpdateNoteType(
long id,
[FromBody] NoteTypeDto noteTypeDto)
{
noteTypeDto.Id = id;
var result = await _noteTypeService.UpdateNoteType(noteTypeDto);
return Ok(result);
}

//[HttpDelete("{id}")]
//[SwaggerResponse(StatusCodes.Status200OK, type: typeof(BaseResult<bool>))]
/// <summary>
/// Delete's a NoteType object from the database.
/// </summary>
/// <param name="companyKey">This is a code given to your agency</param>
/// <param name="id">
/// This is the ID of the note that should be deleted
/// </param>
/// <returns></returns>
[HttpDelete("{companyKey}/{id}")]
[SwaggerResponse(
StatusCodes.Status200OK,
"HTTP 200 means a model is being returned. Check the WasSuccessfulTrue to determine if it worked properly",
typeof(IResult<NoteTypeDto>))]
[SwaggerResponseExample(
StatusCodes.Status200OK,
typeof(NoteTypeControllerSwashbuckleExamples.NoteTypeDeleteResultsExampleSuccess))]
public async Task<IActionResult> DeleteNoteType(
string companyKey,
long id)
{
var result = await _noteTypeService.DeleteNoteType(companyKey, id);
return Ok(result);
}
}
}