Skip to content

Commit

Permalink
Merge pull request #79 from AndLetgo/develop
Browse files Browse the repository at this point in the history
🚀 [DEPLOY]: 13차 배포
  • Loading branch information
gyehwan24 authored Jan 14, 2024
2 parents bc51f22 + eee9500 commit 951e9c6
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() + " 님이 감상평을 남겼어요");
}
}

Expand All @@ -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() + " 님이 별점을 남겼어요");
}
}

Expand All @@ -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: 나를 팔로우 -> 알림 생성
Expand All @@ -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: 관심 전시회 시작 전 -> 알림 생성
Expand Down Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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()
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,15 +29,18 @@

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Slf4j
@Service
public class AddService {

private final ExhibitionRepository exhibitionRepository;
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");
Expand Down Expand Up @@ -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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 951e9c6

Please sign in to comment.