Bhargava 6063bd1724 Help Project:
1. Initial Commit - a boiler plate code and POC to realize the concept of context
sensitive help
2. Frontend code written in ReactJS
3. Backend code written in Java, Spring Boot Framework
4. Frontend Start:
        pre-requisites : node, npm
	npm run dev  ==> to start the frontend vite server
5. Backend Start:
	pre-requisites : java, mvn
        mvn spring-boot:run  ==> to start the backend server
6. Visit http://localhost:5173/ for basic demo of help, press F1 in textboxes
7. Visit http://localhost:5173/editor and enter "admin123" to add/modify texts.

Happy Coding !!!

Thank you,
Bhargava.
2025-07-04 15:54:13 +05:30

73 lines
2.6 KiB
Java

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<String, Object> helpContent = mapper.readValue(is, new TypeReference<Map<String, Object>>() {});
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<String, Object> helpContent = mapper.readValue(path.toFile(), new TypeReference<Map<String, Object>>() {});
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<String, HelpItem> 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.");
}
}
}