Skip to content

Commit

Permalink
Merge pull request #55 from AndLetgo/develop
Browse files Browse the repository at this point in the history
🚀 7차 배포
  • Loading branch information
gyehwan24 authored Jan 8, 2024
2 parents 12da27d + 845f6d8 commit 9adf41c
Show file tree
Hide file tree
Showing 41 changed files with 696 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
touch ./src/main/resources/application-auth.yml
echo "${{ secrets.AUTH_YML }}" | base64 --decode > src/main/resources/application-auth.yml
touch ./src/main/resources/forbidden-words.txt
echo "${{ secrets.FORBIDDEN_TXT }}" | base64 --decode > src/main/resources/forbidden-words.txt
#추가
- name: Make Gradle Wrapper script executable
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ out/
/src/main/resources/application-h2.yml
/src/main/resources/application-s3.yml
/src/main/resources/application-auth.yml

/src/main/resources/forbidden-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import depth.jeonsilog.global.DefaultAssert;
import depth.jeonsilog.global.config.security.token.UserPrincipal;
import depth.jeonsilog.global.payload.ApiResponse;
import depth.jeonsilog.global.payload.Message;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -80,6 +81,7 @@ public ResponseEntity<?> getActivityAlarmList(UserPrincipal userPrincipal) {
.imgUrl(sender.get().getProfileImg())
.contents(content)
.dateTime(alarm.getCreatedDate())
.isChecked(alarm.getIsChecked())
.build();
alarmResList.add(alarmRes);
}
Expand All @@ -106,6 +108,7 @@ public ResponseEntity<?> getExhibitionAlarmList(UserPrincipal userPrincipal) {
.imgUrl(exhibition.get().getImageUrl())
.contents("[" + exhibition.get().getName() + "] " + alarm.getContents())
.dateTime(alarm.getCreatedDate())
.isChecked(alarm.getIsChecked())
.build();
alarmResList.add(alarmRes);
}
Expand All @@ -114,6 +117,23 @@ public ResponseEntity<?> getExhibitionAlarmList(UserPrincipal userPrincipal) {
return ResponseEntity.ok(apiResponse);
}

// TODO: 알림 확인
@Transactional
public ResponseEntity<?> checkAlarm(UserPrincipal userPrincipal, Long alarmId) {

User findUser = userService.validateUserByToken(userPrincipal);

Optional<Alarm> alarm = alarmRepository.findById(alarmId);
DefaultAssert.isTrue(alarm.isPresent(), "알림 정보가 올바르지 않습니다.");
DefaultAssert.isTrue(findUser.equals(alarm.get().getUser()), "알림 수신자만 알림을 확인할 수 있습니다.");

Alarm findAlarm = alarm.get();
findAlarm.updateIsChecked(true);

ApiResponse apiResponse = ApiResponse.toApiResponse(Message.builder().message("알림이 확인되었습니다.").build());
return ResponseEntity.ok(apiResponse);
}

