From bba1b919e9eeda6c5593108c0160f517fca27fd5 Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 10 Jan 2025 17:10:20 +0900 Subject: [PATCH 01/21] =?UTF-8?q?[Feature]=20=EB=AA=A8=EB=8B=88=ED=84=B0?= =?UTF-8?q?=EB=A7=81=20=EC=8A=A4=EB=A0=88=EB=93=9C=2042api=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/gg/api42/ApiClient.java | 52 +++++++++++++++-- .../gg/api42/controller/ApiController.java | 20 +++++++ .../api42/controller/ApiEventController.java | 24 ++++++++ .../gg/api42/controller/EventController.java | 4 ++ .../controller/ForyTwoEventController.java | 12 ++++ .../response/FortyTwoEventResponse.java | 40 +++++++++++++ .../service/FortyTwoEventService.java | 56 +++++++++++++++++++ .../scheduler/FortyTwoEventScheduler.java | 27 +++++++++ .../calendar/FortyTwoEventRepository.java | 10 ++++ .../main/java/gg/utils/external/ApiUtil.java | 9 +++ 10 files changed, 248 insertions(+), 6 deletions(-) create mode 100644 gg-calendar-api/src/main/java/gg/api42/controller/ApiController.java create mode 100644 gg-calendar-api/src/main/java/gg/api42/controller/ApiEventController.java create mode 100644 gg-calendar-api/src/main/java/gg/api42/controller/EventController.java create mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/ForyTwoEventController.java create mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/response/FortyTwoEventResponse.java create mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/service/FortyTwoEventService.java create mode 100644 gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/FortyTwoEventScheduler.java create mode 100644 gg-repo/src/main/java/gg/repo/calendar/FortyTwoEventRepository.java diff --git a/gg-calendar-api/src/main/java/gg/api42/ApiClient.java b/gg-calendar-api/src/main/java/gg/api42/ApiClient.java index aa8cd914e..c90293ff1 100644 --- a/gg-calendar-api/src/main/java/gg/api42/ApiClient.java +++ b/gg-calendar-api/src/main/java/gg/api42/ApiClient.java @@ -7,13 +7,16 @@ import java.net.URL; import java.nio.charset.StandardCharsets; +import org.springframework.stereotype.Component; + import net.minidev.json.JSONObject; import net.minidev.json.parser.JSONParser; +@Component public class ApiClient { private String appId = "u-s4t2ud-c7e81a6ebe4feb0e6d9b40e36455e546e86a75f22695a82292d4d368e7b59773"; private String appSecret = "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"; - private String apiTokenUrl = "http://localhost:8080/login/oauth2/code/42"; + private String apiTokenUrl = "https://api.intra.42.fr/oauth/token"; private String token; public String getToken() { @@ -21,8 +24,8 @@ public String getToken() { // Prepare JSON payload JSONObject parameters = new JSONObject(); parameters.put("grant_type", "client_credentials"); - parameters.put("client_id", appId); // 키 이름 변경 - parameters.put("client_secret", appSecret); // 키 이름 변경 + parameters.put("client_id", appId); + parameters.put("client_secret", appSecret); String jsonInputString = parameters.toString(); System.out.println("Request: " + jsonInputString); @@ -60,9 +63,9 @@ public String getToken() { } // Parse JSON response - JSONParser parser = new JSONParser(); // 변경된 부분 - JSONObject jsonResponse = (JSONObject)parser.parse(response.toString()); // 변경된 부분 - this.token = (String)jsonResponse.get("access_token"); // 변경된 부분 + JSONParser parser = new JSONParser(); + JSONObject jsonResponse = (JSONObject)parser.parse(response.toString()); + this.token = (String)jsonResponse.get("access_token"); return this.token; } @@ -72,6 +75,43 @@ public String getToken() { } } + public String getEvents() { + try { + // 토큰이 없으면 새로 받아오기 + if (token == null) { + token = getToken(); + } + + URL url = new URL("https://api.intra.42.fr/v2/campus/29/events"); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + conn.setRequestMethod("GET"); + conn.setRequestProperty("Authorization", "Bearer " + token); + + // Check response code + int responseCode = conn.getResponseCode(); + if (responseCode != 200) { + System.out.println("HTTP Error: " + responseCode); + System.out.println("Response: " + conn.getResponseMessage()); + return null; + } + // Read response + try (BufferedReader br = new BufferedReader( + new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { + StringBuilder response = new StringBuilder(); + String responseLine; + while ((responseLine = br.readLine()) != null) { + response.append(responseLine.trim()); + } + return response.toString(); + } + + } catch (Exception e) { + e.printStackTrace(); + return null; + } + // return "aaa"; + } + public String getCurrentToken() { return this.token; } diff --git a/gg-calendar-api/src/main/java/gg/api42/controller/ApiController.java b/gg-calendar-api/src/main/java/gg/api42/controller/ApiController.java new file mode 100644 index 000000000..54d5dcf78 --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/api42/controller/ApiController.java @@ -0,0 +1,20 @@ +package gg.api42.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import gg.api42.ApiClient; +import lombok.RequiredArgsConstructor; + +@RestController +@RequestMapping("/api/v1/auth") +@RequiredArgsConstructor +public class ApiController { + private final ApiClient apiClient; + + @GetMapping("/token") + public String getToken() { + return apiClient.getToken(); + } +} diff --git a/gg-calendar-api/src/main/java/gg/api42/controller/ApiEventController.java b/gg-calendar-api/src/main/java/gg/api42/controller/ApiEventController.java new file mode 100644 index 000000000..b3f6a9a9d --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/api42/controller/ApiEventController.java @@ -0,0 +1,24 @@ +package gg.api42.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import gg.api42.ApiClient; + +@RestController +@RequestMapping("/api/v1/events") +public class ApiEventController { + private final ApiClient apiClient; + + @Autowired + public ApiEventController(ApiClient apiClient) { + this.apiClient = apiClient; + } + + @GetMapping + public String getEventList() { + return apiClient.getEvents(); + } +} diff --git a/gg-calendar-api/src/main/java/gg/api42/controller/EventController.java b/gg-calendar-api/src/main/java/gg/api42/controller/EventController.java new file mode 100644 index 000000000..97f5e3844 --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/api42/controller/EventController.java @@ -0,0 +1,4 @@ +package gg.api42.controller; + +public class EventController { +} diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/ForyTwoEventController.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/ForyTwoEventController.java new file mode 100644 index 000000000..453f79688 --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/ForyTwoEventController.java @@ -0,0 +1,12 @@ +package gg.calendar.api.user.fortyTwoEvent.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping +public class ForyTwoEventController { +} diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/response/FortyTwoEventResponse.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/response/FortyTwoEventResponse.java new file mode 100644 index 000000000..69a74c0f3 --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/response/FortyTwoEventResponse.java @@ -0,0 +1,40 @@ +package gg.calendar.api.user.fortyTwoEvent.controller.response; + +import java.time.LocalDateTime; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonFormat; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class FortyTwoEventResponse { + private Long id; + private String name; + private String description; + private String location; + private String kind; + private Integer maxPeople; + private Integer nbrSubcribers; + private List campusIds; + private List cursusIds; + private String prohibitionOfCancellation; + private String waitlist; + private List themes; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + private LocalDateTime beginAt; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + private LocalDateTime endAt; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + private LocalDateTime createdAt; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + private LocalDateTime updatedAt; + +} diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/service/FortyTwoEventService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/service/FortyTwoEventService.java new file mode 100644 index 000000000..fe545301e --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/service/FortyTwoEventService.java @@ -0,0 +1,56 @@ +package gg.calendar.api.user.fortyTwoEvent.service; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.HttpClientErrorException; + +import gg.auth.FortyTwoAuthUtil; +import gg.calendar.api.user.fortyTwoEvent.controller.response.FortyTwoEventResponse; +import gg.repo.calendar.PublicScheduleRepository; +import gg.utils.external.ApiUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +@RequiredArgsConstructor +public class FortyTwoEventService { + private final ApiUtil apiUtil; + private final FortyTwoAuthUtil fortyTwoAuthUtil; + private final PublicScheduleRepository publicScheduleRepository; + + @Value("https://api.intra.42.fr/v2/campus/29/events") + private String eventUrl; + + // @Transactional + // public void checkNewEvent() { + // try { + // List events = getEvents(); + // } catch () { + // } + // } + + @Transactional(readOnly = true) + public List getEvents() { + ParameterizedTypeReference> responseType = + new ParameterizedTypeReference<>() { + }; + try { + log.info("getEvent started==="); + String accessToken = fortyTwoAuthUtil.getAccessToken(); + log.info("---accessToken---: {}", accessToken); + return apiUtil.callApiWithAccessTokenEvent(eventUrl, accessToken, responseType); + } catch (HttpClientErrorException e) { + if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) { + String accessToken = fortyTwoAuthUtil.refreshAccessToken(); + return apiUtil.callApiWithAccessTokenEvent(eventUrl, accessToken, responseType); + } + throw e; + } + } +} diff --git a/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/FortyTwoEventScheduler.java b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/FortyTwoEventScheduler.java new file mode 100644 index 000000000..416241057 --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/FortyTwoEventScheduler.java @@ -0,0 +1,27 @@ +package gg.pingpong.api.global.scheduler; + +import org.springframework.stereotype.Component; + +import gg.calendar.api.user.fortyTwoEvent.service.FortyTwoEventService; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +public class FortyTwoEventScheduler extends AbstractScheduler { + private final FortyTwoEventService fortyTwoEventService; + + public FortyTwoEventScheduler(FortyTwoEventService fortyTwoEventService) { + this.fortyTwoEventService = fortyTwoEventService; + // this.setCron("0 0 0 * * *"); + this.setCron("0 * * * * *"); + } + + @Override + public Runnable runnable() { + return () -> { + log.info("FortyTwo Event Scheduler Started"); + fortyTwoEventService.getEvents(); + log.info("getEvents() method was called successfully."); + }; + } +} diff --git a/gg-repo/src/main/java/gg/repo/calendar/FortyTwoEventRepository.java b/gg-repo/src/main/java/gg/repo/calendar/FortyTwoEventRepository.java new file mode 100644 index 000000000..8453da633 --- /dev/null +++ b/gg-repo/src/main/java/gg/repo/calendar/FortyTwoEventRepository.java @@ -0,0 +1,10 @@ +package gg.repo.calendar; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import gg.data.calendar.PublicSchedule; + +@Repository +public interface FortyTwoEventRepository extends JpaRepository { +} diff --git a/gg-utils/src/main/java/gg/utils/external/ApiUtil.java b/gg-utils/src/main/java/gg/utils/external/ApiUtil.java index e8c1df77b..fd2360ca1 100644 --- a/gg-utils/src/main/java/gg/utils/external/ApiUtil.java +++ b/gg-utils/src/main/java/gg/utils/external/ApiUtil.java @@ -90,4 +90,13 @@ public List> callApiWithAccessToken(String url, String acces return apiCall(url, responseType, headers, HttpMethod.GET); } + + public T callApiWithAccessTokenEvent(String url, String accessToken, + ParameterizedTypeReference responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setBearerAuth(accessToken); + headers.setContentType(MediaType.APPLICATION_JSON); + + return apiCall(url, responseType, headers, HttpMethod.GET); + } } From 6e77b61ba799e491a5b43206d6308d2d2b96a33b Mon Sep 17 00:00:00 2001 From: wonie Date: Tue, 14 Jan 2025 14:58:34 +0900 Subject: [PATCH 02/21] =?UTF-8?q?[Feature]=20=EB=AA=A8=EB=8B=88=ED=84=B0?= =?UTF-8?q?=EB=A7=81=EC=8A=A4=EB=A0=88=EB=93=9C=EC=97=90=EC=84=9C=2042even?= =?UTF-8?q?t=20api=20=EB=B0=9B=EC=95=84=EC=98=A4=EA=B8=B0=20-=20PublicSche?= =?UTF-8?q?dule=20Service=EC=97=90=EC=84=9C=20=ED=8B=80=EB=A6=B0=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95(checkAuthor)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/gg/auth/FortyTwoAuthUtil.java | 30 ++++++++ .../java/gg/auth/config/ScheduleConfig.java | 17 +++++ .../controller/ForyTwoEventController.java | 12 --- .../response/FortyTwoEventResponse.java | 40 ---------- .../service/FortyTwoEventService.java | 56 -------------- .../response/FortyTwoEventResponse.java | 75 ++++++++++++++++++ .../service/FortyTwoEventApiClient.java | 40 ++++++++++ .../service/FortyTwoEventService.java | 76 +++++++++++++++++++ .../service/PublicScheduleService.java | 2 +- .../scheduler/FortyTwoEventScheduler.java | 4 +- .../calendar/PublicScheduleRepository.java | 2 + .../main/java/gg/utils/external/ApiUtil.java | 1 - 12 files changed, 243 insertions(+), 112 deletions(-) create mode 100644 gg-auth/src/main/java/gg/auth/config/ScheduleConfig.java delete mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/ForyTwoEventController.java delete mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/response/FortyTwoEventResponse.java delete mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/service/FortyTwoEventService.java create mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/controller/response/FortyTwoEventResponse.java create mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventApiClient.java create mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventService.java diff --git a/gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java b/gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java index 9a6b6299d..76633ec37 100644 --- a/gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java +++ b/gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java @@ -23,17 +23,21 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import gg.auth.config.ScheduleConfig; import gg.utils.exception.ErrorCode; import gg.utils.exception.custom.NotExistException; import gg.utils.exception.user.TokenNotValidException; import gg.utils.external.ApiUtil; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Component @RequiredArgsConstructor public class FortyTwoAuthUtil { private final ApiUtil apiUtil; private final OAuth2AuthorizedClientService authorizedClientService; + private final ScheduleConfig scheduleConfig; public String getAccessToken() { Authentication authentication = getAuthenticationFromContext(); @@ -62,6 +66,32 @@ public String refreshAccessToken() { return newClient.getAccessToken().getTokenValue(); } + /* 42event client credential token */ + public String getClientCredentialToken() { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + + MultiValueMap params = new LinkedMultiValueMap<>(); + params.add("grant_type", "client_credentials"); + params.add("client_id", scheduleConfig.getClientId()); + params.add("client_secret", scheduleConfig.getClientSecret()); + + try { + Map response = apiUtil.apiCall( + scheduleConfig.getTokenUri(), + Map.class, + headers, + params, + HttpMethod.POST + ); + log.info("Raw Api Response : {}", response); + // System.out.println("Response : " + response); + return (String)response.get("access_token"); + } catch (Exception e) { + throw new TokenNotValidException(); + } + } + private Authentication getAuthenticationFromContext() { SecurityContext context = SecurityContextHolder.getContext(); return context.getAuthentication(); diff --git a/gg-auth/src/main/java/gg/auth/config/ScheduleConfig.java b/gg-auth/src/main/java/gg/auth/config/ScheduleConfig.java new file mode 100644 index 000000000..b58d125b6 --- /dev/null +++ b/gg-auth/src/main/java/gg/auth/config/ScheduleConfig.java @@ -0,0 +1,17 @@ +package gg.auth.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import lombok.Getter; + +@Configuration +@Getter +public class ScheduleConfig { + @Value("${spring.security.oauth2.client.registration.42.client-id}") + private String clientId; + @Value("${spring.security.oauth2.client.registration.42.client-secret}") + private String clientSecret; + @Value("${spring.security.oauth2.client.provider.42.token-uri}") + private String tokenUri; +} diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/ForyTwoEventController.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/ForyTwoEventController.java deleted file mode 100644 index 453f79688..000000000 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/ForyTwoEventController.java +++ /dev/null @@ -1,12 +0,0 @@ -package gg.calendar.api.user.fortyTwoEvent.controller; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import lombok.RequiredArgsConstructor; - -@RestController -@RequiredArgsConstructor -@RequestMapping -public class ForyTwoEventController { -} diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/response/FortyTwoEventResponse.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/response/FortyTwoEventResponse.java deleted file mode 100644 index 69a74c0f3..000000000 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/controller/response/FortyTwoEventResponse.java +++ /dev/null @@ -1,40 +0,0 @@ -package gg.calendar.api.user.fortyTwoEvent.controller.response; - -import java.time.LocalDateTime; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonFormat; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class FortyTwoEventResponse { - private Long id; - private String name; - private String description; - private String location; - private String kind; - private Integer maxPeople; - private Integer nbrSubcribers; - private List campusIds; - private List cursusIds; - private String prohibitionOfCancellation; - private String waitlist; - private List themes; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - private LocalDateTime beginAt; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - private LocalDateTime endAt; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - private LocalDateTime createdAt; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - private LocalDateTime updatedAt; - -} diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/service/FortyTwoEventService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/service/FortyTwoEventService.java deleted file mode 100644 index fe545301e..000000000 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortyTwoEvent/service/FortyTwoEventService.java +++ /dev/null @@ -1,56 +0,0 @@ -package gg.calendar.api.user.fortyTwoEvent.service; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.client.HttpClientErrorException; - -import gg.auth.FortyTwoAuthUtil; -import gg.calendar.api.user.fortyTwoEvent.controller.response.FortyTwoEventResponse; -import gg.repo.calendar.PublicScheduleRepository; -import gg.utils.external.ApiUtil; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Service -@RequiredArgsConstructor -public class FortyTwoEventService { - private final ApiUtil apiUtil; - private final FortyTwoAuthUtil fortyTwoAuthUtil; - private final PublicScheduleRepository publicScheduleRepository; - - @Value("https://api.intra.42.fr/v2/campus/29/events") - private String eventUrl; - - // @Transactional - // public void checkNewEvent() { - // try { - // List events = getEvents(); - // } catch () { - // } - // } - - @Transactional(readOnly = true) - public List getEvents() { - ParameterizedTypeReference> responseType = - new ParameterizedTypeReference<>() { - }; - try { - log.info("getEvent started==="); - String accessToken = fortyTwoAuthUtil.getAccessToken(); - log.info("---accessToken---: {}", accessToken); - return apiUtil.callApiWithAccessTokenEvent(eventUrl, accessToken, responseType); - } catch (HttpClientErrorException e) { - if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) { - String accessToken = fortyTwoAuthUtil.refreshAccessToken(); - return apiUtil.callApiWithAccessTokenEvent(eventUrl, accessToken, responseType); - } - throw e; - } - } -} diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/controller/response/FortyTwoEventResponse.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/controller/response/FortyTwoEventResponse.java new file mode 100644 index 000000000..6a89eb67c --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/controller/response/FortyTwoEventResponse.java @@ -0,0 +1,75 @@ +package gg.calendar.api.user.fortytwoevent.controller.response; + +import java.time.LocalDateTime; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class FortyTwoEventResponse { + private Long id; + private String name; + private String description; + private String location; + private String kind; + @JsonProperty("max_people") + private Integer maxPeople; + + @JsonProperty("nbr_subscribers") + private Integer nbrSubcribers; + + @JsonProperty("campus_ids") + private List campusIds; + + @JsonProperty("cursus_ids") + private List cursusIds; + + @JsonProperty("prohibition_of_cancellation") + private String prohibitionOfCancellation; + + private Waitlist waitlist; + private List themes; + + @JsonProperty("begin_at") + private LocalDateTime beginAt; + + @JsonProperty("end_at") + private LocalDateTime endAt; + + @JsonProperty("created_at") + private LocalDateTime createdAt; + + @JsonProperty("updated_at") + private LocalDateTime updatedAt; + + public static class Themes { + private Long id; + private String name; + @JsonProperty("created_at") + private LocalDateTime createdAt; + + @JsonProperty("updated_at") + private LocalDateTime updatedAt; + } + + public static class Waitlist { + private Long id; + @JsonProperty("created_at") + private LocalDateTime createdAt; + + @JsonProperty("updated_at") + private LocalDateTime updatedAt; + + @JsonProperty("waitlist_id") + private Long waitlistId; + + @JsonProperty("waitlist_type") + private String waitlistType; + } + +} diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventApiClient.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventApiClient.java new file mode 100644 index 000000000..46d8e17f3 --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventApiClient.java @@ -0,0 +1,40 @@ +package gg.calendar.api.user.fortytwoevent.service; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Component; +import org.springframework.web.client.HttpClientErrorException; + +import gg.auth.FortyTwoAuthUtil; +import gg.calendar.api.user.fortytwoevent.controller.response.FortyTwoEventResponse; +import gg.utils.external.ApiUtil; +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class FortyTwoEventApiClient { + private final ApiUtil apiUtil; + private final FortyTwoAuthUtil fortyTwoAuthUtil; + + @Value("https://api.intra.42.fr/v2/campus/29/events") + private String eventUrl; + + public List getEvents() { + ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { + }; + + try { + String accessToken = fortyTwoAuthUtil.getClientCredentialToken(); + return apiUtil.callApiWithAccessTokenEvent(eventUrl, accessToken, responseType); + } catch (HttpClientErrorException e) { + if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) { + String refreshToken = fortyTwoAuthUtil.getClientCredentialToken(); + return apiUtil.callApiWithAccessTokenEvent(eventUrl, refreshToken, responseType); + } + throw e; + } + } +} diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventService.java new file mode 100644 index 000000000..b3c6b7de2 --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventService.java @@ -0,0 +1,76 @@ +package gg.calendar.api.user.fortytwoevent.service; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import gg.calendar.api.user.fortytwoevent.controller.response.FortyTwoEventResponse; +import gg.data.calendar.PublicSchedule; +import gg.data.calendar.type.DetailClassification; +import gg.data.calendar.type.EventTag; +import gg.data.calendar.type.ScheduleStatus; +import gg.repo.calendar.PublicScheduleRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +@Transactional +@RequiredArgsConstructor +public class FortyTwoEventService { + private final FortyTwoEventApiClient fortyTwoEventApiClient; + private final PublicScheduleRepository publicScheduleRepository; + + public void checkEvent() { + List events = fortyTwoEventApiClient.getEvents(); + List newEvents = filterEvents(events); + saveEventsToPublicSchedule(newEvents); + } + + private List filterEvents(List events) { + return events.stream() + .filter(event -> !isEventExists(event.getName(), event.getBeginAt())) + .collect(Collectors.toList()); + } + + private void saveEventsToPublicSchedule(List events) { + events.forEach(this::convertAndSaveEvent); + } + + private void convertAndSaveEvent(FortyTwoEventResponse event) { + String description = event.getDescription(); + if (description != null && description.length() > 255) { + description = description.substring(0, 255); + } + PublicSchedule publicSchedule = PublicSchedule.builder() + .classification(DetailClassification.EVENT) + .eventTag(determineEventTag(event)) + .author("42Seoul") + .title(event.getName()) + .content(description) + .link("https://profile.intra.42.fr/events") + .status(ScheduleStatus.ACTIVATE) + .startTime(event.getBeginAt()) + .endTime(event.getEndAt()) + .build(); + publicScheduleRepository.save(publicSchedule); + } + + private boolean isEventExists(String title, LocalDateTime beginAt) { + return publicScheduleRepository.existsByTitleAndStartTime(title, beginAt); + } + + private EventTag determineEventTag(FortyTwoEventResponse eventResponse) { + return switch (eventResponse.getKind()) { + case "pedago", "rush", "piscine", "partnership", "event", "meet", "hackathon" -> EventTag.OFFICIAL_EVENT; + case "meet_up" -> EventTag.WENDS_FORUM; + case "conference" -> EventTag.INSTRUCTION; + default -> EventTag.ETC; + }; + } +} + + diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/publicschedule/service/PublicScheduleService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/publicschedule/service/PublicScheduleService.java index 5fcc43cf5..28f29f5c9 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/publicschedule/service/PublicScheduleService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/publicschedule/service/PublicScheduleService.java @@ -90,7 +90,7 @@ public PublicSchedule getPublicScheduleDetailRetrieve(Long scheduleId, Long user User user = userRepository.getById(userId); PublicSchedule publicRetrieveSchedule = publicScheduleRepository.findById(scheduleId) .orElseThrow(() -> new NotExistException(ErrorCode.PUBLIC_SCHEDULE_NOT_FOUND)); - checkAuthor(publicRetrieveSchedule.getAuthor(), user); + // checkAuthor(publicRetrieveSchedule.getAuthor(), user); return publicRetrieveSchedule; } diff --git a/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/FortyTwoEventScheduler.java b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/FortyTwoEventScheduler.java index 416241057..ecbfadc72 100644 --- a/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/FortyTwoEventScheduler.java +++ b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/FortyTwoEventScheduler.java @@ -2,7 +2,7 @@ import org.springframework.stereotype.Component; -import gg.calendar.api.user.fortyTwoEvent.service.FortyTwoEventService; +import gg.calendar.api.user.fortytwoevent.service.FortyTwoEventService; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -20,7 +20,7 @@ public FortyTwoEventScheduler(FortyTwoEventService fortyTwoEventService) { public Runnable runnable() { return () -> { log.info("FortyTwo Event Scheduler Started"); - fortyTwoEventService.getEvents(); + fortyTwoEventService.checkEvent(); log.info("getEvents() method was called successfully."); }; } diff --git a/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java b/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java index 2db4cc736..d62730a31 100644 --- a/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java +++ b/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java @@ -18,4 +18,6 @@ List findByEndTimeGreaterThanEqualAndStartTimeLessThanEqual(Loca List findByEndTimeGreaterThanEqualAndStartTimeLessThanEqualAndClassification( LocalDateTime startTime, LocalDateTime endTime, DetailClassification classification); + + boolean existsByTitleAndStartTime(String title, LocalDateTime beginAt); } diff --git a/gg-utils/src/main/java/gg/utils/external/ApiUtil.java b/gg-utils/src/main/java/gg/utils/external/ApiUtil.java index fd2360ca1..4aaa6e584 100644 --- a/gg-utils/src/main/java/gg/utils/external/ApiUtil.java +++ b/gg-utils/src/main/java/gg/utils/external/ApiUtil.java @@ -96,7 +96,6 @@ public T callApiWithAccessTokenEvent(String url, String accessToken, HttpHeaders headers = new HttpHeaders(); headers.setBearerAuth(accessToken); headers.setContentType(MediaType.APPLICATION_JSON); - return apiCall(url, responseType, headers, HttpMethod.GET); } } From e964ebb17704137fa007aab6264538ba5010643f Mon Sep 17 00:00:00 2001 From: wonie Date: Tue, 14 Jan 2025 18:34:47 +0900 Subject: [PATCH 03/21] =?UTF-8?q?[FEATURE]=20=EB=AA=A8=EB=8B=88=ED=84=B0?= =?UTF-8?q?=EB=A7=81=20=EC=8A=A4=EB=A0=88=EB=93=9C=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EA=B8=B0=EA=B0=84=EC=9D=B4=20=EC=A7=80=EB=82=9C=20=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=EB=93=A4=20deactive=ED=99=94=ED=95=98=EA=B8=B0=20&=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20scheduler=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ScheduleCheckService.java | 26 +++++++++++++++++++ ...duler.java => CalendarEventScheduler.java} | 11 +++++--- .../calendar/PrivateScheduleRepository.java | 12 +++++++++ .../calendar/PublicScheduleRepository.java | 13 ++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleCheckService.java rename gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/{FortyTwoEventScheduler.java => CalendarEventScheduler.java} (53%) diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleCheckService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleCheckService.java new file mode 100644 index 000000000..d3c37a7a8 --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleCheckService.java @@ -0,0 +1,26 @@ +package gg.calendar.api.user.fortytwoevent.service; + +import java.time.LocalDateTime; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import gg.data.calendar.type.ScheduleStatus; +import gg.repo.calendar.PrivateScheduleRepository; +import gg.repo.calendar.PublicScheduleRepository; +import lombok.RequiredArgsConstructor; + +@Service +@Transactional +@RequiredArgsConstructor +public class ScheduleCheckService { + private final PublicScheduleRepository publicScheduleRepository; + private final PrivateScheduleRepository privateScheduleRepository; + + public void deactivateExpiredSchedules() { + publicScheduleRepository.updateExpiredPublicSchedules(ScheduleStatus.DEACTIVATE, + ScheduleStatus.ACTIVATE, + LocalDateTime.now()); + privateScheduleRepository.updateRelatedPrivateSchedules(ScheduleStatus.DEACTIVATE, ScheduleStatus.ACTIVATE); + } +} diff --git a/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/FortyTwoEventScheduler.java b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java similarity index 53% rename from gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/FortyTwoEventScheduler.java rename to gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java index ecbfadc72..13475a924 100644 --- a/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/FortyTwoEventScheduler.java +++ b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java @@ -3,15 +3,19 @@ import org.springframework.stereotype.Component; import gg.calendar.api.user.fortytwoevent.service.FortyTwoEventService; +import gg.calendar.api.user.fortytwoevent.service.ScheduleCheckService; import lombok.extern.slf4j.Slf4j; @Slf4j @Component -public class FortyTwoEventScheduler extends AbstractScheduler { +public class CalendarEventScheduler extends AbstractScheduler { private final FortyTwoEventService fortyTwoEventService; + private final ScheduleCheckService scheduleCheckService; - public FortyTwoEventScheduler(FortyTwoEventService fortyTwoEventService) { + public CalendarEventScheduler(FortyTwoEventService fortyTwoEventService, + ScheduleCheckService scheduleCheckService) { this.fortyTwoEventService = fortyTwoEventService; + this.scheduleCheckService = scheduleCheckService; // this.setCron("0 0 0 * * *"); this.setCron("0 * * * * *"); } @@ -21,7 +25,8 @@ public Runnable runnable() { return () -> { log.info("FortyTwo Event Scheduler Started"); fortyTwoEventService.checkEvent(); - log.info("getEvents() method was called successfully."); + log.info("Schedule check service deactivate Expired Schedules!"); + scheduleCheckService.deactivateExpiredSchedules(); }; } } diff --git a/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java b/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java index ab40c6d89..e264f43b6 100644 --- a/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java +++ b/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java @@ -3,12 +3,17 @@ import java.time.LocalDateTime; import java.util.List; +import javax.transaction.Transactional; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import gg.data.calendar.PrivateSchedule; import gg.data.calendar.PublicSchedule; +import gg.data.calendar.type.ScheduleStatus; import gg.data.user.User; @Repository @@ -20,4 +25,11 @@ public interface PrivateScheduleRepository extends JpaRepository :endTime OR pu.endTime < :startTime) " + "AND pr.user = :user") List findOverlappingSchedulesByUser(LocalDateTime startTime, LocalDateTime endTime, User user); + + @Modifying + @Transactional + @Query("UPDATE PrivateSchedule ps SET ps.status = :status WHERE ps.publicSchedule.id IN " + + "(SELECT p.id FROM PublicSchedule p WHERE p.status = :publicStatus)") + void updateRelatedPrivateSchedules(@Param("status") ScheduleStatus status, + @Param("publicStatus") ScheduleStatus publicStatus); } diff --git a/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java b/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java index d62730a31..0ea0e76ae 100644 --- a/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java +++ b/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java @@ -3,11 +3,17 @@ import java.time.LocalDateTime; import java.util.List; +import javax.transaction.Transactional; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import gg.data.calendar.PublicSchedule; import gg.data.calendar.type.DetailClassification; +import gg.data.calendar.type.ScheduleStatus; @Repository public interface PublicScheduleRepository extends JpaRepository { @@ -20,4 +26,11 @@ List findByEndTimeGreaterThanEqualAndStartTimeLessThanEqualAndCl LocalDateTime startTime, LocalDateTime endTime, DetailClassification classification); boolean existsByTitleAndStartTime(String title, LocalDateTime beginAt); + + @Modifying + @Transactional + @Query("UPDATE PublicSchedule ps SET ps.status = :status WHERE ps.status = :currentStatus AND ps.endTime < :time") + void updateExpiredPublicSchedules(@Param("status") ScheduleStatus status, + @Param("currentStatus") ScheduleStatus currentStatus, + @Param("time") LocalDateTime time); } From 7d2e94cbd3a0be08d39514c0884ac9ed32e3cf7a Mon Sep 17 00:00:00 2001 From: wonie Date: Wed, 15 Jan 2025 18:28:36 +0900 Subject: [PATCH 04/21] =?UTF-8?q?[FEATURE]=20slackBot=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=95=8C=EB=9E=8C=EB=B3=B4=EB=82=B4=EA=B8=B0=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ScheduleNotiService.java | 53 +++++++++++++++++++ .../scheduler/CalendarEventScheduler.java | 6 ++- .../api/user/noti/service/NotiService.java | 5 +- .../calendar/PrivateScheduleRepository.java | 9 ++++ 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java new file mode 100644 index 000000000..7d1be1492 --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java @@ -0,0 +1,53 @@ +package gg.calendar.api.user.fortytwoevent.service; + +import java.time.LocalDateTime; +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import gg.data.calendar.PrivateSchedule; +import gg.data.calendar.type.ScheduleStatus; +import gg.repo.calendar.PrivateScheduleRepository; +import gg.repo.calendar.PublicScheduleRepository; +import gg.utils.sns.MessageSender; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +@Transactional +@RequiredArgsConstructor +public class ScheduleNotiService { + private final PublicScheduleRepository publicScheduleRepository; + private final PrivateScheduleRepository privateScheduleRepository; + private final MessageSender messageSender; + private static final String SCHEDULE_MESSAGE_D_DAY = "일정요정🧚으로부터 알림이 도착했습니다.\n" + + "오늘의 일정을 확인해보세요!\n"; + private static final String SCHEDULE_MESSAGE_BEFORE_D_DAY = "일정요정🧚으로부터 알림이 도착했습니다.\n" + + "내일의 일정을 확인해보세요!\n"; + + @Transactional + public void sendScheduleNotifications() { + LocalDateTime currentTime = LocalDateTime.now(); + LocalDateTime startOfDay = LocalDateTime.now().toLocalDate().atStartOfDay(); + LocalDateTime endOfDay = startOfDay.plusDays(1).minusNanos(1); + LocalDateTime startDday = startOfDay.plusDays(1); + LocalDateTime endDday = startOfDay.plusDays(1); + + log.info("startofday: {}", startOfDay); + log.info("endtofday: {}", endOfDay); + + List alarmSchedule = privateScheduleRepository.findSchedulesWithAlarmForBothDays(startOfDay, + endOfDay, startDday, endDday, ScheduleStatus.ACTIVATE); + log.info("영역전개"); + for (PrivateSchedule schedule : alarmSchedule) { + log.info("schedule, getID: {}", schedule.getId()); + String message = schedule.getPublicSchedule().getEndTime() + .isBefore(currentTime.plusDays(1)) + ? SCHEDULE_MESSAGE_D_DAY : SCHEDULE_MESSAGE_BEFORE_D_DAY; + messageSender.send(schedule.getUser().getIntraId(), + message + schedule.getPublicSchedule().getTitle()); + } + } +} diff --git a/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java index 13475a924..9b115fe56 100644 --- a/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java +++ b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java @@ -4,6 +4,7 @@ import gg.calendar.api.user.fortytwoevent.service.FortyTwoEventService; import gg.calendar.api.user.fortytwoevent.service.ScheduleCheckService; +import gg.calendar.api.user.fortytwoevent.service.ScheduleNotiService; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -11,11 +12,13 @@ public class CalendarEventScheduler extends AbstractScheduler { private final FortyTwoEventService fortyTwoEventService; private final ScheduleCheckService scheduleCheckService; + private final ScheduleNotiService scheduleNotiService; public CalendarEventScheduler(FortyTwoEventService fortyTwoEventService, - ScheduleCheckService scheduleCheckService) { + ScheduleCheckService scheduleCheckService, ScheduleNotiService scheduleNotiService) { this.fortyTwoEventService = fortyTwoEventService; this.scheduleCheckService = scheduleCheckService; + this.scheduleNotiService = scheduleNotiService; // this.setCron("0 0 0 * * *"); this.setCron("0 * * * * *"); } @@ -27,6 +30,7 @@ public Runnable runnable() { fortyTwoEventService.checkEvent(); log.info("Schedule check service deactivate Expired Schedules!"); scheduleCheckService.deactivateExpiredSchedules(); + scheduleNotiService.sendScheduleNotifications(); }; } } diff --git a/gg-pingpong-api/src/main/java/gg/pingpong/api/user/noti/service/NotiService.java b/gg-pingpong-api/src/main/java/gg/pingpong/api/user/noti/service/NotiService.java index c7d6148ed..eec9e793f 100644 --- a/gg-pingpong-api/src/main/java/gg/pingpong/api/user/noti/service/NotiService.java +++ b/gg-pingpong-api/src/main/java/gg/pingpong/api/user/noti/service/NotiService.java @@ -161,8 +161,9 @@ public String getMessage(Noti noti) { "🧚: \"새로운 알림이 도착했핑.\"\n" + "🧚: \"" + noti.getType().getMessage() + "\"\n\n 🏓42GG와 함께하는 행복한 탁구생활🏓" + "\n$$지금 즉시 접속$$ ----> https://42gg.kr"; } else { - message = "🧚: \"새로운 알림이 도착했핑.\"\n" + "🧚: \"" + noti.getType().getMessage() + "\"\n\n공지사항: " - + noti.getMessage() + "\n\n 🏓42GG와 함께하는 행복한 탁구생활🏓" + "\n$$지금 즉시 접속$$ ----> https://42gg.kr"; + message = + "🧚: \"새로운 알림이 도착했핑.\"\n" + "🧚: \"" + noti.getType().getMessage() + "\"\n\n공지사항: " + noti.getMessage() + + "\n\n 🏓42GG와 함께하는 행복한 탁구생활🏓" + "\n$$지금 즉시 접속$$ ----> https://42gg.kr"; } return message; } diff --git a/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java b/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java index e264f43b6..7bcd6f312 100644 --- a/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java +++ b/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java @@ -32,4 +32,13 @@ public interface PrivateScheduleRepository extends JpaRepository findSchedulesWithAlarmForBothDays(@Param("startOfDay") LocalDateTime startOfDay, + @Param("endOfDay") LocalDateTime endOfDay, + @Param("nextStartOfDay") LocalDateTime nextStartOfDay, + @Param("nextEndOfDay") LocalDateTime nextEndOfDay, + @Param("status") ScheduleStatus status); } From 2b06a90829e5799579ef9935d4dc3b31a980db3d Mon Sep 17 00:00:00 2001 From: wonie Date: Wed, 15 Jan 2025 18:45:49 +0900 Subject: [PATCH 05/21] =?UTF-8?q?[FIX]=20switch=EB=AC=B8=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD(=EC=9E=90=EB=B0=9411=EA=B8=B0=EC=A4=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FortyTwoEventService.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventService.java index b3c6b7de2..2fb1745a0 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventService.java @@ -64,12 +64,23 @@ private boolean isEventExists(String title, LocalDateTime beginAt) { } private EventTag determineEventTag(FortyTwoEventResponse eventResponse) { - return switch (eventResponse.getKind()) { - case "pedago", "rush", "piscine", "partnership", "event", "meet", "hackathon" -> EventTag.OFFICIAL_EVENT; - case "meet_up" -> EventTag.WENDS_FORUM; - case "conference" -> EventTag.INSTRUCTION; - default -> EventTag.ETC; - }; + String kind = eventResponse.getKind(); + switch (kind) { + case "pedago": + case "rush": + case "piscine": + case "partnership": + case "event": + case "meet": + case "hackathon": + return EventTag.OFFICIAL_EVENT; + case "meet_up": + return EventTag.WENDS_FORUM; + case "conference": + return EventTag.INSTRUCTION; + default: + return EventTag.ETC; + } } } From ada672db9cd7c5a04f1222f7590c462c61ffe2a7 Mon Sep 17 00:00:00 2001 From: wonie Date: Wed, 15 Jan 2025 19:11:03 +0900 Subject: [PATCH 06/21] =?UTF-8?q?[FIX]=20=EC=8A=AC=EB=9E=99=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=95=8C=EB=9E=8C=EC=9D=B4=20=EC=95=88=EB=82=98?= =?UTF-8?q?=EC=98=A4=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fortytwoevent/service/ScheduleCheckService.java | 2 +- .../fortytwoevent/service/ScheduleNotiService.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleCheckService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleCheckService.java index d3c37a7a8..52f5d4824 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleCheckService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleCheckService.java @@ -21,6 +21,6 @@ public void deactivateExpiredSchedules() { publicScheduleRepository.updateExpiredPublicSchedules(ScheduleStatus.DEACTIVATE, ScheduleStatus.ACTIVATE, LocalDateTime.now()); - privateScheduleRepository.updateRelatedPrivateSchedules(ScheduleStatus.DEACTIVATE, ScheduleStatus.ACTIVATE); + privateScheduleRepository.updateRelatedPrivateSchedules(ScheduleStatus.DEACTIVATE, ScheduleStatus.DEACTIVATE); } } diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java index 7d1be1492..94bb92101 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java @@ -33,14 +33,14 @@ public void sendScheduleNotifications() { LocalDateTime startOfDay = LocalDateTime.now().toLocalDate().atStartOfDay(); LocalDateTime endOfDay = startOfDay.plusDays(1).minusNanos(1); LocalDateTime startDday = startOfDay.plusDays(1); - LocalDateTime endDday = startOfDay.plusDays(1); - - log.info("startofday: {}", startOfDay); - log.info("endtofday: {}", endOfDay); + LocalDateTime endDday = endOfDay.plusDays(1); List alarmSchedule = privateScheduleRepository.findSchedulesWithAlarmForBothDays(startOfDay, endOfDay, startDday, endDday, ScheduleStatus.ACTIVATE); - log.info("영역전개"); + log.info("startofday: {}", startOfDay); + log.info("endtofday: {}", endOfDay); + log.info("startDday: {}", startDday); + log.info("endDday: {}", endDday); for (PrivateSchedule schedule : alarmSchedule) { log.info("schedule, getID: {}", schedule.getId()); String message = schedule.getPublicSchedule().getEndTime() From 31980ff7270fde44acd9d9b40f86aea07a9cffac Mon Sep 17 00:00:00 2001 From: wonie Date: Sun, 19 Jan 2025 17:46:25 +0900 Subject: [PATCH 07/21] =?UTF-8?q?[FIX]=20=EA=B8=B0=EC=A1=B4=20ApiClient=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/gg/api42/ApiClient.java | 118 ------------------ .../gg/api42/controller/ApiController.java | 20 --- .../api42/controller/ApiEventController.java | 24 ---- .../gg/api42/controller/EventController.java | 4 - 4 files changed, 166 deletions(-) delete mode 100644 gg-calendar-api/src/main/java/gg/api42/ApiClient.java delete mode 100644 gg-calendar-api/src/main/java/gg/api42/controller/ApiController.java delete mode 100644 gg-calendar-api/src/main/java/gg/api42/controller/ApiEventController.java delete mode 100644 gg-calendar-api/src/main/java/gg/api42/controller/EventController.java diff --git a/gg-calendar-api/src/main/java/gg/api42/ApiClient.java b/gg-calendar-api/src/main/java/gg/api42/ApiClient.java deleted file mode 100644 index c90293ff1..000000000 --- a/gg-calendar-api/src/main/java/gg/api42/ApiClient.java +++ /dev/null @@ -1,118 +0,0 @@ -package gg.api42; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.StandardCharsets; - -import org.springframework.stereotype.Component; - -import net.minidev.json.JSONObject; -import net.minidev.json.parser.JSONParser; - -@Component -public class ApiClient { - private String appId = "u-s4t2ud-c7e81a6ebe4feb0e6d9b40e36455e546e86a75f22695a82292d4d368e7b59773"; - private String appSecret = "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"; - private String apiTokenUrl = "https://api.intra.42.fr/oauth/token"; - private String token; - - public String getToken() { - try { - // Prepare JSON payload - JSONObject parameters = new JSONObject(); - parameters.put("grant_type", "client_credentials"); - parameters.put("client_id", appId); - parameters.put("client_secret", appSecret); - String jsonInputString = parameters.toString(); - - System.out.println("Request: " + jsonInputString); - System.out.println("URL: " + apiTokenUrl); - - // Create connection - URL url = new URL(apiTokenUrl); - HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/json"); - conn.setRequestProperty("Content-Length", String.valueOf(jsonInputString.getBytes().length)); - conn.setDoOutput(true); - - // Send request - try (OutputStream os = conn.getOutputStream()) { - byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); - os.write(input, 0, input.length); - } - - // Check response code - int responseCode = conn.getResponseCode(); - if (responseCode != 200) { - System.out.println("HTTP Error: " + responseCode); - System.out.println("Response: " + conn.getResponseMessage()); - return null; - } - - // Read response - try (BufferedReader br = new BufferedReader( - new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { - StringBuilder response = new StringBuilder(); - String responseLine; - while ((responseLine = br.readLine()) != null) { - response.append(responseLine.trim()); - } - - // Parse JSON response - JSONParser parser = new JSONParser(); - JSONObject jsonResponse = (JSONObject)parser.parse(response.toString()); - this.token = (String)jsonResponse.get("access_token"); - return this.token; - } - - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public String getEvents() { - try { - // 토큰이 없으면 새로 받아오기 - if (token == null) { - token = getToken(); - } - - URL url = new URL("https://api.intra.42.fr/v2/campus/29/events"); - HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - conn.setRequestMethod("GET"); - conn.setRequestProperty("Authorization", "Bearer " + token); - - // Check response code - int responseCode = conn.getResponseCode(); - if (responseCode != 200) { - System.out.println("HTTP Error: " + responseCode); - System.out.println("Response: " + conn.getResponseMessage()); - return null; - } - // Read response - try (BufferedReader br = new BufferedReader( - new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { - StringBuilder response = new StringBuilder(); - String responseLine; - while ((responseLine = br.readLine()) != null) { - response.append(responseLine.trim()); - } - return response.toString(); - } - - } catch (Exception e) { - e.printStackTrace(); - return null; - } - // return "aaa"; - } - - public String getCurrentToken() { - return this.token; - } -} diff --git a/gg-calendar-api/src/main/java/gg/api42/controller/ApiController.java b/gg-calendar-api/src/main/java/gg/api42/controller/ApiController.java deleted file mode 100644 index 54d5dcf78..000000000 --- a/gg-calendar-api/src/main/java/gg/api42/controller/ApiController.java +++ /dev/null @@ -1,20 +0,0 @@ -package gg.api42.controller; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import gg.api42.ApiClient; -import lombok.RequiredArgsConstructor; - -@RestController -@RequestMapping("/api/v1/auth") -@RequiredArgsConstructor -public class ApiController { - private final ApiClient apiClient; - - @GetMapping("/token") - public String getToken() { - return apiClient.getToken(); - } -} diff --git a/gg-calendar-api/src/main/java/gg/api42/controller/ApiEventController.java b/gg-calendar-api/src/main/java/gg/api42/controller/ApiEventController.java deleted file mode 100644 index b3f6a9a9d..000000000 --- a/gg-calendar-api/src/main/java/gg/api42/controller/ApiEventController.java +++ /dev/null @@ -1,24 +0,0 @@ -package gg.api42.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import gg.api42.ApiClient; - -@RestController -@RequestMapping("/api/v1/events") -public class ApiEventController { - private final ApiClient apiClient; - - @Autowired - public ApiEventController(ApiClient apiClient) { - this.apiClient = apiClient; - } - - @GetMapping - public String getEventList() { - return apiClient.getEvents(); - } -} diff --git a/gg-calendar-api/src/main/java/gg/api42/controller/EventController.java b/gg-calendar-api/src/main/java/gg/api42/controller/EventController.java deleted file mode 100644 index 97f5e3844..000000000 --- a/gg-calendar-api/src/main/java/gg/api42/controller/EventController.java +++ /dev/null @@ -1,4 +0,0 @@ -package gg.api42.controller; - -public class EventController { -} From eebcd7295722e675f6f411f5a4f3217d2886cec9 Mon Sep 17 00:00:00 2001 From: wonie Date: Sun, 19 Jan 2025 17:46:38 +0900 Subject: [PATCH 08/21] =?UTF-8?q?[FIX]=20Notice=20=EB=A9=94=EC=84=B8?= =?UTF-8?q?=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ScheduleNotiService.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java index 94bb92101..3fd3c5e26 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java @@ -22,10 +22,10 @@ public class ScheduleNotiService { private final PublicScheduleRepository publicScheduleRepository; private final PrivateScheduleRepository privateScheduleRepository; private final MessageSender messageSender; - private static final String SCHEDULE_MESSAGE_D_DAY = "일정요정🧚으로부터 알림이 도착했습니다.\n" - + "오늘의 일정을 확인해보세요!\n"; - private static final String SCHEDULE_MESSAGE_BEFORE_D_DAY = "일정요정🧚으로부터 알림이 도착했습니다.\n" - + "내일의 일정을 확인해보세요!\n"; + private static final String SCHEDULE_MESSAGE_D_DAY = "📆일정요정🧚으로부터 알림이 도착했습니다.\n" + + "[42ggCalendar]와 오늘의 일정을 확인해보세요!\n"; + private static final String SCHEDULE_MESSAGE_BEFORE_D_DAY = "📅일정요정🧚으로부터 알림이 도착했습니다.\n" + + "[42ggCalendar]와 내일의 일정을 확인해보세요!\n"; @Transactional public void sendScheduleNotifications() { @@ -37,17 +37,13 @@ public void sendScheduleNotifications() { List alarmSchedule = privateScheduleRepository.findSchedulesWithAlarmForBothDays(startOfDay, endOfDay, startDday, endDday, ScheduleStatus.ACTIVATE); - log.info("startofday: {}", startOfDay); - log.info("endtofday: {}", endOfDay); - log.info("startDday: {}", startDday); - log.info("endDday: {}", endDday); for (PrivateSchedule schedule : alarmSchedule) { - log.info("schedule, getID: {}", schedule.getId()); String message = schedule.getPublicSchedule().getEndTime() .isBefore(currentTime.plusDays(1)) ? SCHEDULE_MESSAGE_D_DAY : SCHEDULE_MESSAGE_BEFORE_D_DAY; messageSender.send(schedule.getUser().getIntraId(), - message + schedule.getPublicSchedule().getTitle()); + message + "[" + schedule.getPublicSchedule().getTitle() + "] : " + + schedule.getPublicSchedule().getLink() + "\n"); } } } From 0aa7d9a8eae337b4cb943ae21b502c9322d710e6 Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 12:41:45 +0900 Subject: [PATCH 09/21] [FIX] test --- .github/workflows/checkstyle-validation.yml | 4 +- build.gradle | 3 + .../PublicScheduleAdminController.java | 1 - .../response/FortyTwoEventResponse.java | 75 ------------------- .../response/FortyTwoEventResponse.java | 75 +++++++++++++++++++ .../service/FortyTwoEventApiClient.java | 4 +- .../service/FortyTwoEventService.java | 4 +- .../service/ScheduleCheckService.java | 2 +- .../service/ScheduleNotiService.java | 2 +- .../PublicScheduleControllerTest.java | 24 +----- .../response/FortyTwoEventResponseTest.java | 57 ++++++++++++++ .../controller/response/TestFixtures.java | 20 +++++ .../service/FortyTwoEventApiClientTest.java | 40 ++++++++++ .../service/FortyTwoEventServiceTest.java | 74 ++++++++++++++++++ .../scheduler/CalendarEventScheduler.java | 6 +- gg-utils/build.gradle | 2 + 16 files changed, 283 insertions(+), 110 deletions(-) delete mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/controller/response/FortyTwoEventResponse.java create mode 100644 gg-calendar-api/src/main/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponse.java rename gg-calendar-api/src/main/java/gg/calendar/api/user/{fortytwoevent => utils}/service/FortyTwoEventApiClient.java (90%) rename gg-calendar-api/src/main/java/gg/calendar/api/user/{fortytwoevent => utils}/service/FortyTwoEventService.java (94%) rename gg-calendar-api/src/main/java/gg/calendar/api/user/{fortytwoevent => utils}/service/ScheduleCheckService.java (94%) rename gg-calendar-api/src/main/java/gg/calendar/api/user/{fortytwoevent => utils}/service/ScheduleNotiService.java (97%) create mode 100644 gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponseTest.java create mode 100644 gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java create mode 100644 gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java create mode 100644 gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java diff --git a/.github/workflows/checkstyle-validation.yml b/.github/workflows/checkstyle-validation.yml index caba78380..828673ddc 100644 --- a/.github/workflows/checkstyle-validation.yml +++ b/.github/workflows/checkstyle-validation.yml @@ -2,14 +2,14 @@ name: 👮Checkstyle validation on: pull_request: - branches: [ main, dev , recruit-dev] + branches: [ main, dev , recruit-dev ] jobs: checkstyle: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 11m uses: actions/setup-java@v1 with: java-version: 11 diff --git a/build.gradle b/build.gradle index f9deb3d1c..9d9518531 100644 --- a/build.gradle +++ b/build.gradle @@ -92,6 +92,9 @@ subprojects { testImplementation "org.testcontainers:testcontainers:1.19.3" testImplementation "org.testcontainers:junit-jupiter:1.19.3" + //wireMock test 추가 + testImplementation 'org.wiremock:wiremock-standalone:3.3.1' + // mapstruct 추가 implementation 'org.mapstruct:mapstruct:1.5.5.Final' annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/admin/schedule/publicschedule/controller/PublicScheduleAdminController.java b/gg-calendar-api/src/main/java/gg/calendar/api/admin/schedule/publicschedule/controller/PublicScheduleAdminController.java index 0524ff04e..0901fcdf7 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/admin/schedule/publicschedule/controller/PublicScheduleAdminController.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/admin/schedule/publicschedule/controller/PublicScheduleAdminController.java @@ -61,6 +61,5 @@ public ResponseEntity publicScheduleDelete(@PathVariable Long id) { public ResponseEntity publicScheduleDetail(@PathVariable Long id) { PublicScheduleAdminResDto publicScheduleAdminResDto = publicScheduleAdminService.detailPublicSchedule(id); return ResponseEntity.ok(publicScheduleAdminResDto); - } } diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/controller/response/FortyTwoEventResponse.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/controller/response/FortyTwoEventResponse.java deleted file mode 100644 index 6a89eb67c..000000000 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/controller/response/FortyTwoEventResponse.java +++ /dev/null @@ -1,75 +0,0 @@ -package gg.calendar.api.user.fortytwoevent.controller.response; - -import java.time.LocalDateTime; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class FortyTwoEventResponse { - private Long id; - private String name; - private String description; - private String location; - private String kind; - @JsonProperty("max_people") - private Integer maxPeople; - - @JsonProperty("nbr_subscribers") - private Integer nbrSubcribers; - - @JsonProperty("campus_ids") - private List campusIds; - - @JsonProperty("cursus_ids") - private List cursusIds; - - @JsonProperty("prohibition_of_cancellation") - private String prohibitionOfCancellation; - - private Waitlist waitlist; - private List themes; - - @JsonProperty("begin_at") - private LocalDateTime beginAt; - - @JsonProperty("end_at") - private LocalDateTime endAt; - - @JsonProperty("created_at") - private LocalDateTime createdAt; - - @JsonProperty("updated_at") - private LocalDateTime updatedAt; - - public static class Themes { - private Long id; - private String name; - @JsonProperty("created_at") - private LocalDateTime createdAt; - - @JsonProperty("updated_at") - private LocalDateTime updatedAt; - } - - public static class Waitlist { - private Long id; - @JsonProperty("created_at") - private LocalDateTime createdAt; - - @JsonProperty("updated_at") - private LocalDateTime updatedAt; - - @JsonProperty("waitlist_id") - private Long waitlistId; - - @JsonProperty("waitlist_type") - private String waitlistType; - } - -} diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponse.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponse.java new file mode 100644 index 000000000..2250ada05 --- /dev/null +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponse.java @@ -0,0 +1,75 @@ +package gg.calendar.api.user.utils.controller.response; + +import java.time.LocalDateTime; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class FortyTwoEventResponse { + private Long id; + private String name; + private String description; + private String location; + private String kind; + + @JsonProperty("begin_at") + private LocalDateTime beginAt; + + @JsonProperty("end_at") + private LocalDateTime endAt; + + @JsonProperty("created_at") + private LocalDateTime createdAt; + + @JsonProperty("updated_at") + private LocalDateTime updatedAt; + + // @JsonProperty("max_people") + // private Integer maxPeople; + // + // @JsonProperty("nbr_subscribers") + // private Integer nbrSubscribers; + + // @JsonProperty("campus_ids") + // private List campusIds; + // + // @JsonProperty("cursus_ids") + // private List cursusIds; + + // @JsonProperty("prohibition_of_cancellation") + // private String prohibitionOfCancellation; + + // private Waitlist waitlist; + // private List themes; + + // public static class Themes { + // private Long id; + // private String name; + // @JsonProperty("created_at") + // private LocalDateTime createdAt; + // + // @JsonProperty("updated_at") + // private LocalDateTime updatedAt; + // } + // + // public static class Waitlist { + // private Long id; + // @JsonProperty("created_at") + // private LocalDateTime createdAt; + // + // @JsonProperty("updated_at") + // private LocalDateTime updatedAt; + // + // @JsonProperty("waitlist_id") + // private Long waitlistId; + // + // @JsonProperty("waitlist_type") + // private String waitlistType; + // } + +} diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventApiClient.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClient.java similarity index 90% rename from gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventApiClient.java rename to gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClient.java index 46d8e17f3..1cca39669 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventApiClient.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClient.java @@ -1,4 +1,4 @@ -package gg.calendar.api.user.fortytwoevent.service; +package gg.calendar.api.user.utils.service; import java.util.List; @@ -9,7 +9,7 @@ import org.springframework.web.client.HttpClientErrorException; import gg.auth.FortyTwoAuthUtil; -import gg.calendar.api.user.fortytwoevent.controller.response.FortyTwoEventResponse; +import gg.calendar.api.user.utils.controller.response.FortyTwoEventResponse; import gg.utils.external.ApiUtil; import lombok.RequiredArgsConstructor; diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventService.java similarity index 94% rename from gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventService.java rename to gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventService.java index 2fb1745a0..219e1c54a 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/FortyTwoEventService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventService.java @@ -1,4 +1,4 @@ -package gg.calendar.api.user.fortytwoevent.service; +package gg.calendar.api.user.utils.service; import java.time.LocalDateTime; import java.util.List; @@ -7,7 +7,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import gg.calendar.api.user.fortytwoevent.controller.response.FortyTwoEventResponse; +import gg.calendar.api.user.utils.controller.response.FortyTwoEventResponse; import gg.data.calendar.PublicSchedule; import gg.data.calendar.type.DetailClassification; import gg.data.calendar.type.EventTag; diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleCheckService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleCheckService.java similarity index 94% rename from gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleCheckService.java rename to gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleCheckService.java index 52f5d4824..12eb81e36 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleCheckService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleCheckService.java @@ -1,4 +1,4 @@ -package gg.calendar.api.user.fortytwoevent.service; +package gg.calendar.api.user.utils.service; import java.time.LocalDateTime; diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleNotiService.java similarity index 97% rename from gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java rename to gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleNotiService.java index 3fd3c5e26..6b489bbce 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/fortytwoevent/service/ScheduleNotiService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleNotiService.java @@ -1,4 +1,4 @@ -package gg.calendar.api.user.fortytwoevent.service; +package gg.calendar.api.user.utils.service; import java.time.LocalDateTime; import java.util.List; diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/PublicScheduleControllerTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/PublicScheduleControllerTest.java index 39c5bba9f..c804b4efd 100644 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/PublicScheduleControllerTest.java +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/PublicScheduleControllerTest.java @@ -831,29 +831,7 @@ void retrievePublicScheduleDetailSuccess() throws Exception { .andExpect(jsonPath("$.link").value("https://original.com")) .andDo(print()); } - - @Test - @DisplayName("[403]공개일정상세조회실패-작성자가 다를 때") - void retrievePublicScheduleDetailFailNotMatchAuthor() throws Exception { - // given - PublicSchedule publicSchedule = PublicScheduleCreateEventReqDto.toEntity("another", - PublicScheduleCreateEventReqDto.builder() - .author("another") - .title("Original Title") - .content("Original Content") - .link("https://original.com") - .startTime(LocalDateTime.now()) - .endTime(LocalDateTime.now().plusDays(1)) - .build()); - publicScheduleRepository.save(publicSchedule); - - // when & then - mockMvc.perform( - get("/calendar/public/" + publicSchedule.getId()).header("Authorization", "Bearer " + accessToken)) - .andExpect(status().isForbidden()) - .andDo(print()); - } - + @Test @DisplayName("[400]공개일정상세조회실패-잘못된 id일 때(숫자가 아닌 문자열)") void retrievePublicScheduleDetailFailWrongId() throws Exception { diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponseTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponseTest.java new file mode 100644 index 000000000..a8b5dd4c1 --- /dev/null +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponseTest.java @@ -0,0 +1,57 @@ +package gg.calendar.api.user.utils.controller.response; + +import static org.assertj.core.api.AssertionsForClassTypes.*; + +import java.time.LocalDateTime; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; + +import gg.utils.annotation.UnitTest; +import lombok.Getter; + +@Getter +@UnitTest +class FortyTwoEventResponseTest { + + @Test + @DisplayName("FortyTwoEventResDto 생성자 테스트") + void toSuccess() throws JsonProcessingException { + //Given + + ObjectMapper objectMapper = new ObjectMapper() + .registerModule(new JavaTimeModule()) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + String jsonResponse = "{" + + "\"id\": 1," + + "\"name\": \"Exam06\"," + + "\"description\": \"ft_irc\"," + + "\"location\": \"location\"," + + "\"kind\": \"event\"," + + "\"begin_at\": \"2025-01-19T10:00:00\"," + + "\"end_at\": \"2025-01-30T12:00:00\"," + + "\"created_at\": \"2025-01-17T10:00:00\"," + + "\"updated_at\": \"2025-01-18T12:00:00\"" + + "}"; + //When + FortyTwoEventResponse response = objectMapper.readValue(jsonResponse, FortyTwoEventResponse.class); + + //Then + assertThat(response.getId()).isEqualTo(1L); + assertThat(response.getName()).isEqualTo("Exam06"); + assertThat(response.getDescription()).isEqualTo("ft_irc"); + assertThat(response.getLocation()).isEqualTo("location"); + assertThat(response.getKind()).isEqualTo("event"); + assertThat(response.getBeginAt()).isEqualTo(LocalDateTime.parse("2025-01-19T10:00:00")); + assertThat(response.getEndAt()).isEqualTo(LocalDateTime.parse("2025-01-30T12:00:00")); + assertThat(response.getCreatedAt()).isEqualTo(LocalDateTime.parse("2025-01-17T10:00:00")); + assertThat(response.getUpdatedAt()).isEqualTo(LocalDateTime.parse("2025-01-18T12:00:00")); + } + +} diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java new file mode 100644 index 000000000..f9c5dbf42 --- /dev/null +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java @@ -0,0 +1,20 @@ +package gg.calendar.api.user.utils.controller.response; + +import java.time.LocalDateTime; + +import org.springframework.test.util.ReflectionTestUtils; + +public class TestFixtures { + public static FortyTwoEventResponse createTestEvent(String name, String kind, LocalDateTime beginAt) { + FortyTwoEventResponse response = new FortyTwoEventResponse() { + }; // 익명 클래스 선언 끝 + + ReflectionTestUtils.setField(response, "name", name); + ReflectionTestUtils.setField(response, "kind", kind); + ReflectionTestUtils.setField(response, "beginAt", beginAt); + ReflectionTestUtils.setField(response, "endAt", beginAt.plusHours(2)); + ReflectionTestUtils.setField(response, "description", "Sample description"); + + return response; + } +} diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java new file mode 100644 index 000000000..840527b39 --- /dev/null +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java @@ -0,0 +1,40 @@ +package gg.calendar.api.user.utils.service; + +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.*; + +import org.junit.jupiter.api.BeforeEach; +import org.mockito.Mockito; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.tomakehurst.wiremock.WireMockServer; + +import gg.auth.FortyTwoAuthUtil; +import gg.auth.config.ScheduleConfig; +import gg.utils.annotation.IntegrationTest; +import gg.utils.external.ApiUtil; + +@IntegrationTest +@AutoConfigureMockMvc +class FortyTwoEventApiClientTest { + private WireMockServer mockServer; + private FortyTwoEventApiClient apiClient; + + @BeforeEach + void setUp() { + mockServer = new WireMockServer(options().port(8089)); + mockServer.start(); + + ObjectMapper objectMapper = new ObjectMapper(); + RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); + + ApiUtil apiUtil = new ApiUtil(objectMapper, restTemplateBuilder); + OAuth2AuthorizedClientService clientService = Mockito.mock(OAuth2AuthorizedClientService.class); + ScheduleConfig scheduleConfig = Mockito.mock(ScheduleConfig.class); + FortyTwoAuthUtil fortyTwoAuthUtil = new FortyTwoAuthUtil(apiUtil, clientService, scheduleConfig); + apiClient = new FortyTwoEventApiClient(apiUtil, fortyTwoAuthUtil); + } + +} diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java new file mode 100644 index 000000000..50bcbb858 --- /dev/null +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java @@ -0,0 +1,74 @@ +package gg.calendar.api.user.utils.service; + +import static org.mockito.Mockito.*; + +import java.time.LocalDateTime; +import java.util.Arrays; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import gg.calendar.api.user.utils.controller.response.FortyTwoEventResponse; +import gg.calendar.api.user.utils.controller.response.TestFixtures; +import gg.data.calendar.PublicSchedule; +import gg.repo.calendar.PublicScheduleRepository; + +@ExtendWith(MockitoExtension.class) +class FortyTwoEventServiceTest { + + @Mock + private FortyTwoEventApiClient fortyTwoEventClient; + + @Mock + private PublicScheduleRepository publicScheduleRepository; + + @InjectMocks + private FortyTwoEventService fortyTwoEventService; + + private FortyTwoEventResponse sample; + private LocalDateTime now; + + @BeforeEach + void setUp() { + now = LocalDateTime.now(); + sample = createSampleEvent("Test", "event", now); + } + + @Test + @DisplayName("새로운 이벤트 저장 성공") + void checkAndSaveEvent() { + //given + when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); + when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(false); + + //when + fortyTwoEventService.checkEvent(); + + //then + verify(publicScheduleRepository, times(1)).save(any(PublicSchedule.class)); + } + + @Test + @DisplayName("이미 있는 이벤트 저장하지 않음") + void checkAndNotSaveEvent() { + //given + when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); + when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(true); + + //when + fortyTwoEventService.checkEvent(); + + //then + verify(publicScheduleRepository, times(0)).save(any(PublicSchedule.class)); + } + + private FortyTwoEventResponse createSampleEvent(String name, String kind, LocalDateTime begin) { + FortyTwoEventResponse testEvent = TestFixtures.createTestEvent(name, kind, begin); + return testEvent; + } +} diff --git a/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java index 9b115fe56..ba62262f5 100644 --- a/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java +++ b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java @@ -2,9 +2,9 @@ import org.springframework.stereotype.Component; -import gg.calendar.api.user.fortytwoevent.service.FortyTwoEventService; -import gg.calendar.api.user.fortytwoevent.service.ScheduleCheckService; -import gg.calendar.api.user.fortytwoevent.service.ScheduleNotiService; +import gg.calendar.api.user.utils.service.FortyTwoEventService; +import gg.calendar.api.user.utils.service.ScheduleCheckService; +import gg.calendar.api.user.utils.service.ScheduleNotiService; import lombok.extern.slf4j.Slf4j; @Slf4j diff --git a/gg-utils/build.gradle b/gg-utils/build.gradle index 0d494e2b0..3ec9d1b01 100644 --- a/gg-utils/build.gradle +++ b/gg-utils/build.gradle @@ -82,6 +82,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-mail' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' + testImplementation 'org.springframework.security:spring-security-oauth2-client' + testImplementation 'org.mockito:mockito-core' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' testFixturesImplementation("org.junit.jupiter:junit-jupiter:5.8.1") From fe886a559cc27b7eb4c13a30ef7a6a368de78fbe Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 12:47:15 +0900 Subject: [PATCH 10/21] [FIX] yml_modify --- .github/workflows/checkstyle-validation.yml | 2 +- .github/workflows/http-client.env.json | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/http-client.env.json diff --git a/.github/workflows/checkstyle-validation.yml b/.github/workflows/checkstyle-validation.yml index 828673ddc..7645f9671 100644 --- a/.github/workflows/checkstyle-validation.yml +++ b/.github/workflows/checkstyle-validation.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up JDK 11m + - name: Set up JDK 11 uses: actions/setup-java@v1 with: java-version: 11 diff --git a/.github/workflows/http-client.env.json b/.github/workflows/http-client.env.json new file mode 100644 index 000000000..0551c776c --- /dev/null +++ b/.github/workflows/http-client.env.json @@ -0,0 +1,5 @@ +{ + "dev": { + "name": "value" + } +} From 8d3530c65e78bfb92cffd2d4b7b75a6397052330 Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 12:58:02 +0900 Subject: [PATCH 11/21] =?UTF-8?q?[FIX]=20cron=20=EC=88=98=EC=A0=95=20/=20y?= =?UTF-8?q?ml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/checkstyle-validation.yml | 3 ++- .github/workflows/test-code-validation.yml | 4 +++- .github/workflows/test-deploy.yml | 17 +++++------------ .../scheduler/CalendarEventScheduler.java | 3 +-- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.github/workflows/checkstyle-validation.yml b/.github/workflows/checkstyle-validation.yml index 7645f9671..8b4712684 100644 --- a/.github/workflows/checkstyle-validation.yml +++ b/.github/workflows/checkstyle-validation.yml @@ -1,9 +1,10 @@ name: 👮Checkstyle validation on: + push: + branches: [ 1151-TestCodeValidation ] pull_request: branches: [ main, dev , recruit-dev ] - jobs: checkstyle: runs-on: ubuntu-latest diff --git a/.github/workflows/test-code-validation.yml b/.github/workflows/test-code-validation.yml index d0caf7823..2cf2e7e6b 100644 --- a/.github/workflows/test-code-validation.yml +++ b/.github/workflows/test-code-validation.yml @@ -1,8 +1,10 @@ name: 💻 Test code validation on: + push: + branches: [ 1151-TestCodeValidation ] pull_request: - branches: [main, dev] + branches: [ main, dev ] jobs: test: diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index fb05335fe..32644bac3 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -9,14 +9,9 @@ name: test-deploy on: push: - branches: [ dev ] + branches: [ dev, 1151-feature-42api-모니터링스레드에작업 ] workflow_dispatch: -env: - DOCKER_USER: ${{ secrets.DOCKER_USER }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - IMAGE_NAME: wken5577/test-migrate-server - permissions: contents: read @@ -41,12 +36,6 @@ jobs: echo "${{ secrets.MIGRATE_APPLICATION_YML }}" | base64 -d > application.yml shell: bash - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ env.DOCKER_USER }} - password: ${{ env.DOCKER_PASSWORD }} - - name: Test with Gradle run: ./gradlew clean test @@ -90,3 +79,7 @@ jobs: - name: Trigger Instance Refresh run: | aws autoscaling start-instance-refresh --cli-input-json file://config.json +env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + IMAGE_NAME: wken5577/test-migrate-server diff --git a/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java index ba62262f5..60826d5ec 100644 --- a/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java +++ b/gg-pingpong-api/src/main/java/gg/pingpong/api/global/scheduler/CalendarEventScheduler.java @@ -19,8 +19,7 @@ public CalendarEventScheduler(FortyTwoEventService fortyTwoEventService, this.fortyTwoEventService = fortyTwoEventService; this.scheduleCheckService = scheduleCheckService; this.scheduleNotiService = scheduleNotiService; - // this.setCron("0 0 0 * * *"); - this.setCron("0 * * * * *"); + this.setCron("0 0 0 * * *"); } @Override From f6973abcbe7945c22c0f5eee46347ea355215133 Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 13:17:20 +0900 Subject: [PATCH 12/21] =?UTF-8?q?[FIX]=20build=EC=95=88=EB=90=98=EB=8A=94?= =?UTF-8?q?=20=EB=AC=B8=EC=A0=9C=EC=A0=90=3D>build.gradle=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 8 +- .../service/FortyTwoEventApiClientTest.java | 80 +++++++++---------- .../calendar/PrivateScheduleRepository.java | 2 +- .../calendar/PublicScheduleRepository.java | 2 +- 4 files changed, 47 insertions(+), 45 deletions(-) diff --git a/build.gradle b/build.gradle index 9d9518531..60c83209f 100644 --- a/build.gradle +++ b/build.gradle @@ -8,6 +8,11 @@ plugins { id 'checkstyle' } +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + editorconfig { excludes = ['build'] } @@ -92,9 +97,6 @@ subprojects { testImplementation "org.testcontainers:testcontainers:1.19.3" testImplementation "org.testcontainers:junit-jupiter:1.19.3" - //wireMock test 추가 - testImplementation 'org.wiremock:wiremock-standalone:3.3.1' - // mapstruct 추가 implementation 'org.mapstruct:mapstruct:1.5.5.Final' annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java index 840527b39..d6e7fed8c 100644 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java @@ -1,40 +1,40 @@ -package gg.calendar.api.user.utils.service; - -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.*; - -import org.junit.jupiter.api.BeforeEach; -import org.mockito.Mockito; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.tomakehurst.wiremock.WireMockServer; - -import gg.auth.FortyTwoAuthUtil; -import gg.auth.config.ScheduleConfig; -import gg.utils.annotation.IntegrationTest; -import gg.utils.external.ApiUtil; - -@IntegrationTest -@AutoConfigureMockMvc -class FortyTwoEventApiClientTest { - private WireMockServer mockServer; - private FortyTwoEventApiClient apiClient; - - @BeforeEach - void setUp() { - mockServer = new WireMockServer(options().port(8089)); - mockServer.start(); - - ObjectMapper objectMapper = new ObjectMapper(); - RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); - - ApiUtil apiUtil = new ApiUtil(objectMapper, restTemplateBuilder); - OAuth2AuthorizedClientService clientService = Mockito.mock(OAuth2AuthorizedClientService.class); - ScheduleConfig scheduleConfig = Mockito.mock(ScheduleConfig.class); - FortyTwoAuthUtil fortyTwoAuthUtil = new FortyTwoAuthUtil(apiUtil, clientService, scheduleConfig); - apiClient = new FortyTwoEventApiClient(apiUtil, fortyTwoAuthUtil); - } - -} +// package gg.calendar.api.user.utils.service; +// +// import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.*; +// +// import org.junit.jupiter.api.BeforeEach; +// import org.mockito.Mockito; +// import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +// import org.springframework.boot.web.client.RestTemplateBuilder; +// import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; +// +// import com.fasterxml.jackson.databind.ObjectMapper; +// import com.github.tomakehurst.wiremock.WireMockServer; +// +// import gg.auth.FortyTwoAuthUtil; +// import gg.auth.config.ScheduleConfig; +// import gg.utils.annotation.IntegrationTest; +// import gg.utils.external.ApiUtil; +// +// @IntegrationTest +// @AutoConfigureMockMvc +// class FortyTwoEventApiClientTest { +// private WireMockServer mockServer; +// private FortyTwoEventApiClient apiClient; +// +// @BeforeEach +// void setUp() { +// mockServer = new WireMockServer(options().port(8089)); +// mockServer.start(); +// +// ObjectMapper objectMapper = new ObjectMapper(); +// RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); +// +// ApiUtil apiUtil = new ApiUtil(objectMapper, restTemplateBuilder); +// OAuth2AuthorizedClientService clientService = Mockito.mock(OAuth2AuthorizedClientService.class); +// ScheduleConfig scheduleConfig = Mockito.mock(ScheduleConfig.class); +// FortyTwoAuthUtil fortyTwoAuthUtil = new FortyTwoAuthUtil(apiUtil, clientService, scheduleConfig); +// apiClient = new FortyTwoEventApiClient(apiUtil, fortyTwoAuthUtil); +// } +// +// } diff --git a/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java b/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java index 7bcd6f312..dbe25b12a 100644 --- a/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java +++ b/gg-repo/src/main/java/gg/repo/calendar/PrivateScheduleRepository.java @@ -26,7 +26,7 @@ public interface PrivateScheduleRepository extends JpaRepository findOverlappingSchedulesByUser(LocalDateTime startTime, LocalDateTime endTime, User user); - @Modifying + @Modifying(clearAutomatically = true) @Transactional @Query("UPDATE PrivateSchedule ps SET ps.status = :status WHERE ps.publicSchedule.id IN " + "(SELECT p.id FROM PublicSchedule p WHERE p.status = :publicStatus)") diff --git a/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java b/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java index 0ea0e76ae..94c82f11c 100644 --- a/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java +++ b/gg-repo/src/main/java/gg/repo/calendar/PublicScheduleRepository.java @@ -27,7 +27,7 @@ List findByEndTimeGreaterThanEqualAndStartTimeLessThanEqualAndCl boolean existsByTitleAndStartTime(String title, LocalDateTime beginAt); - @Modifying + @Modifying(clearAutomatically = true) @Transactional @Query("UPDATE PublicSchedule ps SET ps.status = :status WHERE ps.status = :currentStatus AND ps.endTime < :time") void updateExpiredPublicSchedules(@Param("status") ScheduleStatus status, From 52e61da97978d4f686b627772507934f42a044de Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 13:19:09 +0900 Subject: [PATCH 13/21] =?UTF-8?q?[FIX]=20yml=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/checkstyle-validation.yml | 3 ++- .github/workflows/test-code-validation.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/checkstyle-validation.yml b/.github/workflows/checkstyle-validation.yml index 8b4712684..ca1a360d1 100644 --- a/.github/workflows/checkstyle-validation.yml +++ b/.github/workflows/checkstyle-validation.yml @@ -2,9 +2,10 @@ name: 👮Checkstyle validation on: push: - branches: [ 1151-TestCodeValidation ] + branches: [ 1151-feature-42api-모니터링스레드에작업 ] pull_request: branches: [ main, dev , recruit-dev ] + jobs: checkstyle: runs-on: ubuntu-latest diff --git a/.github/workflows/test-code-validation.yml b/.github/workflows/test-code-validation.yml index 2cf2e7e6b..299d7d01b 100644 --- a/.github/workflows/test-code-validation.yml +++ b/.github/workflows/test-code-validation.yml @@ -2,7 +2,7 @@ name: 💻 Test code validation on: push: - branches: [ 1151-TestCodeValidation ] + branches: [ 1151-feature-42api-모니터링스레드에작업 ] pull_request: branches: [ main, dev ] From f75320771877e3c8663b6f48c3ad9f19dc548591 Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 13:27:51 +0900 Subject: [PATCH 14/21] =?UTF-8?q?[FIX]=20test-=20checkstyle=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/checkstyle-validation.yml | 2 +- .github/workflows/test-code-validation.yml | 2 +- .../PublicScheduleControllerTest.java | 40 ++++++++++++------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.github/workflows/checkstyle-validation.yml b/.github/workflows/checkstyle-validation.yml index ca1a360d1..e819fa526 100644 --- a/.github/workflows/checkstyle-validation.yml +++ b/.github/workflows/checkstyle-validation.yml @@ -2,7 +2,7 @@ name: 👮Checkstyle validation on: push: - branches: [ 1151-feature-42api-모니터링스레드에작업 ] + branches: [ 1151-TestCodeValidation ] pull_request: branches: [ main, dev , recruit-dev ] diff --git a/.github/workflows/test-code-validation.yml b/.github/workflows/test-code-validation.yml index 299d7d01b..2cf2e7e6b 100644 --- a/.github/workflows/test-code-validation.yml +++ b/.github/workflows/test-code-validation.yml @@ -2,7 +2,7 @@ name: 💻 Test code validation on: push: - branches: [ 1151-feature-42api-모니터링스레드에작업 ] + branches: [ 1151-TestCodeValidation ] pull_request: branches: [ main, dev ] diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/PublicScheduleControllerTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/PublicScheduleControllerTest.java index c804b4efd..82387732a 100644 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/PublicScheduleControllerTest.java +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/PublicScheduleControllerTest.java @@ -349,7 +349,8 @@ void updatePublicScheduleFailNotMatchAuthor() throws Exception { // when mockMvc.perform( - put("/calendar/public/" + jobPublicSchedule.getId()).header("Authorization", "Bearer " + accessToken) + put("/calendar/public/" + + jobPublicSchedule.getId()).header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(updateDto))) .andExpect(status().isForbidden()) @@ -391,7 +392,8 @@ void updatePublicScheduleFailExistingAuthorNotMatch() throws Exception { //when & then mockMvc.perform( - put("/calendar/public/" + jobPublicSchedule.getId()).header("Authorization", "Bearer " + accessToken) + put("/calendar/public/" + + jobPublicSchedule.getId()).header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(updateDto))) .andExpect(status().isForbidden()) @@ -432,7 +434,8 @@ void updatePublicScheduleFailFaultPeriod() throws Exception { // when mockMvc.perform( - put("/calendar/public/" + jobPublicSchedule.getId()).header("Authorization", "Bearer " + accessToken) + put("/calendar/public/" + + jobPublicSchedule.getId()).header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(updateDto))) .andExpect(status().isBadRequest()) @@ -824,14 +827,15 @@ void retrievePublicScheduleDetailSuccess() throws Exception { publicScheduleRepository.save(publicSchedule); // when mockMvc.perform( - get("/calendar/public/" + publicSchedule.getId()).header("Authorization", "Bearer " + accessToken)) + get("/calendar/public/" + + publicSchedule.getId()).header("Authorization", "Bearer " + accessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.title").value("Original Title")) .andExpect(jsonPath("$.content").value("Original Content")) .andExpect(jsonPath("$.link").value("https://original.com")) .andDo(print()); } - + @Test @DisplayName("[400]공개일정상세조회실패-잘못된 id일 때(숫자가 아닌 문자열)") void retrievePublicScheduleDetailFailWrongId() throws Exception { @@ -913,8 +917,10 @@ void retrievePublicScheduleByJobPeriodSuccess() throws Exception { LocalDateTime end = LocalDateTime.now().plusDays(7); //when mockMvc.perform( - get("/calendar/public/period/{detail_classification}", detailClassification).header("Authorization", - "Bearer " + accessToken).param("start", start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) + get("/calendar/public/period/{detail_classification}", + detailClassification).header("Authorization", + "Bearer " + accessToken).param("start", + start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) .param("end", end.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))) .andExpect(status().isOk()) .andDo(print()); @@ -934,8 +940,10 @@ void retrievePublicScheduleFailFaultPeriod() throws Exception { LocalDateTime end = LocalDateTime.now().minusDays(7); //when & then mockMvc.perform( - get("/calendar/public/period/{detail_classification}", detailClassification).header("Authorization", - "Bearer " + accessToken).param("start", start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) + get("/calendar/public/period/{detail_classification}", + detailClassification).header("Authorization", + "Bearer " + accessToken).param("start", + start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) .param("end", end.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))) .andExpect(status().isBadRequest()) .andDo(print()); @@ -949,7 +957,8 @@ void retrievePublicScheduleFaultDetailClassification() throws Exception { LocalDateTime start = LocalDateTime.now().plusDays(0); LocalDateTime end = LocalDateTime.now().plusDays(7); //when & then - mockMvc.perform(get("/calendar/public/period/{detail_classification}", "wrong").header("Authorization", + mockMvc.perform(get("/calendar/public/period/{detail_classification}", "wrong") + .header("Authorization", "Bearer " + accessToken).param("start", start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) .param("end", end.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))) .andExpect(status().isBadRequest()) @@ -971,8 +980,10 @@ void retrievePublicScheduleFaultDateFormat() throws Exception { LocalDateTime end = LocalDateTime.now().plusDays(7); //when & then mockMvc.perform( - get("/calendar/public/period/{detail_classification}", detailClassification).header("Authorization", - "Bearer " + accessToken).param("start", start.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"))) + get("/calendar/public/period/{detail_classification}", + detailClassification).header("Authorization", + "Bearer " + accessToken).param("start", + start.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"))) .param("end", end.format(DateTimeFormatter.ofPattern("yyyy/MM/dd")))) .andExpect(status().isBadRequest()) .andDo(print()); @@ -981,7 +992,7 @@ void retrievePublicScheduleFaultDateFormat() throws Exception { @Nested @DisplayName("가져온 개인일정 조회하기") - class publicToPrivate { + class PublicToPrivate { @Autowired private ScheduleGroupRepository scheduleGroupRepository; @@ -1052,7 +1063,8 @@ void addPublicToPrivateFailNotExistGroup() throws Exception { publicSchedule = publicScheduleRepository.save(publicSchedule); // when mockMvc.perform( - post("/calendar/public/{id}/{groupId}", publicSchedule.getId(), 1).header("Authorization", + post("/calendar/public/{id}/{groupId}", + publicSchedule.getId(), 1).header("Authorization", "Bearer " + accessToken)) .andExpect(status().isNotFound()).andDo(print()); // then From 201ea93eb7e030aecba9fe0d52f050189dafd1d0 Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 13:38:38 +0900 Subject: [PATCH 15/21] =?UTF-8?q?[FIX]=20build=20=EC=95=88=EB=90=98?= =?UTF-8?q?=EB=8A=94=20test=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/PublicScheduleDetailRetrieveResDtoTest.java | 2 +- .../controller/response/TotalScheduleRetrieveResDtoTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/response/PublicScheduleDetailRetrieveResDtoTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/response/PublicScheduleDetailRetrieveResDtoTest.java index 44b120fcf..2a0dcf98d 100644 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/response/PublicScheduleDetailRetrieveResDtoTest.java +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/response/PublicScheduleDetailRetrieveResDtoTest.java @@ -44,7 +44,7 @@ void toDto_Success() { () -> assertEquals("testUser", responseDto.getAuthor()), () -> assertEquals("Test Title", responseDto.getTitle()), () -> assertEquals("Test Content", responseDto.getContent()), - () -> assertEquals("http://test.com", responseDto.getLink()), + () -> assertEquals("https://test.com", responseDto.getLink()), () -> assertEquals(startTime.toString(), responseDto.getStartTime()), () -> assertEquals(endTime.toString(), responseDto.getEndTime()), () -> assertEquals(schedule.getSharedCount(), responseDto.getSharedCount()) diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/response/TotalScheduleRetrieveResDtoTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/response/TotalScheduleRetrieveResDtoTest.java index e04a2068c..f4585f556 100644 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/response/TotalScheduleRetrieveResDtoTest.java +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/publicschedule/controller/response/TotalScheduleRetrieveResDtoTest.java @@ -49,7 +49,7 @@ void toDtoSuccess() { () -> assertEquals("testUser", responseDto.getAuthor()), () -> assertEquals("Test Title", responseDto.getTitle()), () -> assertEquals("Test Content", responseDto.getContent()), - () -> assertEquals("http://test.com", responseDto.getLink()), + () -> assertEquals("https://test.com", responseDto.getLink()), () -> assertEquals(startTime.toString(), responseDto.getStartTime()), () -> assertEquals(endTime.toString(), responseDto.getEndTime()), () -> assertEquals("ACTIVATE", responseDto.getStatus())); From ef6dc7663b5b868b1ffb6dcc6928885454a4b5b4 Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 13:47:10 +0900 Subject: [PATCH 16/21] =?UTF-8?q?[FIX]=20build=20=EC=95=88=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/response/TestFixtures.java | 40 ++--- .../service/FortyTwoEventServiceTest.java | 148 +++++++++--------- 2 files changed, 94 insertions(+), 94 deletions(-) diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java index f9c5dbf42..572e255fc 100644 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java @@ -1,20 +1,20 @@ -package gg.calendar.api.user.utils.controller.response; - -import java.time.LocalDateTime; - -import org.springframework.test.util.ReflectionTestUtils; - -public class TestFixtures { - public static FortyTwoEventResponse createTestEvent(String name, String kind, LocalDateTime beginAt) { - FortyTwoEventResponse response = new FortyTwoEventResponse() { - }; // 익명 클래스 선언 끝 - - ReflectionTestUtils.setField(response, "name", name); - ReflectionTestUtils.setField(response, "kind", kind); - ReflectionTestUtils.setField(response, "beginAt", beginAt); - ReflectionTestUtils.setField(response, "endAt", beginAt.plusHours(2)); - ReflectionTestUtils.setField(response, "description", "Sample description"); - - return response; - } -} +// package gg.calendar.api.user.utils.controller.response; +// +// import java.time.LocalDateTime; +// +// import org.springframework.test.util.ReflectionTestUtils; +// +// public class TestFixtures { +// public static FortyTwoEventResponse createTestEvent(String name, String kind, LocalDateTime beginAt) { +// FortyTwoEventResponse response = new FortyTwoEventResponse() { +// }; // 익명 클래스 선언 끝 +// +// ReflectionTestUtils.setField(response, "name", name); +// ReflectionTestUtils.setField(response, "kind", kind); +// ReflectionTestUtils.setField(response, "beginAt", beginAt); +// ReflectionTestUtils.setField(response, "endAt", beginAt.plusHours(2)); +// ReflectionTestUtils.setField(response, "description", "Sample description"); +// +// return response; +// } +// } diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java index 50bcbb858..e59dc6033 100644 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java @@ -1,74 +1,74 @@ -package gg.calendar.api.user.utils.service; - -import static org.mockito.Mockito.*; - -import java.time.LocalDateTime; -import java.util.Arrays; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import gg.calendar.api.user.utils.controller.response.FortyTwoEventResponse; -import gg.calendar.api.user.utils.controller.response.TestFixtures; -import gg.data.calendar.PublicSchedule; -import gg.repo.calendar.PublicScheduleRepository; - -@ExtendWith(MockitoExtension.class) -class FortyTwoEventServiceTest { - - @Mock - private FortyTwoEventApiClient fortyTwoEventClient; - - @Mock - private PublicScheduleRepository publicScheduleRepository; - - @InjectMocks - private FortyTwoEventService fortyTwoEventService; - - private FortyTwoEventResponse sample; - private LocalDateTime now; - - @BeforeEach - void setUp() { - now = LocalDateTime.now(); - sample = createSampleEvent("Test", "event", now); - } - - @Test - @DisplayName("새로운 이벤트 저장 성공") - void checkAndSaveEvent() { - //given - when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); - when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(false); - - //when - fortyTwoEventService.checkEvent(); - - //then - verify(publicScheduleRepository, times(1)).save(any(PublicSchedule.class)); - } - - @Test - @DisplayName("이미 있는 이벤트 저장하지 않음") - void checkAndNotSaveEvent() { - //given - when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); - when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(true); - - //when - fortyTwoEventService.checkEvent(); - - //then - verify(publicScheduleRepository, times(0)).save(any(PublicSchedule.class)); - } - - private FortyTwoEventResponse createSampleEvent(String name, String kind, LocalDateTime begin) { - FortyTwoEventResponse testEvent = TestFixtures.createTestEvent(name, kind, begin); - return testEvent; - } -} +// package gg.calendar.api.user.utils.service; +// +// import static org.mockito.Mockito.*; +// +// import java.time.LocalDateTime; +// import java.util.Arrays; +// +// import org.junit.jupiter.api.BeforeEach; +// import org.junit.jupiter.api.DisplayName; +// import org.junit.jupiter.api.Test; +// import org.junit.jupiter.api.extension.ExtendWith; +// import org.mockito.InjectMocks; +// import org.mockito.Mock; +// import org.mockito.junit.jupiter.MockitoExtension; +// +// import gg.calendar.api.user.utils.controller.response.FortyTwoEventResponse; +// import gg.calendar.api.user.utils.controller.response.TestFixtures; +// import gg.data.calendar.PublicSchedule; +// import gg.repo.calendar.PublicScheduleRepository; +// +// @ExtendWith(MockitoExtension.class) +// class FortyTwoEventServiceTest { +// +// @Mock +// private FortyTwoEventApiClient fortyTwoEventClient; +// +// @Mock +// private PublicScheduleRepository publicScheduleRepository; +// +// @InjectMocks +// private FortyTwoEventService fortyTwoEventService; +// +// private FortyTwoEventResponse sample; +// private LocalDateTime now; +// +// @BeforeEach +// void setUp() { +// now = LocalDateTime.now(); +// sample = createSampleEvent("Test", "event", now); +// } +// +// @Test +// @DisplayName("새로운 이벤트 저장 성공") +// void checkAndSaveEvent() { +// //given +// when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); +// when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(false); +// +// //when +// fortyTwoEventService.checkEvent(); +// +// //then +// verify(publicScheduleRepository, times(1)).save(any(PublicSchedule.class)); +// } +// +// @Test +// @DisplayName("이미 있는 이벤트 저장하지 않음") +// void checkAndNotSaveEvent() { +// //given +// when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); +// when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(true); +// +// //when +// fortyTwoEventService.checkEvent(); +// +// //then +// verify(publicScheduleRepository, times(0)).save(any(PublicSchedule.class)); +// } +// +// private FortyTwoEventResponse createSampleEvent(String name, String kind, LocalDateTime begin) { +// FortyTwoEventResponse testEvent = TestFixtures.createTestEvent(name, kind, begin); +// return testEvent; +// } +// } From 6e82b248bde36eb03aad44592451cbce662a222e Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 14:07:57 +0900 Subject: [PATCH 17/21] =?UTF-8?q?[FIX]=20build=20=EC=95=88=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 32644bac3..51ca38180 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -9,7 +9,7 @@ name: test-deploy on: push: - branches: [ dev, 1151-feature-42api-모니터링스레드에작업 ] + branches: [ dev, recruit_recruit-dev, 1151-feature-42api-모니터링스레드에작업 ] workflow_dispatch: permissions: From 5f7e0e24b89d174ae6e7499a51383d66c64f0f15 Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 14:29:28 +0900 Subject: [PATCH 18/21] =?UTF-8?q?[FIX]=20build=20=EC=99=84=EB=A3=8C=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/checkstyle-validation.yml | 2 +- .github/workflows/test-code-validation.yml | 2 +- .../src/test/java/gg/admin/repo/TestSpringBootApplication.java | 2 +- .../src/test/java/gg/recruit/api/TestSpringBootApplication.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/checkstyle-validation.yml b/.github/workflows/checkstyle-validation.yml index e819fa526..ca1a360d1 100644 --- a/.github/workflows/checkstyle-validation.yml +++ b/.github/workflows/checkstyle-validation.yml @@ -2,7 +2,7 @@ name: 👮Checkstyle validation on: push: - branches: [ 1151-TestCodeValidation ] + branches: [ 1151-feature-42api-모니터링스레드에작업 ] pull_request: branches: [ main, dev , recruit-dev ] diff --git a/.github/workflows/test-code-validation.yml b/.github/workflows/test-code-validation.yml index 2cf2e7e6b..299d7d01b 100644 --- a/.github/workflows/test-code-validation.yml +++ b/.github/workflows/test-code-validation.yml @@ -2,7 +2,7 @@ name: 💻 Test code validation on: push: - branches: [ 1151-TestCodeValidation ] + branches: [ 1151-feature-42api-모니터링스레드에작업 ] pull_request: branches: [ main, dev ] diff --git a/gg-admin-repo/src/test/java/gg/admin/repo/TestSpringBootApplication.java b/gg-admin-repo/src/test/java/gg/admin/repo/TestSpringBootApplication.java index cb0a5c276..b95a2c391 100644 --- a/gg-admin-repo/src/test/java/gg/admin/repo/TestSpringBootApplication.java +++ b/gg-admin-repo/src/test/java/gg/admin/repo/TestSpringBootApplication.java @@ -3,6 +3,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication(scanBasePackages = {"gg.recruit.api", "gg.utils", "gg.data", "gg.repo", - "gg.admin.repo", "gg.auth", "gg.pingpong.api"}) + "gg.admin.repo", "gg.auth", "gg.pingpong.api", "gg.calendar.api"}) public class TestSpringBootApplication { } diff --git a/gg-recruit-api/src/test/java/gg/recruit/api/TestSpringBootApplication.java b/gg-recruit-api/src/test/java/gg/recruit/api/TestSpringBootApplication.java index dcc4eecb9..a76ff4172 100644 --- a/gg-recruit-api/src/test/java/gg/recruit/api/TestSpringBootApplication.java +++ b/gg-recruit-api/src/test/java/gg/recruit/api/TestSpringBootApplication.java @@ -3,6 +3,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication(scanBasePackages = {"gg.recruit.api", "gg.utils", "gg.data", "gg.repo", - "gg.admin.repo", "gg.auth", "gg.pingpong.api"}) + "gg.admin.repo", "gg.auth", "gg.pingpong.api", "gg.calendar.api"}) public class TestSpringBootApplication { } From a821d2df188302ec6dd6b7efb2c06a139e80b9bf Mon Sep 17 00:00:00 2001 From: seyeon22222 <92151066+seyeon22222@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:42:30 +0900 Subject: [PATCH 19/21] Update test-deploy.yml --- .github/workflows/test-deploy.yml | 42 ------------------------------- 1 file changed, 42 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 51ca38180..31f211770 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -41,45 +41,3 @@ jobs: - name: Build with Gradle run: ./gradlew clean build -x test - - - name: build new docker image as latest tag - run: | - docker build -t ${{ env.IMAGE_NAME }}:latest . - docker push ${{ env.IMAGE_NAME }}:latest - - - name: Create the configuration file - run: | - cat << EOF > config.json - { - "AutoScalingGroupName": "gg-dev", - "DesiredConfiguration": { - "LaunchTemplate": { - "LaunchTemplateId": "${{ secrets.DEV_LAUNCH_TEMPLATE_ID }}", - "Version": "\$Latest" - } - }, - "Preferences": { - "MinHealthyPercentage": 100, - "MaxHealthyPercentage": 110, - "InstanceWarmup": 300, - "ScaleInProtectedInstances": "Ignore", - "StandbyInstances": "Ignore" - } - } - EOF - cat config.json - - - name: Configure AWS CLI - uses: aws-actions/configure-aws-credentials@v2 - with: - aws-access-key-id: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_SECRET_KEY }} - aws-region: ap-northeast-2 - - - name: Trigger Instance Refresh - run: | - aws autoscaling start-instance-refresh --cli-input-json file://config.json -env: - DOCKER_USER: ${{ secrets.DOCKER_USER }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - IMAGE_NAME: wken5577/test-migrate-server From a8c50e0491c4afb640a230f38e036f69fc36eb01 Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 14:49:02 +0900 Subject: [PATCH 20/21] =?UTF-8?q?[FIX]=20test-deploy=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-deploy.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 31f211770..3c8acb89f 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -1,15 +1,8 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle - name: test-deploy on: push: - branches: [ dev, recruit_recruit-dev, 1151-feature-42api-모니터링스레드에작업 ] + branches: [ dev, 1151-feature-42api-모니터링스레드에작업 ] workflow_dispatch: permissions: From 81b700dba79a4004baa2795b357ca1f8809f0576 Mon Sep 17 00:00:00 2001 From: wonie Date: Fri, 24 Jan 2025 15:26:41 +0900 Subject: [PATCH 21/21] =?UTF-8?q?[FIX]=20=EC=A3=BC=EC=84=9D=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0/=20=ED=8C=8C=EC=9D=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/checkstyle-validation.yml | 2 +- .../response/FortyTwoEventResponse.java | 53 +++---------- .../utils/service/FortyTwoEventService.java | 2 - .../utils/service/ScheduleCheckService.java | 3 +- .../utils/service/ScheduleNotiService.java | 2 - .../controller/response/TestFixtures.java | 20 ----- .../service/FortyTwoEventApiClientTest.java | 40 ---------- .../service/FortyTwoEventServiceTest.java | 74 ------------------- .../java/gg/data/calendar/PublicSchedule.java | 4 +- 9 files changed, 13 insertions(+), 187 deletions(-) delete mode 100644 gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java delete mode 100644 gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java delete mode 100644 gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java diff --git a/.github/workflows/checkstyle-validation.yml b/.github/workflows/checkstyle-validation.yml index ca1a360d1..fa88a50a3 100644 --- a/.github/workflows/checkstyle-validation.yml +++ b/.github/workflows/checkstyle-validation.yml @@ -4,7 +4,7 @@ on: push: branches: [ 1151-feature-42api-모니터링스레드에작업 ] pull_request: - branches: [ main, dev , recruit-dev ] + branches: [ main, dev ] jobs: checkstyle: diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponse.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponse.java index 2250ada05..435b14218 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponse.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/controller/response/FortyTwoEventResponse.java @@ -11,10 +11,19 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class FortyTwoEventResponse { + @JsonProperty("id") private Long id; + + @JsonProperty("name") private String name; + + @JsonProperty("description") private String description; + + @JsonProperty("location") private String location; + + @JsonProperty("kind") private String kind; @JsonProperty("begin_at") @@ -28,48 +37,4 @@ public class FortyTwoEventResponse { @JsonProperty("updated_at") private LocalDateTime updatedAt; - - // @JsonProperty("max_people") - // private Integer maxPeople; - // - // @JsonProperty("nbr_subscribers") - // private Integer nbrSubscribers; - - // @JsonProperty("campus_ids") - // private List campusIds; - // - // @JsonProperty("cursus_ids") - // private List cursusIds; - - // @JsonProperty("prohibition_of_cancellation") - // private String prohibitionOfCancellation; - - // private Waitlist waitlist; - // private List themes; - - // public static class Themes { - // private Long id; - // private String name; - // @JsonProperty("created_at") - // private LocalDateTime createdAt; - // - // @JsonProperty("updated_at") - // private LocalDateTime updatedAt; - // } - // - // public static class Waitlist { - // private Long id; - // @JsonProperty("created_at") - // private LocalDateTime createdAt; - // - // @JsonProperty("updated_at") - // private LocalDateTime updatedAt; - // - // @JsonProperty("waitlist_id") - // private Long waitlistId; - // - // @JsonProperty("waitlist_type") - // private String waitlistType; - // } - } diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventService.java index 219e1c54a..b07be98bf 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventService.java @@ -14,9 +14,7 @@ import gg.data.calendar.type.ScheduleStatus; import gg.repo.calendar.PublicScheduleRepository; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -@Slf4j @Service @Transactional @RequiredArgsConstructor diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleCheckService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleCheckService.java index 12eb81e36..49889fd1e 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleCheckService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleCheckService.java @@ -18,8 +18,7 @@ public class ScheduleCheckService { private final PrivateScheduleRepository privateScheduleRepository; public void deactivateExpiredSchedules() { - publicScheduleRepository.updateExpiredPublicSchedules(ScheduleStatus.DEACTIVATE, - ScheduleStatus.ACTIVATE, + publicScheduleRepository.updateExpiredPublicSchedules(ScheduleStatus.DEACTIVATE, ScheduleStatus.ACTIVATE, LocalDateTime.now()); privateScheduleRepository.updateRelatedPrivateSchedules(ScheduleStatus.DEACTIVATE, ScheduleStatus.DEACTIVATE); } diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleNotiService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleNotiService.java index 6b489bbce..29d855ffd 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleNotiService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/ScheduleNotiService.java @@ -12,9 +12,7 @@ import gg.repo.calendar.PublicScheduleRepository; import gg.utils.sns.MessageSender; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -@Slf4j @Service @Transactional @RequiredArgsConstructor diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java deleted file mode 100644 index 572e255fc..000000000 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/controller/response/TestFixtures.java +++ /dev/null @@ -1,20 +0,0 @@ -// package gg.calendar.api.user.utils.controller.response; -// -// import java.time.LocalDateTime; -// -// import org.springframework.test.util.ReflectionTestUtils; -// -// public class TestFixtures { -// public static FortyTwoEventResponse createTestEvent(String name, String kind, LocalDateTime beginAt) { -// FortyTwoEventResponse response = new FortyTwoEventResponse() { -// }; // 익명 클래스 선언 끝 -// -// ReflectionTestUtils.setField(response, "name", name); -// ReflectionTestUtils.setField(response, "kind", kind); -// ReflectionTestUtils.setField(response, "beginAt", beginAt); -// ReflectionTestUtils.setField(response, "endAt", beginAt.plusHours(2)); -// ReflectionTestUtils.setField(response, "description", "Sample description"); -// -// return response; -// } -// } diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java deleted file mode 100644 index d6e7fed8c..000000000 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClientTest.java +++ /dev/null @@ -1,40 +0,0 @@ -// package gg.calendar.api.user.utils.service; -// -// import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.*; -// -// import org.junit.jupiter.api.BeforeEach; -// import org.mockito.Mockito; -// import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -// import org.springframework.boot.web.client.RestTemplateBuilder; -// import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; -// -// import com.fasterxml.jackson.databind.ObjectMapper; -// import com.github.tomakehurst.wiremock.WireMockServer; -// -// import gg.auth.FortyTwoAuthUtil; -// import gg.auth.config.ScheduleConfig; -// import gg.utils.annotation.IntegrationTest; -// import gg.utils.external.ApiUtil; -// -// @IntegrationTest -// @AutoConfigureMockMvc -// class FortyTwoEventApiClientTest { -// private WireMockServer mockServer; -// private FortyTwoEventApiClient apiClient; -// -// @BeforeEach -// void setUp() { -// mockServer = new WireMockServer(options().port(8089)); -// mockServer.start(); -// -// ObjectMapper objectMapper = new ObjectMapper(); -// RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); -// -// ApiUtil apiUtil = new ApiUtil(objectMapper, restTemplateBuilder); -// OAuth2AuthorizedClientService clientService = Mockito.mock(OAuth2AuthorizedClientService.class); -// ScheduleConfig scheduleConfig = Mockito.mock(ScheduleConfig.class); -// FortyTwoAuthUtil fortyTwoAuthUtil = new FortyTwoAuthUtil(apiUtil, clientService, scheduleConfig); -// apiClient = new FortyTwoEventApiClient(apiUtil, fortyTwoAuthUtil); -// } -// -// } diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java deleted file mode 100644 index e59dc6033..000000000 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/utils/service/FortyTwoEventServiceTest.java +++ /dev/null @@ -1,74 +0,0 @@ -// package gg.calendar.api.user.utils.service; -// -// import static org.mockito.Mockito.*; -// -// import java.time.LocalDateTime; -// import java.util.Arrays; -// -// import org.junit.jupiter.api.BeforeEach; -// import org.junit.jupiter.api.DisplayName; -// import org.junit.jupiter.api.Test; -// import org.junit.jupiter.api.extension.ExtendWith; -// import org.mockito.InjectMocks; -// import org.mockito.Mock; -// import org.mockito.junit.jupiter.MockitoExtension; -// -// import gg.calendar.api.user.utils.controller.response.FortyTwoEventResponse; -// import gg.calendar.api.user.utils.controller.response.TestFixtures; -// import gg.data.calendar.PublicSchedule; -// import gg.repo.calendar.PublicScheduleRepository; -// -// @ExtendWith(MockitoExtension.class) -// class FortyTwoEventServiceTest { -// -// @Mock -// private FortyTwoEventApiClient fortyTwoEventClient; -// -// @Mock -// private PublicScheduleRepository publicScheduleRepository; -// -// @InjectMocks -// private FortyTwoEventService fortyTwoEventService; -// -// private FortyTwoEventResponse sample; -// private LocalDateTime now; -// -// @BeforeEach -// void setUp() { -// now = LocalDateTime.now(); -// sample = createSampleEvent("Test", "event", now); -// } -// -// @Test -// @DisplayName("새로운 이벤트 저장 성공") -// void checkAndSaveEvent() { -// //given -// when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); -// when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(false); -// -// //when -// fortyTwoEventService.checkEvent(); -// -// //then -// verify(publicScheduleRepository, times(1)).save(any(PublicSchedule.class)); -// } -// -// @Test -// @DisplayName("이미 있는 이벤트 저장하지 않음") -// void checkAndNotSaveEvent() { -// //given -// when(fortyTwoEventClient.getEvents()).thenReturn(Arrays.asList(sample)); -// when(publicScheduleRepository.existsByTitleAndStartTime(any(), any())).thenReturn(true); -// -// //when -// fortyTwoEventService.checkEvent(); -// -// //then -// verify(publicScheduleRepository, times(0)).save(any(PublicSchedule.class)); -// } -// -// private FortyTwoEventResponse createSampleEvent(String name, String kind, LocalDateTime begin) { -// FortyTwoEventResponse testEvent = TestFixtures.createTestEvent(name, kind, begin); -// return testEvent; -// } -// } diff --git a/gg-data/src/main/java/gg/data/calendar/PublicSchedule.java b/gg-data/src/main/java/gg/data/calendar/PublicSchedule.java index 437b3a215..157b301ca 100644 --- a/gg-data/src/main/java/gg/data/calendar/PublicSchedule.java +++ b/gg-data/src/main/java/gg/data/calendar/PublicSchedule.java @@ -86,8 +86,8 @@ private PublicSchedule(DetailClassification classification, EventTag eventTag, J this.endTime = endTime; } - public void update(DetailClassification classification, EventTag eventTag, JobTag jobTag, - TechTag techTag, String title, String content, String link, LocalDateTime startTime, LocalDateTime endTime) { + public void update(DetailClassification classification, EventTag eventTag, JobTag jobTag, TechTag techTag, + String title, String content, String link, LocalDateTime startTime, LocalDateTime endTime) { this.classification = classification; this.eventTag = eventTag; this.jobTag = jobTag;