Skip to content
Snippets Groups Projects
Commit a6864141 authored by Zain Munshi's avatar Zain Munshi
Browse files

added link to customer controller

parent dcc3d093
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,7 @@ public class ComplaintController {
String accessLevel = authentication.getAuthorities().iterator().next().toString().toLowerCase();
ModelAndView modelandView = new ModelAndView(String.format("redirect:/%s/complaint", accessLevel));
return modelandView;
}
......
......@@ -12,7 +12,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static java.lang.Math.*;
......@@ -79,6 +81,16 @@ public class CustomerController {
List<Comment> commentList = commentService.getAllCommentsByComplaint(authentication, id);
modelAndView.addObject("commentObjects", commentList);
// linked Complaints
List<Map<String, Object>> linkedComplaints = complaintService.getLink(authentication,id);
ArrayList<String> values = new ArrayList<String>();
for(int i = 0; i < linkedComplaints.size(); i++){
values.add(linkedComplaints.get(i).values().toArray()[1].toString());
}
modelAndView.addObject("linkedComplaints", values);
return modelAndView;
}
}
\ No newline at end of file
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity6">
<head>
<meta charset="UTF-8">
<title th:text="'CMS | ' + ${complaintObject.title}"></title>
<link th:replace="~{fragments/header :: bootstrap-css}"/>
......@@ -72,7 +73,7 @@
</div>
<div class="d-flex flex-column mt-3">
<div class="d-flex flex-column mt-3" sec:authorize="hasAnyAuthority('STAFF', 'ADMIN')" >
<form th:action = "@{/complaint/link}" method="post">
<input type="number" name = "to_id" id="to_id" placeholder="Link Complaint Id">
<input type="hidden" name = "complaint" th:value="${complaintObject.id}" id="complaint">
......
......@@ -34,22 +34,10 @@ public class LinkComplaintTests {
@Test
@WithMockUser(username = "user", authorities = {"CUSTOMER"})
public void shouldAddOneEntryToDB() throws Exception{
public void shouldAddOneLinkFromComplaint1toComplaint5() throws Exception{
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Complaint complaint = new Complaint();
complaint.setTitle("title");
complaint.setPolicyNumber("user");
complaint.setComplaintMethod(ComplaintMethod.EMAIL);
complaint.setComplaintType(FCAType.FCA);
complaint.setComplaintStatus(Boolean.TRUE);
complaint.setTextBox("asdfasdfasfas");
int initialNumOfEntries = complaintService.getNumberOfComplaints(authentication);
complaintService.addComplaint(complaint,authentication);
int finalNumOfEntries = complaintService.getNumberOfComplaints(authentication);
assertTrue(finalNumOfEntries - initialNumOfEntries == 1 );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment