Skip to content

Commit

Permalink
IKC-300 Fetch and display survey for user
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Belke authored and Piotr Belke committed Sep 8, 2023
1 parent 759d228 commit fbf6fcd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.consdata.kouncil.survey;

import static com.consdata.kouncil.config.security.RoleNames.ADMIN_ROLE;
import static com.consdata.kouncil.config.security.RoleNames.EDITOR_ROLE;
import static com.consdata.kouncil.config.security.RoleNames.VIEWER_ROLE;

import javax.annotation.security.RolesAllowed;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class SurveyController {

@Value("${kouncil.survey.base-path:}")
private String surveyBasePath;

@RolesAllowed({ADMIN_ROLE, EDITOR_ROLE, VIEWER_ROLE})
@GetMapping("/api/survey/config")
public String getSurveyBasePath() {
return surveyBasePath;
}
}
2 changes: 2 additions & 0 deletions kouncil-backend/src/main/resources/kouncil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ kouncil:
role-admin: admin_group
role-editor: editor_group
role-viewer: viewer_group
survey:
base-path: "http://base-path/kouncil"
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class SurveyComponent implements OnInit {
}

ngOnInit(): void {
this.fetchSurvey();
this.fetchSurveyBasePath();
}

rejectSurvey(): void {
Expand Down Expand Up @@ -122,4 +122,10 @@ export class SurveyComponent implements OnInit {
closeSurvey(): void {
this.hidePanel = true;
}

private fetchSurveyBasePath() {
this.surveyService.fetchSurveyBasePath$().subscribe(()=>{
this.fetchSurvey();
});
}
}
14 changes: 11 additions & 3 deletions kouncil-frontend/apps/kouncil/src/app/survey/survey.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import {SurveyAnswer} from './model/survey-answer';
})
export class SurveyService {

surveyBasePath: string;

constructor(protected http: HttpClient) {
}

fetchSurvey$(): Observable<Array<SurveyPending>> {
return this.http.post<Array<SurveyPending>>(`http://localhost:8082/kouncil/result/pending-with-definition/${localStorage.getItem('userId')}`, {
return this.http.post<Array<SurveyPending>>(`${this.surveyBasePath}/result/pending-with-definition/${localStorage.getItem('userId')}/${localStorage.getItem('installationId')}`, {
receiverAttributes: [
{
name: 'kouncil-user-id',
Expand All @@ -31,13 +33,19 @@ export class SurveyService {
}

answerSurvey$(answer: SurveyAnswer): Observable<void> {
return this.http.patch<void>(`http://localhost:8082/kouncil/result/answer/${localStorage.getItem('userId')}`, answer);
return this.http.patch<void>(`${this.surveyBasePath}/result/answer/${localStorage.getItem('userId')}/${localStorage.getItem('installationId')}`, answer);
}

markSurveyAsOpened(sentId: string): void {
const params = {'sentId': sentId};
this.http.post<void>(`http://localhost:8082/kouncil/activity/SURVEY_OPENED/${localStorage.getItem('userId')}`, {}, {
this.http.post<void>(`${this.surveyBasePath}/activity/SURVEY_OPENED/${localStorage.getItem('userId')}/${localStorage.getItem('installationId')}`, {}, {
params
}).pipe().subscribe();
}

fetchSurveyBasePath$(): Observable<void> {
return this.http.get('/api/survey/config', {responseType: 'text'}).pipe(map((basePath) => {
this.surveyBasePath = basePath;
}));
}
}

0 comments on commit fbf6fcd

Please sign in to comment.