Skip to content

Commit b3cb75d

Browse files
committed
[add] additional sample controllers
1 parent c579098 commit b3cb75d

File tree

9 files changed

+172
-0
lines changed

9 files changed

+172
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Simplify.Web;
4+
using Simplify.Web.Attributes;
5+
using Simplify.Web.Json.Responses;
6+
using TesterApp.ViewModels;
7+
8+
namespace TesterApp.Controllers.Api.v1.Groups;
9+
10+
[Produces("application/json")]
11+
[Get("/api/v1/groups")]
12+
public class GetMultipleController : Simplify.Web.Controller
13+
{
14+
public override ControllerResponse Invoke()
15+
{
16+
var items = new List<GroupViewModel>
17+
{
18+
new GroupViewModel
19+
{
20+
Name = "Group 1"
21+
},
22+
new GroupViewModel
23+
{
24+
Name = "Group 2"
25+
}
26+
};
27+
28+
// Items retrieve
29+
30+
return new Json(items);
31+
}
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Simplify.Web;
3+
using Simplify.Web.Attributes;
4+
5+
namespace TesterApp.Controllers.Api.v1.Groups;
6+
7+
[Produces("application/text")]
8+
[Authorize]
9+
[Patch("/api/v1/groups/{id:int}/rename")]
10+
public class RenameController : Simplify.Web.Controller
11+
{
12+
public override ControllerResponse Invoke()
13+
{
14+
if (RouteParameters.id <= 0)
15+
return StatusCode(400, "User ID is invalid");
16+
17+
return NoContent();
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Simplify.Web;
5+
using Simplify.Web.Attributes;
6+
using TesterApp.ViewModels;
7+
8+
namespace TesterApp.Controllers.Api.v1.Users;
9+
10+
[Produces("application/text")]
11+
[Post("/api/v1/users")]
12+
public class CreateController : AsyncController<UserAddViewModel>
13+
{
14+
public override async Task<ControllerResponse> Invoke()
15+
{
16+
await ReadModelAsync();
17+
18+
return Content($"User created at {DateTime.Now.ToLongTimeString()}'");
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Simplify.Web;
2+
using Simplify.Web.Attributes;
3+
4+
namespace TesterApp.Controllers.Api.v1.Users;
5+
6+
[Authorize]
7+
[Delete("/api/v1/users/{id:int}")]
8+
public class DeleteController : Simplify.Web.Controller
9+
{
10+
public override ControllerResponse Invoke()
11+
{
12+
if (RouteParameters.id <= 0)
13+
return StatusCode(400, "User ID is invalid");
14+
15+
if (RouteParameters.id > 100)
16+
return StatusCode(500, "Internal Server Error");
17+
18+
return NoContent();
19+
}
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using Simplify.Web;
3+
using Simplify.Web.Attributes;
4+
using Simplify.Web.Json.Responses;
5+
using TesterApp.ViewModels;
6+
7+
namespace TesterApp.Controllers.Api.v1.Users;
8+
9+
[Get("/api/v1/users/{id:int}")]
10+
public class GetController : Simplify.Web.Controller
11+
{
12+
public override ControllerResponse Invoke() =>
13+
new Json(new UserViewModel
14+
{
15+
UserName = "User 1",
16+
CreationTime = DateTime.Now
17+
});
18+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Simplify.Web;
5+
using Simplify.Web.Attributes;
6+
using Simplify.Web.Json.Responses;
7+
using TesterApp.ViewModels;
8+
9+
namespace TesterApp.Controllers.Api.v1.Users;
10+
11+
[Produces("application/json")]
12+
[Get("/api/v1/users")]
13+
public class GetMultipleController : Simplify.Web.Controller
14+
{
15+
public override ControllerResponse Invoke()
16+
{
17+
var items = new List<UserViewModel>
18+
{
19+
new UserViewModel
20+
{
21+
UserName = "User 1",
22+
CreationTime = DateTime.Now
23+
},
24+
new UserViewModel
25+
{
26+
UserName = "User 2",
27+
CreationTime = DateTime.Now.Subtract(TimeSpan.FromDays(1))
28+
}
29+
};
30+
31+
return new Json(items);
32+
}
33+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace TesterApp.ViewModels
2+
{
3+
public class GroupViewModel
4+
{
5+
public string Name { get; set; }
6+
}
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Simplify.Web.Model.Validation.Attributes;
2+
3+
namespace TesterApp.ViewModels
4+
{
5+
public class UserAddViewModel
6+
{
7+
[Required]
8+
public string UserName { get; set; }
9+
10+
[Required]
11+
public string Password { get; set; }
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace TesterApp.ViewModels
4+
{
5+
public class UserViewModel
6+
{
7+
public string UserName { get; set; }
8+
public DateTime CreationTime { get; set; }
9+
}
10+
}

0 commit comments

Comments
 (0)