package com.contextual.help; import org.springframework.web.bind.annotation.*; import org.springframework.http.ResponseEntity; import org.springframework.http.HttpStatus; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.type.TypeReference; import java.io.IOException; import java.io.InputStream; import java.util.Map; import java.nio.file.Path; import java.nio.file.Files; @RestController @RequestMapping("/api/help") public class HelpController { /* @GetMapping public ResponseEntity getHelp(@RequestParam String lang) { String fileName = String.format("help/help.%s.json", lang); try (InputStream is = getClass().getClassLoader().getResourceAsStream(fileName)) { if (is == null) { return ResponseEntity.status(HttpStatus.NOT_FOUND) .body("Help content not found for language: " + lang); } ObjectMapper mapper = new ObjectMapper(); Map helpContent = mapper.readValue(is, new TypeReference>() {}); return ResponseEntity.ok(helpContent); } catch (IOException e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body("Error loading help content"); } }*/ @GetMapping public ResponseEntity getHelp(@RequestParam String lang) { Path path = Path.of("src/main/resources/help/help." + lang + ".json"); if (!Files.exists(path)) { return ResponseEntity.status(HttpStatus.NOT_FOUND) .body("Help content not found for language: " + lang); } try { ObjectMapper mapper = new ObjectMapper(); Map helpContent = mapper.readValue(path.toFile(), new TypeReference>() {}); return ResponseEntity.ok(helpContent); } catch (IOException e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body("Error loading help content: " + e.getMessage()); } } @PutMapping public ResponseEntity updateHelp(@RequestBody Map newData, @RequestParam(defaultValue = "en") String lang) { try { Path path = Path.of("src/main/resources/help/help." + lang + ".json"); new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(path.toFile(), newData); return ResponseEntity.ok().build(); } catch (IOException e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to save data."); } } }