Skip to content

Commit

Permalink
#6 Adding get value functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
josdem committed Jul 27, 2023
1 parent 75044ad commit bb821d6
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/main/java/com/josdem/catcher/controller/StatusController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/catcher")
public class StatusController {

@PostMapping("/{key}/{value}")
public Mono<Void> storeStatus(@PathVariable String key, @PathVariable String value) {
log.info("Storing status with key: {} and value: {}", key, value);
return Mono.empty();
}
private final Map<String, String> memory = new ConcurrentHashMap<>();

@PostMapping("/{key}/{value}")
public Mono<Void> storeStatus(@PathVariable String key, @PathVariable String value) {
log.info("Storing status with key: {} and value: {}", key, value);
memory.putIfAbsent(key, value);
return Mono.empty();
}

@GetMapping("/{key}")
public Mono<String> getStatus(@PathVariable String key) {
log.info("Getting status from key: {}", key);
return Mono.just(memory.get(key));
}
}

0 comments on commit bb821d6

Please sign in to comment.