WiP: Building stateless backend
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user