File History: src/main/java/com/paymentlink/controller/api/TranslationApiController.java

← View file content

File Content at Commit 690c1f6

1 package com.paymentlink.controller.api;
2
3 import com.paymentlink.model.entity.Translation;
4 import com.paymentlink.service.TranslationService;
5 import org.springframework.http.HttpStatus;
6 import org.springframework.http.ResponseEntity;
7 import org.springframework.web.bind.annotation.*;
8
9 import java.util.HashMap;
10 import java.util.List;
11 import java.util.Map;
12
13 @RestController
14 @RequestMapping("/api/admin/translations")
15 public class TranslationApiController {
16
17 private final TranslationService translationService;
18
19 public TranslationApiController(TranslationService translationService) {
20 this.translationService = translationService;
21 }
22
23 /**
24 * GET /api/admin/translations - List all translations
25 */
26 @GetMapping
27 public ResponseEntity<Map<String, Object>> getAllTranslations() {
28 try {
29 // In a production app, this would be paginated
30 Map<String, Object> response = new HashMap<>();
31 response.put("success", true);
32 response.put("message", "Use specific endpoints to get translations for entities");
33 response.put("supportedLanguages", translationService.getSupportedLanguages());
34
35 return ResponseEntity.ok(response);
36 } catch (Exception e) {
37 Map<String, Object> error = new HashMap<>();
38 error.put("success", false);
39 error.put("error", e.getMessage());
40 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
41 }
42 }
43
44 /**
45 * GET /api/admin/translations/{entityType}/{entityId} - Get all translations for an entity
46 */
47 @GetMapping("/{entityType}/{entityId}")
48 public ResponseEntity<Map<String, Object>> getTranslationsForEntity(
49 @PathVariable String entityType,
50 @PathVariable String entityId) {
51
52 try {
53 List<Translation> translations = translationService.getTranslationsForEntity(entityType, entityId);
54
55 Map<String, Object> response = new HashMap<>();
56 response.put("success", true);
57 response.put("translations", translations);
58 response.put("total", translations.size());
59
60 return ResponseEntity.ok(response);
61 } catch (Exception e) {
62 Map<String, Object> error = new HashMap<>();
63 error.put("success", false);
64 error.put("error", e.getMessage());
65 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
66 }
67 }
68
69 /**
70 * POST /api/admin/translations - Create or update a translation
71 */
72 @PostMapping
73 public ResponseEntity<Map<String, Object>> saveTranslation(@RequestBody Map<String, String> request) {
74 try {
75 String entityType = request.get("entityType");
76 String entityId = request.get("entityId");
77 String fieldName = request.get("fieldName");
78 String languageCode = request.get("languageCode");
79 String translatedText = request.get("translatedText");
80
81 // Validate required fields
82 if (entityType == null || entityId == null || fieldName == null ||
83 languageCode == null || translatedText == null) {
84 Map<String, Object> error = new HashMap<>();
85 error.put("success", false);
86 error.put("error", "Missing required fields");
87 return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(error);
88 }
89
90 Translation translation = translationService.saveTranslation(
91 entityType, entityId, fieldName, languageCode, translatedText);
92
93 Map<String, Object> response = new HashMap<>();
94 response.put("success", true);
95 response.put("translation", translation);
96 response.put("message", "Translation saved successfully");
97
98 return ResponseEntity.ok(response);
99 } catch (Exception e) {
100 Map<String, Object> error = new HashMap<>();
101 error.put("success", false);
102 error.put("error", e.getMessage());
103 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
104 }
105 }
106
107 /**
108 * DELETE /api/admin/translations/{id} - Delete a translation
109 */
110 @DeleteMapping("/{id}")
111 public ResponseEntity<Map<String, Object>> deleteTranslation(@PathVariable Long id) {
112 try {
113 translationService.deleteTranslation(id);
114
115 Map<String, Object> response = new HashMap<>();
116 response.put("success", true);
117 response.put("message", "Translation deleted successfully");
118
119 return ResponseEntity.ok(response);
120 } catch (Exception e) {
121 Map<String, Object> error = new HashMap<>();
122 error.put("success", false);
123 error.put("error", e.getMessage());
124 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
125 }
126 }
127
128 /**
129 * GET /api/admin/translations/languages - Get supported languages
130 */
131 @GetMapping("/languages")
132 public ResponseEntity<Map<String, Object>> getSupportedLanguages() {
133 try {
134 List<String> languages = translationService.getSupportedLanguages();
135
136 Map<String, Object> response = new HashMap<>();
137 response.put("success", true);
138 response.put("languages", languages);
139
140 return ResponseEntity.ok(response);
141 } catch (Exception e) {
142 Map<String, Object> error = new HashMap<>();
143 error.put("success", false);
144 error.put("error", e.getMessage());
145 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
146 }
147 }
148 }
149

Commits

Commit Author Date Message File SHA Actions
f0438c2 <f69e50@finnacloud.com> 1766443042 +0300 12/22/2025, 10:37:22 PM increment once more eea10c9 View
188fc92 <f69e50@finnacloud.com> 1766442998 +0300 12/22/2025, 10:36:38 PM increment eea10c9 View
4617f76 <f69e50@finnacloud.com> 1766442953 +0300 12/22/2025, 10:35:53 PM rename branch from main to master oops eea10c9 View
e6d1548 <f69e50@finnacloud.com> 1766442769 +0300 12/22/2025, 10:32:49 PM add initial test workflow file eea10c9 View
9c24ca4 <f69e50@finnacloud.com> 1766442705 +0300 12/22/2025, 10:31:45 PM add CI configuration and test script for Jenkins build eea10c9 View
690c1f6 <f69e50@finnacloud.com> 1766368110 +0300 12/22/2025, 1:48:30 AM initialize backend structure with controllers, DTOs, and configuration files eea10c9 Hide