diff --git a/src/main/generated/com/gamegoo/domain/QMember.java b/src/main/generated/com/gamegoo/domain/QMember.java index 22b717ca..35e88cff 100644 --- a/src/main/generated/com/gamegoo/domain/QMember.java +++ b/src/main/generated/com/gamegoo/domain/QMember.java @@ -51,11 +51,13 @@ public class QMember extends EntityPathBase { public final ListPath memberGameStyleList = this.createList("memberGameStyleList", com.gamegoo.domain.gamestyle.MemberGameStyle.class, com.gamegoo.domain.gamestyle.QMemberGameStyle.class, PathInits.DIRECT2); + public final BooleanPath mike = createBoolean("mike"); + public final ListPath notificationList = this.createList("notificationList", com.gamegoo.domain.notification.Notification.class, com.gamegoo.domain.notification.QNotification.class, PathInits.DIRECT2); public final StringPath password = createString("password"); - public final StringPath profileImage = createString("profileImage"); + public final NumberPath profileImage = createNumber("profileImage", Integer.class); public final StringPath rank = createString("rank"); diff --git a/src/main/generated/com/gamegoo/domain/board/QBoard.java b/src/main/generated/com/gamegoo/domain/board/QBoard.java index 81a0364e..69cc41ee 100644 --- a/src/main/generated/com/gamegoo/domain/board/QBoard.java +++ b/src/main/generated/com/gamegoo/domain/board/QBoard.java @@ -26,7 +26,7 @@ public class QBoard extends EntityPathBase { public final ListPath boardGameStyles = this.createList("boardGameStyles", BoardGameStyle.class, QBoardGameStyle.class, PathInits.DIRECT2); - public final StringPath boardProfileImage = createString("boardProfileImage"); + public final NumberPath boardProfileImage = createNumber("boardProfileImage", Integer.class); public final StringPath content = createString("content"); diff --git a/src/main/generated/com/gamegoo/domain/QFriend.java b/src/main/generated/com/gamegoo/domain/friend/QFriend.java similarity index 81% rename from src/main/generated/com/gamegoo/domain/QFriend.java rename to src/main/generated/com/gamegoo/domain/friend/QFriend.java index c2db7608..00197511 100644 --- a/src/main/generated/com/gamegoo/domain/QFriend.java +++ b/src/main/generated/com/gamegoo/domain/friend/QFriend.java @@ -1,4 +1,4 @@ -package com.gamegoo.domain; +package com.gamegoo.domain.friend; import static com.querydsl.core.types.PathMetadataFactory.*; @@ -16,7 +16,7 @@ @Generated("com.querydsl.codegen.DefaultEntitySerializer") public class QFriend extends EntityPathBase { - private static final long serialVersionUID = -762196062L; + private static final long serialVersionUID = -138403158L; private static final PathInits INITS = PathInits.DIRECT2; @@ -27,13 +27,13 @@ public class QFriend extends EntityPathBase { //inherited public final DateTimePath createdAt = _super.createdAt; - public final QMember fromMember; + public final com.gamegoo.domain.QMember fromMember; public final NumberPath id = createNumber("id", Long.class); public final BooleanPath isLiked = createBoolean("isLiked"); - public final QMember toMember; + public final com.gamegoo.domain.QMember toMember; //inherited public final DateTimePath updatedAt = _super.updatedAt; @@ -56,8 +56,8 @@ public QFriend(PathMetadata metadata, PathInits inits) { public QFriend(Class type, PathMetadata metadata, PathInits inits) { super(type, metadata, inits); - this.fromMember = inits.isInitialized("fromMember") ? new QMember(forProperty("fromMember")) : null; - this.toMember = inits.isInitialized("toMember") ? new QMember(forProperty("toMember")) : null; + this.fromMember = inits.isInitialized("fromMember") ? new com.gamegoo.domain.QMember(forProperty("fromMember")) : null; + this.toMember = inits.isInitialized("toMember") ? new com.gamegoo.domain.QMember(forProperty("toMember")) : null; } } diff --git a/src/main/generated/com/gamegoo/domain/QFriendRequests.java b/src/main/generated/com/gamegoo/domain/friend/QFriendRequests.java similarity index 78% rename from src/main/generated/com/gamegoo/domain/QFriendRequests.java rename to src/main/generated/com/gamegoo/domain/friend/QFriendRequests.java index 5dcc2e9c..3c075168 100644 --- a/src/main/generated/com/gamegoo/domain/QFriendRequests.java +++ b/src/main/generated/com/gamegoo/domain/friend/QFriendRequests.java @@ -1,4 +1,4 @@ -package com.gamegoo.domain; +package com.gamegoo.domain.friend; import static com.querydsl.core.types.PathMetadataFactory.*; @@ -16,7 +16,7 @@ @Generated("com.querydsl.codegen.DefaultEntitySerializer") public class QFriendRequests extends EntityPathBase { - private static final long serialVersionUID = -955592314L; + private static final long serialVersionUID = -1336304498L; private static final PathInits INITS = PathInits.DIRECT2; @@ -27,13 +27,13 @@ public class QFriendRequests extends EntityPathBase { //inherited public final DateTimePath createdAt = _super.createdAt; - public final QMember fromMember; + public final com.gamegoo.domain.QMember fromMember; public final NumberPath id = createNumber("id", Long.class); - public final BooleanPath isApproved = createBoolean("isApproved"); + public final EnumPath status = createEnum("status", FriendRequestStatus.class); - public final QMember toMember; + public final com.gamegoo.domain.QMember toMember; //inherited public final DateTimePath updatedAt = _super.updatedAt; @@ -56,8 +56,8 @@ public QFriendRequests(PathMetadata metadata, PathInits inits) { public QFriendRequests(Class type, PathMetadata metadata, PathInits inits) { super(type, metadata, inits); - this.fromMember = inits.isInitialized("fromMember") ? new QMember(forProperty("fromMember")) : null; - this.toMember = inits.isInitialized("toMember") ? new QMember(forProperty("toMember")) : null; + this.fromMember = inits.isInitialized("fromMember") ? new com.gamegoo.domain.QMember(forProperty("fromMember")) : null; + this.toMember = inits.isInitialized("toMember") ? new com.gamegoo.domain.QMember(forProperty("toMember")) : null; } } diff --git a/src/main/generated/com/gamegoo/domain/manner/QMannerRating.java b/src/main/generated/com/gamegoo/domain/manner/QMannerRating.java index d260b98e..a9e489c5 100644 --- a/src/main/generated/com/gamegoo/domain/manner/QMannerRating.java +++ b/src/main/generated/com/gamegoo/domain/manner/QMannerRating.java @@ -31,6 +31,8 @@ public class QMannerRating extends EntityPathBase { public final NumberPath id = createNumber("id", Long.class); + public final BooleanPath isPositive = createBoolean("isPositive"); + public final ListPath mannerRatingKeywordList = this.createList("mannerRatingKeywordList", MannerRatingKeyword.class, QMannerRatingKeyword.class, PathInits.DIRECT2); public final com.gamegoo.domain.QMember toMember; diff --git a/src/main/generated/com/gamegoo/domain/notification/QNotification.java b/src/main/generated/com/gamegoo/domain/notification/QNotification.java index a0bf4c6c..c9eccaac 100644 --- a/src/main/generated/com/gamegoo/domain/notification/QNotification.java +++ b/src/main/generated/com/gamegoo/domain/notification/QNotification.java @@ -37,6 +37,8 @@ public class QNotification extends EntityPathBase { public final QNotificationType notificationType; + public final NumberPath sourceId = createNumber("sourceId", Long.class); + //inherited public final DateTimePath updatedAt = _super.updatedAt; diff --git a/src/main/generated/com/gamegoo/domain/notification/QNotificationType.java b/src/main/generated/com/gamegoo/domain/notification/QNotificationType.java index d2e2fe1b..2b57f6ab 100644 --- a/src/main/generated/com/gamegoo/domain/notification/QNotificationType.java +++ b/src/main/generated/com/gamegoo/domain/notification/QNotificationType.java @@ -30,7 +30,9 @@ public class QNotificationType extends EntityPathBase { public final StringPath imgUrl = createString("imgUrl"); - public final StringPath name = createString("name"); + public final StringPath sourceUrl = createString("sourceUrl"); + + public final EnumPath title = createEnum("title", NotificationTypeTitle.class); //inherited public final DateTimePath updatedAt = _super.updatedAt; diff --git a/src/main/java/com/gamegoo/apiPayload/code/status/ErrorStatus.java b/src/main/java/com/gamegoo/apiPayload/code/status/ErrorStatus.java index 96718460..76bd516c 100644 --- a/src/main/java/com/gamegoo/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/com/gamegoo/apiPayload/code/status/ErrorStatus.java @@ -40,9 +40,6 @@ public enum ErrorStatus implements BaseErrorCode { // Position 관련 에러 POSITION_NOT_FOUND(HttpStatus.NOT_FOUND, "POSITION404", "해당 Position을 찾을 수 없습니다."), - // Profile_Image 관련 에러 - PROFILE_IMAGE_BAD_REQUEST(HttpStatus.BAD_REQUEST, "PROFILE_IMAGE400", "profile_image가 30자를 초과했습니다."), - // Email 인증 관련 에러 EMAIL_SEND_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "EMAIL500", "이메일 전송 도중, 에러가 발생했습니다."), EMAIL_NOT_FOUND(HttpStatus.NOT_FOUND, "EMAIL404", "해당 이메일을 찾을 수 없습니다."), @@ -50,32 +47,37 @@ public enum ErrorStatus implements BaseErrorCode { EMAIL_INVALID_TIME(HttpStatus.BAD_REQUEST, "EMAIL400", "이메일 인증 시간이 3분 초과했습니다."), // 매칭 관련 에러 - MATCHING_STATUS_BAD_REQUEST(HttpStatus.BAD_REQUEST, "MATCH400", "status는 SUCCESS, QUIT 둘 중 하나로만 변경이 가능합니다."), + MATCHING_STATUS_BAD_REQUEST(HttpStatus.BAD_REQUEST, "MATCH400", + "status는 SUCCESS, QUIT 둘 중 하나로만 변경이 가능합니다."), MATCHING_NOT_FOUND(HttpStatus.NOT_FOUND, "MATCH404", "해당 사용자의 매칭 정보가 없습니다."), // Riot 관련 에러 RIOT_NOT_FOUND(HttpStatus.NOT_FOUND, "RIOT404", "해당 Riot 계정이 존재하지 않습니다."), - RIOT_MATCH_NOT_FOUND(HttpStatus.NOT_FOUND, "RIOTMATCH404", "해당 Riot 계정의 매칭을 불러오는 도중 에러가 발생했습니다. 최근 100판 이내 이벤트 매칭 제외, 일반 매칭(일반게임,랭크게임,칼바람)을 많이 한 계정으로 다시 시도하세요."), - RIOT_PREFER_CHAMPION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "RIOTCHAMPION500", "선호 챔피언을 연동하는 도중 에러가 발생했습니다"), + RIOT_MATCH_NOT_FOUND(HttpStatus.NOT_FOUND, "RIOTMATCH404", + "해당 Riot 계정의 매칭을 불러오는 도중 에러가 발생했습니다. 최근 100판 이내 이벤트 매칭 제외, 일반 매칭(일반게임,랭크게임,칼바람)을 많이 한 계정으로 다시 시도하세요."), + RIOT_PREFER_CHAMPION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "RIOTCHAMPION500", + "선호 챔피언을 연동하는 도중 에러가 발생했습니다"), CHAMPION_NOT_FOUND(HttpStatus.NOT_FOUND, "CHAMPION404", "해당 챔피언이 존재하지 않습니다."), RIOT_MEMBER_CONFLICT(HttpStatus.CONFLICT, "RIOT409", "해당 이메일 계정은 이미 다른 RIOT 계정과 연동되었습니다."), RIOT_ACCOUNT_CONFLICT(HttpStatus.CONFLICT, "RIOT409", "해당 RIOT 계정은 이미 다른 이메일과 연동되어있습니다."), RIOT_INSUFFICIENT_MATCHES(HttpStatus.NOT_FOUND, "RIOT404", - "해당 RIOT 계정은 최근 100판 이내에 솔로랭크, 자유랭크, 일반게임, 칼바람을 플레이한 적이 없기 때문에 선호하는 챔피언 3명을 정할 수 없습니다."), + "해당 RIOT 계정은 최근 100판 이내에 솔로랭크, 자유랭크, 일반게임, 칼바람을 플레이한 적이 없기 때문에 선호하는 챔피언 3명을 정할 수 없습니다."), RIOT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "RIOT500", "RIOT API 연동 중 에러가 발생했습니다."), // 차단 관련 에러 TARGET_MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "BLOCK401", "차단 대상 회원을 찾을 수 없습니다."), ALREADY_BLOCKED(HttpStatus.BAD_REQUEST, "BLOCK402", "이미 차단한 회원입니다."), TARGET_MEMBER_NOT_BLOCKED(HttpStatus.BAD_REQUEST, "BLOCK403", "차단 목록에 존재하지 않는 회원입니다."), + BLOCK_MEMBER_BAD_REQUEST(HttpStatus.BAD_REQUEST, "BLOCK404", "잘못된 친구 차단 요청입니다."), // 신고 관련 에러 REPORT_TARGET_MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "REPORT401", "신고 대상 회원을 찾을 수 없습니다."), MEMBER_AND_TARGET_MEMBER_SAME(HttpStatus.BAD_REQUEST, "REPORT402", "회원과 신고 대상 회원이 같습니다."), // 게시판 글 작성 관련 에러 - BOARD_GAME_STYLE_BAD_REQUEST(HttpStatus.BAD_REQUEST, "BOARD400", "게임 스타일 선택 개수(최대 3개)를 초과했습니다."), + BOARD_GAME_STYLE_BAD_REQUEST(HttpStatus.BAD_REQUEST, "BOARD400", + "게임 스타일 선택 개수(최대 3개)를 초과했습니다."), GAME_MODE_INVALID(HttpStatus.BAD_REQUEST, "BOARD401", "게임모드 값은 1~4만 가능합니다."), MAIN_POSITION_INVALID(HttpStatus.BAD_REQUEST, "BOARD401", "주포지션 값은 1~5만 가능합니다."), SUB_POSITION_INVALID(HttpStatus.BAD_REQUEST, "BOARD401", "부포지션 값은 1~5만 가능합니다."), @@ -88,11 +90,33 @@ public enum ErrorStatus implements BaseErrorCode { // 게시판 글 삭제 관련 에러 BOARD_DELETE_UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "BOARD401", "글 작성자만 삭제 가능합니다."), + // 매너평가 관련 에러 + MANNER_TARGET_MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "MANNER401", "매너 평가 대상 회원을 찾을 수 없습니다."), + MANNER_KEYWORD_TYPE_INVALID(HttpStatus.BAD_REQUEST, "MANNER401", "매너 키워드 유형은 1~6만 가능합니다."), + BAD_MANNER_KEYWORD_TYPE_INVALID(HttpStatus.BAD_REQUEST, "MANNER401", + "비매너 키워드 유형은 7~12만 가능합니다."), + MANNER_KEYWORD_NOT_FOUND(HttpStatus.NOT_FOUND, "MANNER404", "해당 매너 키워드를 찾을 수 없습니다."), + MANNER_CONFLICT(HttpStatus.CONFLICT, "MANNER409", "매너 평가는 최초 1회만 가능합니다."), + BAD_MANNER_CONFLICT(HttpStatus.CONFLICT, "MANNER409", "비매너 평가는 최초 1회만 가능합니다."), + // 채팅 관련 에러 - CHAT_TARGET_NOT_FOUND(HttpStatus.NOT_FOUND, "CHAT4001", "채팅 대상 회원을 찾을 수 없습니다."), - CHATROOM_NOT_EXIST(HttpStatus.NOT_FOUND, "CHAT4002", "채팅방을 찾을 수 없습니다."), - CHATROOM_ACCESS_DENIED(HttpStatus.BAD_REQUEST, "CHAT4003", "접근할 수 없는 채팅방 입니다."), - CHAT_MESSAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "CHAT4004", "해당 메시지를 찾을 수 없습니다"); + CHAT_TARGET_NOT_FOUND(HttpStatus.NOT_FOUND, "CHAT401", "채팅 대상 회원을 찾을 수 없습니다."), + CHATROOM_NOT_EXIST(HttpStatus.NOT_FOUND, "CHAT402", "채팅방을 찾을 수 없습니다."), + CHATROOM_ACCESS_DENIED(HttpStatus.BAD_REQUEST, "CHAT403", "접근할 수 없는 채팅방 입니다."), + CHAT_MESSAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "CHAT404", "해당 메시지를 찾을 수 없습니다"), + + // 친구 관련 에러 + FRIEND_BAD_REQUEST(HttpStatus.BAD_REQUEST, "FRIEND401", "잘못된 친구 요청입니다."), + FRIEND_TARGET_IS_BLOCKED(HttpStatus.BAD_REQUEST, "FRIEND402", + "내가 차단한 회원입니다. 친구 요청을 보낼 수 없습니다."), + BLOCKED_BY_FRIEND_TARGET(HttpStatus.BAD_REQUEST, "FRIEND403", + "나를 차단한 회원입니다. 친구 요청을 보낼 수 없습니다."), + + // 알림 관련 에러 + NOTIFICATION_TYPE_NOT_FOUND(HttpStatus.NOT_FOUND, "NOTI401", "잘못된 알림 타입입니다."), + NOTIFICATION_METHOD_BAD_REQUEST(HttpStatus.BAD_REQUEST, "NOTI402", "알림 생성 메소드 호출이 잘못되었습니다."), + + ; private final HttpStatus httpStatus; private final String code; @@ -101,19 +125,19 @@ public enum ErrorStatus implements BaseErrorCode { @Override public ErrorReasonDTO getReason() { return ErrorReasonDTO.builder() - .message(message) - .code(code) - .isSuccess(false) - .build(); + .message(message) + .code(code) + .isSuccess(false) + .build(); } @Override public ErrorReasonDTO getReasonHttpStatus() { return ErrorReasonDTO.builder() - .message(message) - .code(code) - .isSuccess(false) - .httpStatus(httpStatus) - .build(); + .message(message) + .code(code) + .isSuccess(false) + .httpStatus(httpStatus) + .build(); } } diff --git a/src/main/java/com/gamegoo/apiPayload/exception/handler/FriendHandler.java b/src/main/java/com/gamegoo/apiPayload/exception/handler/FriendHandler.java new file mode 100644 index 00000000..8fde6871 --- /dev/null +++ b/src/main/java/com/gamegoo/apiPayload/exception/handler/FriendHandler.java @@ -0,0 +1,11 @@ +package com.gamegoo.apiPayload.exception.handler; + +import com.gamegoo.apiPayload.code.BaseErrorCode; +import com.gamegoo.apiPayload.exception.GeneralException; + +public class FriendHandler extends GeneralException { + + public FriendHandler(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/gamegoo/apiPayload/exception/handler/MannerHandler.java b/src/main/java/com/gamegoo/apiPayload/exception/handler/MannerHandler.java new file mode 100644 index 00000000..ba2dbe4f --- /dev/null +++ b/src/main/java/com/gamegoo/apiPayload/exception/handler/MannerHandler.java @@ -0,0 +1,10 @@ +package com.gamegoo.apiPayload.exception.handler; + +import com.gamegoo.apiPayload.code.BaseErrorCode; +import com.gamegoo.apiPayload.exception.GeneralException; + +public class MannerHandler extends GeneralException { + public MannerHandler(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/gamegoo/apiPayload/exception/handler/NotificationHandler.java b/src/main/java/com/gamegoo/apiPayload/exception/handler/NotificationHandler.java new file mode 100644 index 00000000..b686b036 --- /dev/null +++ b/src/main/java/com/gamegoo/apiPayload/exception/handler/NotificationHandler.java @@ -0,0 +1,11 @@ +package com.gamegoo.apiPayload.exception.handler; + +import com.gamegoo.apiPayload.code.BaseErrorCode; +import com.gamegoo.apiPayload.exception.GeneralException; + +public class NotificationHandler extends GeneralException { + + public NotificationHandler(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/gamegoo/config/SecurityConfig.java b/src/main/java/com/gamegoo/config/SecurityConfig.java index 9488186b..addf8f27 100644 --- a/src/main/java/com/gamegoo/config/SecurityConfig.java +++ b/src/main/java/com/gamegoo/config/SecurityConfig.java @@ -1,15 +1,11 @@ package com.gamegoo.config; -import static org.springframework.security.config.Customizer.withDefaults; - import com.gamegoo.apiPayload.exception.handler.JWTExceptionHandlerFilter; import com.gamegoo.filter.JWTFilter; import com.gamegoo.filter.LoginFilter; import com.gamegoo.repository.member.MemberRepository; import com.gamegoo.security.CustomUserDetailService; import com.gamegoo.util.JWTUtil; -import java.util.Arrays; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -26,6 +22,11 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; +import java.util.Arrays; +import java.util.List; + +import static org.springframework.security.config.Customizer.withDefaults; + @Configuration @EnableWebSecurity @RequiredArgsConstructor @@ -38,16 +39,16 @@ public class SecurityConfig { @Bean public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) - throws Exception { + throws Exception { return configuration.getAuthenticationManager(); } @Bean public JWTFilter jwtFilter() { List excludedPaths = Arrays.asList("/swagger-ui/", "/v3/api-docs", - "/v1/member/join", "/v1/member/login", "/v1/member/email", "/v1/member/refresh", - "/v1/member/riot", "/v1/posts/list", "/v1/posts/list/{boardId}", - "/v1/test/chatroom/create/matched"); + "/v1/member/join", "/v1/member/login", "/v1/member/email", "/v1/member/refresh", + "/v1/member/riot", "/v1/posts/list", "/v1/posts/list/{boardId}", + "/v1/test/chatroom/create/matched", "/v1/member/password/reset"); return new JWTFilter(jwtUtil, excludedPaths, customUserDetailService); } @@ -61,24 +62,24 @@ public BCryptPasswordEncoder bCryptPasswordEncoder() { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http - .csrf(AbstractHttpConfigurer::disable) - .formLogin(AbstractHttpConfigurer::disable) - .httpBasic(AbstractHttpConfigurer::disable) - .cors(withDefaults()) - .authorizeHttpRequests((auth) -> auth - .antMatchers("/", "/v1/member/join", "/v1/member/login", "/v1/member/email/**", - "/v1/member/refresh", "/v1/member/riot", "/v1/posts/list/**", - "/v1/test/chatroom/create/matched").permitAll() - .antMatchers("/", "/swagger-ui/**", "/v3/api-docs/**").permitAll() - .anyRequest().authenticated()) - .addFilterBefore(new JWTExceptionHandlerFilter(), - UsernamePasswordAuthenticationFilter.class) - .addFilterAt( - new LoginFilter(authenticationManager(authenticationConfiguration), jwtUtil, - memberRepository), UsernamePasswordAuthenticationFilter.class) - .addFilterBefore(jwtFilter(), LoginFilter.class) - .sessionManagement((session) -> session - .sessionCreationPolicy(SessionCreationPolicy.STATELESS)); + .csrf(AbstractHttpConfigurer::disable) + .formLogin(AbstractHttpConfigurer::disable) + .httpBasic(AbstractHttpConfigurer::disable) + .cors(withDefaults()) + .authorizeHttpRequests((auth) -> auth + .antMatchers("/", "/v1/member/join", "/v1/member/login", "/v1/member/email/**", + "/v1/member/refresh", "/v1/member/riot", "/v1/posts/list/**", + "/v1/test/chatroom/create/matched", "/v1/member/password/reset").permitAll() + .antMatchers("/", "/swagger-ui/**", "/v3/api-docs/**").permitAll() + .anyRequest().authenticated()) + .addFilterBefore(new JWTExceptionHandlerFilter(), + UsernamePasswordAuthenticationFilter.class) + .addFilterAt( + new LoginFilter(authenticationManager(authenticationConfiguration), jwtUtil, + memberRepository), UsernamePasswordAuthenticationFilter.class) + .addFilterBefore(jwtFilter(), LoginFilter.class) + .sessionManagement((session) -> session + .sessionCreationPolicy(SessionCreationPolicy.STATELESS)); return http.build(); } diff --git a/src/main/java/com/gamegoo/controller/TestController.java b/src/main/java/com/gamegoo/controller/TestController.java index 3ad1e0a6..c8f2b444 100644 --- a/src/main/java/com/gamegoo/controller/TestController.java +++ b/src/main/java/com/gamegoo/controller/TestController.java @@ -1,11 +1,18 @@ package com.gamegoo.controller; +import com.gamegoo.apiPayload.ApiResponse; import com.gamegoo.apiPayload.code.status.ErrorStatus; import com.gamegoo.apiPayload.exception.handler.TempHandler; +import com.gamegoo.domain.Member; +import com.gamegoo.domain.notification.NotificationTypeTitle; +import com.gamegoo.service.member.ProfileService; +import com.gamegoo.service.notification.NotificationService; +import com.gamegoo.util.JWTUtil; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -15,6 +22,9 @@ @Slf4j public class TestController { + private final NotificationService notificationService; + private final ProfileService profileService; + @GetMapping("/test/hello") @Operation(summary = "swagger 테스트용 API 입니다.", description = "simple API for swagger test!") public String hello() { @@ -26,5 +36,20 @@ public String hello() { public String apiResponseTest() { throw new TempHandler(ErrorStatus.TEMP_EXCEPTION); } - + + @GetMapping("/test/send/notifications/{times}") + @Operation(summary = "테스트용 알림 생성 API 입니다.", description = "서버 테스트용 입니다!!") + public ApiResponse sendTestNotifications( + @PathVariable(name = "times") int times + ) { + Long memberId = JWTUtil.getCurrentUserId(); + Member member = profileService.findMember(memberId); + + for (int i = 0; i < times; i++) { + notificationService.createNotification(NotificationTypeTitle.TEST_ALARM, null, null, + member); + } + return ApiResponse.onSuccess("테스트 알림 생성 성공"); + } + } diff --git a/src/main/java/com/gamegoo/controller/mannner/MannerController.java b/src/main/java/com/gamegoo/controller/mannner/MannerController.java new file mode 100644 index 00000000..fc1ead76 --- /dev/null +++ b/src/main/java/com/gamegoo/controller/mannner/MannerController.java @@ -0,0 +1,74 @@ +package com.gamegoo.controller.mannner; + +import com.gamegoo.apiPayload.ApiResponse; +import com.gamegoo.domain.manner.MannerRating; +import com.gamegoo.dto.manner.MannerRequest; +import com.gamegoo.dto.manner.MannerResponse; +import com.gamegoo.service.manner.MannerService; +import com.gamegoo.util.JWTUtil; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.Valid; +import java.util.List; +import java.util.stream.Collectors; + +@RestController +@RequiredArgsConstructor +@Slf4j +@RequestMapping("/v1/manner") +@Tag(name = "MannerRating", description = "매너 평가 관련 API") +public class MannerController { + + private final MannerService mannerService; + + @PostMapping("/good") + @Operation(summary = "매너 평가 등록 API", description = "매너 평가하기 API 입니다. 매너 키워드 유형 1~6 을 입력하세요.") + public ApiResponse mannerInsert( + @RequestBody @Valid MannerRequest.mannerInsertDTO request + ){ + Long memberId = JWTUtil.getCurrentUserId(); + + MannerRating mannerrating = mannerService.insertManner(request, memberId); + + List mannerRatingKeywordList = mannerrating.getMannerRatingKeywordList().stream() + .map(mannerRatingKeyword -> mannerRatingKeyword.getMannerKeyword().getId()) + .collect(Collectors.toList()); + + MannerResponse.mannerInsertResponseDTO result = MannerResponse.mannerInsertResponseDTO.builder() + .mannerId(mannerrating.getId()) + .toMemberId(mannerrating.getToMember().getId()) + .mannerRatingKeywordList(mannerRatingKeywordList) + .build(); + + return ApiResponse.onSuccess(result); + } + + @PostMapping("/bad") + @Operation(summary = "비매너 평가 등록 API", description = "비매너 평가하기 API 입니다. 비매너 키워드 유형 7~12 를 입력하세요.") + public ApiResponse badMannerInsert( + @RequestBody @Valid MannerRequest.mannerInsertDTO request + ){ + Long memberId = JWTUtil.getCurrentUserId(); + + MannerRating mannerrating = mannerService.insertBadManner(request, memberId); + + List mannerRatingKeywordList = mannerrating.getMannerRatingKeywordList().stream() + .map(mannerRatingKeyword -> mannerRatingKeyword.getMannerKeyword().getId()) + .collect(Collectors.toList()); + + MannerResponse.mannerInsertResponseDTO result = MannerResponse.mannerInsertResponseDTO.builder() + .mannerId(mannerrating.getId()) + .toMemberId(mannerrating.getToMember().getId()) + .mannerRatingKeywordList(mannerRatingKeywordList) + .build(); + + return ApiResponse.onSuccess(result); + } +} diff --git a/src/main/java/com/gamegoo/controller/member/MemberController.java b/src/main/java/com/gamegoo/controller/member/BlockController.java similarity index 67% rename from src/main/java/com/gamegoo/controller/member/MemberController.java rename to src/main/java/com/gamegoo/controller/member/BlockController.java index 7a6fb613..d120767e 100644 --- a/src/main/java/com/gamegoo/controller/member/MemberController.java +++ b/src/main/java/com/gamegoo/controller/member/BlockController.java @@ -2,16 +2,13 @@ import com.gamegoo.apiPayload.ApiResponse; import com.gamegoo.converter.MemberConverter; -import com.gamegoo.domain.Friend; import com.gamegoo.domain.Member; import com.gamegoo.dto.member.MemberResponse; -import com.gamegoo.service.member.MemberService; +import com.gamegoo.service.member.BlockService; import com.gamegoo.util.JWTUtil; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; -import java.util.List; -import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; @@ -24,58 +21,45 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j -@Tag(name = "Member", description = "회원 관련 API") +@Tag(name = "Block", description = "회원 차단 관련 API") @RestController @RequiredArgsConstructor -@RequestMapping("/v1/member") -public class MemberController { +@RequestMapping("/v1/member/block") +public class BlockController { - private final MemberService memberService; + private final BlockService blockService; @Operation(summary = "회원 차단 API", description = "대상 회원을 차단하는 API 입니다.") @Parameter(name = "memberId", description = "차단할 대상 회원의 id 입니다.") - @PostMapping("/block/{memberId}") + @PostMapping("/{memberId}") public ApiResponse blockMember(@PathVariable(name = "memberId") Long targetMemberId) { Long memberId = JWTUtil.getCurrentUserId(); //헤더에 있는 jwt 토큰에서 id를 가져오는 코드 - memberService.blockMember(memberId, targetMemberId); + blockService.blockMember(memberId, targetMemberId); return ApiResponse.onSuccess("회원 차단 성공"); } @Operation(summary = "차단한 회원 목록 조회 API", description = "내가 차단한 회원의 목록을 조회하는 API 입니다.") @Parameter(name = "page", description = "페이지 번호, 1 이상의 숫자를 입력해 주세요.") - @GetMapping("/block") + @GetMapping public ApiResponse getBlockList( @RequestParam(name = "page") Integer page) { Long memberId = JWTUtil.getCurrentUserId(); - Page blockList = memberService.getBlockList(memberId, page - 1); + Page blockList = blockService.getBlockList(memberId, page - 1); return ApiResponse.onSuccess(MemberConverter.toBlockListDTO(blockList)); } @Operation(summary = "회원 차단 해제 API", description = "해당 회원에 대한 차단을 해제하는 API 입니다.") @Parameter(name = "memberId", description = "차단을 해제할 대상 회원의 id 입니다.") - @DeleteMapping("/block/{memberId}") + @DeleteMapping("/{memberId}") public ApiResponse unBlockMember(@PathVariable(name = "memberId") Long targetMemberId) { Long memberId = JWTUtil.getCurrentUserId(); - memberService.unBlockMember(memberId, targetMemberId); + blockService.unBlockMember(memberId, targetMemberId); return ApiResponse.onSuccess("차단 해제 성공"); } - @Operation(summary = "친구 목록 조회 API", description = "해당 회원의 친구 목록을 조회하는 API 입니다.") - @GetMapping("/friends") - public ApiResponse getFriendList() { - Long memberId = JWTUtil.getCurrentUserId(); - List friends = memberService.getFriends(memberId); - - List friendInfoDTOList = friends.stream() - .map(MemberConverter::toFriendInfoDto).collect( - Collectors.toList()); - - return ApiResponse.onSuccess(friendInfoDTOList); - - } } diff --git a/src/main/java/com/gamegoo/controller/member/FriendController.java b/src/main/java/com/gamegoo/controller/member/FriendController.java new file mode 100644 index 00000000..87e6e612 --- /dev/null +++ b/src/main/java/com/gamegoo/controller/member/FriendController.java @@ -0,0 +1,61 @@ +package com.gamegoo.controller.member; + +import com.gamegoo.apiPayload.ApiResponse; +import com.gamegoo.converter.MemberConverter; +import com.gamegoo.domain.friend.Friend; +import com.gamegoo.domain.friend.FriendRequests; +import com.gamegoo.dto.member.MemberResponse; +import com.gamegoo.service.member.FriendService; +import com.gamegoo.util.JWTUtil; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.List; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Slf4j +@Tag(name = "Friend", description = "친구 관련 API") +@RestController +@RequiredArgsConstructor +@RequestMapping("/v1/friends") +public class FriendController { + + private final FriendService friendService; + + @Operation(summary = "친구 목록 조회 API", description = "해당 회원의 친구 목록을 조회하는 API 입니다.") + @GetMapping + public ApiResponse> getFriendList() { + Long memberId = JWTUtil.getCurrentUserId(); + List friends = friendService.getFriends(memberId); + + List friendInfoDTOList = friends.stream() + .map(MemberConverter::toFriendInfoDto).collect( + Collectors.toList()); + + return ApiResponse.onSuccess(friendInfoDTOList); + + } + + @Operation(summary = "친구 요청 전송 API", description = "대상 회원에게 친구 요청을 전송하는 API 입니다." + + "대상 회원에게 친구 요청 알림을 전송하며, 대상 회원이 현재 접속 중인 경우 socket을 통해 실시간 알림을 전송합니다.") + @Parameter(name = "memberId", description = "친구 요청을 전송할 대상 회원의 id 입니다.") + @PostMapping("/send/{memberId}") + public ApiResponse sendFriendRequest( + @PathVariable(name = "memberId") Long targetMemberId) { + Long memberId = JWTUtil.getCurrentUserId(); + + FriendRequests friendRequests = friendService.sendFriendRequest(memberId, targetMemberId); + + return ApiResponse.onSuccess("친구 요청 전송 성공"); + + } + + +} diff --git a/src/main/java/com/gamegoo/controller/member/PasswordController.java b/src/main/java/com/gamegoo/controller/member/PasswordController.java index 5718dd87..9f2435f6 100644 --- a/src/main/java/com/gamegoo/controller/member/PasswordController.java +++ b/src/main/java/com/gamegoo/controller/member/PasswordController.java @@ -23,13 +23,13 @@ public class PasswordController { private final PasswordService passwordService; @PostMapping("/check") - @Operation(summary = "비밀번호 확인 API 입니다.", description = "API for checking password") - public ApiResponse checkPassword( - @RequestBody MemberRequest.PasswordRequestDTO passwordRequestDTO) { + @Operation(summary = "JWT 토큰이 필요한 비밀번호 확인 API 입니다.", description = "API for checking password with JWT") + public ApiResponse checkPasswordWithJWT( + @RequestBody MemberRequest.PasswordRequestJWTDTO passwordRequestDTO) { Long currentUserId = JWTUtil.getCurrentUserId(); //헤더에 있는 jwt 토큰에서 id를 가져오는 코드 boolean isPasswordValid = passwordService.checkPasswordById(currentUserId, - passwordRequestDTO.getPassword()); //request body에 있는 password와 currentUserId를 전달 + passwordRequestDTO.getPassword()); //request body에 있는 password와 currentUserId를 전달 if (isPasswordValid) { return ApiResponse.onSuccess("비밀번호가 일치합니다."); @@ -38,13 +38,23 @@ public ApiResponse checkPassword( } } + @PostMapping("/reset/jwt") + @Operation(summary = "JWT 토큰이 필요한 비밀번호 재설정 API 입니다.", description = "API for reseting password with JWT") + public ApiResponse resetPasswordWithJWT( + @RequestBody MemberRequest.PasswordRequestJWTDTO passwordRequestDTO) { + Long currentUserId = JWTUtil.getCurrentUserId(); + + passwordService.updatePassword(currentUserId, passwordRequestDTO.getPassword()); + + return ApiResponse.onSuccess("비밀번호 재설정을 완료했습니다."); + } + @PostMapping("/reset") @Operation(summary = "비밀번호 재설정 API 입니다.", description = "API for reseting password") public ApiResponse resetPassword( - @RequestBody MemberRequest.PasswordRequestDTO passwordRequestDTO) { - Long currentUserId = JWTUtil.getCurrentUserId(); + @RequestBody MemberRequest.PasswordRequestDTO passwordRequestDTO) { - passwordService.updatePassword(currentUserId, passwordRequestDTO.getPassword()); + passwordService.updatePasswordWithEmail(passwordRequestDTO.getEmail(), passwordRequestDTO.getPassword()); return ApiResponse.onSuccess("비밀번호 재설정을 완료했습니다."); } diff --git a/src/main/java/com/gamegoo/controller/member/ProfileController.java b/src/main/java/com/gamegoo/controller/member/ProfileController.java index d64fdc82..435bf086 100644 --- a/src/main/java/com/gamegoo/controller/member/ProfileController.java +++ b/src/main/java/com/gamegoo/controller/member/ProfileController.java @@ -30,8 +30,9 @@ public class ProfileController { public ApiResponse> addGameStyle( @RequestBody MemberRequest.GameStyleRequestDTO gameStyleRequestDTO) { Long memberId = JWTUtil.getCurrentUserId(); + List gameStyleIdList = gameStyleRequestDTO.getGameStyleIdList(); List memberGameStyles = profileService.addMemberGameStyles( - gameStyleRequestDTO, memberId); + gameStyleIdList, memberId); List dtoList = memberGameStyles.stream() .map(memberGameStyle -> MemberResponse.GameStyleResponseDTO.builder() @@ -60,7 +61,7 @@ public ApiResponse modifyPosition( public ApiResponse modifyPosition( @RequestBody MemberRequest.ProfileImageRequestDTO profileImageDTO) { Long userId = JWTUtil.getCurrentUserId(); - String profileImage = profileImageDTO.getProfileImage(); + Integer profileImage = profileImageDTO.getProfileImage(); profileService.modifyProfileImage(userId, profileImage); @@ -80,7 +81,6 @@ public ApiResponse blindMember() { @Operation(summary = "회원 조회하는 API 입니다.", description = "API for looking up member") @GetMapping("/profile") public ApiResponse getBlockList() { - System.out.println("PROFILE : "); Long memberId = JWTUtil.getCurrentUserId(); Member myProfile = profileService.findMember(memberId); diff --git a/src/main/java/com/gamegoo/converter/MemberConverter.java b/src/main/java/com/gamegoo/converter/MemberConverter.java index 4f99948c..de947eb8 100644 --- a/src/main/java/com/gamegoo/converter/MemberConverter.java +++ b/src/main/java/com/gamegoo/converter/MemberConverter.java @@ -1,38 +1,37 @@ package com.gamegoo.converter; -import com.gamegoo.domain.Friend; import com.gamegoo.domain.Member; +import com.gamegoo.domain.friend.Friend; import com.gamegoo.dto.member.MemberResponse; -import org.springframework.data.domain.Page; - import java.util.List; import java.util.stream.Collectors; +import org.springframework.data.domain.Page; public class MemberConverter { public static MemberResponse.blockListDTO toBlockListDTO(Page blockList) { List blockedMemberDtoList = blockList.stream() - .map(MemberConverter::toBlockedMemberDTO) - .collect(Collectors.toList()); + .map(MemberConverter::toBlockedMemberDTO) + .collect(Collectors.toList()); return MemberResponse.blockListDTO.builder() - .blockedMemberDTOList(blockedMemberDtoList) - .listSize(blockedMemberDtoList.size()) - .totalPage(blockList.getTotalPages()) - .totalElements(blockList.getTotalElements()) - .isFirst(blockList.isFirst()) - .isLast(blockList.isLast()) - .build(); + .blockedMemberDTOList(blockedMemberDtoList) + .listSize(blockedMemberDtoList.size()) + .totalPage(blockList.getTotalPages()) + .totalElements(blockList.getTotalElements()) + .isFirst(blockList.isFirst()) + .isLast(blockList.isLast()) + .build(); } public static MemberResponse.blockedMemberDTO toBlockedMemberDTO(Member member) { return MemberResponse.blockedMemberDTO.builder() - .memberId(member.getId()) - .profileImg(member.getProfileImage()) - .email(member.getEmail()) - .name(member.getGameName()) - .build(); + .memberId(member.getId()) + .profileImg(member.getProfileImage()) + .email(member.getEmail()) + .name(member.getGameName()) + .build(); } @@ -40,23 +39,24 @@ public static MemberResponse.myProfileMemberDTO toMyProfileDTO(Member member) { List gameStyleResponseDTOList = null; if (member.getMemberGameStyleList() != null) { gameStyleResponseDTOList = member.getMemberGameStyleList().stream() - .map(memberGameStyle -> MemberResponse.GameStyleResponseDTO.builder() - .gameStyleId(memberGameStyle.getGameStyle().getId()) - .gameStyleName(memberGameStyle.getGameStyle().getStyleName()) - .build()).collect(Collectors.toList()); + .map(memberGameStyle -> MemberResponse.GameStyleResponseDTO.builder() + .gameStyleId(memberGameStyle.getGameStyle().getId()) + .gameStyleName(memberGameStyle.getGameStyle().getStyleName()) + .build()).collect(Collectors.toList()); } List championResponseDTOList = null; if (member.getMemberChampionList() != null) { championResponseDTOList = member.getMemberChampionList().stream() - .map(memberChampion -> MemberResponse.ChampionResponseDTO.builder() - .championId(memberChampion.getMember().getId()) - .championName(memberChampion.getChampion().getName()) - .build()).collect(Collectors.toList()); + .map(memberChampion -> MemberResponse.ChampionResponseDTO.builder() + .championId(memberChampion.getMember().getId()) + .championName(memberChampion.getChampion().getName()) + .build()).collect(Collectors.toList()); } - return MemberResponse.myProfileMemberDTO.builder() + .id(member.getId()) + .mike(member.getMike()) .email(member.getEmail()) .gameName(member.getGameName()) .tag(member.getTag()) @@ -67,15 +67,16 @@ public static MemberResponse.myProfileMemberDTO toMyProfileDTO(Member member) { .gameStyleResponseDTOList(gameStyleResponseDTOList) .championResponseDTOList(championResponseDTOList) .build(); + } public static MemberResponse.friendInfoDTO toFriendInfoDto(Friend friend) { return MemberResponse.friendInfoDTO.builder() - .memberId(friend.getToMember().getId()) - .name(friend.getToMember().getGameName()) - .memberProfileImg(friend.getToMember().getProfileImage()) - .isLiked(friend.getIsLiked()) - .build(); + .memberId(friend.getToMember().getId()) + .name(friend.getToMember().getGameName()) + .memberProfileImg(friend.getToMember().getProfileImage()) + .isLiked(friend.getIsLiked()) + .build(); } } diff --git a/src/main/java/com/gamegoo/domain/Member.java b/src/main/java/com/gamegoo/domain/Member.java index 2cb57389..7ad9b052 100644 --- a/src/main/java/com/gamegoo/domain/Member.java +++ b/src/main/java/com/gamegoo/domain/Member.java @@ -9,30 +9,16 @@ import com.gamegoo.domain.manner.MannerRating; import com.gamegoo.domain.notification.Notification; import com.gamegoo.domain.report.Report; +import lombok.*; + +import javax.persistence.*; import java.util.ArrayList; import java.util.List; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; @Entity @Table(name = "Member") @Getter -@Setter @Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @@ -49,8 +35,8 @@ public class Member extends BaseDateTimeEntity { @Column(name = "password", nullable = false, length = 500) private String password; - @Column(name = "profile_image", length = 30) - private String profileImage = "default"; + @Column(name = "profile_image") + private Integer profileImage; @Column(name = "manner_level") private Integer mannerLevel = 0; @@ -86,6 +72,9 @@ public class Member extends BaseDateTimeEntity { @Column(name = "refresh_token") private String refreshToken; + @Column(name = "mike") + private Boolean mike = false; + @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) private List boardList = new ArrayList<>(); @@ -110,5 +99,46 @@ public class Member extends BaseDateTimeEntity { @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) private List memberChatroomList = new ArrayList<>(); + public void updatePosition(Integer mainPosition, Integer subPosition) { + this.mainPosition = mainPosition; + this.subPosition = subPosition; + } + + public void updateProfileImage(Integer profileImage) { + this.profileImage = profileImage; + } + + public void deactiveMember() { + this.blind = true; + } + + public void updateMemberFromMatching(Integer mainPosition, Integer subPosition, Boolean mike) { + this.mainPosition = mainPosition; + this.subPosition = subPosition; + this.mike = mike; + } + + public void initializeMemberChampionList() { + this.memberChampionList = new ArrayList<>(); + } + + public void updateRiotDetails(String tier, String rank, Double winRate) { + this.tier = tier; + this.rank = rank; + this.winRate = winRate; + } + + public void updateRiotBasic(String gameName, String tag) { + this.gameName = gameName; + this.tag = tag; + } + + public void updatePassword(String password) { + this.password = password; + } + + public void updateRefreshToken(String refreshToken) { + this.refreshToken = refreshToken; + } } diff --git a/src/main/java/com/gamegoo/domain/board/Board.java b/src/main/java/com/gamegoo/domain/board/Board.java index 4a5c2bf8..20e3f743 100644 --- a/src/main/java/com/gamegoo/domain/board/Board.java +++ b/src/main/java/com/gamegoo/domain/board/Board.java @@ -40,7 +40,7 @@ public class Board extends BaseDateTimeEntity { private String content; @Column(name = "board_profile_image") - private String boardProfileImage; + private Integer boardProfileImage; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id", nullable = false) @@ -50,8 +50,8 @@ public class Board extends BaseDateTimeEntity { private List boardGameStyles = new ArrayList<>(); // 연관관계 메소드 - public void setMember(Member member){ - if (this.member != null){ + public void setMember(Member member) { + if (this.member != null) { this.member.getBoardList().remove(this); } this.member = member; @@ -60,7 +60,7 @@ public void setMember(Member member){ } } - public void updateBoard(Integer mode, Integer mainPosition, Integer subPosition, Integer wantPosition, Boolean voice, String content, String boardProfileImage) { + public void updateBoard(Integer mode, Integer mainPosition, Integer subPosition, Integer wantPosition, Boolean voice, String content, Integer boardProfileImage) { this.mode = mode; this.mainPosition = mainPosition; this.subPosition = subPosition; diff --git a/src/main/java/com/gamegoo/domain/champion/MemberChampion.java b/src/main/java/com/gamegoo/domain/champion/MemberChampion.java index 7ef4ecd0..afe9c8d9 100644 --- a/src/main/java/com/gamegoo/domain/champion/MemberChampion.java +++ b/src/main/java/com/gamegoo/domain/champion/MemberChampion.java @@ -5,7 +5,6 @@ import lombok.*; import javax.persistence.*; -import java.util.ArrayList; @Getter @Entity @@ -34,7 +33,7 @@ public void setMember(Member member) { } this.member = member; if (this.member.getMemberChampionList() == null) { - this.member.setMemberChampionList(new ArrayList<>()); + this.member.initializeMemberChampionList(); } this.member.getMemberChampionList().add(this); } diff --git a/src/main/java/com/gamegoo/domain/Friend.java b/src/main/java/com/gamegoo/domain/friend/Friend.java similarity index 93% rename from src/main/java/com/gamegoo/domain/Friend.java rename to src/main/java/com/gamegoo/domain/friend/Friend.java index 2f6d48b2..a464b0c6 100644 --- a/src/main/java/com/gamegoo/domain/Friend.java +++ b/src/main/java/com/gamegoo/domain/friend/Friend.java @@ -1,5 +1,6 @@ -package com.gamegoo.domain; +package com.gamegoo.domain.friend; +import com.gamegoo.domain.Member; import com.gamegoo.domain.common.BaseDateTimeEntity; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/src/main/java/com/gamegoo/domain/friend/FriendRequestStatus.java b/src/main/java/com/gamegoo/domain/friend/FriendRequestStatus.java new file mode 100644 index 00000000..94c5bff4 --- /dev/null +++ b/src/main/java/com/gamegoo/domain/friend/FriendRequestStatus.java @@ -0,0 +1,9 @@ +package com.gamegoo.domain.friend; + +public enum FriendRequestStatus { + PENDING, // 대기중 + ACCEPTED, // 수락됨 + REJECTED, // 거절됨 + CANCELLED // 취소됨 + +} diff --git a/src/main/java/com/gamegoo/domain/FriendRequests.java b/src/main/java/com/gamegoo/domain/friend/FriendRequests.java similarity index 78% rename from src/main/java/com/gamegoo/domain/FriendRequests.java rename to src/main/java/com/gamegoo/domain/friend/FriendRequests.java index 0f647945..d745c247 100644 --- a/src/main/java/com/gamegoo/domain/FriendRequests.java +++ b/src/main/java/com/gamegoo/domain/friend/FriendRequests.java @@ -1,8 +1,11 @@ -package com.gamegoo.domain; +package com.gamegoo.domain.friend; +import com.gamegoo.domain.Member; import com.gamegoo.domain.common.BaseDateTimeEntity; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -27,8 +30,9 @@ public class FriendRequests extends BaseDateTimeEntity { @Column(name = "friend_request_id") private Long id; - @Column(nullable = false) - private Boolean isApproved; + @Enumerated(EnumType.STRING) + @Column(columnDefinition = "VARCHAR(30)", nullable = false) + private FriendRequestStatus status; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "from_member_id", nullable = false) diff --git a/src/main/java/com/gamegoo/domain/manner/MannerKeyword.java b/src/main/java/com/gamegoo/domain/manner/MannerKeyword.java index fa39aa5d..ba2dbf59 100644 --- a/src/main/java/com/gamegoo/domain/manner/MannerKeyword.java +++ b/src/main/java/com/gamegoo/domain/manner/MannerKeyword.java @@ -16,9 +16,9 @@ public class MannerKeyword extends BaseDateTimeEntity { @Column(name = "manner_keyword_id") private Long id; - @Column(nullable = false, length = 200) + @Column(name = "contents", nullable = false, length = 200) private String contents; - @Column(nullable = false) + @Column(name = "is_positive", nullable = false) private Boolean isPositive; } diff --git a/src/main/java/com/gamegoo/domain/manner/MannerRating.java b/src/main/java/com/gamegoo/domain/manner/MannerRating.java index 9a0453c1..16e11d0d 100644 --- a/src/main/java/com/gamegoo/domain/manner/MannerRating.java +++ b/src/main/java/com/gamegoo/domain/manner/MannerRating.java @@ -31,5 +31,15 @@ public class MannerRating extends BaseDateTimeEntity { @JoinColumn(name = "to_member_id", nullable = false) private Member toMember; - + @Column(name = "is_Positive") + private Boolean isPositive; + + // 연관관계 메소드 + public void setToMember(Member toMember){ + if (this.toMember != null){ + this.toMember.getMannerRatingList().remove(this); + } + this.toMember = toMember; + this.toMember.getMannerRatingList().add(this); + } } diff --git a/src/main/java/com/gamegoo/domain/manner/MannerRatingKeyword.java b/src/main/java/com/gamegoo/domain/manner/MannerRatingKeyword.java index ff2d9490..c9d18b8f 100644 --- a/src/main/java/com/gamegoo/domain/manner/MannerRatingKeyword.java +++ b/src/main/java/com/gamegoo/domain/manner/MannerRatingKeyword.java @@ -24,4 +24,13 @@ public class MannerRatingKeyword extends BaseDateTimeEntity { @JoinColumn(name = "manner_keyword_id", nullable = false) private MannerKeyword mannerKeyword; + // 연관관계 메소드 + public void setMannerRating(MannerRating mannerRating){ + if (this.mannerRating != null){ + this.mannerRating.getMannerRatingKeywordList().remove(this); + } + this.mannerRating = mannerRating; + this.mannerRating.getMannerRatingKeywordList().add(this); + } + } diff --git a/src/main/java/com/gamegoo/domain/notification/Notification.java b/src/main/java/com/gamegoo/domain/notification/Notification.java index acaf798d..ba250b2f 100644 --- a/src/main/java/com/gamegoo/domain/notification/Notification.java +++ b/src/main/java/com/gamegoo/domain/notification/Notification.java @@ -2,9 +2,19 @@ import com.gamegoo.domain.Member; import com.gamegoo.domain.common.BaseDateTimeEntity; -import lombok.*; - -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Entity @Getter @@ -12,6 +22,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor public class Notification extends BaseDateTimeEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "notification_id") @@ -21,7 +32,9 @@ public class Notification extends BaseDateTimeEntity { private String content; @Column(nullable = false) - private Boolean isRead; + private boolean isRead; + + private Long sourceId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id", nullable = false) @@ -31,4 +44,13 @@ public class Notification extends BaseDateTimeEntity { @JoinColumn(name = "notification_type_id", nullable = false) private NotificationType notificationType; + // 연관관계 메소드 + public void setMember(Member member) { + if (this.member != null) { + this.member.getNotificationList().remove(this); + } + this.member = member; + this.member.getNotificationList().add(this); + } + } diff --git a/src/main/java/com/gamegoo/domain/notification/NotificationType.java b/src/main/java/com/gamegoo/domain/notification/NotificationType.java index 50d8fb00..9382d539 100644 --- a/src/main/java/com/gamegoo/domain/notification/NotificationType.java +++ b/src/main/java/com/gamegoo/domain/notification/NotificationType.java @@ -1,9 +1,18 @@ package com.gamegoo.domain.notification; import com.gamegoo.domain.common.BaseDateTimeEntity; -import lombok.*; - -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Entity @Getter @@ -11,13 +20,15 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor public class NotificationType extends BaseDateTimeEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "notification_type_id") private Long id; - @Column(nullable = false, length = 30) - private String name; + @Enumerated(EnumType.STRING) + @Column(columnDefinition = "VARCHAR(30)", nullable = false) + private NotificationTypeTitle title; @Column(nullable = false, length = 400) private String content; @@ -25,5 +36,6 @@ public class NotificationType extends BaseDateTimeEntity { @Column(nullable = false, length = 200) private String imgUrl; + private String sourceUrl; } diff --git a/src/main/java/com/gamegoo/domain/notification/NotificationTypeTitle.java b/src/main/java/com/gamegoo/domain/notification/NotificationTypeTitle.java new file mode 100644 index 00000000..ab73c9bf --- /dev/null +++ b/src/main/java/com/gamegoo/domain/notification/NotificationTypeTitle.java @@ -0,0 +1,29 @@ +package com.gamegoo.domain.notification; + +public enum NotificationTypeTitle { + FRIEND_REQUEST_SEND("님에게 친구 요청을 보냈어요.", null), + FRIEND_REQUEST_RECEIVED("님에게 친구 요청이 왔어요.", "/member/profile/"), + FRIEND_REQUEST_ACCEPTED("님이 친구를 수락했어요.", null), + FRIEND_REQUEST_REJECTED("님이 친구를 거절했어요.", null), + MANNER_LEVEL_UP("매너레벨이 n단계로 올라갔어요!", "/member/manner"), + MANNER_LEVEL_DOWN("매너레벨이 n단계로 떨어졌어요.", "/member/manner"), + MANNER_KEYWORD_RATED("지난 매칭에서 n 키워드를 받았어요.", "/member/manner"), + TEST_ALARM("TEST PUSH. NUMBER: ", null), + ; + + private final String content; + private final String sourceUrl; + + NotificationTypeTitle(String content, String sourceUrl) { + this.content = content; + this.sourceUrl = sourceUrl; + } + + public String getMessage() { + return content; + } + + public String getSourceUrl() { + return sourceUrl; + } +} diff --git a/src/main/java/com/gamegoo/dto/board/BoardRequest.java b/src/main/java/com/gamegoo/dto/board/BoardRequest.java index b72cd6be..4e159088 100644 --- a/src/main/java/com/gamegoo/dto/board/BoardRequest.java +++ b/src/main/java/com/gamegoo/dto/board/BoardRequest.java @@ -12,8 +12,8 @@ public class BoardRequest { @Getter @Setter - public static class boardInsertDTO{ - String boardProfileImage; + public static class boardInsertDTO { + Integer boardProfileImage; @NotNull Integer gameMode; @@ -27,7 +27,7 @@ public static class boardInsertDTO{ Integer wantPosition; @Schema(description = "마이크 사용 여부", defaultValue = "false") - Boolean voice=false; + Boolean voice = false; List gameStyles; String contents; @@ -37,8 +37,8 @@ public static class boardInsertDTO{ @AllArgsConstructor @Getter @Setter - public static class boardUpdateDTO{ - String boardProfileImage; + public static class boardUpdateDTO { + Integer boardProfileImage; Integer gameMode; Integer mainPosition; diff --git a/src/main/java/com/gamegoo/dto/board/BoardResponse.java b/src/main/java/com/gamegoo/dto/board/BoardResponse.java index b4888884..b374d858 100644 --- a/src/main/java/com/gamegoo/dto/board/BoardResponse.java +++ b/src/main/java/com/gamegoo/dto/board/BoardResponse.java @@ -11,10 +11,10 @@ public class BoardResponse { @Setter @NoArgsConstructor @AllArgsConstructor - public static class boardInsertResponseDTO{ + public static class boardInsertResponseDTO { Long boardId; Long memberId; - String profileImage; + Integer profileImage; String gameName; String tag; String tier; @@ -33,10 +33,10 @@ public static class boardInsertResponseDTO{ @Setter @NoArgsConstructor @AllArgsConstructor - public static class boardUpdateResponseDTO{ + public static class boardUpdateResponseDTO { Long boardId; Long memberId; - String profileImage; + Integer profileImage; String gameName; String tag; String tier; @@ -54,10 +54,10 @@ public static class boardUpdateResponseDTO{ @Setter @NoArgsConstructor @AllArgsConstructor - public static class boardListResponseDTO{ + public static class boardListResponseDTO { Long boardId; Long memberId; - String profileImage; + Integer profileImage; String gameName; Integer mannerLevel; String tier; @@ -76,11 +76,11 @@ public static class boardListResponseDTO{ @Setter @NoArgsConstructor @AllArgsConstructor - public static class boardByIdResponseDTO{ + public static class boardByIdResponseDTO { Long boardId; Long memberId; LocalDateTime createdAt; - String profileImage; + Integer profileImage; String gameName; String tag; Integer mannerLevel; @@ -104,7 +104,7 @@ public static class boardByIdResponseDTO{ public static class myBoardListResponseDTO { Long boardId; Long memberId; - String profileImage; + Integer profileImage; String gameName; String tag; String tier; diff --git a/src/main/java/com/gamegoo/dto/chat/ChatResponse.java b/src/main/java/com/gamegoo/dto/chat/ChatResponse.java index 01dbf10a..045971ab 100644 --- a/src/main/java/com/gamegoo/dto/chat/ChatResponse.java +++ b/src/main/java/com/gamegoo/dto/chat/ChatResponse.java @@ -1,11 +1,12 @@ package com.gamegoo.dto.chat; -import java.util.List; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.List; + public class ChatResponse { @Builder @@ -28,7 +29,7 @@ public static class ChatroomViewDTO { Long chatroomId; String uuid; - String targetMemberImg; + Integer targetMemberImg; String targetMemberName; String lastMsg; String lastMsgAt; @@ -44,7 +45,7 @@ public static class ChatroomEnterDTO { String uuid; Long memberId; String gameName; - String memberProfileImg; + Integer memberProfileImg; ChatMessageListDTO chatMessageList; } @@ -69,7 +70,7 @@ public static class ChatMessageDTO { Long senderId; String senderName; - String senderProfileImg; + Integer senderProfileImg; String message; String createdAt; Long timestamp; @@ -83,7 +84,7 @@ public static class ChatCreateResultDTO { Long senderId; String senderName; - String senderProfileImg; + Integer senderProfileImg; String message; String createdAt; Long timestamp; diff --git a/src/main/java/com/gamegoo/dto/manner/MannerRequest.java b/src/main/java/com/gamegoo/dto/manner/MannerRequest.java new file mode 100644 index 00000000..be4ac112 --- /dev/null +++ b/src/main/java/com/gamegoo/dto/manner/MannerRequest.java @@ -0,0 +1,20 @@ +package com.gamegoo.dto.manner; + +import lombok.Getter; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.List; + +public class MannerRequest { + + @Getter + public static class mannerInsertDTO { + @NotNull + Long toMemberId; + + @NotEmpty + List mannerRatingKeywordList; + + } +} diff --git a/src/main/java/com/gamegoo/dto/manner/MannerResponse.java b/src/main/java/com/gamegoo/dto/manner/MannerResponse.java new file mode 100644 index 00000000..5cc53902 --- /dev/null +++ b/src/main/java/com/gamegoo/dto/manner/MannerResponse.java @@ -0,0 +1,17 @@ +package com.gamegoo.dto.manner; + +import lombok.*; + +import java.util.List; + +public class MannerResponse { + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class mannerInsertResponseDTO{ + Long mannerId; + Long toMemberId; + List mannerRatingKeywordList; + } +} diff --git a/src/main/java/com/gamegoo/dto/matching/MatchingRequest.java b/src/main/java/com/gamegoo/dto/matching/MatchingRequest.java index 9886f720..9c412d7b 100644 --- a/src/main/java/com/gamegoo/dto/matching/MatchingRequest.java +++ b/src/main/java/com/gamegoo/dto/matching/MatchingRequest.java @@ -7,6 +7,7 @@ import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import java.util.List; public class MatchingRequest { @Getter @@ -36,6 +37,8 @@ public static class SaveMatchingRequestDTO { @Min(value = 1, message = "원하는 상대 포지션의 값은 1이상이어야 합니다.") @Max(value = 5, message = "원하는 상대 포지션의 값은 1이상이어야합니다.") int wantP; + + List gameStyleIdList; } @Getter diff --git a/src/main/java/com/gamegoo/dto/member/MemberRequest.java b/src/main/java/com/gamegoo/dto/member/MemberRequest.java index 8934ce91..460422ba 100644 --- a/src/main/java/com/gamegoo/dto/member/MemberRequest.java +++ b/src/main/java/com/gamegoo/dto/member/MemberRequest.java @@ -55,13 +55,23 @@ public static class JoinRequestDTO { } @Getter - public static class PasswordRequestDTO { + public static class PasswordRequestJWTDTO { + @NotBlank(message = "password는 비워둘 수 없습니다.") + String password; + } + + @Getter + public static class PasswordRequestDTO { + @Email(message = "Email 형식이 올바르지 않습니다.") + @NotBlank(message = "Email은 비워둘 수 없습니다.") + String email; @NotBlank(message = "password는 비워둘 수 없습니다.") String password; } + @Getter public static class PositionRequestDTO { @Min(value = 0, message = "메인 포지션의 값은 0이상이어야 합니다.") @@ -74,8 +84,10 @@ public static class PositionRequestDTO { @Getter public static class ProfileImageRequestDTO { + @Min(value = 1, message = "메인 포지션의 값은 1이상이어야 합니다.") + @Max(value = 8, message = "메인 포지션의 값은 8이하이어야 합니다.") @NotBlank(message = "profileImage 값은 비워둘 수 없습니다.") - String profileImage; + Integer profileImage; } @Getter diff --git a/src/main/java/com/gamegoo/dto/member/MemberResponse.java b/src/main/java/com/gamegoo/dto/member/MemberResponse.java index df994ce9..78ea736e 100644 --- a/src/main/java/com/gamegoo/dto/member/MemberResponse.java +++ b/src/main/java/com/gamegoo/dto/member/MemberResponse.java @@ -1,8 +1,11 @@ package com.gamegoo.dto.member; -import lombok.*; - import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; public class MemberResponse { @@ -11,6 +14,7 @@ public class MemberResponse { @NoArgsConstructor @AllArgsConstructor public static class blockListDTO { + List blockedMemberDTOList; Integer listSize; Integer totalPage; @@ -25,8 +29,9 @@ public static class blockListDTO { @NoArgsConstructor @AllArgsConstructor public static class blockedMemberDTO { + Long memberId; - String profileImg; + Integer profileImg; String email; String name; } @@ -77,7 +82,9 @@ public static class RefreshTokenResponseDTO { @AllArgsConstructor public static class myProfileMemberDTO { - String profileImg; + Long id; + Integer profileImg; + Boolean mike; String email; String gameName; String tag; @@ -96,7 +103,8 @@ public static class friendInfoDTO { Long memberId; String name; - String memberProfileImg; + Integer memberProfileImg; boolean isLiked; } + } diff --git a/src/main/java/com/gamegoo/filter/LoginFilter.java b/src/main/java/com/gamegoo/filter/LoginFilter.java index c38cad22..44e88477 100644 --- a/src/main/java/com/gamegoo/filter/LoginFilter.java +++ b/src/main/java/com/gamegoo/filter/LoginFilter.java @@ -8,11 +8,6 @@ import com.gamegoo.repository.member.MemberRepository; import com.gamegoo.security.CustomUserDetails; import com.gamegoo.util.JWTUtil; -import java.io.IOException; -import java.util.Objects; -import javax.servlet.FilterChain; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.InternalAuthenticationServiceException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -22,6 +17,12 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.web.bind.annotation.ResponseBody; +import javax.servlet.FilterChain; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Objects; + @ResponseBody // 로그인 시 실행되는 로그인 필터 public class LoginFilter extends UsernamePasswordAuthenticationFilter { @@ -31,26 +32,26 @@ public class LoginFilter extends UsernamePasswordAuthenticationFilter { private final MemberRepository memberRepository; public LoginFilter(AuthenticationManager authenticationManager, JWTUtil jwtUtil, - MemberRepository memberRepository) { + MemberRepository memberRepository) { this.authenticationManager = authenticationManager; this.jwtUtil = jwtUtil; this.memberRepository = memberRepository; this.setRequiresAuthenticationRequestMatcher( - new AntPathRequestMatcher("/v1/member/login", "POST")); + new AntPathRequestMatcher("/v1/member/login", "POST")); this.setUsernameParameter("email"); this.setPasswordParameter("password"); } @Override public Authentication attemptAuthentication(HttpServletRequest request, - HttpServletResponse response) throws AuthenticationException { + HttpServletResponse response) throws AuthenticationException { // 클라이언트 요청에서 username, password 추출 String email = obtainUsername(request); String password = obtainPassword(request); // 스프링 시큐리티에서 username과 password를 검증하기 위해서는 token에 담아야 함 UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken( - email, password, null); + email, password, null); // token에 담은 검증을 위한 AuthenticationManager로 전달 return authenticationManager.authenticate(authToken); @@ -59,8 +60,8 @@ public Authentication attemptAuthentication(HttpServletRequest request, // 로그인 성공시 실행하는 메소드 (JWT 발급) @Override protected void successfulAuthentication(HttpServletRequest request, - HttpServletResponse response, FilterChain chain, Authentication authentication) - throws IOException { + HttpServletResponse response, FilterChain chain, Authentication authentication) + throws IOException { CustomUserDetails customUserDetails = (CustomUserDetails) authentication.getPrincipal(); // 사용자 id 불러오기 @@ -72,8 +73,8 @@ protected void successfulAuthentication(HttpServletRequest request, // refresh token DB에 저장하기 Member member = memberRepository.findById(id) - .orElseThrow(); - member.setRefreshToken(refresh_token); + .orElseThrow(); + member.updateRefreshToken(refresh_token); memberRepository.save(member); // 해당 유저 이름 불러오기 @@ -81,7 +82,7 @@ protected void successfulAuthentication(HttpServletRequest request, // Response body에 넣기 MemberResponse.LoginResponseDTO loginResponseDTO = new MemberResponse.LoginResponseDTO( - access_token, refresh_token, gameuserName); + access_token, refresh_token, gameuserName); // 헤더에 추가 response.addHeader("Authorization", "Bearer " + access_token); @@ -97,19 +98,19 @@ protected void successfulAuthentication(HttpServletRequest request, // 로그인 실패시 실행하는 메소드 @Override protected void unsuccessfulAuthentication(HttpServletRequest request, - HttpServletResponse response, AuthenticationException failed) throws IOException { + HttpServletResponse response, AuthenticationException failed) throws IOException { // 어떤 에러인지 확인 ErrorStatus errorStatus = getErrorStatus(failed); // 에러 응답 생성하기 ApiResponse apiResponse = ApiResponse.onFailure(errorStatus.getCode(), - errorStatus.getMessage(), null); + errorStatus.getMessage(), null); response.setStatus(errorStatus.getHttpStatus().value()); apiResponse(response, apiResponse); } private static void apiResponse(HttpServletResponse response, ApiResponse apiResponse) - throws IOException { + throws IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); new ObjectMapper().writeValue(response.getWriter(), apiResponse); diff --git a/src/main/java/com/gamegoo/repository/member/FriendRepository.java b/src/main/java/com/gamegoo/repository/friend/FriendRepository.java similarity index 73% rename from src/main/java/com/gamegoo/repository/member/FriendRepository.java rename to src/main/java/com/gamegoo/repository/friend/FriendRepository.java index 8d31248f..fd59bbb3 100644 --- a/src/main/java/com/gamegoo/repository/member/FriendRepository.java +++ b/src/main/java/com/gamegoo/repository/friend/FriendRepository.java @@ -1,6 +1,6 @@ -package com.gamegoo.repository.member; +package com.gamegoo.repository.friend; -import com.gamegoo.domain.Friend; +import com.gamegoo.domain.friend.Friend; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/gamegoo/repository/friend/FriendRequestsRepository.java b/src/main/java/com/gamegoo/repository/friend/FriendRequestsRepository.java new file mode 100644 index 00000000..8cc0fe7f --- /dev/null +++ b/src/main/java/com/gamegoo/repository/friend/FriendRequestsRepository.java @@ -0,0 +1,8 @@ +package com.gamegoo.repository.friend; + +import com.gamegoo.domain.friend.FriendRequests; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FriendRequestsRepository extends JpaRepository { + +} diff --git a/src/main/java/com/gamegoo/repository/manner/MannerKeywordRepository.java b/src/main/java/com/gamegoo/repository/manner/MannerKeywordRepository.java new file mode 100644 index 00000000..6191077f --- /dev/null +++ b/src/main/java/com/gamegoo/repository/manner/MannerKeywordRepository.java @@ -0,0 +1,7 @@ +package com.gamegoo.repository.manner; + +import com.gamegoo.domain.manner.MannerKeyword; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MannerKeywordRepository extends JpaRepository { +} diff --git a/src/main/java/com/gamegoo/repository/manner/MannerRatingKeywordRepository.java b/src/main/java/com/gamegoo/repository/manner/MannerRatingKeywordRepository.java new file mode 100644 index 00000000..edbce8a3 --- /dev/null +++ b/src/main/java/com/gamegoo/repository/manner/MannerRatingKeywordRepository.java @@ -0,0 +1,11 @@ +package com.gamegoo.repository.manner; + +import com.gamegoo.domain.manner.MannerRating; +import com.gamegoo.domain.manner.MannerRatingKeyword; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface MannerRatingKeywordRepository extends JpaRepository { + List findByMannerRating(MannerRating mannerRating); +} diff --git a/src/main/java/com/gamegoo/repository/manner/MannerRatingRepository.java b/src/main/java/com/gamegoo/repository/manner/MannerRatingRepository.java new file mode 100644 index 00000000..b7934c1a --- /dev/null +++ b/src/main/java/com/gamegoo/repository/manner/MannerRatingRepository.java @@ -0,0 +1,10 @@ +package com.gamegoo.repository.manner; + +import com.gamegoo.domain.manner.MannerRating; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface MannerRatingRepository extends JpaRepository { + List findByFromMemberIdAndToMemberId(Long fromMember, Long toMember); +} diff --git a/src/main/java/com/gamegoo/repository/notification/NotificationRepository.java b/src/main/java/com/gamegoo/repository/notification/NotificationRepository.java new file mode 100644 index 00000000..40604827 --- /dev/null +++ b/src/main/java/com/gamegoo/repository/notification/NotificationRepository.java @@ -0,0 +1,8 @@ +package com.gamegoo.repository.notification; + +import com.gamegoo.domain.notification.Notification; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NotificationRepository extends JpaRepository { + +} diff --git a/src/main/java/com/gamegoo/repository/notification/NotificationTypeRepository.java b/src/main/java/com/gamegoo/repository/notification/NotificationTypeRepository.java new file mode 100644 index 00000000..8fe3cc71 --- /dev/null +++ b/src/main/java/com/gamegoo/repository/notification/NotificationTypeRepository.java @@ -0,0 +1,12 @@ +package com.gamegoo.repository.notification; + +import com.gamegoo.domain.notification.NotificationType; +import com.gamegoo.domain.notification.NotificationTypeTitle; +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NotificationTypeRepository extends JpaRepository { + + Optional findNotificationTypeByTitle(NotificationTypeTitle title); + +} diff --git a/src/main/java/com/gamegoo/service/board/BoardService.java b/src/main/java/com/gamegoo/service/board/BoardService.java index ccf157fd..4e55762c 100644 --- a/src/main/java/com/gamegoo/service/board/BoardService.java +++ b/src/main/java/com/gamegoo/service/board/BoardService.java @@ -4,8 +4,8 @@ import com.gamegoo.apiPayload.exception.handler.BoardHandler; import com.gamegoo.apiPayload.exception.handler.MemberHandler; import com.gamegoo.apiPayload.exception.handler.PageHandler; -import com.gamegoo.domain.board.Board; import com.gamegoo.domain.Member; +import com.gamegoo.domain.board.Board; import com.gamegoo.domain.board.BoardGameStyle; import com.gamegoo.domain.champion.MemberChampion; import com.gamegoo.domain.gamestyle.GameStyle; @@ -40,32 +40,32 @@ public class BoardService { // 게시판 글 작성. @Transactional - public Board save(BoardRequest.boardInsertDTO request,Long memberId, Member memberProfile){ + public Board save(BoardRequest.boardInsertDTO request, Long memberId, Member memberProfile) { - Member member = memberRepository.findById(memberId).orElseThrow(()->new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); + Member member = memberRepository.findById(memberId).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); // 게임 모드 값 검증. (1 ~ 4 값만 가능) - if (request.getGameMode()<1 || request.getGameMode()>4){ + if (request.getGameMode() < 1 || request.getGameMode() > 4) { throw new BoardHandler(ErrorStatus.GAME_MODE_INVALID); } // 주 포지션 값 검증. (1 ~ 5값만 가능) - if (request.getMainPosition()<1 || request.getMainPosition()>5){ + if (request.getMainPosition() < 1 || request.getMainPosition() > 5) { throw new BoardHandler(ErrorStatus.MAIN_POSITION_INVALID); } // 부 포지션 값 검증. (1 ~ 5값만 가능) - if (request.getSubPosition()<1 || request.getSubPosition()>5){ + if (request.getSubPosition() < 1 || request.getSubPosition() > 5) { throw new BoardHandler(ErrorStatus.SUB_POSITION_INVALID); } // 상대 포지션 값 검증. (1 ~ 5값만 가능) - if (request.getWantPosition()<1 || request.getWantPosition()>5){ + if (request.getWantPosition() < 1 || request.getWantPosition() > 5) { throw new BoardHandler(ErrorStatus.WANT_POSITION_INVALID); } // 마이크 설정 (default=false) - if (request.getVoice()==null){ + if (request.getVoice() == null) { request.setVoice(false); } @@ -81,10 +81,10 @@ public Board save(BoardRequest.boardInsertDTO request,Long memberId, Member memb .collect(Collectors.toList()); // 게시판 글 작성 - 프로필 이미지 수정 여부 검증. - String boardProfileImage; - if (request.getBoardProfileImage()!=null && !request.getBoardProfileImage().isEmpty()){ + Integer boardProfileImage; + if (request.getBoardProfileImage() != null) { boardProfileImage = request.getBoardProfileImage(); - } else{ + } else { // 프로필 페이지에 있는 프로필 이미지 정보 가져오기. boardProfileImage = memberProfile.getProfileImage(); } @@ -101,7 +101,7 @@ public Board save(BoardRequest.boardInsertDTO request,Long memberId, Member memb .build(); board.setMember(member); - Board saveBoard= boardRepository.save(board); + Board saveBoard = boardRepository.save(board); // BoardGameStyle 엔티티 생성 및 연관관계 매핑. gameStyleList.forEach(gameStyle -> { @@ -159,10 +159,10 @@ public Board update(BoardRequest.boardUpdateDTO request, Long memberId, Long boa .collect(Collectors.toList()); // 게시판 글 수정 - 프로필 이미지 수정 여부 검증. - String boardProfileImage; - if (request.getBoardProfileImage()!=null && !request.getBoardProfileImage().isEmpty()){ + Integer boardProfileImage; + if (request.getBoardProfileImage() != null) { boardProfileImage = request.getBoardProfileImage(); - } else{ + } else { // 기존 게시글에 있는 프로필 이미지 정보 가져오기. boardProfileImage = board.getBoardProfileImage(); } @@ -223,7 +223,7 @@ public Board update(BoardRequest.boardUpdateDTO request, Long memberId, Long boa // 게시판 글 삭제. @Transactional - public void delete(Long boardId, Long memberId){ + public void delete(Long boardId, Long memberId) { Board board = boardRepository.findById(boardId).orElseThrow(() -> new BoardHandler(ErrorStatus.BOARD_NOT_FOUND)); @@ -239,14 +239,13 @@ public void delete(Long boardId, Long memberId){ // 게시판 글 목록 조회 @Transactional(readOnly = true) public List getBoardList(Integer mode, String tier, Integer mainPosition, Boolean voice, int pageIdx){ - // pageIdx 값 검증. - if (pageIdx <= 0){ + if (pageIdx <= 0) { throw new PageHandler(ErrorStatus.PAGE_INVALID); } // 사용자로부터 받은 pageIdx를 1 감소 -> pageIdx=1 일 때, 1 페이지. - Pageable pageable = PageRequest.of(pageIdx-1, PAGE_SIZE, Sort.by(Sort.Direction.DESC, "createdAt")); + Pageable pageable = PageRequest.of(pageIdx - 1, PAGE_SIZE, Sort.by(Sort.Direction.DESC, "createdAt")); List boards = boardRepository.findByFilters(mode, tier, mainPosition, voice, pageable).getContent(); @@ -276,7 +275,7 @@ public List getBoardList(Integer mode, Strin // 게시판 글 조회 @Transactional(readOnly = true) - public BoardResponse.boardByIdResponseDTO getBoardById(Long boardId){ + public BoardResponse.boardByIdResponseDTO getBoardById(Long boardId) { Board board = boardRepository.findById(boardId).orElseThrow(() -> new BoardHandler(ErrorStatus.BOARD_NOT_FOUND)); diff --git a/src/main/java/com/gamegoo/service/manner/MannerService.java b/src/main/java/com/gamegoo/service/manner/MannerService.java new file mode 100644 index 00000000..b912d768 --- /dev/null +++ b/src/main/java/com/gamegoo/service/manner/MannerService.java @@ -0,0 +1,144 @@ +package com.gamegoo.service.manner; + +import com.gamegoo.apiPayload.code.status.ErrorStatus; +import com.gamegoo.apiPayload.exception.handler.BoardHandler; +import com.gamegoo.apiPayload.exception.handler.MannerHandler; +import com.gamegoo.apiPayload.exception.handler.MemberHandler; +import com.gamegoo.apiPayload.exception.handler.TempHandler; +import com.gamegoo.domain.Member; +import com.gamegoo.domain.manner.MannerKeyword; +import com.gamegoo.domain.manner.MannerRating; +import com.gamegoo.domain.manner.MannerRatingKeyword; +import com.gamegoo.dto.manner.MannerRequest; +import com.gamegoo.repository.manner.MannerKeywordRepository; +import com.gamegoo.repository.manner.MannerRatingKeywordRepository; +import com.gamegoo.repository.manner.MannerRatingRepository; +import com.gamegoo.repository.member.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +@Transactional +public class MannerService { + private final MemberRepository memberRepository; + private final MannerRatingRepository mannerRatingRepository; + private final MannerRatingKeywordRepository mannerRatingKeywordRepository; + private final MannerKeywordRepository mannerKeywordRepository; + + public MannerRating insertManner(MannerRequest.mannerInsertDTO request, Long memberId){ + + Member member = memberRepository.findById(memberId).orElseThrow(()->new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); + + // 매너평가를 받는 회원 존재 여부 검증. + Member targetMember = memberRepository.findById(request.getToMemberId()).orElseThrow(()->new MemberHandler(ErrorStatus.MANNER_TARGET_MEMBER_NOT_FOUND)); + + // 매너평가를 받는 회원 탈퇴 여부 검증. + if (targetMember.getBlind()){ + throw new MemberHandler(ErrorStatus.USER_DEACTIVATED); + } + + // 매너평가 최초 시도 여부 검증. + List mannerRatings = mannerRatingRepository.findByFromMemberIdAndToMemberId(member.getId(), targetMember.getId()); + List positiveMannerRatings = mannerRatings.stream() + .filter(MannerRating::getIsPositive) + .collect(Collectors.toList()); + + if(!positiveMannerRatings.isEmpty()){ + throw new MannerHandler(ErrorStatus.MANNER_CONFLICT); + } + + // mannerKeyword 의 실제 존재 여부 검증. + List mannerRatingKeywordList = new ArrayList<>(); + request.getMannerRatingKeywordList() + .forEach(mannerKeywordId -> { + MannerKeyword mannerKeyword = mannerKeywordRepository.findById(mannerKeywordId).orElseThrow(() -> new MannerHandler(ErrorStatus.MANNER_KEYWORD_NOT_FOUND)); + if(!mannerKeyword.getIsPositive()){ + throw new MannerHandler(ErrorStatus.MANNER_KEYWORD_TYPE_INVALID); + } + mannerRatingKeywordList.add(mannerKeyword); + }); + + // manner rating 엔티티 생성 및 연관관계 매핑. + MannerRating mannerRating = MannerRating.builder() + .fromMember(member) + .mannerRatingKeywordList(new ArrayList<>()) + .isPositive(true) + .build(); + + mannerRating.setToMember(targetMember); + MannerRating saveManner = mannerRatingRepository.save(mannerRating); + + // manner Rating Keyword 엔티티 생성 및 연관관계 매핑. + mannerRatingKeywordList.forEach(mannerKeyword -> { + MannerRatingKeyword mannerRatingKeyword = MannerRatingKeyword.builder() + .mannerKeyword(mannerKeyword) + .build(); + + mannerRatingKeyword.setMannerRating(saveManner); + mannerRatingKeywordRepository.save(mannerRatingKeyword); + }); + return saveManner; + } + + public MannerRating insertBadManner(MannerRequest.mannerInsertDTO request, Long memberId){ + + Member member = memberRepository.findById(memberId).orElseThrow(()->new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); + + // 비매너평가를 받는 회원 존재 여부 검증. + Member targetMember = memberRepository.findById(request.getToMemberId()).orElseThrow(()->new MemberHandler(ErrorStatus.MANNER_TARGET_MEMBER_NOT_FOUND)); + + // 비매너평가를 받는 회원 탈퇴 여부 검증. + if (targetMember.getBlind()){ + throw new MemberHandler(ErrorStatus.USER_DEACTIVATED); + } + + // 비매너평가 최초 시도 여부 검증. + List mannerRatings = mannerRatingRepository.findByFromMemberIdAndToMemberId(member.getId(), targetMember.getId()); + List negativeMannerRatings = mannerRatings.stream() + .filter(rating -> !rating.getIsPositive()) + .collect(Collectors.toList()); + + if(!negativeMannerRatings.isEmpty()){ + throw new MannerHandler(ErrorStatus.BAD_MANNER_CONFLICT); + } + + // mannerKeyword 의 실제 존재 여부 검증. + List mannerRatingKeywordList = new ArrayList<>(); + request.getMannerRatingKeywordList() + .forEach(mannerKeywordId -> { + MannerKeyword mannerKeyword = mannerKeywordRepository.findById(mannerKeywordId).orElseThrow(() -> new MannerHandler(ErrorStatus.MANNER_KEYWORD_NOT_FOUND)); + if(mannerKeyword.getIsPositive()){ + throw new MannerHandler(ErrorStatus.BAD_MANNER_KEYWORD_TYPE_INVALID); + } + mannerRatingKeywordList.add(mannerKeyword); + }); + + // manner rating 엔티티 생성 및 연관관계 매핑. + MannerRating mannerRating = MannerRating.builder() + .fromMember(member) + .mannerRatingKeywordList(new ArrayList<>()) + .isPositive(false) + .build(); + + mannerRating.setToMember(targetMember); + MannerRating saveManner = mannerRatingRepository.save(mannerRating); + + // manner Rating Keyword 엔티티 생성 및 연관관계 매핑. + mannerRatingKeywordList.forEach(mannerKeyword -> { + MannerRatingKeyword mannerRatingKeyword = MannerRatingKeyword.builder() + .mannerKeyword(mannerKeyword) + .build(); + + mannerRatingKeyword.setMannerRating(saveManner); + mannerRatingKeywordRepository.save(mannerRatingKeyword); + }); + return saveManner; + } +} diff --git a/src/main/java/com/gamegoo/service/matching/MatchingService.java b/src/main/java/com/gamegoo/service/matching/MatchingService.java index 50106d87..64d8a7b5 100644 --- a/src/main/java/com/gamegoo/service/matching/MatchingService.java +++ b/src/main/java/com/gamegoo/service/matching/MatchingService.java @@ -8,6 +8,7 @@ import com.gamegoo.dto.matching.MatchingRequest; import com.gamegoo.repository.matching.MatchingRecordRepository; import com.gamegoo.repository.member.MemberRepository; +import com.gamegoo.service.member.ProfileService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -18,6 +19,7 @@ public class MatchingService { private final MemberRepository memberRepository; private final MatchingRecordRepository matchingRecordRepository; + private final ProfileService profileService; /** * 매칭 정보 저장 @@ -45,6 +47,10 @@ public void save(MatchingRequest.SaveMatchingRequestDTO request, Long id) { .member(member) .build(); + // 매칭 기록에 따라 member 정보 변경하기 + member.updateMemberFromMatching(request.getMainP(), request.getSubP(), request.getMike()); + profileService.addMemberGameStyles(request.getGameStyleIdList(), member.getId()); + matchingRecordRepository.save(matchingRecord); } diff --git a/src/main/java/com/gamegoo/service/member/AuthService.java b/src/main/java/com/gamegoo/service/member/AuthService.java index 247b538e..c41fe78b 100644 --- a/src/main/java/com/gamegoo/service/member/AuthService.java +++ b/src/main/java/com/gamegoo/service/member/AuthService.java @@ -28,6 +28,7 @@ import java.time.Duration; import java.time.LocalDateTime; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; @Service @RequiredArgsConstructor @@ -72,12 +73,14 @@ public Member joinMember(String email, String password, String gameName, String // tier, rank, winrate // DB 저장 // 1. Riot 정보 제외 저장 + int randomProfileImage = ThreadLocalRandom.current().nextInt(1, 9); Member member = Member.builder() .email(email) .password(bCryptPasswordEncoder.encode(password)) .loginType(LoginType.GENERAL) - .profileImage("default") + .profileImage(randomProfileImage) .blind(false) + .mike(false) .build(); @@ -166,7 +169,7 @@ public MemberResponse.RefreshTokenResponseDTO verifyRefreshToken(String refresh_ String new_refresh_token = jwtUtil.createJwt(60 * 60 * 24 * 30 * 1000L); // 30일 // refresh token 저장하기 - member.setRefreshToken(new_refresh_token); + member.updateRefreshToken(new_refresh_token); memberRepository.save(member); return new MemberResponse.RefreshTokenResponseDTO(access_token, new_refresh_token); @@ -251,7 +254,7 @@ private String getCertificationMessage(String certificationNumber) { public void logoutMember(Long id) { Member member = memberRepository.findById(id).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); - member.setRefreshToken(null); + member.updateRefreshToken(null); memberRepository.save(member); } diff --git a/src/main/java/com/gamegoo/service/member/MemberService.java b/src/main/java/com/gamegoo/service/member/BlockService.java similarity index 83% rename from src/main/java/com/gamegoo/service/member/MemberService.java rename to src/main/java/com/gamegoo/service/member/BlockService.java index 3fa19a3a..943e94ab 100644 --- a/src/main/java/com/gamegoo/service/member/MemberService.java +++ b/src/main/java/com/gamegoo/service/member/BlockService.java @@ -5,12 +5,10 @@ import com.gamegoo.apiPayload.exception.handler.MemberHandler; import com.gamegoo.apiPayload.exception.handler.PageHandler; import com.gamegoo.domain.Block; -import com.gamegoo.domain.Friend; import com.gamegoo.domain.Member; import com.gamegoo.repository.member.BlockRepository; -import com.gamegoo.repository.member.FriendRepository; import com.gamegoo.repository.member.MemberRepository; -import java.util.List; +import com.gamegoo.util.MemberUtils; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -20,11 +18,10 @@ @Service @RequiredArgsConstructor @Transactional -public class MemberService { +public class BlockService { private final MemberRepository memberRepository; private final BlockRepository blockRepository; - private final FriendRepository friendRepository; Integer pageSize = 9; @@ -42,8 +39,13 @@ public Member blockMember(Long memberId, Long targetMemberId) { Member targetMember = memberRepository.findById(targetMemberId) .orElseThrow(() -> new MemberHandler(ErrorStatus.TARGET_MEMBER_NOT_FOUND)); + // 본인이 본인을 차단 시도하는 경우 + if (member.equals(targetMember)) { + throw new MemberHandler(ErrorStatus.BLOCK_MEMBER_BAD_REQUEST); + } + // 대상 회원의 탈퇴 여부 검증 - checkBlind(targetMember); + MemberUtils.checkBlind(targetMember); // 이미 차단한 회원인지 검증 boolean isblocked = blockRepository.existsByBlockerMemberAndBlockedMember(member, @@ -107,28 +109,5 @@ public void unBlockMember(Long memberId, Long targetMemberId) { blockRepository.delete(block); } - /** - * memberId에 해당하는 회원의 친구 목록 조회 - * - * @param memberId - * @return - */ - @Transactional(readOnly = true) - public List getFriends(Long memberId) { - return friendRepository.findAllByFromMemberId(memberId); - } - - /** - * 해당 회원이 탈퇴했는지 검증 - * - * @param member - */ - public static boolean checkBlind(Member member) { - if (member.getBlind()) { - throw new MemberHandler(ErrorStatus.USER_DEACTIVATED); - } - return false; - } - } diff --git a/src/main/java/com/gamegoo/service/member/FriendService.java b/src/main/java/com/gamegoo/service/member/FriendService.java new file mode 100644 index 00000000..a75cc2ba --- /dev/null +++ b/src/main/java/com/gamegoo/service/member/FriendService.java @@ -0,0 +1,87 @@ +package com.gamegoo.service.member; + +import com.gamegoo.apiPayload.code.status.ErrorStatus; +import com.gamegoo.apiPayload.exception.handler.FriendHandler; +import com.gamegoo.domain.Member; +import com.gamegoo.domain.friend.Friend; +import com.gamegoo.domain.friend.FriendRequestStatus; +import com.gamegoo.domain.friend.FriendRequests; +import com.gamegoo.domain.notification.NotificationTypeTitle; +import com.gamegoo.repository.friend.FriendRepository; +import com.gamegoo.repository.friend.FriendRequestsRepository; +import com.gamegoo.service.notification.NotificationService; +import com.gamegoo.util.MemberUtils; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class FriendService { + + private final FriendRepository friendRepository; + private final FriendRequestsRepository friendRequestsRepository; + private final ProfileService profileService; + private final NotificationService notificationService; + + /** + * memberId에 해당하는 회원의 친구 목록 조회 + * + * @param memberId + * @return + */ + @Transactional(readOnly = true) + public List getFriends(Long memberId) { + return friendRepository.findAllByFromMemberId(memberId); + } + + + /** + * targetMemberId에 해당하는 회원에게 친구 요청 전송 + * + * @param memberId + * @param targetMemberId + * @return + */ + public FriendRequests sendFriendRequest(Long memberId, Long targetMemberId) { + Member member = profileService.findMember(memberId); + + Member targetMember = profileService.findMember(targetMemberId); + + // targetMember로 나 자신을 요청한 경우 + if (member.equals(targetMember)) { + throw new FriendHandler(ErrorStatus.FRIEND_BAD_REQUEST); + } + + // 내가 상대방을 차단한 경우 + if (MemberUtils.isBocked(member, targetMember)) { + throw new FriendHandler(ErrorStatus.FRIEND_TARGET_IS_BLOCKED); + } + + // 상대방이 나를 차단한 경우 + if (MemberUtils.isBocked(targetMember, member)) { + throw new FriendHandler(ErrorStatus.BLOCKED_BY_FRIEND_TARGET); + } + + FriendRequests friendRequests = FriendRequests.builder() + .status(FriendRequestStatus.PENDING) + .fromMember(member) + .toMember(targetMember) + .build(); + + FriendRequests savedFriendRequests = friendRequestsRepository.save(friendRequests); + + // 친구 요청 알림 생성 + // member -> targetMember + notificationService.createNotification(NotificationTypeTitle.FRIEND_REQUEST_SEND, + targetMember.getGameName(), null, member); + + // targetMember -> member + notificationService.createNotification(NotificationTypeTitle.FRIEND_REQUEST_RECEIVED, + member.getGameName(), member.getId(), targetMember); + + return savedFriendRequests; + } +} diff --git a/src/main/java/com/gamegoo/service/member/PasswordService.java b/src/main/java/com/gamegoo/service/member/PasswordService.java index afe26163..610fcb62 100644 --- a/src/main/java/com/gamegoo/service/member/PasswordService.java +++ b/src/main/java/com/gamegoo/service/member/PasswordService.java @@ -40,7 +40,23 @@ public void updatePassword(Long userId, String newPassword) { .orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); // 비밀번호 재설정 - member.setPassword(bCryptPasswordEncoder.encode(newPassword)); + member.updatePassword(bCryptPasswordEncoder.encode(newPassword)); + memberRepository.save(member); + } + + /** + * 비밀번호 수정 + * + * @param email + * @param newPassword + */ + public void updatePasswordWithEmail(String email, String newPassword) { + // jwt 토큰으로 멤버 찾기 + Member member = memberRepository.findByEmail(email) + .orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); + + // 비밀번호 재설정 + member.updatePassword(bCryptPasswordEncoder.encode(newPassword)); memberRepository.save(member); } diff --git a/src/main/java/com/gamegoo/service/member/ProfileService.java b/src/main/java/com/gamegoo/service/member/ProfileService.java index 1a2519a8..cf47f06d 100644 --- a/src/main/java/com/gamegoo/service/member/ProfileService.java +++ b/src/main/java/com/gamegoo/service/member/ProfileService.java @@ -5,7 +5,6 @@ import com.gamegoo.domain.Member; import com.gamegoo.domain.gamestyle.GameStyle; import com.gamegoo.domain.gamestyle.MemberGameStyle; -import com.gamegoo.dto.member.MemberRequest; import com.gamegoo.repository.member.GameStyleRepository; import com.gamegoo.repository.member.MemberGameStyleRepository; import com.gamegoo.repository.member.MemberRepository; @@ -26,18 +25,19 @@ public class ProfileService { /** * MemberGameStyle 데이터 추가 : 회원에 따른 게임 스타일 정보 저장하기 * - * @param request + * @param gameStyleIdList * @param memberId * @return */ @Transactional - public List addMemberGameStyles(MemberRequest.GameStyleRequestDTO request, Long memberId) { + public List addMemberGameStyles(List gameStyleIdList, Long memberId) { // 회원 엔티티 조회 Member member = memberRepository.findById(memberId) .orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); + // 요청으로 온 gamestyleId로 GameStyle 엔티티 리스트를 생성 및 gamestyleId에 해당하는 gamestyle이 db에 존재하는지 검증 - List requestGameStyleList = request.getGameStyleIdList().stream() + List requestGameStyleList = gameStyleIdList.stream() .map(gameStyleId -> gameStyleRepository.findById(gameStyleId) .orElseThrow(() -> new MemberHandler(ErrorStatus.GAMESTYLE_NOT_FOUND))) .toList(); @@ -84,7 +84,8 @@ public void deleteMember(Long userId) { .orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); // Blind 처리 - member.setBlind(true); + member.deactiveMember(); + memberRepository.save(member); } @@ -104,8 +105,7 @@ public void modifyPosition(Long userId, int mainP, int subP) { Member member = memberRepository.findById(userId) .orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); - member.setMainPosition(mainP); - member.setSubPosition(subP); + member.updatePosition(mainP, subP); memberRepository.save(member); } @@ -116,15 +116,12 @@ public void modifyPosition(Long userId, int mainP, int subP) { * @param profileImage */ @Transactional - public void modifyProfileImage(Long userId, String profileImage) { - if (profileImage.length() > 30) { - throw new MemberHandler(ErrorStatus.PROFILE_IMAGE_BAD_REQUEST); - } - + public void modifyProfileImage(Long userId, Integer profileImage) { Member member = memberRepository.findById(userId) .orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); - member.setProfileImage(profileImage); + member.updateProfileImage(profileImage); + memberRepository.save(member); } diff --git a/src/main/java/com/gamegoo/service/notification/NotificationService.java b/src/main/java/com/gamegoo/service/notification/NotificationService.java new file mode 100644 index 00000000..c51aba10 --- /dev/null +++ b/src/main/java/com/gamegoo/service/notification/NotificationService.java @@ -0,0 +1,200 @@ +package com.gamegoo.service.notification; + + +import com.gamegoo.apiPayload.code.status.ErrorStatus; +import com.gamegoo.apiPayload.exception.handler.NotificationHandler; +import com.gamegoo.domain.Member; +import com.gamegoo.domain.notification.Notification; +import com.gamegoo.domain.notification.NotificationType; +import com.gamegoo.domain.notification.NotificationTypeTitle; +import com.gamegoo.repository.notification.NotificationRepository; +import com.gamegoo.repository.notification.NotificationTypeRepository; +import java.util.Random; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class NotificationService { + + private final NotificationTypeRepository notificationTypeRepository; + private final NotificationRepository notificationRepository; + + /** + * 새로운 알림 생성 및 저장 메소드 + * + * @param notificationTypeTitle + * @param content 각 알림에 포함되어어야 할 정보 (사용자 닉네임, 매너레벨 단계, 키둬드) + * @param sourceId 이동해야할 url의 고유 id 파라미터, FRIEND_REQUEST_RECEIVED에서만 필요 + * @param member 알림을 받을 대상 회원 + * @return + */ + public Notification createNotification(NotificationTypeTitle notificationTypeTitle, + String content, Long sourceId, Member member) { + + NotificationType notificationType = notificationTypeRepository.findNotificationTypeByTitle( + notificationTypeTitle) + .orElseThrow(() -> new NotificationHandler(ErrorStatus.NOTIFICATION_TYPE_NOT_FOUND)); + + switch (notificationTypeTitle) { + case FRIEND_REQUEST_SEND: + return createFriendRequestSendNotification(notificationType, content, member); + case FRIEND_REQUEST_RECEIVED: + if (sourceId == null) { + throw new NotificationHandler(ErrorStatus.NOTIFICATION_METHOD_BAD_REQUEST); + } + return createFriendRequestReceivedNotification(notificationType, content, sourceId, + member); + case FRIEND_REQUEST_ACCEPTED: + case FRIEND_REQUEST_REJECTED: + return createFriendRequestAcceptedAndRejectedNotification(notificationType, content, + member); + case MANNER_LEVEL_UP: + case MANNER_LEVEL_DOWN: + return createMannerLevelUpDownNotification(notificationType, content, member); + case MANNER_KEYWORD_RATED: + return createMannerKeywordRatedNotification(notificationType, content, member); + case TEST_ALARM: + // 랜덤 숫자 생성 + Random random = new Random(); + int i = random.nextInt(1000) + 1; + // 숫자를 String 형으로 변환 + String randomNumberString = Integer.toString(i); + return createTestNotification(notificationType, randomNumberString, member); + default: + throw new NotificationHandler(ErrorStatus.NOTIFICATION_TYPE_NOT_FOUND); + } + } + + /** + * 친구 요청 전송됨 알림 생성 + * + * @param notificationType + * @param content + * @param member + * @return + */ + private Notification createFriendRequestSendNotification( + NotificationType notificationType, + String content, Member member) { + Notification notification = Notification.builder() + .notificationType(notificationType) + .content(content + notificationType.getContent()) + .isRead(false) + .build(); + notification.setMember(member); + + return notificationRepository.save(notification); + } + + /** + * 친구 요청 받음 알림 생성 + * + * @param notificationType + * @param content + * @param sourceId + * @param member + * @return + */ + private Notification createFriendRequestReceivedNotification( + NotificationType notificationType, + String content, Long sourceId, Member member + ) { + Notification notification = Notification.builder() + .notificationType(notificationType) + .content(content + notificationType.getContent()) + .sourceId(sourceId) + .isRead(false) + .build(); + notification.setMember(member); + + return notificationRepository.save(notification); + } + + /** + * 친구 요청 수락됨, 거절됨 알림 생성 + * + * @param notificationType + * @param content + * @param member + * @return + */ + private Notification createFriendRequestAcceptedAndRejectedNotification( + NotificationType notificationType, + String content, Member member + ) { + Notification notification = Notification.builder() + .notificationType(notificationType) + .content(content + notificationType.getContent()) + .isRead(false) + .build(); + notification.setMember(member); + + return notificationRepository.save(notification); + } + + /** + * 매너레벨 상승, 하락 알림 생성 + * + * @param notificationType + * @param content + * @param member + * @return + */ + private Notification createMannerLevelUpDownNotification(NotificationType notificationType, + String content, Member member) { + String notificationContent = notificationType.getContent().replace("n", content); + Notification notification = Notification.builder() + .notificationType(notificationType) + .content(notificationContent) + .isRead(false) + .build(); + notification.setMember(member); + + return notificationRepository.save(notification); + } + + /** + * 키워드 평가 알림 생성 + * + * @param notificationType + * @param content + * @param member + * @return + */ + private Notification createMannerKeywordRatedNotification(NotificationType notificationType, + String content, Member member) { + String notificationContent = notificationType.getContent().replace("n", content); + Notification notification = Notification.builder() + .notificationType(notificationType) + .content(notificationContent) + .isRead(false) + .build(); + notification.setMember(member); + + return notificationRepository.save(notification); + } + + /** + * 테스트 알림 생성 + * + * @param notificationType + * @param content + * @param member + * @return + */ + private Notification createTestNotification(NotificationType notificationType, String content, + Member member) { + Notification notification = Notification.builder() + .notificationType(notificationType) + .content(notificationType.getContent() + content) + .isRead(false) + .build(); + notification.setMember(member); + + return notificationRepository.save(notification); + } + +} diff --git a/src/main/java/com/gamegoo/util/MemberUtils.java b/src/main/java/com/gamegoo/util/MemberUtils.java new file mode 100644 index 00000000..6a7a6b7d --- /dev/null +++ b/src/main/java/com/gamegoo/util/MemberUtils.java @@ -0,0 +1,35 @@ +package com.gamegoo.util; + +import com.gamegoo.apiPayload.code.status.ErrorStatus; +import com.gamegoo.apiPayload.exception.handler.MemberHandler; +import com.gamegoo.domain.Member; + +public class MemberUtils { + + /** + * member가 targetMember를 차단한 상태인지 리턴 + * + * @param member + * @param targetMember + * @return + */ + public static boolean isBocked(Member member, Member targetMember) { + + return member.getBlockList().stream() + .anyMatch(block -> block.getBlockedMember().equals(targetMember)); + } + + /** + * 해당 회원이 탈퇴했는지 검증 + * + * @param member + */ + public static boolean checkBlind(Member member) { + if (member.getBlind()) { + throw new MemberHandler(ErrorStatus.USER_DEACTIVATED); + } + return false; + } + + +} diff --git a/src/main/java/com/gamegoo/util/RiotUtil.java b/src/main/java/com/gamegoo/util/RiotUtil.java index 96169a20..7fcc4b61 100644 --- a/src/main/java/com/gamegoo/util/RiotUtil.java +++ b/src/main/java/com/gamegoo/util/RiotUtil.java @@ -162,16 +162,13 @@ public void addTierRankWinRate(Member member, String gameName, String encryptedS winrate = Math.round(winrate * 1000) / 10.0; // DB에 저장 - member.setTier(entry.getTier()); - member.setRank(entry.getRank()); - member.setWinRate(winrate); + member.updateRiotDetails(entry.getTier(), entry.getRank(), winrate); break; } } // 솔랭을 하지 않는 유저는 gameName만 저장 - member.setGameName(gameName); - member.setTag(tag); + member.updateRiotBasic(gameName, tag); } /**