Skip to content

Commit

Permalink
Merge pull request #126 from KUIT-Space/develop
Browse files Browse the repository at this point in the history
24.08.19 배포
  • Loading branch information
hyunn522 authored Aug 18, 2024
2 parents 27830f7 + 5c90d5d commit 57b706d
Show file tree
Hide file tree
Showing 20 changed files with 154 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ public BaseResponse<CreateChatRoomResponse> createChatRoom(
public BaseResponse<ReadChatRoomMemberResponse> readChatRoomMembers(
@JwtLoginAuth Long userId,
@PathVariable Long spaceId,
@PathVariable Long chatRoomId,
@UserSpaceAuth String userSpaceAuth) {

validateManagerPermission(userSpaceAuth);

@PathVariable Long chatRoomId) {
return new BaseResponse<>(chatRoomService.readChatRoomMembers(spaceId, chatRoomId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import space.space_spring.dto.oAuth.KakaoInfo;
import space.space_spring.dto.oAuth.OAuthLoginResponse;
import space.space_spring.entity.User;
import space.space_spring.response.BaseResponse;
import space.space_spring.service.OAuthService;
Expand All @@ -35,7 +36,7 @@ public class OAuthController {
* 유저가 카카오 로그인 동의 시 호출될 콜백 함수
*/
@GetMapping("/callback/kakao")
public BaseResponse<String> kakaoCallback(@RequestParam(name = "code") String code, HttpServletResponse response) {
public BaseResponse<OAuthLoginResponse> kakaoCallback(@RequestParam(name = "code") String code, HttpServletResponse response) {

// TODO 1. 인가코드 받기
// 카카오 인증 서버는 서비스 서버의 Redirect URI로 인가 코드를 전달함
Expand Down Expand Up @@ -70,6 +71,6 @@ public BaseResponse<String> kakaoCallback(@RequestParam(name = "code") String co
response.setHeader("Authorization", "Bearer " + jwtOAuthLogin);
log.info("jwtOAuthLogin = {}", jwtOAuthLogin);

return new BaseResponse<>("카카오 로그인 성공");
return new BaseResponse<>(new OAuthLoginResponse(userByOAuthInfo.getUserId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.web.bind.annotation.*;
import space.space_spring.dto.user.GetUserProfileListDto;
import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth;
import space.space_spring.dto.user.PostLoginDto;
import space.space_spring.dto.user.request.PostUserLoginRequest;
import space.space_spring.dto.user.request.PostUserSignupRequest;
import space.space_spring.dto.user.response.GetSpaceInfoForUserResponse;
Expand Down Expand Up @@ -49,15 +50,15 @@ public BaseResponse<String> signup(@Validated @RequestBody PostUserSignupRequest
* 로그인
*/
@PostMapping("/login")
public BaseResponse<String> login(@Validated @RequestBody PostUserLoginRequest postUserLoginRequest, BindingResult bindingResult, HttpServletResponse response) {
public BaseResponse<PostLoginDto.Response> login(@Validated @RequestBody PostLoginDto.Request request, BindingResult bindingResult, HttpServletResponse response) {
if (bindingResult.hasErrors()) {
throw new CustomException(INVALID_USER_LOGIN, getErrorMessage(bindingResult));
}

String jwtLogin = userService.login(postUserLoginRequest);
response.setHeader("Authorization", "Bearer " + jwtLogin);
PostLoginDto login = userService.login(request);
response.setHeader("Authorization", "Bearer " + login.getJwt());

return new BaseResponse<>("로컬 로그인 성공");
return new BaseResponse<>(new PostLoginDto.Response(login.getUserId()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.web.bind.annotation.*;
import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth;
import space.space_spring.argumentResolver.userSpace.UserSpaceAuth;
import space.space_spring.argumentResolver.userSpace.UserSpaceId;
import space.space_spring.dao.UserSpaceDao;
import space.space_spring.dao.VoiceRoomRepository;
import space.space_spring.dto.VoiceRoom.*;
Expand Down Expand Up @@ -84,6 +85,7 @@ public BaseResponse<String> getToken(
@PathVariable("spaceId") @NotNull long spaceId,
@JwtLoginAuth Long userId,
@PathVariable("voiceRoomId") @NotNull Long roomId,
@UserSpaceId Long userSpaceId,
HttpServletResponse response
){

Expand All @@ -92,7 +94,7 @@ public BaseResponse<String> getToken(
//해당 voiceRoom이 해당 space에 속한것이 맞는지 확인
validateVoiceRoomInSpace(spaceId,roomId);

response.setHeader("Authorization", "Bearer " + voiceRoomService.getToken(spaceId, userId,roomId));
response.setHeader("Authorization", "Bearer " + voiceRoomService.getToken(spaceId, userId,userSpaceId,roomId));
return new BaseResponse<String>(
"보이스룸 토큰 생성에 성공했습니다."
);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/space/space_spring/dao/UserDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,5 @@ public User getUserByEmail(String email, UserSignupType signupType) {
public User findUserByUserId(Long userId) {
return em.find(User.class, userId);
}
public String findProfileImageByUserId(Long userId){
return "Test ProfileImage URL";//findUserByUserId(userId).getProfileImage();
}

}
17 changes: 17 additions & 0 deletions src/main/java/space/space_spring/dao/UserSpaceDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import space.space_spring.entity.enumStatus.UserSpaceAuth;

import java.util.*;
import java.util.stream.Stream;

import static space.space_spring.entity.enumStatus.UserSpaceAuth.MANAGER;

Expand Down Expand Up @@ -134,4 +135,20 @@ public String findUserSpaceAuthById(Long userSpaceId) {
.getSingleResult();

}

public Optional<String> findProfileImageById(Long userSpaceId){
String jpql = "SELECT us.userProfileImg FROM UserSpace us WHERE us.userSpaceId = :userSpaceId AND us.status = 'ACTIVE'";
List<String> result = em.createQuery(jpql, String.class)
.setParameter("userSpaceId",userSpaceId)
.getResultList();
return result.isEmpty() ? Optional.empty() : Optional.ofNullable(result.get(0));
}

public String findUserNameById(Long userSpaceId){
String jpql = "SELECT us.userName FROM UserSpace us WHERE us.userSpaceId = :userSpaceId AND us.status = 'ACTIVE'";
return em.createQuery(jpql, String.class)
.setParameter("userSpaceId", userSpaceId)
.getSingleResult();

}
}
1 change: 1 addition & 0 deletions src/main/java/space/space_spring/dao/VoiceRoomDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Long createVoiceRoom(String name,int order,Space space){
}
}


}


Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static class VoiceRoomInfo{
private int numParticipant;
private int order;
private List<GetParticipantList.ParticipantInfo> participantInfoList;
private String metadate;

public static VoiceRoomInfo convertRoomDto(RoomDto roomDto){
if(roomDto==null){return null;}
Expand All @@ -45,6 +46,7 @@ public static VoiceRoomInfo convertRoomDto(RoomDto roomDto){
.Active(roomDto.getNumParticipants()!=0)
.numParticipant(roomDto.getNumParticipants())
.order(roomDto.getOrder())
.metadate(roomDto.getMetadata())
.participantInfoList(
GetParticipantList.ParticipantInfo.convertParticipantDtoList(roomDto.getParticipantDTOList())
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void setActiveRoom(List<LivekitModels.Room> liveKitRoomList){
if(liveKitRoomList==null||liveKitRoomList.isEmpty()){return;}
boolean find = false;
for(LivekitModels.Room resRoom : liveKitRoomList){
if(EqualRoomIdByNameTag(resRoom.getName(),this.id)){
if(String.valueOf(this.id).equals( resRoom.getName() )){
this.numParticipants = resRoom.getNumParticipants();
this.sid = resRoom.getSid();
this.metadata = resRoom.getMetadata();
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/space/space_spring/dto/oAuth/OAuthLoginResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package space.space_spring.dto.oAuth;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class OAuthLoginResponse {

private Long userId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -28,4 +29,6 @@ public class TotalPayInfoDto {

private boolean isComplete;

private LocalDateTime createdAt; // 정산 생성일 정보

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class Response {

private String spaceName;

private String createdAt; // 스페이스 개설일의 정보를 yyyy년 mm월 dd일 형식으로 변환한 문자열
private LocalDateTime createdAt;

private int memberNum;
}
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/space/space_spring/dto/user/PostLoginDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package space.space_spring.dto.user;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class PostLoginDto {

private String jwt;

private Long userId;

@Getter
@Setter
@NoArgsConstructor
public static class Request {
// '@', '.' 이 있어야 함
@Pattern(regexp = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}$", message = "이메일 형식에 맞지 않습니다.")
@NotBlank
private String email;

@Pattern(
regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,16}$",
message = "8~16글자의 영문 대/소문자, 숫자, 특수문자가 포함되어야 합니다."
)
@NotBlank
private String password;
}

@Getter
@AllArgsConstructor
public static class Response {

private Long userId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public enum BaseExceptionResponseStatus implements ResponseStatus {
CHATROOM_NOT_EXIST(8001, HttpStatus.NOT_FOUND, "존재하지 않는 채팅방입니다."),
INVALID_CHATROOM_JOIN(8001, HttpStatus.BAD_REQUEST, "채팅방 멤버 초대 요청에서 잘못된 값이 존재합니다."),
BASE64_CONVERT_FAIL_IN_MEMORY(8002, HttpStatus.INTERNAL_SERVER_ERROR, "base64 파일 변환 과정에서 문제가 생겼습니다."),
USER_IS_ALREADY_IN_CHAT_ROOM(8003, HttpStatus.BAD_REQUEST, "해당 채팅방에 이미 초대된 멤버가 포함되어 있습니다."),

/**
* 9000 : MultipartFile 오류
Expand Down
42 changes: 30 additions & 12 deletions src/main/java/space/space_spring/service/ChatRoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
import space.space_spring.dto.userSpace.UserInfoInSpace;
import space.space_spring.entity.*;
import space.space_spring.entity.document.ChatMessage;
import static space.space_spring.response.status.BaseExceptionResponseStatus.CHATROOM_NOT_EXIST;
import static space.space_spring.response.status.BaseExceptionResponseStatus.USER_IS_NOT_IN_SPACE;

import space.space_spring.exception.CustomException;
import space.space_spring.util.space.SpaceUtils;
import space.space_spring.util.user.UserUtils;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

import static space.space_spring.response.status.BaseExceptionResponseStatus.*;

@Service
@Slf4j
@RequiredArgsConstructor
Expand All @@ -48,14 +49,19 @@ public ReadChatRoomResponse readChatRooms(Long userId, Long spaceId) {
Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId);

// TODO 3: 해당 user의 해당 space 내의 채팅방 리스트 return
List<ChatRoom> result = chatRoomDao.findByUserAndSpace(userByUserId, spaceBySpaceId);
List<ChatRoom> chatRoomList = chatRoomDao.findByUserAndSpace(userByUserId, spaceBySpaceId);

// TODO 4: chatRoom 리스트에서 active만 find
List<ChatRoom> activeChatRooms = chatRoomList.stream()
.filter(userChatRoom -> "ACTIVE".equals(userChatRoom.getStatus()))
.toList();

return ReadChatRoomResponse.of(result.stream()
return ReadChatRoomResponse.of(activeChatRooms.stream()
.map(cr -> {
// TODO 4: 각 채팅방의 마지막으로 업데이트된 메시지 정보 find
// TODO 5: 각 채팅방의 마지막으로 업데이트된 메시지 정보 find
ChatMessage lastMsg = chattingDao.findTopByChatRoomIdOrderByCreatedAtDesc(cr.getId());

LocalDateTime lastUpdateTime = LocalDateTime.now();
LocalDateTime lastUpdateTime = cr.getCreatedAt().atZone(ZoneId.of("Asia/Seoul")).toLocalDateTime();
HashMap<String, String> lastContent = new HashMap<>();
lastContent.put("text", "메시지를 전송해보세요");

Expand All @@ -64,9 +70,9 @@ public ReadChatRoomResponse readChatRooms(Long userId, Long spaceId) {
lastContent = lastMsg.getContent();
}

// TODO 5: 각 채팅방의 안읽은 메시지 개수 계산
// TODO 6: 각 채팅방의 안읽은 메시지 개수 계산
UserChatRoom userChatRoom = userChatRoomDao.findByUserAndChatRoom(userByUserId, cr);
LocalDateTime lastReadTime = userChatRoom.getLastReadTime();
LocalDateTime lastReadTime = userChatRoom.getLastReadTime().atZone(ZoneId.of("Asia/Seoul")).toLocalDateTime();
int unreadMsgCount = chattingDao.countByChatRoomIdAndCreatedAtBetween(
cr.getId(),
lastReadTime,
Expand Down Expand Up @@ -111,14 +117,19 @@ public ReadChatRoomMemberResponse readChatRoomMembers(Long spaceId, Long chatRoo
// TODO 3: 해당 chatRoom의 userChatRoom 리스트 find
List<UserChatRoom> userChatRoomList = userChatRoomDao.findByChatRoom(chatRoomById);

userChatRoomList.forEach(userChatRoom -> {
// TODO 4: userChatRoom 리스트에서 active만 find
List<UserChatRoom> activeUserChatRooms = userChatRoomList.stream()
.filter(userChatRoom -> "ACTIVE".equals(userChatRoom.getStatus()))
.toList();

activeUserChatRooms.forEach(userChatRoom -> {
User user = userChatRoom.getUser();

// TODO 4: 스페이스 프로필 이미지 get 위해 userSpace find
// TODO 5: 스페이스 프로필 이미지 get 위해 userSpace find
UserSpace userSpace = userSpaceDao.findUserSpaceByUserAndSpace(user, spaceById)
.orElseThrow(() -> new CustomException(USER_IS_NOT_IN_SPACE));

userList.add(new UserInfoInSpace(user.getUserId(), user.getUserName(), userSpace.getUserProfileImg(), user.getSignupType()));
userList.add(new UserInfoInSpace(user.getUserId(), userSpace.getUserName(), userSpace.getUserProfileImg(), userSpace.getUserSpaceAuth()));
});

return ReadChatRoomMemberResponse.of(userList);
Expand All @@ -136,7 +147,7 @@ public ChatSuccessResponse joinChatRoom(Long chatRoomId, JoinChatRoomRequest joi

// TODO 2: 유저가 이미 채팅방에 초대되어있는지 검증
if (isUserInChatRoom(userByUserId, chatRoomByChatRoomId)) {
return ChatSuccessResponse.of(false);
throw new CustomException(USER_IS_ALREADY_IN_CHAT_ROOM);
}

// TODO 3: 초대한 유저에 대한 userChatRoom 테이블 생성
Expand Down Expand Up @@ -169,6 +180,9 @@ public ChatSuccessResponse exitChatRoom(Long userId, Long chatRoomId) {
// TODO 2: 해당 userChatRoom inactive로 변경
userChatRoom.updateInactive();

// TODO 3: DB에 변경 사항 저장
userChatRoomDao.save(userChatRoom);

return ChatSuccessResponse.of(true);
}

Expand All @@ -177,8 +191,12 @@ public ChatSuccessResponse deleteChatRoom(Long chatRoomId) {
ChatRoom chatRoomByChatRoomId = chatRoomDao.findById(chatRoomId)
.orElseThrow(() -> new CustomException(CHATROOM_NOT_EXIST));

// TODO 2: 해당 chatRoom inactive로 변경
chatRoomByChatRoomId.updateInactive();

// TODO 3: DB에 변경 사항 저장
chatRoomDao.save(chatRoomByChatRoomId);

return ChatSuccessResponse.of(true);
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/space/space_spring/service/PayService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import space.space_spring.util.space.SpaceUtils;
import space.space_spring.util.user.UserUtils;

import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -181,7 +183,8 @@ public TotalPayInfoDto getTotalPayInfo(Long spaceId, Long payRequestId) {
payRequestInfoDto.getTotalTargetNum(),
payRequestInfoDto.getReceiveTargetNum(),
payTargetInfoDtoList,
payRequestById.isComplete()
payRequestById.isComplete(),
payRequestById.getCreatedAt().atZone(ZoneId.of("Asia/Seoul")).toLocalDateTime()
);
}

Expand Down
Loading

0 comments on commit 57b706d

Please sign in to comment.