1313import org .springframework .data .domain .Sort ;
1414import org .springframework .data .domain .Sort .Direction ;
1515import org .springframework .messaging .simp .SimpMessagingTemplate ;
16+ import org .springframework .transaction .annotation .Transactional ;
1617import org .springframework .web .bind .annotation .RestController ;
1718
1819import com .fasterxml .jackson .databind .JsonNode ;
1920import com .fasterxml .jackson .databind .node .ArrayNode ;
2021
2122import edu .tamu .app .model .Note ;
2223import edu .tamu .app .model .repo .NoteRepo ;
24+ import edu .tamu .app .model .repo .ServiceRepo ;
2325import edu .tamu .app .model .request .FilteredPageRequest ;
2426import edu .tamu .framework .aspect .annotation .ApiCredentials ;
2527import edu .tamu .framework .aspect .annotation .ApiData ;
@@ -37,6 +39,9 @@ public class NoteController {
3739
3840 @ Autowired
3941 private NoteRepo noteRepo ;
42+
43+ @ Autowired
44+ private ServiceRepo serviceRepo ;
4045
4146 @ Autowired
4247 private SimpMessagingTemplate simpMessagingTemplate ;
@@ -58,8 +63,9 @@ public ApiResponse getNote(@ApiVariable Long id) {
5863 @ ApiValidation (business = { @ ApiValidation .Business (value = CREATE ), @ ApiValidation .Business (value = EXISTS ) })
5964 public ApiResponse create (@ ApiValidatedModel Note note , @ ApiCredentials Credentials credentials ) {
6065 note = noteRepo .create (note , credentials );
61- simpMessagingTemplate .convertAndSend ("/channel/note" , new ApiResponse (SUCCESS , noteRepo .findAll ()));
62- return new ApiResponse (SUCCESS , note );
66+ ApiResponse response = new ApiResponse (SUCCESS , note );
67+ simpMessagingTemplate .convertAndSend ("/channel/note/new" , response );
68+ return response ;
6369 }
6470
6571 @ ApiMapping ("/update" )
@@ -70,12 +76,13 @@ public ApiResponse update(@ApiValidatedModel Note note) {
7076 return new ApiResponse (SUCCESS , note );
7177 }
7278
79+ @ Transactional
7380 @ ApiMapping ("/remove" )
7481 @ Auth (role = "ROLE_SERVICE_MANAGER" )
7582 public ApiResponse remove (@ ApiValidatedModel Note note ) {
7683 noteRepo .delete (note );
7784 simpMessagingTemplate .convertAndSend ("/channel/note" , new ApiResponse (SUCCESS , noteRepo .findAll ()));
78- return new ApiResponse (SUCCESS );
85+ return new ApiResponse (SUCCESS , serviceRepo . getOne ( note . getService (). getId ()) );
7986 }
8087
8188 @ ApiMapping ("/page" )
@@ -89,9 +96,7 @@ public ApiResponse page(@ApiData JsonNode dataNode) {
8996 }
9097
9198 Map <String , String []> filters = new HashMap <String , String []>();
92- System .out .println ("dataNode: " + dataNode .get ("filters" ).get ("title" ));
9399 filters .put ("title" , arrayNodeToStringArray ((ArrayNode ) dataNode .get ("filters" ).get ("title" )));
94-
95100 FilteredPageRequest filteredPageRequest = new FilteredPageRequest (dataNode .get ("page" ).get ("number" ).asInt (), dataNode .get ("page" ).get ("size" ).asInt (), sortDirection , dataNode .get ("direction" ).get ("properties" ).asText (), filters );
96101 Page <Note > notes = noteRepo .findAll (filteredPageRequest );
97102 return new ApiResponse (SUCCESS , notes );
0 commit comments