Skip to content

Commit 18ef8ee

Browse files
Thierry Habarthabarthierry-hue
authored andcommitted
Ticket 24 : Display case plans
1 parent 7b6b3ac commit 18ef8ee

94 files changed

Lines changed: 1282 additions & 515 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/CaseManagement.CMMN.AspNetCore/Apis/CaseFilesController.cs

Lines changed: 102 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,106 @@ public async Task<IActionResult> Count()
4747
});
4848
}
4949

50+
[HttpPost("me")]
51+
[Authorize("me_add_casefile")]
52+
public Task<IActionResult> AddMe([FromBody] AddCaseFileCommand parameter)
53+
{
54+
parameter.Owner = this.GetNameIdentifier();
55+
return InternalAdd(parameter);
56+
}
57+
5058
[HttpPost]
5159
[Authorize("add_casefile")]
52-
public async Task<IActionResult> Create([FromBody] AddCaseFileCommand parameter)
60+
public Task<IActionResult> Add([FromBody] AddCaseFileCommand parameter)
61+
{
62+
return InternalAdd(parameter);
63+
}
64+
65+
[HttpPut("me/{id}")]
66+
[Authorize("me_update_casefile")]
67+
public Task<IActionResult> UpdateMe(string id, [FromBody] UpdateCaseFileCommand parameter)
68+
{
69+
parameter.Id = id;
70+
parameter.BypassUserValidation = false;
71+
parameter.Performer = this.GetNameIdentifier();
72+
return InternalUpdate(parameter);
73+
}
74+
75+
[HttpPut("{id}")]
76+
[Authorize("update_casefile")]
77+
public Task<IActionResult> Update(string id, [FromBody] UpdateCaseFileCommand parameter)
78+
{
79+
parameter.Id = id;
80+
parameter.BypassUserValidation = true;
81+
return InternalUpdate(parameter);
82+
}
83+
84+
[HttpGet("me/{id}/publish")]
85+
[Authorize("me_publish_casefile")]
86+
public Task<IActionResult> PublishMe(string id)
87+
{
88+
var cmd = new PublishCaseFileCommand
89+
{
90+
Id = id,
91+
BypassUserValidation = false,
92+
Performer = this.GetNameIdentifier()
93+
};
94+
return InternalPublish(cmd);
95+
}
96+
97+
[HttpGet("{id}/publish")]
98+
[Authorize("publish_casefile")]
99+
public Task<IActionResult> Publish(string id)
100+
{
101+
var cmd = new PublishCaseFileCommand
102+
{
103+
Id = id,
104+
BypassUserValidation = true
105+
};
106+
return InternalPublish(cmd);
107+
}
108+
109+
[HttpGet("search")]
110+
[Authorize("get_casefile")]
111+
public async Task<IActionResult> Search()
112+
{
113+
var query = HttpContext.Request.Query.ToEnumerable();
114+
var result = await _queryRepository.Find(ExtractFindParameter(query));
115+
return new OkObjectResult(ToDto(result));
116+
}
117+
118+
[HttpGet("me/{id}")]
119+
[Authorize("me_get_casefile")]
120+
public async Task<IActionResult> GetMe(string id)
121+
{
122+
var result = await _queryRepository.FindById(id);
123+
if (result == null)
124+
{
125+
return new NotFoundResult();
126+
}
127+
128+
if (result.Owner != this.GetNameIdentifier())
129+
{
130+
return new UnauthorizedResult();
131+
}
132+
133+
return new OkObjectResult(ToDto(result));
134+
}
135+
136+
[HttpGet("{id}")]
137+
[Authorize("get_casefile")]
138+
public async Task<IActionResult> Get(string id)
139+
{
140+
var result = await _queryRepository.FindById(id);
141+
if (result == null)
142+
{
143+
return new NotFoundResult();
144+
}
145+
146+
return new OkObjectResult(ToDto(result));
147+
}
148+
149+
private async Task<IActionResult> InternalAdd(AddCaseFileCommand parameter)
53150
{
54151
try
55152
{
@@ -70,21 +167,18 @@ public async Task<IActionResult> Create([FromBody] AddCaseFileCommand parameter)
70167
}
71168
}
72169

