Skip to content

Commit

Permalink
Merge pull request #83 from KUIT-Space/develop
Browse files Browse the repository at this point in the history
24.08.12 16:50 ๋ฐฐํฌ
  • Loading branch information
seongjunnoh authored Aug 12, 2024
2 parents 49fbed1 + 96ce12d commit af8f545
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 26 deletions.
97 changes: 95 additions & 2 deletions src/main/java/space/space_spring/controller/SpaceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
import org.springframework.web.multipart.MultipartFile;
import space.space_spring.argument_resolver.jwtLogin.JwtLoginAuth;
import space.space_spring.dto.space.GetSpaceJoinDto;
import space.space_spring.dto.space.PostSpaceJoinDto;
import space.space_spring.dto.space.response.GetUserInfoBySpaceResponse;
import space.space_spring.dto.space.request.PostSpaceCreateRequest;

import space.space_spring.dto.userSpace.GetUserProfileInSpaceDto;
import space.space_spring.dto.userSpace.PutUserProfileInSpaceDto;
import space.space_spring.entity.UserSpace;
import space.space_spring.exception.CustomException;
import space.space_spring.exception.MultipartFileException;
import space.space_spring.exception.SpaceException;
import space.space_spring.response.BaseResponse;
Expand All @@ -19,9 +24,9 @@
import space.space_spring.util.userSpace.UserSpaceUtils;

import java.io.IOException;
import java.util.Optional;

import static space.space_spring.response.status.BaseExceptionResponseStatus.INVALID_SPACE_CREATE;
import static space.space_spring.response.status.BaseExceptionResponseStatus.IS_NOT_IMAGE_FILE;
import static space.space_spring.response.status.BaseExceptionResponseStatus.*;
import static space.space_spring.util.bindingResult.BindingResultUtils.getErrorMessage;

