diff --git a/src/main/java/efub/team4/backend_eweather/domain/calendar/repository/CalendarRepository.java b/src/main/java/efub/team4/backend_eweather/domain/calendar/repository/CalendarRepository.java index e04de4d..54a8fa7 100644 --- a/src/main/java/efub/team4/backend_eweather/domain/calendar/repository/CalendarRepository.java +++ b/src/main/java/efub/team4/backend_eweather/domain/calendar/repository/CalendarRepository.java @@ -1,6 +1,7 @@ package efub.team4.backend_eweather.domain.calendar.repository; import efub.team4.backend_eweather.domain.calendar.entity.Calendar; +import efub.team4.backend_eweather.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; @@ -8,6 +9,6 @@ import java.util.UUID; public interface CalendarRepository extends JpaRepository, JpaSpecificationExecutor { - //Optional findByUser_Id(UUID uuid); Optional findCalendarByForecastDate(String foreCastDate); + Optional findCalendarByForecastDateAndUser_Id(String forCastDate, UUID userId); } diff --git a/src/main/java/efub/team4/backend_eweather/domain/calendar/service/CalendarService.java b/src/main/java/efub/team4/backend_eweather/domain/calendar/service/CalendarService.java index 0967a24..604b124 100644 --- a/src/main/java/efub/team4/backend_eweather/domain/calendar/service/CalendarService.java +++ b/src/main/java/efub/team4/backend_eweather/domain/calendar/service/CalendarService.java @@ -12,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Optional; import java.util.UUID; @Service @@ -22,8 +23,10 @@ public class CalendarService { @Transactional public Calendar save(Calendar calendar) { - calendarRepository.findCalendarByForecastDate(calendar.getForecastDate()) - .ifPresent((existedCalendar) -> new CalendarAlreadyExistsException("Calendar is already exists with date=" + calendar.getForecastDate())); + Optional existedCalendar = calendarRepository.findCalendarByForecastDateAndUser_Id(calendar.getForecastDate(), calendar.getUser().getId()); + if (existedCalendar.isPresent()){ + throw new CalendarAlreadyExistsException("Calendar is already exists with date=" + calendar.getForecastDate()); + } return calendarRepository.save(calendar); } diff --git a/src/main/java/efub/team4/backend_eweather/domain/weather/service/OpenWeatherAPI.java b/src/main/java/efub/team4/backend_eweather/domain/weather/service/OpenWeatherAPI.java index 0b30300..ac36191 100644 --- a/src/main/java/efub/team4/backend_eweather/domain/weather/service/OpenWeatherAPI.java +++ b/src/main/java/efub/team4/backend_eweather/domain/weather/service/OpenWeatherAPI.java @@ -37,7 +37,7 @@ public class OpenWeatherAPI { @Transactional public List findWeather() throws IOException, ParseException { URL url = buildRequestUrl(); // url 생성성 - System.out.println(url); // url 어떻게 되는지 확인 + //System.out.println(url); // url 어떻게 되는지 확인 String stringResult = httpURLConnect(url); JSONArray jsonResult = getItems(stringResult); return buildResponse(jsonResult); @@ -47,7 +47,7 @@ public List findWeather() throws IOException, ParseExcep @Transactional public List findForcastWeather() throws IOException, ParseException{ URL url = buildRequestUrl(); // url 생성성 - System.out.println(url); // url 어떻게 되는지 확인 + //System.out.println(url); // url 어떻게 되는지 확인 String stringResult = httpURLConnect(url); JSONArray jsonResult = getItems(stringResult); return buildForcastResponse(jsonResult); @@ -56,7 +56,7 @@ public List findForcastWeather() throws IOException, ParseEx @Transactional public CurrentWeatherResponseDto findCalendarWeather() throws IOException, ParseException{ URL url = buildRequestUrl(); // url 생성성 - System.out.println(url); // url 어떻게 되는지 확인 + //System.out.println(url); // url 어떻게 되는지 확인 String stringResult = httpURLConnect(url); JSONArray jsonResult = getItems(stringResult); return buildCurrentData(jsonResult); @@ -65,7 +65,7 @@ public CurrentWeatherResponseDto findCalendarWeather() throws IOException, Parse @Transactional public CurrentWeatherResponseDto findCurrentWeather() throws IOException, ParseException{ URL url = buildRequestUrl(); // url 생성성 - System.out.println(url); // url 어떻게 되는지 확인 + //System.out.println(url); // url 어떻게 되는지 확인 String stringResult = httpURLConnect(url); JSONArray jsonResult = getItems(stringResult); return buildCurrentData(jsonResult); @@ -74,7 +74,7 @@ public CurrentWeatherResponseDto findCurrentWeather() throws IOException, ParseE @Transactional public WeatherResponseDto findTemperature() throws IOException, ParseException { URL url = buildRequestUrl(); // url 생성성 - System.out.println(url); // url 어떻게 되는지 확인 + //System.out.println(url); // url 어떻게 되는지 확인 String stringResult = httpURLConnect(url); JSONArray jsonResult = getItems(stringResult); return builldWeatherResponse(jsonResult, "TMP"); @@ -83,7 +83,7 @@ public WeatherResponseDto findTemperature() throws IOException, ParseException { @Transactional public WeatherResponseDto findSkyCode() throws IOException, ParseException{ URL url = buildRequestUrl(); // url 생성성 - System.out.println(url); // url 어떻게 되는지 확인 + //System.out.println(url); // url 어떻게 되는지 확인 String stringResult = httpURLConnect(url); JSONArray jsonResult = getItems(stringResult); return builldWeatherResponse(jsonResult, "SKY"); @@ -92,7 +92,7 @@ public WeatherResponseDto findSkyCode() throws IOException, ParseException{ @Transactional public WeatherResponseDto findPrecipitation() throws IOException, ParseException{ URL url = buildRequestUrl(); // url 생성성 - System.out.println(url); // url 어떻게 되는지 확인 + //System.out.println(url); // url 어떻게 되는지 확인 String stringResult = httpURLConnect(url); JSONArray jsonResult = getItems(stringResult); return builldWeatherResponse(jsonResult, "POP"); @@ -100,7 +100,7 @@ public WeatherResponseDto findPrecipitation() throws IOException, ParseException public BearResponseDto findBearInfo() throws IOException, ParseException{ URL url = buildRequestUrl(); // url 생성성 - System.out.println(url); // url 어떻게 되는지 확인 + //System.out.println(url); // url 어떻게 되는지 확인 String stringResult = httpURLConnect(url); JSONArray jsonResult = getItems(stringResult); return buildBearResponse(jsonResult); @@ -110,14 +110,14 @@ public URL buildRequestUrl() throws IOException { StringBuilder sb = new StringBuilder(BASE_URL); String baseDate = getCurrentDate(); String baseTime = getBaseTime(); - System.out.println(baseDate + " " + baseTime); + //System.out.println(baseDate + " " + baseTime); if(Objects.equals(baseTime, "2300")){ Date dDate = new Date(); dDate = new Date(dDate.getTime()+(1000*60*60*24*-1)); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); baseDate = sdf.format(dDate); } - System.out.println(baseDate + " " + baseTime); + //System.out.println(baseDate + " " + baseTime); sb.append("?").append(URLEncoder.encode("serviceKey", "UTF-8")).append("=").append(serviceKey); sb.append("&").append(URLEncoder.encode("pageNo", "UTF-8")).append("=").append(URLEncoder.encode(pageNo, "UTF-8")); sb.append("&").append(URLEncoder.encode("numOfRows", "UTF-8")).append("=").append(URLEncoder.encode(numOfRows, "UTF-8")); /* 한 페이지 결과 수 */ @@ -135,7 +135,7 @@ public String httpURLConnect(URL url) throws IOException{ HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Content-type", "application/json"); - System.out.println("Response code: " + conn.getResponseCode()); + //System.out.println("Response code: " + conn.getResponseCode()); BufferedReader rd; @@ -425,7 +425,7 @@ public String getBaseTime(){ DateFormat simpleDateFormat = new SimpleDateFormat("k"); Date currentHour = new Date(); String ApiTime = simpleDateFormat.format(currentHour); - System.out.println(ApiTime); + //System.out.println(ApiTime); return switch (ApiTime) { case "24", "1", "2" -> "2300"; case "3", "4", "5" -> "0200"; diff --git a/src/main/java/efub/team4/backend_eweather/global/outh/filter/TokenAuthenticationFilter.java b/src/main/java/efub/team4/backend_eweather/global/outh/filter/TokenAuthenticationFilter.java index 15cb9b2..51ecee3 100644 --- a/src/main/java/efub/team4/backend_eweather/global/outh/filter/TokenAuthenticationFilter.java +++ b/src/main/java/efub/team4/backend_eweather/global/outh/filter/TokenAuthenticationFilter.java @@ -50,8 +50,6 @@ protected void doFilterInternal( authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); SecurityContextHolder.getContext().setAuthentication(authenticationToken); - //Authentication authentication = tokenProvider.getAuthentication(token); - //SecurityContextHolder.getContext().setAuthentication(authentication); } filterChain.doFilter(request, response);