Skip to content

Commit

Permalink
Merge branch 'develop' into feature/answer/#39
Browse files Browse the repository at this point in the history
  • Loading branch information
jihyo-j authored May 16, 2024
2 parents be52e49 + 33e8967 commit 9336d62
Show file tree
Hide file tree
Showing 21 changed files with 143 additions and 40 deletions.
6 changes: 5 additions & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ public class AnswerDetailResponse {
private String imageUrl;
private LocalDateTime createdDate;


public AnswerDetailResponse(Long answerId, Long questionId, String questionContent, Long memberId,
String content, String memberNickname, String nickname, Boolean profileOnOff,
String linkAttachments, String musicName, String musicSinger, String musicAudioUrl,
String imageUrl, LocalDateTime createdDate) {


this.answerId = answerId;
this.questionId = questionId;
this.questionContent = questionContent;
Expand All @@ -50,5 +53,6 @@ public static AnswerDetailResponse of(Long answerId, Long questionId, String que
return new AnswerDetailResponse(answerId, questionId, questionContent, memberId, content, memberNickname,
nickname, profileOnOff, linkAttachments, musicName, musicSinger, musicAudioUrl, imageUrl, createdDate);


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public class Answer {
@Column(name = "sad_count", nullable = false)
private int sadCount;

@Column(name = "connect_count", nullable = false)
private int connectCount;

@Column(name = "created_date", nullable = false)
private LocalDateTime createdDate;

Expand All @@ -82,23 +85,10 @@ public class Answer {

public static Answer of(Long id, Question question, Category category, Member member, String nickname,String content,
List<String> imageFiles, Music music, String linkAttachments, String imageUrl, int heartCount,
int curiousCount, int sadCount, LocalDateTime createdDate, boolean profileOnOff) {
int curiousCount, int sadCount, int connectCount, LocalDateTime createdDate, boolean profileOnOff) {

return new Answer(id, question, category, member, nickname, imageFiles, content, music, linkAttachments,imageUrl, heartCount,
curiousCount, sadCount, createdDate,null, profileOnOff);
curiousCount, sadCount, connectCount, createdDate,null, profileOnOff);
}

public void increaseReactionCount(ReactionValue reaction) {
switch (reaction) {
case HEART: // 좋아요
this.heartCount++;
break;
case CURIOUS: // 궁금해요
this.curiousCount++;
break;
case SAD: // 슬퍼요
this.sadCount++;
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public AnswerDetailResponse toDomain(Answer answer) {
music != null ? music.getMusicAudioUrl() : null,
imageUrl,
answer.getCreatedDate()

);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ public class FcmController implements FcmApi {
@PostMapping("/{memberId}")
public ResponseEntity<Void> addFcmToken(
@PathVariable Long memberId,
@RequestBody FcmRequest.Token request
@RequestBody FcmRequest.CreateToken request
) {
FcmToken token = fcmService.addFcmToken(memberId, request.getFcmToken());
return ResponseEntity.ok().build();
}

@PutMapping("/{memberId}")
public ResponseEntity<Void> updateFcmToken(
@PathVariable Long memberId,
@RequestBody FcmRequest.UpdateToken request
) {
fcmService.updateFcmToken(request.getOldFcmToken(), request.getNewFcmToken(), memberId);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,37 @@ public interface FcmApi {
})
@RequestMapping(method = RequestMethod.POST, value = "/{memberId}")
ResponseEntity<Void> addFcmToken(@PathVariable Long memberId,
@RequestBody FcmRequest.Token request);
@RequestBody FcmRequest.CreateToken request);


@Operation(
summary = "FCM 토큰 업데이트",
description = "회원의 기존 FCM 토큰을 새로운 FCM 토큰으로 업데이트합니다.",
security = @SecurityRequirement(name = "bearerAuth")
)
@Parameter(
in = ParameterIn.HEADER,
name = "Authorization", required = true,
schema = @Schema(type = "string"),
description = "Bearer [Access 토큰]")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "업데이트 성공"),
@ApiResponse(responseCode = "401", description = "토큰 인증 실패",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = "{\n" +
" \"errorCode\": \"T-002\",\n" +
" \"message\": \"해당 토큰은 유효한 토큰이 아닙니다.\"\n" +
"}"))
),
@ApiResponse(responseCode = "404", description = "존재하지 않는 회원",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = "{\n" +
" \"errorCode\": \"M-002\",\n" +
" \"message\": \"존재하지 않는 회원입니다.\"\n" +
"}"))
)
})
@RequestMapping(method = RequestMethod.PUT, value = "/{memberId}")
ResponseEntity<Void> updateFcmToken(@PathVariable Long memberId,
@RequestBody FcmRequest.UpdateToken request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ public class FcmRequest {
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class Token{
public static class CreateToken{
private String fcmToken;
}

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class UpdateToken{
private String oldFcmToken;
private String newFcmToken;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class FcmToken {
@OnDelete(action = OnDeleteAction.CASCADE)
private Member member;

public void updateToken(String newToken) {
this.token = newToken;
}
public void updateLastUsedTime() {
this.lastUsedTime = LocalDateTime.now();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
@RequiredArgsConstructor
public enum FcmException implements ErrorCode {

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

private final HttpStatus httpStatus;
private final String errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.transaction.annotation.Transactional;

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

@Service
@Transactional
Expand All @@ -37,6 +38,36 @@ public FcmToken addFcmToken(Long memberId, String fcmToken) {
return fcmTokenRepository.save(token);
}

public void updateFcmToken(String oldFcmToken, String newFcmToken, Long memberId) {
FcmToken token = fcmTokenRepository.findByToken(oldFcmToken)
.orElseThrow(() -> new BusinessException(FcmException.NOT_FOUND_FCM));

if (!token.getMember().getId().equals(memberId))
throw new BusinessException(FcmException.NOT_MATCH_MEMBER);

token.updateToken(newFcmToken);
fcmTokenRepository.save(token);
}

public void verifyFcmToken(Long memberId, String fcmToken) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new BusinessException(MemberException.NOT_EXIST_MEMBER));

Optional<FcmToken> fcmTokenOptional= fcmTokenRepository.findByToken(fcmToken);
if(fcmTokenOptional.isEmpty()) {
FcmToken token = FcmToken.builder()
.token(fcmToken)
.member(member)
.lastUsedTime(LocalDateTime.now())
.build();

fcmTokenRepository.save(token);
}
}




// FCM 토큰의 마지막 사용 시간을 현재 시간으로 업데이트
public void updateLastUsedTime(FcmToken fcmToken) {
fcmToken.updateLastUsedTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ public ResponseEntity<LoginResponse.SignUpResponse> oauthSignUp(
KakaoUserInfoDto kakaoUserInfo = loginService.getKakaoUserInfo(httpServletRequest);

// 이미 회원이 존재하면 로그인, 없을 시 회원가입 진행
if (loginService.isExistingUser(kakaoUserInfo.getKakaoAccount().getEmail())) {
return ResponseEntity.ok(loginService.loginWithExistingUser(kakaoUserInfo, signUpRequest));
} else {
return ResponseEntity.ok(loginService.signUpNewUser(kakaoUserInfo, signUpRequest));
}
LoginResponse.SignUpResponse response = null;
if (loginService.isExistingUser(kakaoUserInfo.getKakaoAccount().getEmail()))
response = loginService.loginWithExistingUser(kakaoUserInfo, signUpRequest);
else
response = loginService.signUpNewUser(kakaoUserInfo, signUpRequest);

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

return ResponseEntity.ok(response);
}

//회원가입 유무 판별
Expand Down Expand Up @@ -88,7 +93,7 @@ public ResponseEntity<LoginResponse.AccessTokenResponse> refreshToken(
@PostMapping("/logout")
public ResponseEntity<Void> logout(
HttpServletRequest httpServletRequest,
@RequestParam String fcmToken
@RequestParam(required = false) String fcmToken
) {
String authorizationHeader = httpServletRequest.getHeader("Authorization");
String accessToken = null;
Expand All @@ -98,8 +103,10 @@ public ResponseEntity<Void> logout(

//로그아웃 진행
manageTokenService.logoutMember(accessToken);

//fcmToken 삭제
fcmService.deleteFcmToken(fcmToken);
if(fcmToken != null)
fcmService.deleteFcmToken(fcmToken);

return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.lang.Nullable;


public class LoginRequest {
Expand All @@ -20,6 +21,8 @@ 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 @@ -33,7 +33,7 @@ public QuestionDetailResponse createQuestion(QuestionCreateRequest request, Long
Question question = questionMapper.toEntity(request, member);
Question savedQuestion = questionRepository.save(question);

firebaseNotificationService.notifyNewQuestion(member, question); // 파이어베이스 메세지 송신
//firebaseNotificationService.notifyNewQuestion(member, question); // 파이어베이스 메세지 송신

return questionMapper.toDomain(savedQuestion);
}
Expand All @@ -54,7 +54,7 @@ public QuestionDetailResponse updateQuestion(Long questionId, String content, Bo
// 질문 업데이트 후 저장
Question updatedQuestion = questionRepository.save(question);

firebaseNotificationService.notifyNewQuestion(updatedQuestion.getMember(), updatedQuestion); // 파이어베이스 메세지 송신
//firebaseNotificationService.notifyNewQuestion(updatedQuestion.getMember(), updatedQuestion); // 파이어베이스 메세지 송신

return questionMapper.toDomain(updatedQuestion);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ResponseEntity<ReactionResponse.ReactionInformationDto> createReaction(
return ResponseEntity.ok(memberAnswerReactionService.createReaction(memberId, answerId, reactionDto.getReaction()));
}

// 통했당~
/*// 통했당~
@PostMapping("/connection/{memberId}/{answerId}/{destinationMemberId}")
public ResponseEntity<ReactionResponse.ConnectionReactionInformationDto> createClickReaction(
@PathVariable Long memberId, // 자기자신 (통했당 하는 주체)
Expand All @@ -36,5 +36,5 @@ public ResponseEntity<ReactionResponse.ConnectionReactionInformationDto> createC
return ResponseEntity.ok(memberAnswerReactionService.createConnectionReaction(memberId, answerId));
else
return ResponseEntity.ok(memberAnswerReactionService.connectConnectionReaction(memberId, answerId, destinationMemberId));
}
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ResponseEntity<ReactionResponse.ReactionInformationDto> createReaction(@Paramete
@Parameter(description = "답변의 ID", required = true) @PathVariable Long answerId,
@RequestBody ReactionRequest.create reactionDto);

@Operation(
/* @Operation(
summary = "통했당 생성",
description = "지정된 멤버 ID, 답변 ID, 대상 멤버 ID에 대한 '통했당'을 생성합니다. " +
"다른 피드에 '통했당'을 남길경우 memberId, answerId만 필요합니다. " +
Expand Down Expand Up @@ -98,5 +98,5 @@ ResponseEntity<ReactionResponse.ReactionInformationDto> createReaction(@Paramete
})
ResponseEntity<ReactionResponse.ConnectionReactionInformationDto> createClickReaction(@Parameter(description = "멤버의 ID", required = true) @PathVariable Long memberId,
@Parameter(description = "답변의 ID", required = true) @PathVariable Long answerId,
@Parameter(description = "대상 멤버의 ID (피드주인이 통했당 완료할때만 가능)", required = false) @RequestParam(required = false) Long destinationMemberId);
@Parameter(description = "대상 멤버의 ID (피드주인이 통했당 완료할때만 가능)", required = false) @RequestParam(required = false) Long destinationMemberId);*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ public static class ReactionInformationDto {
private int heartCount;
private int curiousCount;
private int sadCount;
private int connectCount;

public static ReactionInformationDto of(Answer answer, boolean isClicked) {
return ReactionInformationDto.builder()
.isClicked(isClicked)
.heartCount(answer.getHeartCount())
.curiousCount(answer.getCuriousCount())
.sadCount(answer.getSadCount())
.connectCount(answer.getConnectCount())
.build();
}
}

@Getter
/*@Getter
@Setter
@Builder
@NoArgsConstructor
Expand All @@ -60,5 +62,5 @@ public static ConnectionReactionInformationDto of(boolean isClicked, boolean isM
.isMatched(isMatched)
.build();
}
}
}*/
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.web.baebaeBE.domain.reaction.entity;

public enum ReactionValue {
HEART, CURIOUS, SAD, CONNECTION
HEART, CURIOUS, SAD, CONNECT
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ReactionResponse.ReactionInformationDto createReaction(Long memberId, Lon
return ReactionResponse.ReactionInformationDto.of(answer,isClicked);
}

// 피드 주인이 아닌 다른 사람이 통했당 신청
/*// 피드 주인이 아닌 다른 사람이 통했당 신청
public ReactionResponse.ConnectionReactionInformationDto createConnectionReaction(Long memberId, Long answerId) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new BusinessException(ReactionException.NOT_EXIST_MEMBER));
Expand Down Expand Up @@ -107,5 +107,5 @@ public ReactionResponse.ConnectionReactionInformationDto connectConnectionReacti
} else {
throw new BusinessException(ReactionException.NOT_EXIST_CONNECTION_REACTION);
}
}
}*/
}
Loading

0 comments on commit 9336d62

Please sign in to comment.