@RestController
Expand All @@ -33,6 +38,7 @@ public class SpaceController {
private final SpaceService spaceService;
private final S3Uploader s3Uploader;
private final String spaceImgDirName = "spaceImg";
private final String userProfileImgDirName = "userProfileImg";
private final UserSpaceUtils userSpaceUtils;

@PostMapping("")
Expand Down Expand Up @@ -93,4 +99,91 @@ private void validateIsUserAlreadySpaceMember(Long userId, Long spaceId) {
userSpaceUtils.isUserAlreadySpaceMember(userId, spaceId);
}

/**
* ์ŠคํŽ˜์ด์Šค ๋ณ„ ์œ ์ € ํ”„๋กœํ•„ ์ •๋ณด ์กฐํšŒ
* ๋ณธ์ธ์˜ ํ”„๋กœํ•„ ์กฐํšŒํ•˜๋Š” ๊ฒฝ์šฐ -> requestParam์œผ๋กœ userId ๋ฐ›์ง€ X
* ๋‹ค๋ฅธ ๋ฉค๋ฒ„์˜ ํ”„๋กœํ•„ ์กฐํšŒํ•˜๋Š” ๊ฒฝ์šฐ -> requestParam์œผ๋กœ userId ๋ฐ›์Œ
*/
@GetMapping("/{spaceId}/member-profile")
public BaseResponse<GetUserProfileInSpaceDto.Response> getUserProfileInSpace(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @RequestParam(name = "userId", required = false) Long targetUserId) {

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

// TODO 1. ์š”์ฒญ๋ณด๋‚ด๋Š” ์œ ์ €๊ฐ€ ์ŠคํŽ˜์ด์Šค์— ๊ฐ€์ž…๋˜์–ด ์žˆ๋Š”์ง€ ๊ฒ€์ฆ
validateIsUserInSpace(userId, spaceId);

// TODO 2. ๋ณธ์ธ์˜ ํ”„๋กœํ•„์„ ์กฐํšŒํ•˜๋Š”์ง€ ๋‹ค๋ฅธ ๋ฉค๋ฒ„์˜ ํ”„๋กœํ•„์„ ์กฐํšŒํ•˜๋Š”์ง€ ์ฒดํฌ
if (targetUserId == null) {
targetUserId = userId;
}

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

// TODO 3. ์œ ์ € ํ”„๋กœํ•„ ์ •๋ณด return
return new BaseResponse<>(spaceService.getUserProfileInSpace(targetUserId, spaceId));
}

private void validateIsUserInSpace(Long userId, Long spaceId) {
userSpaceUtils.isUserInSpace(userId, spaceId);
}

/**
* ์ŠคํŽ˜์ด์Šค ๋ณ„ ์œ ์ € ํ”„๋กœํ•„ ์ •๋ณด ์ˆ˜์ •
*/
@PutMapping("/{spaceId}/member-profile")
public BaseResponse<PutUserProfileInSpaceDto.Response> updateUserProfileInSpace(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @Validated @ModelAttribute PutUserProfileInSpaceDto.Request request, BindingResult bindingResult) throws IOException {
if (bindingResult.hasErrors()) {
throw new SpaceException(INVALID_USER_SPACE_PROFILE, getErrorMessage(bindingResult));
}

// TODO 1. ์œ ์ €๊ฐ€ ์ŠคํŽ˜์ด์Šค์— ๊ฐ€์ž…๋˜์–ด ์žˆ๋Š”์ง€ ๊ฒ€์ฆ
validateIsUserInSpace(userId, spaceId);

// TODO 2. ์œ ์ € ํ”„๋กœํ•„ ์ธ๋„ค์ผ์„ s3์— upload
String userProfileImgUrl = processUserProfileImage(request.getUserProfileImg());

// TODO 3. ์œ ์ € ํ”„๋กœํ•„ ์ •๋ณด update
PutUserProfileInSpaceDto putUserProfileInSpaceDto = new PutUserProfileInSpaceDto(
request.getUserName(),
userProfileImgUrl,
request.getUserProfileMsg()
);

return new BaseResponse<>(spaceService.changeUserProfileInSpace(userId, spaceId, putUserProfileInSpaceDto));
}

private String processUserProfileImage(MultipartFile userProfileImg) throws IOException {
if (userProfileImg == null) {
return null;
}
validateImageFile(userProfileImg);
return s3Uploader.upload(userProfileImg, userProfileImgDirName);
}

/**
* ์œ ์ €์˜ ์ŠคํŽ˜์ด์Šค ๊ฐ€์ž… ์ฒ˜๋ฆฌ
*/
@PostMapping("/{spaceId}/join")
BaseResponse<String> joinUserToSpace(@JwtLoginAuth Long userId, @PathVariable Long spaceId, @Validated @ModelAttribute PostSpaceJoinDto.Request request, BindingResult bindingResult) throws IOException {
if (bindingResult.hasErrors()) {
throw new CustomException(INVALID_SPACE_JOIN_REQUEST, getErrorMessage(bindingResult));
}

// TODO 1. ์œ ์ €๊ฐ€ ์ŠคํŽ˜์ด์Šค์— ๊ฐ€์ž…๋˜์–ด ์žˆ๋Š”์ง€ ๊ฒ€์ฆ
validateIsUserAlreadySpaceMember(userId, spaceId);

// TODO 2. ์œ ์ € ํ”„๋กœํ•„ ์ธ๋„ค์ผ์„ s3์— upload
String userProfileImgUrl = processUserProfileImage(request.getUserProfileImg());

// TODO 3. ์œ ์ €์˜ ์ŠคํŽ˜์ด์Šค ๊ฐ€์ž… ์ฒ˜๋ฆฌ
PostSpaceJoinDto postSpaceJoinDto = new PostSpaceJoinDto(
userProfileImgUrl,
request.getUserName(),
request.getUserProfileMsg()
);

spaceService.createUserSpace(userId, spaceId, postSpaceJoinDto);

return new BaseResponse<>("์œ ์ €์˜ ์ŠคํŽ˜์ด์Šค ๊ฐ€์ž… ์ฒ˜๋ฆฌ ์„ฑ๊ณต");
}
}
5 changes: 3 additions & 2 deletions src/main/java/space/space_spring/dao/UserSpaceDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import space.space_spring.entity.Space;
import space.space_spring.entity.User;
import space.space_spring.entity.UserSpace;
import space.space_spring.entity.enumStatus.UserSpaceAuth;

import java.util.*;

