Skip to content

Commit

Permalink
Merge pull request #86 from KUIT-Space/feat/#82/스페이스-전체-설정-스페이스-프로필-관…
Browse files Browse the repository at this point in the history
…리-view-api

Feat/#82/스페이스 전체 설정 스페이스 프로필 관리 view api
  • Loading branch information
seongjunnoh authored Aug 12, 2024
2 parents fbd098d + 1da3782 commit 0c229d5
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/space/space_spring/config/InterceptorURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public enum InterceptorURL {
SPACE("/space/**"),
TEST("/test/**"),
SPACE_LIST_FOR_USER("/user/space-choice"),
VOICE_ROOM("/voiceRoom/**");
VOICE_ROOM("/voiceRoom/**"),
USER_PROFILE_LIST("/user/profile");

private final String urlPattern;

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/space/space_spring/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
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.request.PostUserLoginRequest;
import space.space_spring.dto.user.request.PostUserSignupRequest;
Expand Down Expand Up @@ -68,4 +69,14 @@ public BaseResponse<GetSpaceInfoForUserResponse> showUserSpaceList(@JwtLoginAuth
return new BaseResponse<>(userService.getSpaceListForUser(userId, size, lastUserSpaceId));
}

/**
* 스페이스 전체 설정 -> 스페이스 프로필 관리 view
*/
@GetMapping("/profile")
public BaseResponse<GetUserProfileListDto.Response> showUserProfileList(@JwtLoginAuth Long userId) {

log.info("userId = {}", userId);

return new BaseResponse<>(userService.getUserProfileList(userId));
}
}
8 changes: 8 additions & 0 deletions src/main/java/space/space_spring/dao/UserSpaceDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,20 @@ public int calculateSpaceMemberNum(Space space) {
return query.getSingleResult().intValue();
}

public List<UserSpace> findUserSpaceListByUser(User user) {
String jpql = "SELECT us FROM UserSpace us WHERE us.user = :user AND us.status = 'ACTIVE'";
TypedQuery<UserSpace> query = em.createQuery(jpql, UserSpace.class);
query.setParameter("user", user);

return query.getResultList();
}

@Transactional(readOnly = true)
public String findUserSpaceAuthById(Long userSpaceId) {
String jpql = "SELECT us.userSpaceAuth FROM UserSpace us WHERE us.userSpaceId = :userSpaceId";
return em.createQuery(jpql, String.class)
.setParameter("userSpaceId", userSpaceId)
.getSingleResult();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package space.space_spring.dto.user;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.checkerframework.checker.units.qual.A;

import java.util.List;

@Getter
@AllArgsConstructor
public class GetUserProfileListDto {

@Getter
@AllArgsConstructor
public static class Response {

private List<UserProfile> userProfileList;
}

@Getter
@AllArgsConstructor
public static class UserProfile {

private Long spaceId;

private String spaceName;

private String userName;

private String userProfileImg;

private String userAuth;
}
}
35 changes: 35 additions & 0 deletions src/main/java/space/space_spring/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import space.space_spring.dao.UserSpaceDao;
import space.space_spring.dto.user.GetUserProfileListDto;
import space.space_spring.dto.user.dto.SpaceChoiceViewDto;
import space.space_spring.dto.user.request.PostUserLoginRequest;
import space.space_spring.dto.user.request.PostUserSignupRequest;
Expand All @@ -20,6 +21,8 @@
import space.space_spring.util.user.UserUtils;
import space.space_spring.util.userSpace.UserSpaceUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static space.space_spring.entity.enumStatus.UserSignupType.LOCAL;
Expand Down Expand Up @@ -96,4 +99,36 @@ public GetSpaceInfoForUserResponse getSpaceListForUser(Long userId, int size, Lo
return new GetSpaceInfoForUserResponse(userName, spaceChoiceViewDto.getLastUserSpaceId(), spaceChoiceViewDto.getSpaceChoiceInfoList());
}

@Transactional
public GetUserProfileListDto.Response getUserProfileList(Long userId) {
// TODO 1. userId로 User find
User userByUserId = userUtils.findUserByUserId(userId);

// TODO 2. 유저가 속해있는 UserSpace list get
List<UserSpace> userSpaceListByUser = userSpaceDao.findUserSpaceListByUser(userByUserId);

// TODO 3. return
List<GetUserProfileListDto.UserProfile> userProfileList = createUserProfileList(userSpaceListByUser);

return new GetUserProfileListDto.Response(userProfileList);
}

private List<GetUserProfileListDto.UserProfile> createUserProfileList(List<UserSpace> userSpaceList) {
List<GetUserProfileListDto.UserProfile> userProfileList = new ArrayList<>();

for (UserSpace userSpace : userSpaceList) {
GetUserProfileListDto.UserProfile userProfile = new GetUserProfileListDto.UserProfile(
userSpace.getSpace().getSpaceId(),
userSpace.getSpace().getSpaceName(),
userSpace.getUserName(),
userSpace.getUserProfileImg(),
userSpace.getUserSpaceAuth()
);

userProfileList.add(userProfile);
}

return userProfileList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public enum AllowedImageFileExtensions {
}

public static boolean contains(String extension) {
extension = extension.toLowerCase(); // 입력된 확장자를 소문자로 변환

for (AllowedImageFileExtensions allowedImageFileExtensions : AllowedImageFileExtensions.values()) {
if (allowedImageFileExtensions.getExtension().equals(extension)) {
return true;
Expand Down

0 comments on commit 0c229d5

Please sign in to comment.