73-
[HttpPut("{id}")]
74-
[Authorize("update_casefile")]
75-
public async Task<IActionResult> Update(string id, [FromBody] UpdateCaseFileCommand parameter)
170+
private async Task<IActionResult> InternalUpdate(UpdateCaseFileCommand parameter)
76171
{
77172
try
78173
{
79-
parameter.Id = id;
80174
await _updateCaseFileCommandHandler.Handle(parameter);
81175
return new OkResult();
82176
}
83-
catch(UnknownCaseFileException)
177+
catch (UnknownCaseFileException)
84178
{
85179
return new NotFoundResult();
86180
}
87-
catch(UnauthorizedCaseFileException)
181+
catch (UnauthorizedCaseFileException)
88182
{
89183
return new UnauthorizedResult();
90184
}
@@ -94,13 +188,10 @@ public async Task<IActionResult> Update(string id, [FromBody] UpdateCaseFileComm
94188
}
95189
}
96190

97-
[HttpPost("{id}/publish")]
98-
[Authorize("publish_casefile")]
99-
public async Task<IActionResult> Publish(string id, [FromBody] PublishCaseFileCommand publishCaseFileCommand)
191+
private async Task<IActionResult> InternalPublish(PublishCaseFileCommand publishCaseFileCommand)
100192
{
101193
try
102194
{
103-
publishCaseFileCommand.Id = id;
104195
var newCaseFileId = await _publishCaseFileCommandHandler.Handle(publishCaseFileCommand);
105196
return new OkObjectResult(new JObject
106197
{
@@ -121,28 +212,6 @@ public async Task<IActionResult> Publish(string id, [FromBody] PublishCaseFileCo
121212
}
122213
}
123214

124-
[HttpGet("search")]
125-
[Authorize("get_casefile")]
126-
public async Task<IActionResult> Search()
127-
{
128-
var query = HttpContext.Request.Query.ToEnumerable();
129-
var result = await _queryRepository.Find(ExtractFindParameter(query));
130-
return new OkObjectResult(ToDto(result));
131-
}
132-
133-
[HttpGet("{id}")]
134-
[Authorize("get_casefile")]
135-
public async Task<IActionResult> Get(string id)
136-
{
137-
var result = await _queryRepository.FindById(id);
138-
if (result == null)
139-
{
140-
return new NotFoundResult();
141-
}
142-
143-
return new OkObjectResult(ToDto(result));
144-
}
145-
146215
private static JObject ToDto(FindResponse<CaseFileAggregate> resp)
147216
{
148217
return new JObject

src/CaseManagement.CMMN.AspNetCore/Apis/CaseFormInstancesController.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using CaseManagement.CMMN.Persistence;
55
using CaseManagement.CMMN.Persistence.Parameters;
66
using CaseManagement.CMMN.Persistence.Responses;
7+
using Microsoft.AspNetCore.Authorization;
78
using Microsoft.AspNetCore.Http;
89
using Microsoft.AspNetCore.Mvc;
910
using Newtonsoft.Json.Linq;
@@ -27,21 +28,14 @@ public CaseFormInstancesController(IFormInstanceQueryRepository formInstanceQuer
2728
}
2829

2930
[HttpGet("search")]
31+
[Authorize("get_forminstances")]
3032
public async Task<IActionResult> Search()
3133
{
3234
var query = HttpContext.Request.Query.ToEnumerable();
3335
var result = await _formInstanceQueryRepository.Find(ExtractFindFormInstanceParameter(query));
3436
return new OkObjectResult(ToDto(result));
3537
}
3638

37-
[HttpGet("me/search")]
38-
public async Task<IActionResult> SearchMyCaseFormInstances()
39-
{
40-
var query = HttpContext.Request.Query.ToEnumerable();
41-
var result = await _formInstanceQueryRepository.Find(ExtractFindFormInstanceParameter(query));
42-
return new OkObjectResult(ToDto(result));
43-
}
44-
4539
private static JObject ToDto(FindResponse<FormInstanceAggregate> resp)
4640
{
4741
return new JObject

0 commit comments

Comments
 (0)