Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3c96e8b
✨ [Feature] 개인 일정 상세조회 api #1060 (#1131)
taehyeon3 Jan 6, 2025
e74db2c
✨ [Feature] 전체일정 조회하기 dto, controller, service 생성 및 test 완료 #1128 (#1…
wonies Jan 6, 2025
11752a1
✨ [Feature] 전체일정 기간조회 api 생성 및 완료 #1062 (#1134)
wonies Jan 7, 2025
711ff6b
✨ [Feature] 관리자 페이지 일정 검색 API 추가 #1120 (#1133)
seyeon22222 Jan 7, 2025
006e447
✨ [Feature] Admin 페이지 전체일정 조회 #1074 (#1135)
seyeon22222 Jan 7, 2025
361c210
✨ [Feature] 개인일정 기간 조회 api #1061 (#1136)
taehyeon3 Jan 7, 2025
838fc46
✨ [Feature] 전체일정 개인일정에 추가 api 작성 #1064 (#1138)
wonies Jan 8, 2025
44c2d03
✨ [Feature] 개인일정 커스터 마이징 추가 api (#1140)
taehyeon3 Jan 8, 2025
c5deb00
🛠️ [Refactoring] PublicScheduleDto에 누락된 status정보 추가 #1141 (#1142)
wonies Jan 8, 2025
850983b
✨ [Feature] 개인일정 커스터 마이징 수정 api #1070 (#1143)
taehyeon3 Jan 8, 2025
2db6cdd
✨ [Feature] 개인일정 커스터 마이징 목록 조회 api #1071 (#1144)
taehyeon3 Jan 8, 2025
2d10ed0
✨ [Feature] 개인일정 커스터 마이징 삭제 api #1073 (#1145)
taehyeon3 Jan 9, 2025
73f1c89
✨ [Feature] 개인일정 커스터 마이징 API DTO 검증 로직 추가 #1146 (#1147)
taehyeon3 Jan 9, 2025
de35cba
✨ [Feature] 42API 받아오는 모니터링 쓰레드 작업 #1149
seyeon22222 Jan 9, 2025
c734943
✨ [Feature] 모니터링 쓰레드 기능 추가 #1149
seyeon22222 Jan 10, 2025
b777e1e
✨ [Fix] SecurityConfig파일 설정 원래대로 변경
seyeon22222 Jan 10, 2025
2551499
🔨 [Refactoring] 디데이, 디데이-1 쿼리문 2번 나가는거 1번으로 쿼리합친 후 for문으로 분기하는 내용으로 변경
seyeon22222 Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
package gg.admin.repo.calendar;

import java.time.LocalDateTime;
import java.util.List;

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 org.springframework.transaction.annotation.Transactional;

import gg.data.calendar.PrivateSchedule;
import gg.data.calendar.type.ScheduleStatus;

@Repository
public interface PrivateScheduleAdminRepository extends JpaRepository<PrivateSchedule, Long> {

List<PrivateSchedule> findByPublicScheduleId(Long publicScheduleId);

@Query("SELECT ps FROM PrivateSchedule ps " + "JOIN ps.publicSchedule p " + "WHERE ps.alarm = true "
+ "AND ps.status = :status " + "AND (p.endTime BETWEEN :startOfDay AND :endOfDay OR "
+ "p.endTime BETWEEN :nextStartOfDay AND :nextEndOfDay)")
List<PrivateSchedule> findSchedulesWithAlarmForBothDays(@Param("startOfDay") LocalDateTime startOfDay,
@Param("endOfDay") LocalDateTime endOfDay,
@Param("nextStartOfDay") LocalDateTime nextStartOfDay,
@Param("nextEndOfDay") LocalDateTime nextEndOfDay,
@Param("status") ScheduleStatus status);

@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);

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
package gg.admin.repo.calendar;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
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 org.springframework.transaction.annotation.Transactional;

import gg.data.calendar.PublicSchedule;
import gg.data.calendar.type.DetailClassification;
import gg.data.calendar.type.ScheduleStatus;

@Repository
public interface PublicScheduleAdminRepository extends JpaRepository<PublicSchedule, Long> {
public interface PublicScheduleAdminRepository extends JpaRepository<PublicSchedule, Long>,
JpaSpecificationExecutor<PublicSchedule> {

List<PublicSchedule> findByAuthor(String author);

Page<PublicSchedule> findAllByClassification(DetailClassification detailClassification, Pageable pageable);

List<PublicSchedule> findAll();

Optional<PublicSchedule> findByTitleAndCreatedAtBetween(String name, LocalDateTime start, LocalDateTime end);

@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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
51 changes: 41 additions & 10 deletions gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import static gg.utils.exception.ErrorCode.*;

import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
Expand All @@ -20,8 +22,6 @@
import org.springframework.security.oauth2.core.OAuth2AccessToken;
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import gg.utils.exception.ErrorCode;
import gg.utils.exception.custom.NotExistException;
Expand All @@ -44,6 +44,35 @@ public String getAccessToken() {
return client.getAccessToken().getTokenValue();
}

public String getClientToken(String clientId, String clientSecret, String tokenUri) {

Map<String, String> parameters = new HashMap<>();
parameters.put("grant_type", "client_credentials");
parameters.put("client_id", clientId);
parameters.put("client_secret", clientSecret);

// HTTP 요청 헤더 설정
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

// 요청 바디를 JSON으로 변환
HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(parameters, headers);

// ApiUtil의 apiCall 메서드 호출
Map<String, Object> response = apiUtil.apiCall(
tokenUri, // URL
Map.class, // 응답 타입
headers, // HTTP 헤더
requestEntity.getBody(), // 요청 바디 (JSON 파라미터)
HttpMethod.POST // HTTP 메서드
);

if (Objects.isNull(response) || response.isEmpty()) {
throw new NotExistException(ErrorCode.AUTH_NOT_FOUND);
}
return ((String)response.get("access_token"));
}

/**
* 토큰 갱신
* @return 갱신된 OAuth2AuthorizedClient
Expand Down Expand Up @@ -79,20 +108,22 @@ private OAuth2AuthorizedClient requestNewClient(OAuth2AuthorizedClient client, C
}

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.setContentType(MediaType.APPLICATION_JSON);

Map<String, String> params = new HashMap<>();
params.put("grant_type", "refresh_token");
params.put("refresh_token", client.getRefreshToken().getTokenValue());
params.put("client_id", registration.getClientId());
params.put("client_secret", registration.getClientSecret());
params.put("redirect_uri", registration.getRedirectUri());

MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("grant_type", "refresh_token");
params.add("refresh_token", client.getRefreshToken().getTokenValue());
params.add("client_id", registration.getClientId());
params.add("client_secret", registration.getClientSecret());
params.add("redirect_uri", registration.getRedirectUri());
HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(params, headers);

List<Map<String, Object>> responseBody = apiUtil.apiCall(
registration.getProviderDetails().getTokenUri(),
List.class,
headers,
params,
requestEntity.getBody(),
HttpMethod.POST
);
if (Objects.isNull(responseBody) || responseBody.isEmpty()) {
Expand Down
78 changes: 78 additions & 0 deletions gg-calendar-api/src/main/java/gg/api42/ApiClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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 net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;

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 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 getCurrentToken() {
return this.token;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gg.data.calendar.type.DetailClassification;
import gg.data.calendar.type.EventTag;
import gg.data.calendar.type.JobTag;
import gg.data.calendar.type.ScheduleStatus;
import gg.data.calendar.type.TechTag;
import lombok.AccessLevel;
import lombok.Builder;
Expand Down Expand Up @@ -39,6 +40,8 @@ public class PrivateScheduleAdminDetailResDto {

private String groupBackgroundColor;

private ScheduleStatus status;

private boolean isAlarm;

private LocalDateTime startTime;
Expand All @@ -56,6 +59,7 @@ private PrivateScheduleAdminDetailResDto(PrivateSchedule privateSchedule, Schedu
this.title = privateSchedule.getPublicSchedule().getTitle();
this.content = privateSchedule.getPublicSchedule().getContent();
this.link = privateSchedule.getPublicSchedule().getLink();
this.status = privateSchedule.getPublicSchedule().getStatus();
this.groupTitle = scheduleGroup.getTitle();
this.groupBackgroundColor = scheduleGroup.getBackgroundColor();
this.isAlarm = privateSchedule.isAlarm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PublicScheduleAdminCreateEventReqDto {

private DetailClassification classification;

@NotNull
private EventTag eventTag;

Expand Down Expand Up @@ -50,7 +48,6 @@ public class PublicScheduleAdminCreateEventReqDto {
public PublicScheduleAdminCreateEventReqDto(EventTag eventTag, String title, String content, String link,
ScheduleStatus status, LocalDateTime startTime,
LocalDateTime endTime) {
this.classification = DetailClassification.EVENT;
this.eventTag = eventTag;
this.title = title;
this.content = content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PublicScheduleAdminCreateJobReqDto {

private DetailClassification classification;

@NotNull
private JobTag jobTag;

Expand Down Expand Up @@ -54,8 +52,6 @@ public class PublicScheduleAdminCreateJobReqDto {
public PublicScheduleAdminCreateJobReqDto(JobTag jobTag,
TechTag techTag, String title, String content, String link, ScheduleStatus status, LocalDateTime startTime,
LocalDateTime endTime) {

this.classification = DetailClassification.JOB_NOTICE;
this.jobTag = jobTag;
this.techTag = techTag;
this.title = title;
Expand All @@ -69,7 +65,7 @@ public PublicScheduleAdminCreateJobReqDto(JobTag jobTag,
public static PublicSchedule toEntity(PublicScheduleAdminCreateJobReqDto publicScheduleAdminCreateJobReqDto) {

return PublicSchedule.builder()
.classification(publicScheduleAdminCreateJobReqDto.classification)
.classification(DetailClassification.JOB_NOTICE)
.jobTag(publicScheduleAdminCreateJobReqDto.jobTag)
.techTag(publicScheduleAdminCreateJobReqDto.techTag)
.author("42GG")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import gg.calendar.api.admin.schedule.totalschedule.controller.request.TotalScheduleAdminSearchReqDto;
import gg.calendar.api.admin.schedule.totalschedule.controller.response.TotalScheduleAdminResDto;
import gg.calendar.api.admin.schedule.totalschedule.controller.response.TotalScheduleAdminSearchListResDto;
import gg.calendar.api.admin.schedule.totalschedule.service.TotalScheduleAdminService;
import gg.data.calendar.type.DetailClassification;
import gg.utils.dto.PageRequestDto;
Expand Down Expand Up @@ -45,4 +47,20 @@ public ResponseEntity<PageResponseDto<TotalScheduleAdminResDto>> totalScheduleAd

return ResponseEntity.ok(pageResponseDto);
}

@GetMapping("/search")
public ResponseEntity<TotalScheduleAdminSearchListResDto> totalScheduleAdminSearchList(
@ModelAttribute @Valid TotalScheduleAdminSearchReqDto totalScheduleAdminSearchReqDto) {
TotalScheduleAdminSearchListResDto scheduleList = totalScheduleAdminService
.searchTotalScheduleAdminList(totalScheduleAdminSearchReqDto);

return ResponseEntity.ok(scheduleList);
}

@GetMapping("/total")
public ResponseEntity<TotalScheduleAdminSearchListResDto> totalScheduleAdminList() {
TotalScheduleAdminSearchListResDto scheduleList = totalScheduleAdminService.totalScheduleAdminList();

return ResponseEntity.ok(scheduleList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package gg.calendar.api.admin.schedule.totalschedule.controller.request;

import java.time.LocalDate;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.springframework.format.annotation.DateTimeFormat;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class TotalScheduleAdminSearchReqDto {

// title, author, content, detailClassification
@NotNull
private String type;

@NotBlank
private String content;

@NotNull
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate startTime;

@NotNull
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate endTime;

}
Loading