Skip to content

Commit 5cd52f9

Browse files
committed
[edit] controller with specified type in route swithc to v2 controllers
[r] formatting
1 parent 7af6ab2 commit 5cd52f9

File tree

7 files changed

+23
-31
lines changed

7 files changed

+23
-31
lines changed

src/TesterApp/Controllers/Api/v1/Groups/GetMultipleController.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Simplify.Web;
44
using Simplify.Web.Attributes;
55
using Simplify.Web.Swagger;
6-
using TesterApp.ViewModels;
76
using TesterApp.ViewModels.Groups;
87

98
namespace TesterApp.Controllers.Api.v1.Groups;
@@ -12,7 +11,7 @@ namespace TesterApp.Controllers.Api.v1.Groups;
1211
[ApiVersion("1.0")]
1312
[ProducesResponse(StatusCodes.Status200OK, typeof(IList<GroupViewModel>), MediaTypeNames.Application.Json)]
1413
[ProducesResponse(StatusCodes.Status500InternalServerError)]
15-
public class GetMultipleController : Simplify.Web.Controller
14+
public class GetMultipleController : Controller
1615
{
1716
public override ControllerResponse Invoke()
1817
{
@@ -23,13 +22,13 @@ public override ControllerResponse Invoke()
2322
switch (languageCode)
2423
{
2524
case "ru":
26-
items.Add(new() { Name = "Группа 1" });
27-
items.Add(new() { Name = "Группа 2" });
25+
items.Add(new GroupViewModel { Name = "Группа 1" });
26+
items.Add(new GroupViewModel { Name = "Группа 2" });
2827
break;
2928

3029
default:
31-
items.Add(new() { Name = "Group 1" });
32-
items.Add(new() { Name = "Group 2" });
30+
items.Add(new GroupViewModel { Name = "Group 1" });
31+
items.Add(new GroupViewModel { Name = "Group 2" });
3332
break;
3433
}
3534

src/TesterApp/Controllers/Api/v1/Groups/RenameController.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@
55

66
namespace TesterApp.Controllers.Api.v1.Groups;
77

8-
[Patch("/api/v1/groups/{id:int}/rename")]
8+
[Patch("/api/v1/groups/{id}/rename")]
99
[Authorize]
1010
[ApiVersion("1.0")]
1111
[Produces("application/text")]
1212
[ProducesResponseType(StatusCodes.Status204NoContent)]
1313
[ProducesResponseType(StatusCodes.Status400BadRequest)]
1414
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
15-
public class RenameController : Simplify.Web.Controller
15+
public class RenameController : Controller2
1616
{
17-
public override ControllerResponse Invoke()
18-
{
19-
if (RouteParameters.id <= 0)
20-
return StatusCode(400, "User ID is invalid");
21-
22-
return NoContent();
23-
}
17+
public ControllerResponse Invoke(int id) =>
18+
id <= 0
19+
? StatusCode(400, "User ID is invalid")
20+
: NoContent();
2421
}

src/TesterApp/Controllers/Api/v1/Users/CreateController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Simplify.Web;
44
using Simplify.Web.Attributes;
55
using Simplify.Web.Swagger;
6-
using TesterApp.ViewModels;
76
using TesterApp.ViewModels.Users;
87

98
namespace TesterApp.Controllers.Api.v1.Users;

src/TesterApp/Controllers/Api/v1/Users/DeleteController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55

66
namespace TesterApp.Controllers.Api.v1.Users;
77

8-
[Delete("/api/v1/users/{id:int}")]
8+
[Delete("/api/v1/users/{id}")]
99
[Authorize]
1010
[ApiVersion("1.0")]
1111
[ProducesResponse(StatusCodes.Status204NoContent)]
1212
[ProducesResponse(StatusCodes.Status400BadRequest)]
1313
[ProducesResponse(StatusCodes.Status500InternalServerError)]
14-
public class DeleteController : Simplify.Web.Controller
14+
public class DeleteController : Controller2
1515
{
16-
public override ControllerResponse Invoke()
16+
public ControllerResponse Invoke(int id)
1717
{
18-
if (RouteParameters.id <= 0)
18+
if (id <= 0)
1919
return StatusCode(400, "User ID is invalid");
2020

21-
if (RouteParameters.id > 100)
21+
if (id > 100)
2222
return StatusCode(500, "Internal Server Error");
2323

2424
return NoContent();

src/TesterApp/Controllers/Api/v1/Users/GetController.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22
using Simplify.Web;
33
using Simplify.Web.Attributes;
44
using Simplify.Web.Swagger;
5-
using TesterApp.ViewModels;
65
using TesterApp.ViewModels.Users;
76

87
namespace TesterApp.Controllers.Api.v1.Users;
98

10-
[Get("/api/v1/users/{id:int}")]
9+
[Get("/api/v1/users/{id}")]
1110
[ApiVersion("1.0")]
1211
[ProducesResponse(StatusCodes.Status200OK, typeof(UserViewModel), "application/json")]
1312
[ProducesResponse(StatusCodes.Status500InternalServerError)]
14-
public class GetController : Simplify.Web.Controller
13+
public class GetController : Controller2
1514
{
16-
public override ControllerResponse Invoke() =>
15+
public ControllerResponse Invoke(int id) =>
1716
Json(new UserViewModel
1817
{
19-
UserName = $"User {RouteParameters.id}",
18+
UserName = $"User {id}",
2019
CreationTime = DateTime.Now
2120
});
2221
}

src/TesterApp/Controllers/Api/v1/Users/GetMultipleController.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
using Simplify.Web;
33
using Simplify.Web.Attributes;
44
using Simplify.Web.Swagger;
5-
using TesterApp.ViewModels;
65
using TesterApp.ViewModels.Users;
76

87
namespace TesterApp.Controllers.Api.v1.Users;
98

109
[Get("/api/v1/users")]
1110
[ApiVersion("1.0")]
12-
// [Produces("application/json")]
1311
[ProducesResponse(StatusCodes.Status200OK, typeof(IList<UserViewModel>), "application/json")]
1412
[ProducesResponse(StatusCodes.Status500InternalServerError)]
15-
public class GetMultipleController : Simplify.Web.Controller
13+
public class GetMultipleController : Controller
1614
{
1715
public override ControllerResponse Invoke()
1816
{

src/TesterApp/Controllers/StringDisplayController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace TesterApp.Controllers;
77

8-
[Get("string-display/{Str}")]
8+
[Get("string-display/{str}")]
99
[ProducesResponse(StatusCodes.Status200OK, MediaTypeNames.Text.Plain)]
1010
public class StringDisplayController : Controller
1111
{
12-
public override ControllerResponse Invoke() => Content("User string: " + RouteParameters.Str);
12+
public override ControllerResponse Invoke() => Content("User string: " + RouteParameters.str);
1313
}

0 commit comments

Comments
 (0)