WiP: Building stateless backend
This commit is contained in:
@@ -3,7 +3,6 @@ package com.release11.klaus.controller;
|
||||
|
||||
import com.release11.klaus.model.MockedMessageDto;
|
||||
import com.release11.klaus.model.MockedMessageDtoTest;
|
||||
import com.release11.klaus.model.TestModel;
|
||||
import com.release11.klaus.service.KlausService;
|
||||
import com.release11.klaus.utilis.BusinessKey;
|
||||
import com.release11.klaus.utilis.TrackingClient;
|
||||
@@ -40,12 +39,6 @@ public class KlausController {
|
||||
.httpHeaders(new HashMap<>())
|
||||
.build();
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping(value = "klaus/v1/get/test/test")
|
||||
public TestModel getTestTest(){
|
||||
TestModel testModel = new TestModel();
|
||||
return testModel;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping(value = "klaus/v1/get/test/msgtest")
|
||||
@@ -109,20 +102,4 @@ public class KlausController {
|
||||
Objects.requireNonNull(HttpStatus.valueOf(mockedMessageDto.getHttpStatus())));
|
||||
}
|
||||
|
||||
// @PostMapping(value = "klaus/v1/set/{clientUUID}/{mockedResponseId}")
|
||||
// public ResponseEntity<String> setMockedResponse(@PathVariable UUID clientUUID,
|
||||
// @PathVariable int mockedResponseId,
|
||||
// @RequestParam(required = false) Integer httpStatus,
|
||||
// RequestEntity<String> requestEntity){
|
||||
// TrackingClient.setBusinessKeys(Map.of(BusinessKey.INTERFACE_NAME, "setMockedResponse",
|
||||
// BusinessKey.CLIENT_UUID, String.valueOf(clientUUID),
|
||||
// BusinessKey.MESSAGE_ID, String.valueOf(mockedResponseId)));
|
||||
// if (httpStatus == null) httpStatus = 200;
|
||||
//
|
||||
// MockedMessageDto mockedMessageDto = new MockedMessageDto(clientUUID, mockedResponseId,
|
||||
// requestEntity.getHeaders().getContentType().toString(), requestEntity.getBody(),
|
||||
// requestEntity.getHeaders().toSingleValueMap(), httpStatus);
|
||||
// return klausService.setMockedResponse(mockedMessageDto);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.*;
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping
|
||||
@RequestMapping("/old")
|
||||
@AllArgsConstructor
|
||||
public class KlausMvcController {
|
||||
private final KlausService klausService;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.release11.klaus.controller;
|
||||
|
||||
import com.release11.klaus.model.MockedMessageDto;
|
||||
import com.release11.klaus.service.KlausService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping
|
||||
@AllArgsConstructor
|
||||
public class MockController {
|
||||
private final KlausService klausService;
|
||||
//TODO: Write a method
|
||||
private final MockedMessageDto defaultMessage = MockedMessageDto.builder().build();
|
||||
private UUID sessionUUID;
|
||||
private final Set<MockedMessageDto> globalMockedMessageDtoList = new HashSet<>();
|
||||
|
||||
|
||||
//TODO: Add cookie in javascript
|
||||
/**
|
||||
* Responds to first user request. If UUID is given then it's set if it's not, then new one is generated.
|
||||
* Next recalls method that populates model based on UUID
|
||||
* @param clientUUID
|
||||
* @param uuid
|
||||
* @return
|
||||
*/
|
||||
@SneakyThrows
|
||||
@GetMapping({"/mock", "/mock/{uuid}"})
|
||||
public String showHome(@RequestParam(required = false) UUID clientUUID,
|
||||
@PathVariable(required = false) UUID uuid){
|
||||
if (uuid != null) clientUUID = uuid;
|
||||
if (clientUUID != null) sessionUUID = clientUUID;
|
||||
else sessionUUID = UUID.randomUUID();
|
||||
this.updateGlobalMockedMessageDtoList();
|
||||
return "mock";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Populates model with current message list based on sessionUUID
|
||||
*/
|
||||
private void updateGlobalMockedMessageDtoList(){
|
||||
globalMockedMessageDtoList.clear();
|
||||
List<MockedMessageDto> mockedMessageDtoList = klausService.getAllMockedResponses(sessionUUID);
|
||||
if (mockedMessageDtoList.size() == 0) mockedMessageDtoList.add(defaultMessage);
|
||||
globalMockedMessageDtoList.addAll(mockedMessageDtoList);
|
||||
}
|
||||
|
||||
//TODO: Add json file
|
||||
private static MockedMessageDto buildDefaultMessage(){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.release11.klaus.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
@JsonPropertyOrder({ "name", "lastname" })
|
||||
public class TestModel {
|
||||
private String name = "Jason";
|
||||
private String lastname = "Born";
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user