// TODO: 팔로잉한 사람의 new 감상평 -> 알림 생성
@Transactional
public void makeReviewAlarm(Review review) {
Expand All @@ -125,6 +145,7 @@ public void makeReviewAlarm(Review review) {
.alarmType(AlarmType.REVIEW)
.targetId(review.getId())
.clickId(review.getId())
.isChecked(false)
.build();
alarmRepository.save(alarm);
}
Expand All @@ -141,6 +162,7 @@ public void makeRatingAlarm(Rating rating) {
.alarmType(AlarmType.RATING)
.targetId(rating.getId())
.clickId(rating.getExhibition().getId())
.isChecked(false)
.build();
alarmRepository.save(alarm);
}
Expand All @@ -155,6 +177,7 @@ public void makeReplyAlarm(Reply reply) {
.alarmType(AlarmType.REPLY)
.targetId(reply.getId())
.clickId(reply.getReview().getId())
.isChecked(false)
.build();
alarmRepository.save(alarm);
}
Expand All @@ -168,13 +191,14 @@ public void makeFollowAlarm(Follow follow) {
.alarmType(AlarmType.FOLLOW)
.targetId(follow.getId())
.clickId(follow.getUser().getId())
.isChecked(false)
.build();
alarmRepository.save(alarm);
}

// 관심 전시회 시작 전 -> 알림 생성
@Transactional
@Scheduled(cron = "0 0 0 * * *") // 매일 자정에 실행
@Scheduled(cron = "0 0 9 * * *") // 오전 9시에 실행
public void makeExhibitionAlarm() {
List<Interest> interests = interestRepository.findByExhibition_OperatingKeyword(OperatingKeyword.BEFORE_DISPLAY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static Alarm toExhibitionAlarm(Interest interest, String contents) {
.targetId(interest.getExhibition().getId())
.clickId(interest.getExhibition().getId())
.contents(contents)
.isChecked(false)
.build();
}
}
9 changes: 8 additions & 1 deletion src/main/java/depth/jeonsilog/domain/alarm/domain/Alarm.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,21 @@ public class Alarm extends BaseEntity {
@Nullable
private String contents;

private Boolean isChecked = false;

public void updateIsChecked(Boolean isChecked) {
this.isChecked = isChecked;
}

@Builder
public Alarm(Long id, User user, @Nullable Long senderId, AlarmType alarmType, Long targetId, Long clickId, @Nullable String contents) {
public Alarm(Long id, User user, @Nullable Long senderId, AlarmType alarmType, Long targetId, Long clickId, @Nullable String contents, Boolean isChecked) {
this.id = id;
this.user = user;
this.senderId = senderId;
this.alarmType = alarmType;
this.targetId = targetId;
this.clickId = clickId;
this.contents = contents;
this.isChecked = isChecked;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ public static class AlarmRes {

@Schema(type = "LocalDateTime", example = "2023-12-22 23:51:45.848882", description = "알림이 생성된 DateTime을 출력합니다.")
private LocalDateTime dateTime;

@Schema(type = "boolean", example = "true", description = "알림을 확인했는지 출력합니다.")
private Boolean isChecked;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import depth.jeonsilog.global.config.security.token.CurrentUser;
import depth.jeonsilog.global.config.security.token.UserPrincipal;
import depth.jeonsilog.global.payload.ErrorResponse;
import depth.jeonsilog.global.payload.Message;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
Expand All @@ -17,7 +18,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand Down Expand Up @@ -52,4 +54,17 @@ public ResponseEntity<?> getExhibitionAlarmList(
) {
return alarmService.getExhibitionAlarmList(userPrincipal);
}

@Operation(summary = "알림 확인", description = "알림 확인")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "확인 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}),
@ApiResponse(responseCode = "400", description = "확인 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@PatchMapping("/check/{alarmId}")
public ResponseEntity<?> checkReport(
@Parameter(description = "Access Token을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal,
@Parameter(description = "알림 Id를 입력해주세요.", required = true) @PathVariable Long alarmId
) {
return alarmService.checkAlarm(userPrincipal, alarmId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import depth.jeonsilog.domain.auth.domain.Token;
import depth.jeonsilog.domain.auth.domain.repository.TokenRepository;
import depth.jeonsilog.domain.auth.dto.*;
import depth.jeonsilog.domain.common.Status;
import depth.jeonsilog.domain.user.application.UserService;
import depth.jeonsilog.domain.user.domain.User;
import depth.jeonsilog.domain.user.domain.repository.UserRepository;
Expand All @@ -13,6 +12,7 @@
import depth.jeonsilog.global.payload.ApiResponse;
import depth.jeonsilog.global.payload.Message;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
Expand All @@ -21,7 +21,13 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

@RequiredArgsConstructor
Expand Down Expand Up @@ -119,8 +125,19 @@ public ResponseEntity<?> signout(UserPrincipal userPrincipal) {

public ResponseEntity<?> checkNickname(String nickname) {

List<String> forbiddenList = loadForbiddenWords();
System.out.println(forbiddenList);
boolean isForbidden = false;
for (String forbiddenWord : forbiddenList) {
if (nickname.contains(forbiddenWord)) {
isForbidden = true;
break;
}
}

AuthResponseDto.NicknameCheckRes nicknameCheckRes = AuthResponseDto.NicknameCheckRes.builder()
.isAvailable(!userRepository.existsByNickname(nickname))
.isDuplicate(userRepository.existsByNickname(nickname))
.isForbidden(isForbidden)
.build();

ApiResponse apiResponse = ApiResponse.toApiResponse(nicknameCheckRes);
Expand All @@ -144,4 +161,19 @@ private boolean valid(String refreshToken){

return true;
}

// Description: 금칙어 리스트 파일에서 리스트를 읽어서 반환하는 메서드
public List<String> loadForbiddenWords() {
List<String> forbiddenList = new ArrayList<>();
try {
ClassPathResource resource = new ClassPathResource("forbidden-words.txt");
byte[] fileData = FileCopyUtils.copyToByteArray(resource.getInputStream());
String content = new String(fileData, StandardCharsets.UTF_8);
String[] lines = content.split(System.lineSeparator());
forbiddenList.addAll(Arrays.asList(lines));
} catch (IOException e) {
e.printStackTrace();
}
return forbiddenList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public static class AuthRes {
@Builder
public static class NicknameCheckRes {

@Schema(type = "boolean", example = "true", description = "사용 가능한 닉네임일 경우 true를 출력합니다.")
private Boolean isAvailable;
@Schema(type = "boolean", example = "true", description = "중복일 경우 true를 출력합니다.")
private Boolean isDuplicate;

@Schema(type = "boolean", example = "true", description = "금칙어일 경우 true를 출력합니다.")
private Boolean isForbidden;
}
}
Loading

0 comments on commit 9adf41c

Please sign in to comment.