Expand All @@ -21,9 +22,9 @@ public class UserSpaceDao {
@PersistenceContext
private EntityManager em;

public UserSpace createUserSpace(User manager, Space saveSpace) {
public UserSpace createUserSpace(User manager, Space saveSpace, UserSpaceAuth userSpaceAuth) {
UserSpace userSpace = new UserSpace();
userSpace.createUserSpace(manager, saveSpace, MANAGER);
userSpace.createUserSpace(manager, saveSpace, userSpaceAuth);

em.persist(userSpace);
return userSpace;
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/space/space_spring/dto/space/PostSpaceJoinDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package space.space_spring.dto.space;

import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;
import org.springframework.web.multipart.MultipartFile;

@Getter
@AllArgsConstructor
public class PostSpaceJoinDto {

private String userProfileImg;

private String userName;

private String userProfileMsg;

@Getter
@Setter
@NoArgsConstructor
public static class Request {

@Nullable
private MultipartFile userProfileImg;

@NotBlank(message = "์œ ์ € ์ด๋ฆ„์€ ๊ณต๋ฐฑ์ผ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
@Length(min = 1, max = 10, message = "์ด๋ฆ„์€ 10์ž์ด๋‚ด์˜ ๋ฌธ์ž์—ด์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.")
private String userName;

@Nullable
@Length(max = 50, message = "ํ”„๋กœํ•„ ์ƒํƒœ๋ฉ”์‹œ์ง€๋Š” 50์ž์ด๋‚ด์˜ ๋ฌธ์ž์—ด์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.")
private String userProfileMsg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package space.space_spring.dto.userSpace;

import com.amazonaws.services.ec2.model.CpuOptionsRequest;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class GetUserProfileInSpaceDto {

@Getter
@AllArgsConstructor
public static class Response {

private String userProfileImg;

private String userName;

private String userAuth;

private String userProfileMsg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package space.space_spring.dto.userSpace;

import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;
import org.springframework.web.multipart.MultipartFile;

@Getter
@AllArgsConstructor
public class PutUserProfileInSpaceDto {

private String userName;

private String userProfileImg;

private String userProfileMsg;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class Request {

@Nullable
private MultipartFile userProfileImg;

@NotBlank(message = "์œ ์ € ์ด๋ฆ„์€ ๊ณต๋ฐฑ์ผ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
@Length(min = 1, max = 10, message = "์ด๋ฆ„์€ 10์ž์ด๋‚ด์˜ ๋ฌธ์ž์—ด์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.")
private String userName;

@Nullable
@Length(max = 50, message = "ํ”„๋กœํ•„ ์ƒํƒœ๋ฉ”์‹œ์ง€๋Š” 50์ž์ด๋‚ด์˜ ๋ฌธ์ž์—ด์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.")
private String userProfileMsg;
}

@Getter
@AllArgsConstructor
public static class Response {

private String userProfileImg;

private String userAuth;

private String userName;

private String userProfileMsg;
}
}
15 changes: 15 additions & 0 deletions src/main/java/space/space_spring/entity/UserSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,20 @@ public void createUserSpace(User user, Space space, UserSpaceAuth userSpaceAuth)
this.userSpaceAuth = userSpaceAuth.getAuth();
}

public void changeUserName(String userName) {
this.userName = userName;
}

public void changeUserProfileImg(String profileImg) {
this.userProfileImg = profileImg;
}

public void changeUserProfileMsg(String profileMsg) {
this.userProfileMsg = profileMsg;
}

// ์œ ์ € ๊ถŒํ•œ ๋ณ€๊ฒฝ ๊ธฐ๋Šฅ ์•„์ง ๊ฐœ๋ฐœ X
public void changeUserSpaceAuth(String auth) {
this.userSpaceAuth = auth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,20 @@ public enum BaseExceptionResponseStatus implements ResponseStatus {
EMAIL_NOT_FOUND(4006, HttpStatus.BAD_REQUEST, "์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค."),
INVALID_USER_LOGIN(4007, HttpStatus.BAD_REQUEST, "๋กœ๊ทธ์ธ ์š”์ฒญ์—์„œ ์ž˜๋ชป๋œ ๊ฐ’์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค."),


/**
* 6000: Space ์˜ค๋ฅ˜
*/
INVALID_SPACE_CREATE(6000, HttpStatus.BAD_REQUEST, "์ŠคํŽ˜์ด์Šค ์ƒ์„ฑ ์š”์ฒญ์—์„œ ์ž˜๋ชป๋œ ๊ฐ’์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค."),
SPACE_NOT_FOUND(6001, HttpStatus.BAD_REQUEST, "์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ŠคํŽ˜์ด์Šค์ž…๋‹ˆ๋‹ค."),
adff(6002, HttpStatus.BAD_REQUEST, "์ด๋ฏธ ์กด์žฌํ•˜๋Š” ๋‹‰๋„ค์ž„์ž…๋‹ˆ๋‹ค."),
baab(6003, HttpStatus.BAD_REQUEST, "์กด์žฌํ•˜์ง€ ์•Š๋Š” ํšŒ์›์ž…๋‹ˆ๋‹ค."),
INVALID_USER_SPACE_PROFILE(6002, HttpStatus.BAD_REQUEST, "์ŠคํŽ˜์ด์Šค ๋ณ„ ์œ ์ € ํ”„๋กœํ•„ ์ •๋ณด ์ˆ˜์ • ์š”์ฒญ์—์„œ ์ž˜๋ชป๋œ ๊ฐ’์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค."),
INVALID_SPACE_JOIN_REQUEST(6003, HttpStatus.BAD_REQUEST, "์ŠคํŽ˜์ด์Šค ๊ฐ€์ž… ์š”์ฒญ์—์„œ ์ž˜๋ชป๋œ ๊ฐ’์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค."),
nff(6004, HttpStatus.BAD_REQUEST, "๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
gnf(6005, HttpStatus.BAD_REQUEST, "์ž˜๋ชป๋œ ํšŒ์› status ๊ฐ’์ž…๋‹ˆ๋‹ค."),
fb(6006, HttpStatus.BAD_REQUEST, "์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค."),


/**
* 7000: UserSpace ์˜ค๋ฅ˜
*/

USER_IS_NOT_IN_SPACE(7000, HttpStatus.BAD_REQUEST, "ํ•ด๋‹น ์ŠคํŽ˜์ด์Šค์— ์†ํ•˜์ง€ ์•Š๋Š” ์œ ์ €์ž…๋‹ˆ๋‹ค."),
UNAUTHORIZED_USER(7001, HttpStatus.UNAUTHORIZED, "ํ•ด๋‹น ์ŠคํŽ˜์ด์Šค์— ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์ด ์—†๋Š” ์œ ์ €์ž…๋‹ˆ๋‹ค."),
USER_IS_ALREADY_IN_SPACE(7002, HttpStatus.BAD_REQUEST, "ํ•ด๋‹น ์ŠคํŽ˜์ด์Šค์— ์ด๋ฏธ ๊ฐ€์ž…๋˜์–ด ์žˆ๋Š” ์œ ์ €์ž…๋‹ˆ๋‹ค"),
Expand All @@ -74,10 +71,6 @@ public enum BaseExceptionResponseStatus implements ResponseStatus {
F(7005, HttpStatus.BAD_REQUEST, "์ž˜๋ชป๋œ ํšŒ์› status ๊ฐ’์ž…๋‹ˆ๋‹ค."),
G(7006, HttpStatus.BAD_REQUEST, "์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค."),





/**
* 8000: Chat ์˜ค๋ฅ˜
*/
Expand All @@ -88,7 +81,7 @@ public enum BaseExceptionResponseStatus implements ResponseStatus {
*/

IS_NOT_IMAGE_FILE(9000, HttpStatus.BAD_REQUEST, "์ง€์›๋˜๋Š” ์ด๋ฏธ์ง€ ํŒŒ์ผ์˜ ํ˜•์‹์ด ์•„๋‹™๋‹ˆ๋‹ค."),

MULTIPARTFILE_CONVERT_FAILE_IN_MEMORY(9001,HttpStatus.INTERNAL_SERVER_ERROR,"multipartFile memory ๋ณ€ํ™˜ ๊ณผ์ •์—์„œ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฒผ์Šต๋‹ˆ๋‹ค."),
/*
* 10000: voice room ์˜ค๋ฅ˜
*/
Expand Down
Loading

0 comments on commit af8f545

Please sign in to comment.