Skip to content

Commit ad2a2bf

Browse files
authored
Merge pull request #7 from sventhiel/master
add annotations for documentation
2 parents 51aceb9 + ce59682 commit ad2a2bf

20 files changed

+177
-88
lines changed

Vaelastrasz.Server/Configurations/AdminConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public class Admin
44
{
5-
public string Name { get; set; }
6-
public string Password { get; set; }
5+
public required string Name { get; set; }
6+
public required string Password { get; set; }
77
}
88
}
Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
using DataAnnotationsExtensions;
2-
using Microsoft.OpenApi;
1+
using Microsoft.OpenApi;
32
using System.ComponentModel.DataAnnotations;
43

54
namespace Vaelastrasz.Server.Configurations
65
{
76
public class OpenApiInfoConfiguration
87
{
9-
public string Title { get; set; }
10-
public string Description { get; set; }
8+
public required string Title { get; set; }
9+
public required string Description { get; set; }
1110

12-
[System.ComponentModel.DataAnnotations.Url]
13-
public string TermsOfService { get; set; }
11+
[Url]
12+
public string? TermsOfService { get; set; }
1413

15-
public OpenApiContactConfiguration Contact { get; set; }
14+
public required OpenApiContactConfiguration Contact { get; set; }
15+
16+
public required OpenApiLicenseConfiguration License { get; set; }
1617

17-
public OpenApiLicenseConfiguration License { get; set; }
18-
19-
2018
public OpenApiInfo GetOpenApiInfo()
2119
{
22-
if(Validator.TryValidateObject(this, new ValidationContext(this), null, validateAllProperties: true))
20+
if (Validator.TryValidateObject(this, new ValidationContext(this), null, validateAllProperties: true))
2321
{
2422
return new OpenApiInfo
2523
{
@@ -42,25 +40,24 @@ public OpenApiInfo GetOpenApiInfo()
4240

4341
return new OpenApiInfo();
4442
}
45-
4643
}
4744

4845
public class OpenApiContactConfiguration
4946
{
50-
public string Name { get; set; }
47+
public required string Name { get; set; }
5148

5249
[EmailAddress]
53-
public string Email { get; set; }
50+
public string? Email { get; set; }
5451

55-
[System.ComponentModel.DataAnnotations.Url]
56-
public string Url { get; set; }
52+
[Url]
53+
public string? Url { get; set; }
5754
}
5855

5956
public class OpenApiLicenseConfiguration
6057
{
61-
public string Name { get; set; }
58+
public required string Name { get; set; }
6259

63-
[System.ComponentModel.DataAnnotations.Url]
64-
public string Url { get; set; }
60+
[Url]
61+
public string? Url { get; set; }
6562
}
66-
}
63+
}

Vaelastrasz.Server/Controllers/ConceptsController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public ConceptsController(IWebHostEnvironment env, ILogger<ConceptsController> l
3232
/// Weitere Informationen finden Sie in der <see href="https://github.com/sventhiel/Vaelastrasz/tree/master/Vaelastrasz.Server#concepts">Dokumentation</see>.
3333
/// </remarks>
3434
[HttpGet("concepts")]
35+
[ProducesResponseType(typeof(ConceptModel), StatusCodes.Status200OK)]
3536
public async Task<IActionResult> GetAsync()
3637
{
3738
string filePath = Path.Combine(_env.WebRootPath, "concepts", "datacite.json");

Vaelastrasz.Server/Controllers/CreateDataCiteModelsController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.AspNetCore.Mvc;
44
using Vaelastrasz.Library.Extensions;
55
using Vaelastrasz.Library.Models;
6-
using Vaelastrasz.Server.Configurations;
76

87
namespace Vaelastrasz.Server.Controllers
98
{

Vaelastrasz.Server/Controllers/DOIsController.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public DOIsController(ILogger<DataCiteController> logger, IConfiguration configu
4040
/// </remarks>
4141
/// <exception cref="UnauthorizedException">Wird ausgelöst, wenn der Benutzer nicht die Berechtigung hat, den DOI zu löschen.</exception>
4242
[HttpDelete("dois/{prefix}/{suffix}")]
43+
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
44+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
4345
public async Task<IActionResult> DeleteAsync(string prefix, string suffix)
4446
{
4547
if (!User.IsInRole("user") || User?.Identity?.Name == null)
@@ -77,6 +79,8 @@ public async Task<IActionResult> DeleteAsync(string prefix, string suffix)
7779
/// </remarks>
7880
/// <exception cref="UnauthorizedAccessException">Wird ausgelöst, wenn die Benutzeridentität nicht verfügbar ist.</exception>
7981
[HttpGet("dois")]
82+
[ProducesResponseType(typeof(ReadDOIModel), StatusCodes.Status200OK)]
83+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
8084
public async Task<IActionResult> GetAsync()
8185
{
8286
if (!User.IsInRole("user") || User?.Identity?.Name == null)
@@ -110,6 +114,8 @@ public async Task<IActionResult> GetAsync()
110114
/// </remarks>
111115
/// <exception cref="UnauthorizedException">Wird ausgelöst, wenn der Benutzer nicht die Berechtigung hat, auf den DOI-Eintrag zuzugreifen.</exception>
112116
[HttpGet("dois/{id}")]
117+
[ProducesResponseType(typeof(ReadDOIModel), StatusCodes.Status200OK)]
118+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
113119
public async Task<IActionResult> GetById(long id)
114120
{
115121
if (!User.IsInRole("user") || User?.Identity?.Name == null)
@@ -147,6 +153,8 @@ public async Task<IActionResult> GetById(long id)
147153
/// </remarks>
148154
/// <exception cref="UnauthorizedException">Wird ausgelöst, wenn der Benutzer nicht die Berechtigung hat, auf den DOI-Eintrag zuzugreifen.</exception>
149155
[HttpGet("dois/{prefix}/{suffix}")]
156+
[ProducesResponseType(typeof(ReadDOIModel), StatusCodes.Status200OK)]
157+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
150158
public async Task<IActionResult> GetByPrefixAndSuffix(string prefix, string suffix)
151159
{
152160
if (!User.IsInRole("user") || User?.Identity?.Name == null)
@@ -169,6 +177,7 @@ public async Task<IActionResult> GetByPrefixAndSuffix(string prefix, string suff
169177

170178
[HttpPost("dois")]
171179
[ProducesResponseType(typeof(ReadDOIModel), StatusCodes.Status201Created)]
180+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
172181
public async Task<IActionResult> Post(CreateDOIModel model)
173182
{
174183
if (!User.IsInRole("user") || User?.Identity?.Name == null)
@@ -198,6 +207,8 @@ public async Task<IActionResult> Post(CreateDOIModel model)
198207
}
199208

200209
[HttpPut("dois/{doi}")]
210+
[ProducesResponseType(typeof(ReadDOIModel), StatusCodes.Status200OK)]
211+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
201212
public async Task<IActionResult> PutByDOI(string doi, UpdateDOIModel model)
202213
{
203214
if (!User.IsInRole("user") || User?.Identity?.Name == null)
@@ -221,6 +232,8 @@ public async Task<IActionResult> PutByDOI(string doi, UpdateDOIModel model)
221232
}
222233

223234
[HttpPut("dois/{prefix}/{suffix}")]
235+
[ProducesResponseType(typeof(ReadDOIModel), StatusCodes.Status200OK)]
236+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
224237
public async Task<IActionResult> PutByPrefixAndSuffix(string prefix, string suffix, UpdateDOIModel model)
225238
{
226239
if (!User.IsInRole("user") || User?.Identity?.Name == null)

Vaelastrasz.Server/Controllers/DataCiteController.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public DataCiteController(ILogger<DataCiteController> logger, IConfiguration con
4343
/// </remarks>
4444
/// <exception cref="NotFoundException">Wird ausgelöst, wenn das Konto des aktuellen Benutzers nicht vorhanden ist.</exception>
4545
[HttpDelete("datacite/{doi}")]
46+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
4647
public async Task<IActionResult> DeleteByDOIAsync(string doi)
4748
{
4849
if (!User.IsInRole("user-datacite") || User?.Identity?.Name == null)
@@ -86,6 +87,8 @@ public async Task<IActionResult> DeleteByDOIAsync(string doi)
8687
/// </remarks>
8788
/// <exception cref="NotFoundException">Wird ausgelöst, wenn das Konto des aktuellen Benutzers nicht existiert.</exception>
8889
[HttpGet("datacite")]
90+
[ProducesResponseType(typeof(List<ReadDataCiteModel>), StatusCodes.Status200OK)]
91+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
8992
public async Task<IActionResult> GetAsync()
9093
{
9194
if (!User.IsInRole("user-datacite") || User?.Identity?.Name == null)
@@ -151,6 +154,8 @@ public async Task<IActionResult> GetAsync()
151154
/// <exception cref="NotFoundException">Wird ausgelöst, wenn das Konto des Benutzers nicht existiert.</exception>
152155
/// <exception cref="UnauthorizedException">Wird ausgelöst, wenn der Benutzer nicht berechtigt ist, den DOI-Datensatz zu sehen.</exception>
153156
[HttpGet("datacite/{prefix}/{suffix}")]
157+
[ProducesResponseType(typeof(ReadDataCiteModel), StatusCodes.Status200OK)]
158+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
154159
public async Task<IActionResult> GetByPrefixAndSuffixAsync(string prefix, string suffix)
155160
{
156161
if (!User.IsInRole("user-datacite") || User?.Identity?.Name == null)
@@ -200,6 +205,8 @@ public async Task<IActionResult> GetByPrefixAndSuffixAsync(string prefix, string
200205
/// <exception cref="UnauthorizedException">Wird ausgelöst, wenn der Benutzer nicht berechtigt ist, Informationen zum DOI abzurufen.</exception>
201206
[HttpGet("datacite/{prefix}/{suffix}/citations")]
202207
[SwaggerCustomHeader("X-Citation-Style", ["apa", "harvard-cite-them-right", "modern-language-association", "vancouver", "chicago-fullnote-bibliography", "ieee"])]
208+
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
209+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
203210
public async Task<IActionResult> GetCitationStyleByPrefixAndSuffixAsync(string prefix, string suffix)
204211
{
205212
if (!User.IsInRole("user-datacite") || User?.Identity?.Name == null)
@@ -254,6 +261,8 @@ public async Task<IActionResult> GetCitationStyleByPrefixAndSuffixAsync(string p
254261
/// <exception cref="UnauthorizedException">Wird ausgelöst, wenn der Benutzer nicht berechtigt ist, Metadaten für den DOI abzurufen.</exception>
255262
[HttpGet("datacite/{prefix}/{suffix}/metadata")]
256263
[SwaggerCustomHeader("X-Metadata-Format", ["application/x-research-info-systems", "application/x-bibtex", "application/vnd.jats+xml", "application/vnd.codemeta.ld+json", "application/vnd.citationstyles.csl+json", "application/vnd.schemaorg.ld+json", "application/vnd.datacite.datacite+json", "application/vnd.datacite.datacite+xml"])]
264+
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
265+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
257266
public async Task<IActionResult> GetMetadataFormatByPrefixAndSuffixAsync(string prefix, string suffix)
258267
{
259268
if (!User.IsInRole("user-datacite") || User?.Identity?.Name == null)
@@ -307,6 +316,7 @@ public async Task<IActionResult> GetMetadataFormatByPrefixAndSuffixAsync(string
307316
/// <exception cref="ForbiddenException">Wird ausgelöst, wenn der DOI ungültig ist oder nicht verwaltet werden kann.</exception>
308317
[HttpPost("datacite")]
309318
[ProducesResponseType(typeof(ReadDataCiteModel), StatusCodes.Status201Created)]
319+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
310320
public async Task<IActionResult> PostAsync(CreateDataCiteModel model)
311321
{
312322
if (!User.IsInRole("user-datacite") || User?.Identity?.Name == null)
@@ -366,6 +376,8 @@ public async Task<IActionResult> PostAsync(CreateDataCiteModel model)
366376
/// </remarks>
367377
/// <exception cref="NotFoundException">Wird ausgelöst, wenn das Konto des Benutzers nicht existiert.</exception>
368378
[HttpPut("datacite/{doi}")]
379+
[ProducesResponseType(typeof(ReadDataCiteModel), StatusCodes.Status200OK)]
380+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
369381
public async Task<IActionResult> PutByDOIAsync(string doi, UpdateDataCiteModel model)
370382
{
371383
if (!User.IsInRole("user-datacite") || User?.Identity?.Name == null)

Vaelastrasz.Server/Controllers/DatabasesController.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNetCore.Mvc;
55
using Vaelastrasz.Library.Exceptions;
66
using Vaelastrasz.Library.Extensions;
7+
using Vaelastrasz.Library.Models;
78

89
namespace Vaelastrasz.Server.Controllers
910
{
@@ -34,6 +35,9 @@ public DatabasesController(ILogger<AccountsController> logger, ConnectionString
3435
/// Die erfolgreiche Ausführung erfordert ausreichende Berechtigungen für den Zugriff auf das Dateisystem.
3536
/// </remarks>
3637
[HttpDelete("databases")]
38+
[ProducesResponseType(typeof(ConceptModel), StatusCodes.Status200OK)]
39+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
40+
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
3741
public IActionResult DeleteAsync()
3842
{
3943
if (!User.IsInRole("admin"))
@@ -43,7 +47,10 @@ public IActionResult DeleteAsync()
4347

4448
database.Delete();
4549

46-
return Ok();
50+
if (database.Exists)
51+
return NotFound();
52+
53+
return Ok(true);
4754
}
4855

4956
/// <summary>
@@ -59,6 +66,9 @@ public IActionResult DeleteAsync()
5966
/// Es ist wichtig, dass die Zugriffsberechtigungen korrekt gesetzt sind, um sicherzustellen, dass der Dateidownload funktioniert.
6067
/// </remarks>
6168
[HttpGet("databases")]
69+
[ProducesResponseType(typeof(ConceptModel), StatusCodes.Status200OK)]
70+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
71+
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
6272
public IActionResult GetAsync()
6373
{
6474
if (!User.IsInRole("admin"))
@@ -67,6 +77,9 @@ public IActionResult GetAsync()
6777
// database
6878
FileInfo database = new FileInfo(_connectionString.Filename);
6979

80+
if (database == null || !database.Exists)
81+
return NotFound();
82+
7083
return File(System.IO.File.OpenRead(database.FullName), "application/octet-stream", $"{database.GetFileNameWithoutExtension()}_{DateTimeOffset.UtcNow.ToString("yyyyMMddHHmmss")}{database.GetExtension()}");
7184
}
7285

@@ -85,29 +98,36 @@ public IActionResult GetAsync()
8598
/// </remarks>
8699
/// <exception cref="BadRequestException">Wird ausgelöst, wenn die hochgeladene Datei nicht den Anforderungen entspricht oder ungültig ist.</exception>
87100
[HttpPost("databases")]
88-
[ProducesResponseType(StatusCodes.Status201Created)]
101+
[ProducesResponseType(typeof(void), StatusCodes.Status201Created)]
102+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
103+
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
89104
public async Task<IActionResult> PostAsync(IFormFile file)
90105
{
91106
if (!User.IsInRole("admin"))
92107
return Forbid();
93108

94109
if (file == null)
95-
throw new BadRequestException("null");
110+
//throw new BadRequestException("null");
111+
return BadRequest("null");
96112

97113
if (file.Length == 0)
98-
throw new BadRequestException("0");
114+
//throw new BadRequestException("0");
115+
return BadRequest("0");
99116

100117
// Validate file extension
101118
var extension = Path.GetExtension(file.FileName).ToLowerInvariant();
102119
if (string.IsNullOrEmpty(extension))
103-
throw new BadRequestException("empty extension");
120+
//throw new BadRequestException("empty extension");
121+
return BadRequest("empty extension");
104122

105123
if (extension != ".db")
106-
throw new BadRequestException("!= .db extension");
124+
//throw new BadRequestException("!= .db extension");
125+
return BadRequest("!= .db extension");
107126

108127
var mimeTypes = new List<string> { "application/x-litedb", "application/octet-stream" };
109128
if (!mimeTypes.Contains(file.ContentType))
110-
throw new BadRequestException("mime type");
129+
//throw new BadRequestException("mime type");
130+
return BadRequest("mime type");
111131

112132
string databasePath = new FileInfo(_connectionString.Filename).FullName;
113133

Vaelastrasz.Server/Controllers/NamesController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public NamesController(ILogger<UsersController> logger)
3131
/// </remarks>
3232
/// <exception cref="ArgumentNullException">Wird ausgelöst, wenn der übergebene Name null ist.</exception>
3333
[HttpPost("names")]
34+
[ProducesResponseType(typeof(HumanName), StatusCodes.Status200OK)]
35+
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
3436
public IActionResult Post([FromBody] string name)
3537
{
3638
if (string.IsNullOrEmpty(name))

Vaelastrasz.Server/Controllers/PlaceholdersController.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public PlaceholdersController(ILogger<PlaceholdersController> logger, IConfigura
4040
/// </remarks>
4141
/// <exception cref="UnauthorizedException">Wird ausgelöst, wenn der Benutzer nicht berechtigt ist, den Platzhalter zu löschen.</exception>
4242
[HttpDelete("placeholders/{id}")]
43+
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
44+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
4345
public async Task<IActionResult> DeleteByIdAsync(long id)
4446
{
4547
using var placeholderService = new PlaceholderService(_connectionString);
@@ -69,6 +71,8 @@ public async Task<IActionResult> DeleteByIdAsync(long id)
6971
/// </remarks>
7072
/// <exception cref="InvalidOperationException">Wird ausgelöst, wenn ein unerwarteter Fehler beim Zugriff auf Benutzerdaten auftritt.</exception>
7173
[HttpGet("placeholders")]
74+
[ProducesResponseType(typeof(IEnumerable<ReadPlaceholderModel>), StatusCodes.Status200OK)]
75+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
7276
public async Task<IActionResult> GetAsync()
7377
{
7478
using var placeholderService = new PlaceholderService(_connectionString);
@@ -104,6 +108,8 @@ public async Task<IActionResult> GetAsync()
104108
/// </remarks>
105109
/// <exception cref="UnauthorizedException">Wird ausgelöst, wenn der Zugriff ohne angemessene Authentifizierung erfolgt.</exception>
106110
[HttpGet("placeholders/{id}")]
111+
[ProducesResponseType(typeof(ReadPlaceholderModel), StatusCodes.Status200OK)]
112+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
107113
public async Task<IActionResult> GetByIdAsync(long id)
108114
{
109115
using var placeholderService = new PlaceholderService(_connectionString);
@@ -134,6 +140,7 @@ public async Task<IActionResult> GetByIdAsync(long id)
134140
/// <exception cref="UnauthorizedException">Wird ausgelöst, wenn der Zugriff ohne ordnungsgemäße Authentifizierung erfolgt.</exception>
135141
[HttpPost("placeholders")]
136142
[ProducesResponseType(typeof(ReadPlaceholderModel), StatusCodes.Status201Created)]
143+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
137144
public async Task<IActionResult> PostAsync(CreatePlaceholderModel model)
138145
{
139146
if (User.IsInRole("admin") || (User.IsInRole("user") && long.TryParse(User.FindFirst("UserId")?.Value, out long userId) && model.UserId == userId))
@@ -170,6 +177,8 @@ public async Task<IActionResult> PostAsync(CreatePlaceholderModel model)
170177
/// </remarks>
171178
/// <exception cref="UnauthorizedException">Wird ausgelöst, wenn ein Benutzer ohne die erforderlichen Berechtigungen versucht, den Platzhalter zu aktualisieren.</exception>
172179
[HttpPut("placeholders/{id}")]
180+
[ProducesResponseType(typeof(ReadPlaceholderModel), StatusCodes.Status200OK)]
181+
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
173182
public async Task<IActionResult> PutByIdAsync(long id, UpdatePlaceholderModel model)
174183
{
175184
using var placeholderService = new PlaceholderService(_connectionString);

0 commit comments

Comments
 (0)