Skip to content

Commit

Permalink
Final update
Browse files Browse the repository at this point in the history
  • Loading branch information
XyL1GaN4eG committed Jul 27, 2024
1 parent 44278a2 commit 1cecf71
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 23 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package weatherproject.tgbotservice.telegram.callbacks;

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.telegram.telegrambots.meta.api.objects.Update;
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;
Expand Down Expand Up @@ -48,18 +47,13 @@ public CallbackHandler(GeocodingClient geocodingClient,
);
}



public SendMessage handleCallback(UserDTO user, Update update) {
var message = update.getMessage();
var chatId = update.getMessage().getChatId().toString();
try {
var currentState = (UserState) UserState.valueOf(user.getState());
var weather = getWeather(message);
var commandHandler = callbacks.get(currentState);
log.info(chatId);
log.info(weather.toString());
log.info(user.toString());
var text = commandHandler.execute(user, weather);
return new SendMessage(chatId, text);
} catch (NullPointerException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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;
Expand All @@ -24,9 +23,10 @@ public class SetCityTextCallback implements Callback {

@Override
public String execute(UserDTO user, WeatherDTO weatherDTO) {
// log.info("Начинаем обрабатывать коллбек setCity от пользователя {} со следующей новой полученной погодой: {}", user.toString(), weatherDTO.toString());
log.info("Начинаем обрабатывать коллбек setCity от пользователя {} со следующей новой полученной погодой: {}", user.toString(), weatherDTO.toString());

if (weatherDTO != null) {
// если погода не пустая
if (!weatherDTO.equals(new WeatherDTO())) {
user.setCity(weatherDTO.getCity());
userServiceClient.createOrUpdateUser(user);
return String.format(NEW_CITY_SETTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class StartCallback implements Callback {
private final UserServiceClient userServiceClient;
@Override
public String execute(UserDTO user, WeatherDTO weatherDTO) {

// Если weatherDTO не пустой
if (!Objects.equals(weatherDTO, new WeatherDTO())) {
user.setCity(weatherDTO.getCity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
@SpringBootTest
class TGUserServiceApplicationTests {

// @Test
// void contextLoads() {
// }
@Test
void contextLoads() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public Object[] getWeather(String city) {
log.info("Отправляем HTTP запрос: {}", request);
var response = getResponse(request);

//TODO: переписать с использованием restTemplate чтобы использовать response.getStatusCode().is2xxSuccessful()
if (response.statusCode() >= 200 && response.statusCode() < 300) {
log.info("Получен успешный HTTP ответ с кодом: " + response.statusCode());
return fetchData(response);
Expand Down

0 comments on commit 1cecf71

Please sign in to comment.