Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
fix: update comment
Browse files Browse the repository at this point in the history
Change-Id: Idf2bbc9c1e2eb4a0c3b89c6f12cf39bb3fda319b
  • Loading branch information
myml committed Dec 28, 2018
1 parent ec4bcce commit d70c282
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<ng-container *ngIf="!deleteConfirm; else Delete">
<button (click)="deleteConfirm = true" i18n>Delete</button>
<div *ngIf="app.active">
<span class="error" *ngIf="error">
<ng-container i18n>Failed to submit</ng-container>
</span>
<button (click)="closed()" i18n>Cancel</button> &nbsp;
<button class="primary" i18n (click)="submit()">Submit</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@
width: 400px;
height: 300px;
}

.error {
color: red;
margin: 1rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class EditComponent implements OnInit {
content: string;
rate: number;
version: string;
error: boolean;
_comment: UserComment;
@Output()
close = new EventEmitter<boolean>();
Expand All @@ -39,7 +40,10 @@ export class EditComponent implements OnInit {
this.version = c.version;
this.app$ = this.appService.getApp(c.appName, false, false);
}
constructor(private commentService: CommentsService, private appService: AppService) {}
constructor(
private commentService: CommentsService,
private appService: AppService,
) {}

ngOnInit() {
this.dialogRef.nativeElement.addEventListener('close', () => {
Expand All @@ -50,13 +54,20 @@ export class EditComponent implements OnInit {
this.close.emit(changed);
}
submit() {
this.commentService.delete(this._comment.id).subscribe(() => {
this.commentService
.create(this._comment.appName, this.content, this.rate * 2, this._comment.version)
.subscribe(() => {
this.closed(true);
});
});
this.commentService
.update(this._comment.id, {
appName: this._comment.appName,
content: this.content,
rate: this.rate * 2,
version: this._comment.version,
})
.toPromise()
.then(() => {
this.closed();
})
.catch(() => {
this.error = true;
});
}
delete() {
this.commentService.delete(this._comment.id).subscribe(() => {
Expand Down
23 changes: 15 additions & 8 deletions src/web/src/app/modules/my-comments/services/comments.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,32 @@ export class CommentsService {
),
);
}
create(appName: string, content: string, rate: number, version: string) {
const c = {
appName,
content,
rate,
version,
};
return this.http.post(this.server + `/api/user/comment/app/${appName}`, c);
create(c: CommentRequest) {
return this.http.post(
this.server + `/api/user/comment/app/${c.appName}`,
c,
);
}
delete(id: number) {
return this.http.delete(this.server + `/api/user/my/comment/${id}`);
}
update(id: number, c: CommentRequest) {
return this.http.patch(this.server + `/api/user/my/comment/${id}`, c);
}
}

interface Result {
comment: (UserComment & HasApp)[];
totalCount: number;
}

interface CommentRequest {
appName: string;
content: string;
rate: number;
version: string;
}

export interface UserComment {
id: number;
appName: string;
Expand Down

0 comments on commit d70c282

Please sign in to comment.