Skip to content

Commit

Permalink
Merge pull request #389 from 6QuizOnTheBlock/be/refactor/#387-refactor
Browse files Browse the repository at this point in the history
Be/refactor/#387 refactor
  • Loading branch information
HABINOH authored May 26, 2024
2 parents ecb0756 + 063e159 commit c73a0af
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.quiz.ourclass.global.util.UserAccessUtil;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -201,8 +202,11 @@ public Boolean postDelete(Long postId) {
}
} else if (requesterRole == Role.TEACHER) {
Long orgId = post.getOrganization().getId();
userAccessUtil.isOrganizationManager(member, orgId)
.orElseThrow(() -> new GlobalException(ErrorCode.MEMBER_NOT_IN_ORGANIZATION));
Optional<Organization> organization =
userAccessUtil.isOrganizationManager(member, orgId);
if (organization.isEmpty()) {
throw new GlobalException(ErrorCode.MEMBER_NOT_IN_ORGANIZATION);
}
}
commentRepository.deleteByPostId(post.getId());
postRepository.delete(post);
Expand Down Expand Up @@ -237,8 +241,11 @@ public Boolean postReport(Long postId) {
Post post = postRepository.findById(postId)
.orElseThrow(() -> new GlobalException(ErrorCode.POST_NOT_FOUND));

userAccessUtil.isMemberOfOrganization(member, post.getOrganization().getId())
.orElseThrow(() -> new GlobalException(ErrorCode.MEMBER_NOT_IN_ORGANIZATION));
Optional<MemberOrganization> memberOrganization =
userAccessUtil.isMemberOfOrganization(member, post.getOrganization().getId());
if (memberOrganization.isEmpty()) {
throw new GlobalException(ErrorCode.MEMBER_NOT_IN_ORGANIZATION);
}

String reportMember = member.getName();
String authorMember = post.getAuthor().getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void exitChatRoom(@PathVariable(value = "id") Long id) {
}

@GetMapping
public ResponseEntity<ResultResponse<?>> chatListView(MessageSliceRequest request) {
public ResponseEntity<ResultResponse<MessageResponse>> chatListView(
MessageSliceRequest request) {
MessageResponse messageResponse = chatService.chatListView(request);
return ResponseEntity.ok(ResultResponse.success(messageResponse));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void exitChatRoom(
}
)
@GetMapping
ResponseEntity<ResultResponse<?>> chatListView(
ResponseEntity<ResultResponse<MessageResponse>> chatListView(
MessageSliceRequest request
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ChatFilterController implements ChatFilterControllerDocs {
private final ChatFilterService chatFilterService;

@PostMapping("/{organizationId}")
public ResponseEntity<ResultResponse<?>> register(
public ResponseEntity<ResultResponse<Long>> register(
@PathVariable(value = "organizationId") Long organizationId,
@RequestBody ChatFilterRequest request
) {
Expand All @@ -33,7 +33,7 @@ public ResponseEntity<ResultResponse<?>> register(
}

@PatchMapping("/{organizationId}/{id}")
public ResponseEntity<ResultResponse<?>> modify(
public ResponseEntity<ResultResponse<Boolean>> modify(
@PathVariable(value = "organizationId") Long organizationId,
@PathVariable(value = "id") Long id,
@RequestBody ChatFilterRequest request
Expand All @@ -43,15 +43,15 @@ public ResponseEntity<ResultResponse<?>> modify(
}

@DeleteMapping("/{id}")
public ResponseEntity<ResultResponse<?>> delete(
public ResponseEntity<ResultResponse<Boolean>> delete(
@PathVariable(value = "id") Long id
) {
Boolean isDelete = chatFilterService.delete(id);
return ResponseEntity.ok(ResultResponse.success(isDelete));
}

@GetMapping
public ResponseEntity<ResultResponse<?>> select(
public ResponseEntity<ResultResponse<ChatFilterResponse>> select(
ChatFilterSliceRequest request
) {
ChatFilterResponse response = chatFilterService.select(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface ChatFilterControllerDocs {
}
)
@PostMapping("/{organizationId}")
ResponseEntity<ResultResponse<?>> register(
ResponseEntity<ResultResponse<Long>> register(
@Parameter(name = "organizationId", description = "단체 ID κ°’", required = true, in = ParameterIn.PATH)
@PathVariable(value = "organizationId") Long organizationId,
@Parameter(name = "request", description = "필터링 단어 DTO", required = true, in = ParameterIn.DEFAULT)
Expand All @@ -57,7 +57,7 @@ ResponseEntity<ResultResponse<?>> register(
}
)
@PatchMapping("/{organizationId}/{id}")
ResponseEntity<ResultResponse<?>> modify(
ResponseEntity<ResultResponse<Boolean>> modify(
@Parameter(name = "organizationId", description = "단체 ID", required = true, in = ParameterIn.PATH)
@PathVariable(value = "organizationId") Long organizationId,
@Parameter(name = "id", description = "단어 필터링 ID κ°’", required = true, in = ParameterIn.PATH)
Expand All @@ -77,7 +77,7 @@ ResponseEntity<ResultResponse<?>> modify(
}
)
@DeleteMapping("/{id}")
ResponseEntity<ResultResponse<?>> delete(
ResponseEntity<ResultResponse<Boolean>> delete(
@Parameter(name = "id", description = "단어 필터링 ID κ°’", required = true, in = ParameterIn.PATH)
@PathVariable(value = "id") Long chatFilterId
);
Expand All @@ -96,7 +96,7 @@ ResponseEntity<ResultResponse<?>> delete(
}
)
@GetMapping
ResponseEntity<ResultResponse<?>> select(
ResponseEntity<ResultResponse<ChatFilterResponse>> select(
ChatFilterSliceRequest request
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ private void handleMessage(
}
connectToChatRoom(accessor, memberId);
break;
case SUBSCRIBE:
case SEND:
case SUBSCRIBE, SEND:
verifyAccessToken(getAccessToken(accessor));
break;
default:
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public interface ChatFilterMapper {

@Mapping(target = "id", ignore = true)
ChatFilter RequestToChatFilter(Organization organization, String badWord);
ChatFilter requestToChatFilter(Organization organization, String badWord);

ChatFilter updateChatFilterFromRequest(
ChatFilterRequest request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Long register(Long organizationId, ChatFilterRequest request) {
duplicateWordCheck(organization, request.badWord());

return chatFilterRepository.save(
chatFilterMapper.RequestToChatFilter(organization, request.badWord())
chatFilterMapper.requestToChatFilter(organization, request.badWord())
).getId();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.quiz.ourclass.global.exception.GlobalException;
import com.quiz.ourclass.global.util.RedisUtil;
import com.quiz.ourclass.global.util.UserAccessUtil;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -60,8 +61,11 @@ public void isMemberAuthorizedToJoinRoom(Long memberId, Long chatRoomId) {
throw new GlobalException(ErrorCode.MEMBER_NOT_IN_ORGANIZATION);
}
} else if (member.getRole() == Role.TEACHER) {
userAccessUtil.isOrganizationManager(member, chatRoomId)
.orElseThrow(() -> new GlobalException(ErrorCode.MEMBER_NOT_IN_ORGANIZATION));
Optional<Organization> organization =
userAccessUtil.isOrganizationManager(member, chatRoomId);
if (organization.isEmpty()) {
throw new GlobalException(ErrorCode.MEMBER_NOT_IN_ORGANIZATION);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.quiz.ourclass.global.config;

import com.quiz.ourclass.global.util.ConstantUtil;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
Expand All @@ -15,37 +16,13 @@
public class SwaggerConfig {

@Bean
public GroupedOpenApi Api() {
public GroupedOpenApi api() {
return GroupedOpenApi.builder()
.group("all-api")
.pathsToMatch("/**")
.build();
}

@Bean
public GroupedOpenApi memberApi() {
return GroupedOpenApi.builder()
.group("member-api")
.pathsToMatch("/members/**")
.build();
}

@Bean
public GroupedOpenApi boardApi() {
return GroupedOpenApi.builder()
.group("board-api")
.pathsToMatch("/board/**")
.build();
}

@Bean
public GroupedOpenApi ChallengeApi() {
return GroupedOpenApi.builder()
.group("challenge-api")
.pathsToMatch("/challenge/**")
.build();
}

@Bean
public OpenAPI openAPI() {
Info info = new Info()
Expand All @@ -56,16 +33,16 @@ public OpenAPI openAPI() {
SecurityScheme bearer = new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("Authorization")
.bearerFormat(ConstantUtil.AUTHORIZATION)
.in(SecurityScheme.In.HEADER)
.name(HttpHeaders.AUTHORIZATION);

// Security μš”μ²­ μ„€μ •
SecurityRequirement addSecurityItem = new SecurityRequirement();
addSecurityItem.addList("Authorization");
addSecurityItem.addList(ConstantUtil.AUTHORIZATION);

Components components = new Components()
.addSecuritySchemes("Authorization", bearer);
.addSecuritySchemes(ConstantUtil.AUTHORIZATION, bearer);

return new OpenAPI()
.components(components)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ public abstract class ConstantUtil {
public static final String REDIS_ORG_KEY = "ORGANIZATION:";
public static final int REDIS_ORG_ALIVE_MINUTE = 10;
public static final String REDIS_CHAT_ROOM_KEY = "chatRoom:";
public static final String MONGO_DB_NAME = "chat";
public static final long HOME_FRIEND_COUNT = 3L;
public static final String BLACKLIST_ACCESS_TOKEN = "AT:";
public static final String QUIZ_GAME = "quiz:";
public static final int RELAY_DEMERIT = -100;
public static final int RELAY_REWARD = 50;
public static final Long RELAY_TIMEOUT_DAY = 1L;
public static final String FCM_KEY_PREFIX = "FCM_";
public static final int MAX_RETRIES = 5; //μ΅œλŒ€ μž¬μ‹œλ„ 횟수
public static final long INITIAL_BACKOFF = 1000L; //초기 λ°±μ˜€ν”„ μ‹œκ°„ (1초)
public static final String QUIZ_GAMER = "gamer";
public static final String QUIZ_QUESTION = "question";
public static final String RANKING = "ranking";
public static final String QUIZ_ANSWER = "answer";
public static final String AUTHORIZATION = "Authorization";

// μΈμŠ€ν„΄μŠ€ν™” 방지
private ConstantUtil() {
throw new UnsupportedOperationException(
"This is a utility class and cannot be instantiated");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public enum FcmType {
CHALLENGE("ν•¨κ»˜λ‹¬λ¦¬κΈ°"),
RELAY("이어달리기"),
;
private final String Type;
private final String type;
}
27 changes: 0 additions & 27 deletions backEnd/src/main/java/com/quiz/ourclass/global/util/FcmUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,6 @@ public void sendMessage(Message message) {
} catch (FirebaseMessagingException e) {
log.error("fcm send error");
}
// int attempt = 0;
// long backoff = ConstantUtil.INITIAL_BACKOFF;
//
// while (attempt < ConstantUtil.MAX_RETRIES) { //μ§€μˆ˜ λ°±μ˜€ν”„ μ „λž΅
// try {
// FirebaseMessaging.getInstance().send(message);
// log.info("FCM Send Success");
// break; // 성곡 μ‹œ 루프 μ’…λ£Œ
// } catch (FirebaseMessagingException e) {
// log.error("FCM Send Error: {}", e.getMessage());
// attempt++;
// if (attempt >= ConstantUtil.MAX_RETRIES) {
// // μ΅œλŒ€ μž¬μ‹œλ„ 횟수 도달 μ‹œ 루프 μ’…λ£Œ
// // λ‹€λ₯Έ λ©”μ‹œμ§€ μ‹œμŠ€ν…œμœΌλ‘œ μ•Œλ¦Όμ„ μ „μ†‘ν•˜λŠ” 방법을 κ³ λ €ν•΄λ³Ό 수 있음
// log.error("Reached Maximum Retry Attempts");
// break;
// }
// try {
// Thread.sleep(backoff); // μ§€μˆ˜ λ°±μ˜€ν”„λ₯Ό μœ„ν•œ λŒ€κΈ°
// } catch (InterruptedException ie) {
// Thread.currentThread().interrupt();
// log.error("Interrupted While Waiting For Retry");
// break; // μΈν„°λŸ½νŠΈ λ°œμƒ μ‹œ 루프 μ’…λ£Œ
// }
// backoff *= 2;
// }
// }
}

public FcmDTO makeFcmDTO(String title, String body) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.quiz.ourclass;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest(classes = OurClassApplicationTests.class)
class OurClassApplicationTests {

@Test
void contextLoads() {
}

}

0 comments on commit c73a0af

Please sign in to comment.