Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Team-baebae/baebae-BE in…
Browse files Browse the repository at this point in the history
…to feature/answer/#39
  • Loading branch information
jihyo-j committed May 23, 2024
2 parents c5f3394 + 1d1a795 commit 256240e
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: |
cd baebae-BE
chmod +x ./gradlew
./gradlew build
./gradlew build -x test
- name: Create deployment package
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ ResponseEntity<AnswerDetailResponse> createAnswer(
summary = "모든 답변 조회",
description = "모든 답변을 페이지네이션으로 조회합니다."
)
@Parameter(
in = ParameterIn.HEADER,
name = "Authorization", required = false,
schema = @Schema(type = "string"),
description = "Bearer [Access 토큰]")
@ApiResponse(responseCode = "200", description = "답변 조회 성공",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Page.class)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@Entity
@Table(name = "categorized_answer")
@IdClass(CategoryIdAnswerId.class)
@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -19,15 +20,12 @@
public class CategorizedAnswer {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "categorized_answer_id")
private Long id;

@ManyToOne
@JoinColumn(name = "category_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private Category category;

@Id
@ManyToOne
@JoinColumn(name = "answer_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.web.baebaeBE.domain.categorized.answer.entity;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@NoArgsConstructor
@EqualsAndHashCode
public class CategoryIdAnswerId implements Serializable {
private Long category;
private Long answer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ResponseEntity<Void> addFcmToken(
@PathVariable Long memberId,
@RequestBody FcmRequest.CreateToken request
) {
FcmToken token = fcmService.addFcmToken(memberId, request.getFcmToken());
fcmService.addFcmToken(memberId, request.getFcmToken());
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ public void updateToken(String newToken) {
public void updateLastUsedTime() {
this.lastUsedTime = LocalDateTime.now();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
public enum FcmException implements ErrorCode {

NOT_FOUND_FCM(HttpStatus.CONFLICT, "F-001", "FCM 토큰을 찾을 수 없습니다."),
NOT_MATCH_MEMBER(HttpStatus.CONFLICT, "F-002", "FCM 토큰과 회원 정보가 일치하지 않습니다.");
NOT_MATCH_MEMBER(HttpStatus.CONFLICT, "F-002", "FCM 토큰과 회원 정보가 일치하지 않습니다."),
TOKEN_ALREADY_EXISTS(HttpStatus.CONFLICT, "F-003", "이미 등록된 FCM 토큰입니다.");

private final HttpStatus httpStatus;
private final String errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public FcmToken addFcmToken(Long memberId, String fcmToken) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new BusinessException(MemberException.NOT_EXIST_MEMBER));

// 중복 토큰 검사
Optional<FcmToken> existingToken = fcmTokenRepository.findByToken(fcmToken);
if (existingToken.isPresent()) {
throw new BusinessException(FcmException.TOKEN_ALREADY_EXISTS);
}

FcmToken token = FcmToken.builder()
.token(fcmToken)
.member(member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public ResponseEntity<LoginResponse.SignUpResponse> oauthSignUp(
else
response = loginService.signUpNewUser(kakaoUserInfo, signUpRequest);

if(signUpRequest.getFcmToken() != null)
fcmService.verifyFcmToken(response.getId(), signUpRequest.getFcmToken());

return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public static class SignUp{
private MemberType memberType;
@Schema(example = "김예찬")
private String nickname;
@Nullable // NULL 가능
private String fcmToken;
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class LoginService {
private final Oauth2Service oauth2Service;
private final JwtTokenProvider jwtTokenProvider;
private final S3ImageStorageService s3ImageStorageService;
public static final Duration REFRESH_TOKEN_DURATION = Duration.ofDays(14); // 리프레시 토큰 유효기간.
public static final Duration ACCESS_TOKEN_DURATION = Duration.ofHours(1); // 액세스 토큰 유효기간.
public static final Duration REFRESH_TOKEN_DURATION = Duration.ofMinutes(2); // 리프레시 토큰 유효기간.
public static final Duration ACCESS_TOKEN_DURATION = Duration.ofMinutes(1); // 액세스 토큰 유효기간.


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class ManageTokenService {

private final MemberRepository memberRepository;
private final JwtTokenProvider jwtTokenProvider;
public static final Duration REFRESH_TOKEN_DURATION = Duration.ofDays(14); // 리프레시 토큰 유효기간.
public static final Duration ACCESS_TOKEN_DURATION = Duration.ofDays(1); // 액세스 토큰 유효기간.
public static final Duration REFRESH_TOKEN_DURATION = Duration.ofMinutes(2); // 리프레시 토큰 유효기간.
public static final Duration ACCESS_TOKEN_DURATION = Duration.ofMinutes(1); // 액세스 토큰 유효기간.


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Question {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "receiver_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private Member receiver;

@Column(nullable = false, columnDefinition = "TEXT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import com.web.baebaeBE.domain.member.entity.Member;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name = "member_answer_reaction")
@IdClass(MemberIdAnswerId.class)
@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -16,15 +19,15 @@
public class MemberAnswerReaction {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private Member member;

@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "answer_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private Answer answer;

@Enumerated(EnumType.STRING)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.web.baebaeBE.domain.reaction.entity;

import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@NoArgsConstructor
@EqualsAndHashCode
public class MemberIdAnswerId implements Serializable {
private Long member;
private Long answer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.web.baebaeBE.domain.answer.entity.Answer;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name = "reaction_count")
Expand All @@ -18,6 +20,7 @@ public class ReactionCount {
@MapsId
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
@JoinColumn(name = "answer_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private Answer answer;

@Column(name = "heart_count", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public String sendNotification(String token, String title, String body) {
.build();

try {
log.info("Send FCM message to {}", token);
return FirebaseMessaging.getInstance().send(message);
log.info("Sending FCM message to token: {}", token);
String response = FirebaseMessaging.getInstance().send(message);
log.info("Successfully sent FCM message. Message ID: {}", response);
return response;
} catch (FirebaseMessagingException e) {
if (e.getMessagingErrorCode().equals(MessagingErrorCode.INVALID_ARGUMENT)) {
// 토큰이 유효하지 않은 경우, 오류 코드를 반환
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ public void notifyNewAnswer(Member member, Question question, Answer answer) {
// 모든 fcm 토큰 가져오기
List<FcmToken> fcmTokens = fcmTokenRepository.findByMemberId(question.getSender().getId());

System.out.println(question.getSender().getId() + " " + question.getSender().getNickname());
for (FcmToken fcmToken : fcmTokens) {
fcmService.updateLastUsedTime(fcmToken);
System.out.println(" "+fcmToken.getToken());
sendNotificationToUser(fcmToken, notificationTitle, notificationBody);
}
}
Expand Down

0 comments on commit 256240e

Please sign in to comment.