Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polish-community-beth
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Beth Davies
polish-community-beth
Commits
0cefe898
Commit
0cefe898
authored
8 months ago
by
Richard Githuba
Browse files
Options
Downloads
Patches
Plain Diff
added the controller
parent
db80c551
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/polish_community_group_11/polish_community/translation/controller/TranslationApisController.java
+80
-0
80 additions, 0 deletions
...ity/translation/controller/TranslationApisController.java
with
80 additions
and
0 deletions
src/main/java/polish_community_group_11/polish_community/translation/controller/TranslationApisController.java
0 → 100644
+
80
−
0
View file @
0cefe898
package
polish_community_group_11.polish_community.translation.controller
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
polish_community_group_11.polish_community.translation.model.Translation
;
import
polish_community_group_11.polish_community.translation.service.TranslationService
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/api/translations"
)
public
class
TranslationApisController
{
private
final
TranslationService
translationService
;
public
TranslationApisController
(
TranslationService
translationService
)
{
this
.
translationService
=
translationService
;
}
// get all translations
@GetMapping
public
ResponseEntity
<
List
<
Translation
>>
getAllTranslations
()
{
List
<
Translation
>
translations
=
translationService
.
getAllTranslations
();
return
ResponseEntity
.
ok
(
translations
);
}
// for specific lang
@GetMapping
(
"/language/{language}"
)
public
ResponseEntity
<
List
<
Translation
>>
getTranslationsByLanguage
(
@PathVariable
String
language
)
{
List
<
Translation
>
translations
=
translationService
.
getTranslationsByLanguage
(
language
);
return
ResponseEntity
.
ok
(
translations
);
}
// for specific key and lang
@GetMapping
(
"/{key}/language/{language}"
)
public
ResponseEntity
<
Translation
>
getTranslationByKeyAndLanguage
(
@PathVariable
String
key
,
@PathVariable
String
language
)
{
Translation
translation
=
translationService
.
getTranslationByKeyAndLanguage
(
key
,
language
);
if
(
translation
==
null
)
{
return
ResponseEntity
.
notFound
().
build
();
}
return
ResponseEntity
.
ok
(
translation
);
}
// adding new translation
@PostMapping
public
ResponseEntity
<
String
>
addTranslation
(
@RequestBody
Translation
translation
)
{
translationService
.
addTranslation
(
translation
);
return
ResponseEntity
.
ok
(
"Translation added successfully."
);
}
// update existing
@PutMapping
(
"/{id}"
)
public
ResponseEntity
<
String
>
updateTranslation
(
@PathVariable
int
id
,
@RequestBody
Translation
translation
)
{
translationService
.
updateTranslation
(
id
,
translation
);
return
ResponseEntity
.
ok
(
"Translation updated successfully."
);
}
// deleting a translation
@DeleteMapping
(
"/{id}"
)
public
ResponseEntity
<
String
>
deleteTranslation
(
@PathVariable
int
id
)
{
translationService
.
deleteTranslation
(
id
);
return
ResponseEntity
.
ok
(
"Translation deleted successfully."
);
}
// get all unique keys
@GetMapping
(
"/keys"
)
public
ResponseEntity
<
List
<
String
>>
getAllTranslationKeys
()
{
List
<
String
>
keys
=
translationService
.
getAllTranslationKeys
();
return
ResponseEntity
.
ok
(
keys
);
}
// get all translations for a specific key across all langs
@GetMapping
(
"/keys/{key}"
)
public
ResponseEntity
<
List
<
Translation
>>
getTranslationsByKey
(
@PathVariable
String
key
)
{
List
<
Translation
>
translations
=
translationService
.
getTranslationsByKey
(
key
);
return
ResponseEntity
.
ok
(
translations
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment