Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit 9622b82

Browse files
committed
patch
1 parent c44b855 commit 9622b82

5 files changed

Lines changed: 32 additions & 8 deletions

File tree

src/Backend/Jp.UserManagement/Controllers/UserAdminController.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,21 @@ public async Task<ActionResult<DefaultResponse<UserViewModel>>> Details(string u
5959
}
6060

6161

62+
[HttpPut, Route("{username}/update"), Authorize(Policy = "Admin")]
63+
public async Task<ActionResult<DefaultResponse<bool>>> Update(string username, [FromBody] UserViewModel model)
64+
{
65+
if (!ModelState.IsValid)
66+
{
67+
NotifyModelStateErrors();
68+
return Response(false);
69+
}
70+
71+
await _userManageAppService.UpdateUser(model);
72+
return Response(true);
73+
}
74+
6275
[HttpPatch, Route("{username}/update"), Authorize(Policy = "Admin")]
63-
public async Task<ActionResult<DefaultResponse<bool>>> Update(string username, [FromBody] JsonPatchDocument<UserViewModel> model)
76+
public async Task<ActionResult<DefaultResponse<bool>>> PartialUpdate(string username, [FromBody] JsonPatchDocument<UserViewModel> model)
6477
{
6578
if (!ModelState.IsValid)
6679
{

src/Frontend/Jp.AdminUI/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Frontend/Jp.AdminUI/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"core-js": "^3.1.4",
5252
"easy-pie-chart": "2.1.7",
5353
"enhanced-resolve": "^4.1.0",
54+
"fast-json-patch": "^3.0.0-1",
5455
"fullcalendar": "^3.10.0",
5556
"intl": "1.2.5",
5657
"jqcloud2": "2.0.3",

src/Frontend/Jp.AdminUI/src/app/panel/users/edit/user-edit.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Observable } from "rxjs";
88
import { UserProfile } from "@shared/viewModel/userProfile.model";
99
import { UserService } from "@shared/services/user.service";
1010
import { ResetPassword } from "@shared/viewModel/reset-password.model";
11+
import * as jsonpatch from 'fast-json-patch';
1112

1213

1314
@Component({
@@ -35,6 +36,7 @@ export class UserEditComponent implements OnInit {
3536
public shouldChangePass: boolean = false;
3637
public shouldChangeUserData: boolean = true;
3738
private username: string;
39+
patchObserver: jsonpatch.Observer<UserProfile>;
3840

3941
constructor(
4042
private route: ActivatedRoute,
@@ -44,7 +46,11 @@ export class UserEditComponent implements OnInit {
4446
public toasterService: ToasterService) { }
4547

4648
public ngOnInit() {
47-
this.route.params.pipe(tap(p => this.username = p["username"])).pipe(flatMap(p => this.userService.getDetails(p["username"]))).subscribe(result => {
49+
this.route.params
50+
.pipe(tap(p => this.username = p["username"]),
51+
flatMap(p => this.userService.getDetails(p["username"])),
52+
tap(user => this.patchObserver = jsonpatch.observe(user.data))
53+
).subscribe(result => {
4854
this.model = result.data;
4955
if (this.model.lockoutEnd != null)
5056
this.model.lockoutEnd = new Date(this.model.lockoutEnd);
@@ -60,7 +66,7 @@ export class UserEditComponent implements OnInit {
6066
this.errors = [];
6167
try {
6268

63-
this.userService.update(this.model).subscribe(
69+
this.userService.patch(this.username, jsonpatch.generate(this.patchObserver)).subscribe(
6470
registerResult => {
6571
if (registerResult.data) {
6672
this.showSuccessMessage();
@@ -78,7 +84,6 @@ export class UserEditComponent implements OnInit {
7884
this.showButtonLoading = false;
7985
return Observable.throw("Unknown error while trying to update");
8086
}
81-
8287
}
8388

8489
public resetPass() {

src/Frontend/Jp.AdminUI/src/app/shared/services/user.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { UserLogin } from "../viewModel/user-login.model";
1010
import { ResetPassword } from "../viewModel/reset-password.model";
1111
import { EventHistoryData } from "../viewModel/event-history-data.model";
1212
import { map } from "rxjs/operators";
13+
import { Operation } from "fast-json-patch";
1314

1415
@Injectable()
1516
export class UserService {
@@ -36,12 +37,11 @@ export class UserService {
3637
}
3738

3839
public update(updateCommand: UserProfile): Observable<DefaultResponse<boolean>> {
39-
4040
return this.http.put<DefaultResponse<boolean>>(environment.ResourceServer + "UserAdmin/update", updateCommand);
4141
}
42-
43-
public patch(updateCommand: UserProfile): Observable<DefaultResponse<boolean>> {
44-
return this.http.patch<DefaultResponse<boolean>>(environment.ResourceServer + "UserAdmin/update", updateCommand);
42+
43+
public patch(username: string, patch: Operation[]): Observable<DefaultResponse<boolean>> {
44+
return this.http.patch<DefaultResponse<boolean>>(environment.ResourceServer + `UserAdmin/${username}/update`, patch);
4545
}
4646

4747
public save(model: UserProfile): Observable<DefaultResponse<boolean>> {

0 commit comments

Comments
 (0)