T248 T245 /mock/json path changed to /api/mock; mapping '/' moved to MainController

This commit is contained in:
2021-03-26 15:27:59 +01:00
parent eba27650e1
commit e81e4b1d56
13 changed files with 104 additions and 80 deletions

View File

@@ -0,0 +1,27 @@
package com.release11.klaus.controller;
import lombok.SneakyThrows;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* Class responsible for returning homepage html
* @author Gabriel Modzelewski
*/
@Controller
@RequestMapping("/")
public class MainController {
/**
* Default path to get the homepage
* @return the view of homepage
*/
@SneakyThrows
@GetMapping
public ModelAndView showHome(){
ModelAndView mov = new ModelAndView();
mov.setViewName("html/mock");
return mov;
}
}

View File

@@ -11,7 +11,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.http.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import java.time.LocalDateTime;
import java.util.*;
@@ -21,23 +20,13 @@ import java.util.*;
* @author Gabriel Modzelewski
*/
@Slf4j
@Controller
@RequestMapping(path = "/")
@RestController
@RequestMapping(path = "/api/mock")
@AllArgsConstructor
public class MockController {
private final KlausService klausService;
/**
* Default path to get the homepage
* @return the view of homepage
*/
@SneakyThrows
@GetMapping
public ModelAndView showHome(){
ModelAndView mov = new ModelAndView();
mov.setViewName("html/mock");
return mov;
}
/**
* Updates queried message with given set of data
@@ -45,8 +34,7 @@ public class MockController {
* @return confirmation and 200 OK
*/
@SneakyThrows
@ResponseBody
@PutMapping("/mock/json")
@PutMapping("/")
public ResponseEntity<String> updateMessage(@RequestBody String body){
ObjectMapper mapper = new ObjectMapper();
MockedMessageDto message = mapper.readValue(body, MockedMessageDto.class);
@@ -59,8 +47,7 @@ public class MockController {
* @param uuidValue the key-uuid of given set of messages
* @return responds with 200 OK and list of {@link MockedMessageDto}
*/
@ResponseBody
@GetMapping({"/mock/json", "/mock/json/{uuidValue}"})
@GetMapping({"/", "/{uuidValue}"})
public List<MockedMessageDto> getListOfMessages(@PathVariable(required = false) String uuidValue){
UUID clientUUID;
if(uuidValue == null || uuidValue.equals("")) clientUUID = UUID.randomUUID();
@@ -80,8 +67,7 @@ public class MockController {
* @param uuidValue the key-uuid of given set of messages
* @return confirmation response with 200 OK
*/
@ResponseBody
@PostMapping("/mock/json/{uuidValue}")
@PostMapping("/{uuidValue}")
public ResponseEntity<String> addNewMessage(@PathVariable String uuidValue){
UUID clientUUID = UUID.fromString(uuidValue);
List<MockedMessageDto> messages = klausService.getAllMockedResponses(clientUUID);
@@ -95,8 +81,7 @@ public class MockController {
* @param idValue unique id of given message
* @return after deletion the confirmation is send with status 200 OK
*/
@ResponseBody
@DeleteMapping("/mock/json/{uuidValue}/{idValue}")
@DeleteMapping("/{uuidValue}/{idValue}")
public ResponseEntity<String> removeMessage(@PathVariable String uuidValue,
@PathVariable String idValue){
UUID clientUUID = UUID.fromString(uuidValue);
@@ -163,7 +148,7 @@ public class MockController {
* @param mockedResponseId unique id of given message
* @return
*/
@GetMapping(value = "/klaus/v1/get/{clientUUID}/{mockedResponseId}")
@GetMapping(value = "/r/{clientUUID}/{mockedResponseId}")
public ResponseEntity getMockedResponse(RequestEntity<String> requestEntity,
@PathVariable UUID clientUUID,
@PathVariable int mockedResponseId) {

View File

@@ -38,7 +38,7 @@ $('#btn-addRow').click(function(){addRow()});
$('#btn-save').click(getUpdate);
function getData(){
$.getJSON(host + '/mock/json/'+clientUUID, function(data) {
$.getJSON(host + '/api/mock/'+clientUUID, function(data) {
json = data;
checkUuid();
console.log(JSON.stringify(json));
@@ -155,7 +155,7 @@ function updateData(){
savedModalDisplay();
}
$.ajax({
url: host + '/mock/json',
url: host + '/api/mock',
type: 'PUT',
data: JSON.stringify(updatedJson, null, 2),
contentType: "application/json",
@@ -174,7 +174,7 @@ function callAddMessage(){
function addMessage(){
$.ajax({
url: host + '/mock/json/'+clientUUID,
url: host + '/api/mock/'+clientUUID,
type: 'POST',
}).done(dataRefresh);
}
@@ -192,7 +192,7 @@ function callRemoveMessage(id){
function removeMessage(id){
var jsonObject = findJsonById(id);
$.ajax({
url: host + '/mock/json/'+clientUUID + '/' + id,
url: host + '/api/mock/'+clientUUID + '/' + id,
type: 'DELETE',
}).done(dataRefresh);
}
@@ -225,7 +225,7 @@ function fillStaticFields(uuid, id, mediaType, body, httpStatus){
}
function createLink(uuid, id){
var link = host + '/klaus/v1/get/'+uuid+'/'+id;
var link = host + '/api/mock/r/'+uuid+'/'+id;
return link;
}

View File

@@ -33,8 +33,6 @@ const startSearch = function(){
}
$('#btn-searchHistory').click(startSearch);
$('#historyFilterSwitch').click(filterSwitch);
function loadHistory(dateFrom, dateTo){
console.log('Request send for history data')
var eventRequest = {