-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
313c1cd
commit 7e9f9ad
Showing
14 changed files
with
498 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tgBotService/src/main/java/weatherproject/tgbotservice/telegram/callbacks/CallBackTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package weatherproject.tgbotservice.telegram.callbacks; | ||
|
||
public enum CallBackTypes { | ||
CITY_NAME, | ||
LOCATION, | ||
COMMAND | ||
} |
10 changes: 7 additions & 3 deletions
10
tgBotService/src/main/java/weatherproject/tgbotservice/telegram/callbacks/Callback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package weatherproject.tgbotservice.telegram.callbacks; | ||
|
||
public class Callback { | ||
private CallbackType callbackType; | ||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage; | ||
import org.telegram.telegrambots.meta.api.objects.Message; | ||
import org.telegram.telegrambots.meta.api.objects.Update; | ||
import weatherproject.tgbotservice.dto.UserDTO; | ||
import weatherproject.tgbotservice.dto.WeatherDTO; | ||
|
||
private String data; | ||
public interface Callback { | ||
String execute(UserDTO user, WeatherDTO weather); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
...ervice/src/main/java/weatherproject/tgbotservice/telegram/callbacks/CallbackTemplate.java
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
tgBotService/src/main/java/weatherproject/tgbotservice/telegram/callbacks/CallbackType.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
...vice/src/main/java/weatherproject/tgbotservice/telegram/callbacks/CityChooseCallback.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...ice/src/main/java/weatherproject/tgbotservice/telegram/callbacks/SetCityTextCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package weatherproject.tgbotservice.telegram.callbacks; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import weatherproject.tgbotservice.clients.GoogleTranslateClient; | ||
import weatherproject.tgbotservice.clients.UserServiceClient; | ||
import weatherproject.tgbotservice.clients.WeatherServiceClient; | ||
import weatherproject.tgbotservice.dto.UserDTO; | ||
import weatherproject.tgbotservice.dto.WeatherDTO; | ||
|
||
import static weatherproject.tgbotservice.utils.Constants.ILLEGAL_CITY; | ||
import static weatherproject.tgbotservice.utils.Constants.NEW_CITY_SETTED; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
@Slf4j | ||
public class SetCityTextCallback implements Callback { | ||
public final WeatherServiceClient weatherServiceClient; | ||
public final GoogleTranslateClient translateClient; | ||
|
||
|
||
|
||
@Override | ||
public String execute(UserDTO user, WeatherDTO weatherDTO) { | ||
// log.info("Начинаем обрабатывать коллбек setCity от пользователя {} со следующей новой полученной погодой: {}", user.toString(), weatherDTO.toString()); | ||
|
||
if (weatherDTO != null) { | ||
return String.format(NEW_CITY_SETTED, | ||
(Object[]) weatherDtoToArray(weatherDTO)); | ||
} | ||
WeatherDTO newWeatherDTO = weatherServiceClient.getWeatherByCity(user.getCity()); | ||
return String.format(ILLEGAL_CITY, | ||
(Object[]) weatherDtoToArray(newWeatherDTO)); | ||
|
||
} | ||
|
||
private String[] weatherDtoToArray(WeatherDTO weatherDTO) { | ||
var translatedWeather = translateClient.translateEngToRussian(weatherDTO.getCity() + ", " + weatherDTO.getCondition()).split(", "); | ||
return new String[]{ | ||
translatedWeather[0], | ||
weatherDTO.getTemperature().toString(), | ||
translatedWeather[1]}; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tgBotService/src/main/java/weatherproject/tgbotservice/telegram/callbacks/StartCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package weatherproject.tgbotservice.telegram.callbacks; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import weatherproject.tgbotservice.clients.GeocodingClient; | ||
import weatherproject.tgbotservice.clients.GoogleTranslateClient; | ||
import weatherproject.tgbotservice.clients.UserServiceClient; | ||
import weatherproject.tgbotservice.clients.WeatherServiceClient; | ||
import weatherproject.tgbotservice.dto.UserDTO; | ||
import weatherproject.tgbotservice.dto.WeatherDTO; | ||
|
||
import static weatherproject.tgbotservice.utils.Constants.CITY_NOT_FOUND; | ||
import static weatherproject.tgbotservice.utils.Constants.FIRST_CITY_SET; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
@Slf4j | ||
public class StartCallback implements Callback { | ||
|
||
private final GoogleTranslateClient translateClient; | ||
|
||
@Override | ||
public String execute(UserDTO user, WeatherDTO weatherDTO) { | ||
if (weatherDTO != null) { | ||
return String.format(FIRST_CITY_SET, (Object[]) weatherDtoToArray(weatherDTO)); | ||
} | ||
return (CITY_NOT_FOUND); | ||
} | ||
|
||
private String[] weatherDtoToArray(WeatherDTO weatherDTO) { | ||
var translatedWeather = translateClient.translateEngToRussian(weatherDTO.getCity() + ", " + weatherDTO.getCondition()).split(", "); | ||
return new String[]{ | ||
translatedWeather[0], | ||
weatherDTO.getTemperature().toString(), | ||
translatedWeather[1]}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.