diff --git a/src/main/java/depth/jeonsilog/domain/alarm/application/AlarmService.java b/src/main/java/depth/jeonsilog/domain/alarm/application/AlarmService.java index 8f670f5..fb806e7 100644 --- a/src/main/java/depth/jeonsilog/domain/alarm/application/AlarmService.java +++ b/src/main/java/depth/jeonsilog/domain/alarm/application/AlarmService.java @@ -173,7 +173,7 @@ public void makeReviewAlarm(Review review) throws IOException { alarmRepository.save(alarm); if (!receiver.getIsRecvActive() || receiver.getFcmToken() == null) return; - fcmService.send(receiver.getFcmToken(), "전시로그", follow.getFollow().getNickname() + " 님이 감상평 남겼어요"); + fcmService.makeActiveAlarm(receiver.getFcmToken(), follow.getFollow().getNickname() + " 님이 감상평을 남겼어요"); } } @@ -194,7 +194,7 @@ public void makeRatingAlarm(Rating rating) throws IOException { alarmRepository.save(alarm); if (!receiver.getIsRecvActive() || receiver.getFcmToken() == null) return; - fcmService.send(receiver.getFcmToken(), "전시로그", follow.getFollow().getNickname() + " 님이 별점을 남겼어요"); + fcmService.makeActiveAlarm(receiver.getFcmToken(), follow.getFollow().getNickname() + " 님이 별점을 남겼어요"); } } @@ -213,7 +213,7 @@ public void makeReplyAlarm(Reply reply) throws IOException { alarmRepository.save(alarm); if (!receiver.getIsRecvActive() || receiver.getFcmToken() == null) return; - fcmService.send(receiver.getFcmToken(), "전시로그", reply.getUser().getNickname() + " 님이 댓글을 남겼어요"); + fcmService.makeActiveAlarm(receiver.getFcmToken(), reply.getUser().getNickname() + " 님이 댓글을 남겼어요"); } // TODO: 나를 팔로우 -> 알림 생성 @@ -231,7 +231,7 @@ public void makeFollowAlarm(Follow follow) throws IOException { alarmRepository.save(alarm); if (!receiver.getIsRecvActive() || receiver.getFcmToken() == null) return; - fcmService.send(receiver.getFcmToken(), "전시로그", follow.getUser().getNickname() + " 님이 나를 팔로우해요"); + fcmService.makeActiveAlarm(receiver.getFcmToken(), follow.getUser().getNickname() + " 님이 나를 팔로우해요"); } // TODO: 관심 전시회 시작 전 -> 알림 생성 @@ -265,7 +265,7 @@ public void makeExhibitionAlarm() { alarmRepository.save(alarm); if (!receiver.getIsRecvExhibition() || receiver.getFcmToken() == null) return; - fcmService.send(receiver.getFcmToken(), "전시로그", "[" + exhibition.getName() + "]\n" + alarm.getContents()); + fcmService.makeExhibitionAlarm(receiver.getFcmToken(), exhibition.getName(), alarm.getContents()); } } diff --git a/src/main/java/depth/jeonsilog/domain/fcm/application/FcmService.java b/src/main/java/depth/jeonsilog/domain/fcm/application/FcmService.java index 19b1200..d50f96f 100644 --- a/src/main/java/depth/jeonsilog/domain/fcm/application/FcmService.java +++ b/src/main/java/depth/jeonsilog/domain/fcm/application/FcmService.java @@ -12,7 +12,6 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; -import java.io.FileInputStream; import java.io.IOException; import java.util.Arrays; @@ -26,7 +25,7 @@ public class FcmService { private static final String MESSAGING_SCOPE = "https://www.googleapis.com/auth/firebase.messaging"; private static final String[] SCOPES = { MESSAGING_SCOPE }; - //AccessToken 발급 받기. -> Header에 포함하여 푸시 알림 요청 + // TODO: AccessToken 발급 받기. -> Header에 포함하여 푸시 알림 요청 private static String getAccessToken() throws IOException { ClassPathResource resource = new ClassPathResource("services-account.json"); GoogleCredential googleCredential = GoogleCredential @@ -38,9 +37,25 @@ private static String getAccessToken() throws IOException { return googleCredential.getAccessToken(); } - public void send(String fcmToken, String title, String body) { + // TODO: 활동 알림 만들기 + public void makeActiveAlarm(String fcmToken, String title) { + + JSONObject jsonValue = new JSONObject(); + jsonValue.put("title", title); + + JSONObject jsonData = new JSONObject(); + jsonData.put("token", fcmToken); + jsonData.put("data", jsonValue); + + JSONObject jsonMessage = new JSONObject(); + jsonMessage.put("message", jsonData); + + pushAlarm(jsonMessage); + } + + // TODO: 전시 알림 만들기 + public void makeExhibitionAlarm(String fcmToken, String title, String body) { - // 1. create message body JSONObject jsonValue = new JSONObject(); jsonValue.put("title", title); jsonValue.put("body", body); @@ -52,7 +67,11 @@ public void send(String fcmToken, String title, String body) { JSONObject jsonMessage = new JSONObject(); jsonMessage.put("message", jsonData); - // 2. create token & send push + pushAlarm(jsonMessage); + } + + // TODO: 만들어진 알림을 받아서 푸시한다. + private void pushAlarm(JSONObject jsonMessage) { try { OkHttpClient okHttpClient = new OkHttpClient(); Request request = new Request.Builder() @@ -63,7 +82,7 @@ public void send(String fcmToken, String title, String body) { .build(); Response response = okHttpClient.newCall(request).execute(); - log.info("### response str : " + response.toString()); + log.info("### response str : " + response); log.info("### response result : " + response.isSuccessful()); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/depth/jeonsilog/domain/openApi/application/AddService.java b/src/main/java/depth/jeonsilog/domain/openApi/application/AddService.java index 78411b2..ebb397c 100644 --- a/src/main/java/depth/jeonsilog/domain/openApi/application/AddService.java +++ b/src/main/java/depth/jeonsilog/domain/openApi/application/AddService.java @@ -14,9 +14,11 @@ import depth.jeonsilog.domain.place.domain.repository.PlaceRepository; import depth.jeonsilog.global.payload.ApiResponse; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.json.JSONObject; import org.json.XML; import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -27,6 +29,7 @@ @RequiredArgsConstructor @Transactional(readOnly = true) +@Slf4j @Service public class AddService { @@ -34,8 +37,10 @@ public class AddService { private final PlaceRepository placeRepository; private final SaveService saveService; + private final ModifyService modifyService; @Transactional +// @Scheduled(cron = "0 0 19 * * *") // 오후 7시에 실행 public ResponseEntity addExhibitionAndPlace() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); @@ -232,13 +237,21 @@ public ResponseEntity addExhibitionAndPlace() { Integer totalCount = exhibitionList.getResponse().getMsgBody().getTotalCount(); Integer rows = exhibitionList.getResponse().getMsgBody().getRows(); Integer numOfPages = (totalCount / rows) + 1; + log.info("numOfPages: " + numOfPages); - if (page == numOfPages) { // 페이지 조절 + if (page == 5) { // 페이지 조절 ApiResponse apiResponse = ApiResponse.builder() .check(true) .information(exhibitionList) .build(); + modifyService.modifyExhibitionName(); + log.info("modifyExhibitionName 호출"); + modifyService.modifyPlaceTel(); + log.info("modifyPlaceTel 호출"); + modifyService.modifyPlaceHomepage(); + log.info("modifyPlaceHomepage 호출"); + return ResponseEntity.ok(apiResponse); } page++; diff --git a/src/main/java/depth/jeonsilog/domain/openApi/application/SaveService.java b/src/main/java/depth/jeonsilog/domain/openApi/application/SaveService.java index 79ece6b..275fdca 100644 --- a/src/main/java/depth/jeonsilog/domain/openApi/application/SaveService.java +++ b/src/main/java/depth/jeonsilog/domain/openApi/application/SaveService.java @@ -283,7 +283,7 @@ public String callExhibitionListApi(Integer cPage, String from, String to) throw urlBuilder.append("&" + URLEncoder.encode("to","UTF-8") + "=" + URLEncoder.encode(to, "UTF-8")); /**/ urlBuilder.append("&" + URLEncoder.encode("cPage","UTF-8") + "=" + URLEncoder.encode(cPage.toString(), "UTF-8")); // 요청 페이지 - urlBuilder.append("&" + URLEncoder.encode("rows","UTF-8") + "=" + URLEncoder.encode("100", "UTF-8")); // 페이지 당 가져올 개수 + urlBuilder.append("&" + URLEncoder.encode("rows","UTF-8") + "=" + URLEncoder.encode("20", "UTF-8")); // 페이지 당 가져올 개수 // URL 생성 후 연결 URL url = new URL(urlBuilder.toString()); diff --git a/src/main/java/depth/jeonsilog/domain/openApi/presentation/AddController.java b/src/main/java/depth/jeonsilog/domain/openApi/presentation/AddController.java index d7eb5f2..36e59cf 100644 --- a/src/main/java/depth/jeonsilog/domain/openApi/presentation/AddController.java +++ b/src/main/java/depth/jeonsilog/domain/openApi/presentation/AddController.java @@ -1,12 +1,14 @@ package depth.jeonsilog.domain.openApi.presentation; import depth.jeonsilog.domain.openApi.application.AddService; +import io.swagger.v3.oas.annotations.Hidden; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +@Hidden @RequiredArgsConstructor @RestController @RequestMapping("/api/adds") diff --git a/src/main/java/depth/jeonsilog/domain/openApi/presentation/ModifyController.java b/src/main/java/depth/jeonsilog/domain/openApi/presentation/ModifyController.java index 1d21f40..8d40128 100644 --- a/src/main/java/depth/jeonsilog/domain/openApi/presentation/ModifyController.java +++ b/src/main/java/depth/jeonsilog/domain/openApi/presentation/ModifyController.java @@ -1,12 +1,14 @@ package depth.jeonsilog.domain.openApi.presentation; import depth.jeonsilog.domain.openApi.application.ModifyService; +import io.swagger.v3.oas.annotations.Hidden; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +@Hidden @RequiredArgsConstructor @RestController @RequestMapping("/api/modification") diff --git a/src/main/java/depth/jeonsilog/domain/openApi/presentation/SaveController.java b/src/main/java/depth/jeonsilog/domain/openApi/presentation/SaveController.java index 05896d5..17f2f52 100644 --- a/src/main/java/depth/jeonsilog/domain/openApi/presentation/SaveController.java +++ b/src/main/java/depth/jeonsilog/domain/openApi/presentation/SaveController.java @@ -1,12 +1,14 @@ package depth.jeonsilog.domain.openApi.presentation; import depth.jeonsilog.domain.openApi.application.SaveService; +import io.swagger.v3.oas.annotations.Hidden; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +@Hidden @RequiredArgsConstructor @RestController @RequestMapping("/api/saves") diff --git a/src/main/java/depth/jeonsilog/domain/user/converter/UserConverter.java b/src/main/java/depth/jeonsilog/domain/user/converter/UserConverter.java index 532713b..9f44a01 100644 --- a/src/main/java/depth/jeonsilog/domain/user/converter/UserConverter.java +++ b/src/main/java/depth/jeonsilog/domain/user/converter/UserConverter.java @@ -1,6 +1,7 @@ package depth.jeonsilog.domain.user.converter; import depth.jeonsilog.domain.follow.domain.repository.FollowRepository; +import depth.jeonsilog.domain.user.domain.Role; import depth.jeonsilog.domain.user.domain.User; import depth.jeonsilog.domain.user.dto.UserResponseDto; @@ -11,8 +12,13 @@ public class UserConverter { // USER -> UserResDTO public static UserResponseDto.UserRes toUserRes(User user, FollowRepository followRepository) { + Boolean isAdmin = false; + if (user.getRole().equals(Role.ADMIN)) + isAdmin = true; + return UserResponseDto.UserRes.builder() .userId(user.getId()) + .isAdmin(isAdmin) .nickname(user.getNickname()) .profileImgUrl(user.getProfileImg()) .numFollowing(followRepository.countByUser(user)) diff --git a/src/main/java/depth/jeonsilog/domain/user/dto/UserResponseDto.java b/src/main/java/depth/jeonsilog/domain/user/dto/UserResponseDto.java index f95f3b0..ecaf369 100644 --- a/src/main/java/depth/jeonsilog/domain/user/dto/UserResponseDto.java +++ b/src/main/java/depth/jeonsilog/domain/user/dto/UserResponseDto.java @@ -1,6 +1,7 @@ package depth.jeonsilog.domain.user.dto; +import depth.jeonsilog.domain.user.domain.Role; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Data; @@ -16,6 +17,9 @@ public static class UserRes { @Schema(type = "long", example = "1", description = "유저의 ID를 출력합니다.") private Long userId; + @Schema(type = "boolean", example = "true", description = "해당 유저가 관리자인지 출력합니다. ADMIN : isAdmin = true") + private Boolean isAdmin; + @Schema(type = "string", example = "루피", description = "닉네임을 출력합니다.") private String nickname; diff --git a/src/main/resources/application-swagger.yml b/src/main/resources/application-swagger.yml index 8a91075..2572290 100644 --- a/src/main/resources/application-swagger.yml +++ b/src/main/resources/application-swagger.yml @@ -6,7 +6,7 @@ springdoc: groups: enabled: true swagger-ui: - operations-sorter: alpha # alpha(알파벳 오름차순), method(HTTP메소드순) + operations-sorter: method # alpha(알파벳 오름차순), method(HTTP메소드순) tags-sorter: alpha # 태그 정렬 기준 path: /swagger # html 문서 접속 경로 disable-swagger-default-url: true