Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.8'

services:
redis:
image: redis:latest
container_name: redis_container
ports:
- "6379:6379" # Expose Redis on port 6379
volumes:
- redis_data:/data # Persist data
command: ["redis-server", "--appendonly", "yes"] # Enable AOF persistence

volumes:
redis_data:
driver: local
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/airpenthouse/GoTel/GoTelApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import org.airpenthouse.GoTel.util.PropertiesUtilManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.cache.annotation.EnableCaching;

@Configuration
@PropertySource("classpath:application.properties")
@SpringBootApplication
@EnableCaching
public class GoTelApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.airpenthouse.GoTel.controllers;

import jakarta.servlet.http.HttpSession;
import org.airpenthouse.GoTel.services.country.CountriesService;
import org.airpenthouse.GoTel.util.PropertiesUtilManager;
import org.airpenthouse.GoTel.util.dto.binder.CountriesRequestCombiner;
Expand All @@ -22,10 +23,11 @@ public class CountriesController {
public CountriesService executor;

@GetMapping("/getAllCountries")
public ResponseEntity<Set<? extends CountriesRequestCombiner>> getAllCountries() {
public ResponseEntity<Set<? extends CountriesRequestCombiner>> getAllCountries(HttpSession session) {
CountriesService.SERVICE_HANDLER = "FIND_ALL_COUNTRIES";
CountriesExecutors.setMapper(mapper);
Set<? extends CountriesRequestCombiner> entities = executor.initializeCountriesService();
session.setAttribute("_getAllCountries",entities);
if (entities.isEmpty()) {
return ResponseEntity.notFound().build();
} else {
Expand All @@ -34,13 +36,14 @@ public ResponseEntity<Set<? extends CountriesRequestCombiner>> getAllCountries()
}

@GetMapping("/{memberUsername}/getAllCountries")
public ResponseEntity<Set<? extends CountriesRequestCombiner>> membersGetAllCountries(@PathVariable String memberUsername, @RequestHeader(name = "x-auth-membership-token") String memberToken) {
public ResponseEntity<Set<? extends CountriesRequestCombiner>> membersGetAllCountries(HttpSession session,@PathVariable String memberUsername, @RequestHeader(name = "x-auth-membership-token") String memberToken) {
CountriesService.SERVICE_HANDLER = "FIND_ALL_COUNTRIES";
CountriesExecutors.setMapper(mapper);
PropertiesUtilManager.setProperties("memberUsername", memberUsername);
PropertiesUtilManager.setProperties("memberToken", memberToken);
if (executor.checkMemberShipStatusAndTokenMatch()) {
Set<? extends CountriesRequestCombiner> entities = executor.initializeCountriesService();
session.setAttribute("_getAllCountriesMembers",entities);
if (entities.isEmpty()) {
return ResponseEntity.notFound().build();
} else {
Expand All @@ -52,14 +55,15 @@ public ResponseEntity<Set<? extends CountriesRequestCombiner>> membersGetAllCoun
}

@GetMapping("/{memberUsername}/getCountryByName/{countryName}")
public ResponseEntity<Set<? extends CountriesRequestCombiner>> membersGetCountryByName(@PathVariable String countryName, @PathVariable String memberUsername, @RequestHeader(name = "x-auth-membership-token") String memberToken) {
public ResponseEntity<Set<? extends CountriesRequestCombiner>> membersGetCountryByName(HttpSession session,@PathVariable String countryName, @PathVariable String memberUsername, @RequestHeader(name = "x-auth-membership-token") String memberToken) {
CountriesService.SERVICE_HANDLER = "FIND_COUNTRY_BY_NAME";
CountriesExecutors.setMapper(mapper);
PropertiesUtilManager.setProperties("memberUsername", memberUsername);
PropertiesUtilManager.setProperties("countryName", countryName);
PropertiesUtilManager.setProperties("memberToken", memberToken);
if (executor.checkMemberShipStatusAndTokenMatch()) {
Set<? extends CountriesRequestCombiner> entities = executor.initializeCountriesService();
session.setAttribute("_getAllCountriesMembership",entities);
if (entities.isEmpty()) {
return ResponseEntity.notFound().build();
} else {
Expand All @@ -71,24 +75,27 @@ public ResponseEntity<Set<? extends CountriesRequestCombiner>> membersGetCountry
}

@GetMapping("/getCountryByName/{countryName}")
public ResponseEntity<Set<? extends CountriesRequestCombiner>> getCountryByName(@PathVariable String countryName) {
public ResponseEntity<Set<? extends CountriesRequestCombiner>> getCountryByName(HttpSession session,@PathVariable String countryName) {
CountriesService.SERVICE_HANDLER = "FIND_COUNTRY_BY_NAME";
CountriesExecutors.setMapper(mapper);
PropertiesUtilManager.setProperties("countryName", countryName);
Set<? extends CountriesRequestCombiner> entities = executor.initializeCountriesService();
session.setAttribute("_getAllCountries",entities);
if (entities.isEmpty()) {
return ResponseEntity.notFound().build();

} else {
return ResponseEntity.ok(entities);
}
}

@GetMapping("/getCountryByContinent/{continentName}")
public ResponseEntity<Set<? extends CountriesRequestCombiner>> getCountryByContinent(@PathVariable String continentName) {
public ResponseEntity<Set<? extends CountriesRequestCombiner>> getCountryByContinent(HttpSession session,@PathVariable String continentName) {
CountriesService.SERVICE_HANDLER = "FIND_COUNTRY_BY_CONTINENT";
CountriesExecutors.setMapper(mapper);
PropertiesUtilManager.setProperties("continentName", continentName);
Set<? extends CountriesRequestCombiner> entities = executor.initializeCountriesService();
session.setAttribute("_getAllCountries",entities);
if (entities.isEmpty()) {
return ResponseEntity.notFound().build();
} else {
Expand All @@ -97,14 +104,15 @@ public ResponseEntity<Set<? extends CountriesRequestCombiner>> getCountryByConti
}

@GetMapping("/{memberUsername}/getCountryByRegion/{regionName}")
public ResponseEntity<Set<? extends CountriesRequestCombiner>> memberGetCountryByRegion(@PathVariable String regionName, @PathVariable String memberUsername, @RequestHeader(name = "x-auth-membership-token") String memberToken) {
public ResponseEntity<Set<? extends CountriesRequestCombiner>> memberGetCountryByRegion(HttpSession session,@PathVariable String regionName, @PathVariable String memberUsername, @RequestHeader(name = "x-auth-membership-token") String memberToken) {
CountriesService.SERVICE_HANDLER = "FIND_COUNTRY_BY_REGION";
CountriesExecutors.setMapper(mapper);
PropertiesUtilManager.setProperties("regionName", regionName);
PropertiesUtilManager.setProperties("memberToken", memberToken);
PropertiesUtilManager.setProperties("memberUsername", memberUsername);
if (executor.checkMemberShipStatusAndTokenMatch()) {
Set<? extends CountriesRequestCombiner> entities = executor.initializeCountriesService();
session.setAttribute("_getAllCountriesMembership",entities);
if (entities.isEmpty()) {
return ResponseEntity.notFound().build();
} else {
Expand All @@ -116,7 +124,7 @@ public ResponseEntity<Set<? extends CountriesRequestCombiner>> memberGetCountryB
}

@GetMapping("/{memberUsername}/getCountryByContinent/{continentName}")
public ResponseEntity<Set<? extends CountriesRequestCombiner>> memberGetCountryByContinent(@PathVariable String continentName, @PathVariable String memberUsername, @RequestHeader String memberToken) {
public ResponseEntity<Set<? extends CountriesRequestCombiner>> memberGetCountryByContinent(HttpSession session,@PathVariable String continentName, @PathVariable String memberUsername, @RequestHeader String memberToken) {
CountriesService.SERVICE_HANDLER = "FIND_COUNTRY_BY_CONTINENT";
CountriesExecutors.setMapper(mapper);
PropertiesUtilManager.setProperties("memberUsername", memberUsername);
Expand All @@ -125,6 +133,7 @@ public ResponseEntity<Set<? extends CountriesRequestCombiner>> memberGetCountryB

if (executor.checkMemberShipStatusAndTokenMatch()) {
Set<? extends CountriesRequestCombiner> entities = executor.initializeCountriesService();
session.setAttribute("_getAllCountries",entities);
if (entities.isEmpty()) {
return ResponseEntity.notFound().build();
} else {
Expand All @@ -136,11 +145,12 @@ public ResponseEntity<Set<? extends CountriesRequestCombiner>> memberGetCountryB
}

@GetMapping("/getCountryByRegion/{regionName}")
public ResponseEntity<Set<? extends CountriesRequestCombiner>> getCountryByRegion(@PathVariable String regionName) {
public ResponseEntity<Set<? extends CountriesRequestCombiner>> getCountryByRegion(HttpSession session,@PathVariable String regionName) {
CountriesService.SERVICE_HANDLER = "FIND_COUNTRY_BY_REGION";
CountriesExecutors.setMapper(mapper);
PropertiesUtilManager.setProperties("regionName", regionName);
Set<? extends CountriesRequestCombiner> entities = executor.initializeCountriesService();
session.setAttribute("_getAllCountries",entities);
if (entities.isEmpty()) {
return ResponseEntity.notFound().build();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import lombok.Getter;
import org.airpenthouse.GoTel.util.dto.binder.CountriesRequestCombiner;

import java.io.Serializable;

@AllArgsConstructor
@Getter
public class CountriesRequest implements CountriesRequestCombiner {
public class CountriesRequest implements CountriesRequestCombiner, Serializable {
@JsonProperty("country_name")
private String countryName;
@JsonProperty("_country_region")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.airpenthouse.GoTel.util.dto.binder.CountriesRequestCombiner;
import org.airpenthouse.GoTel.util.executors.CountriesExecutors;
import org.airpenthouse.GoTel.util.mappers.CountriesMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.*;
Expand All @@ -20,6 +21,7 @@ public class CountriesService extends CountriesExecutors implements Callable<Set
private CountriesMapper mapper;
private MembershipCountriesRequest membershipCountriesRequest;

@Cacheable("countriesAllData")
private Set<? extends CountriesRequestCombiner> getAllCountries() {
ENTITY_TRIGGER = "FIND_ALL_COUNTRIES";
return getRequest();
Expand All @@ -35,16 +37,19 @@ private Set<? extends CountriesRequestCombiner> getRequest() {
return initializeCountriesEntity().stream().map(mapper::mapper).collect(Collectors.toSet());
}

@Cacheable("countriesDataByName")
private Set<? extends CountriesRequestCombiner> getCountryByName() {
ENTITY_TRIGGER = "FIND_COUNTRY_BY_NAME";
return getRequest();
}

@Cacheable("CountriesDataContinent")
private Set<? extends CountriesRequestCombiner> getCountryByContinent() {
ENTITY_TRIGGER = "FIND_COUNTRY_BY_CONTINENT";
return getRequest();
}

@Cacheable("CountriesDataByRegion")
private Set<? extends CountriesRequestCombiner> getCountryByRegion() {
ENTITY_TRIGGER = "FIND_COUNTRY_BY_REGION";
return getRequest();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
spring.application.name=GoTel
jdbc.url=jdbc:mysql://localhost:3306/world
jdbc.username=root
spring.docker.compose.lifecycle-management=start_only
#Retrieve all
jdbc.query.allCountries=SELECT * FROM `country`
jdbc.query.allLanguage=SELECT country.Name,countrylanguage.Language,countrylanguage.isOfficial FROM `countrylanguage` JOIN country ON countrylanguage.CountryCode = country.Code
Expand Down
Loading