Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

프로덕션 코드 리팩토링 #206

Merged
merged 18 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@
@RequiredArgsConstructor
public class AdminQuery {

private static final String ID_VALIDATION_ERROR_MESSAGE = "유효하지 않은 관리자 아이디(%s)입니다.";
private static final String PASSWORD_VALIDATION_ERROR_MESSAGE = "유효하지 않은 관리자 비밀번호(%s)입니다.";

private final AdminRepository adminRepository;

public void checkIdAndPassword(String id, String password) {
Admin admin = adminRepository.findById(id)
.orElseThrow(() -> new NotFoundException(VALIDATION_ERROR,
String.format("유효하지 않은 관리자 아이디(%s)입니다.", id)));
String.format(ID_VALIDATION_ERROR_MESSAGE, id)));

if (admin.isCorrectPassword(password)) {
return;
}
throw new NotFoundException(VALIDATION_ERROR,
String.format("유효하지 않은 관리자 비밀번호(%s)입니다.", password));
String.format(PASSWORD_VALIDATION_ERROR_MESSAGE, password));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import coffeemeet.server.admin.presentation.dto.AdminCustomPage;
import coffeemeet.server.admin.presentation.dto.AdminCustomSlice;
import coffeemeet.server.admin.presentation.dto.AdminLoginHTTP;
import coffeemeet.server.admin.presentation.dto.FindGroupReportsParam;
import coffeemeet.server.admin.presentation.dto.GroupReportHTTP;
import coffeemeet.server.admin.presentation.dto.ReportDeletionHTTP;
import coffeemeet.server.admin.presentation.dto.ReportDetailHTTP;
import coffeemeet.server.admin.presentation.dto.UserPunishmentHTTP;
import coffeemeet.server.admin.service.AdminService;
import coffeemeet.server.certification.service.CertificationService;
Expand All @@ -13,17 +16,13 @@
import coffeemeet.server.inquiry.presentation.dto.InquiryDetailHTTP;
import coffeemeet.server.inquiry.service.InquiryService;
import coffeemeet.server.inquiry.service.dto.InquiryDetailDto;
import coffeemeet.server.inquiry.service.dto.InquirySearchResponse;
import coffeemeet.server.inquiry.service.dto.InquirySearchResponse.InquirySummary;
import coffeemeet.server.report.presentation.dto.FindGroupReports;
import coffeemeet.server.report.presentation.dto.GroupReportHTTP;
import coffeemeet.server.report.presentation.dto.ReportDetailHTTP;
import coffeemeet.server.report.presentation.dto.ReportListHTTP;
import coffeemeet.server.report.presentation.dto.ReportListHTTP.Response;
import coffeemeet.server.inquiry.service.dto.InquirySearchDto;
import coffeemeet.server.inquiry.service.dto.InquirySummary;
import coffeemeet.server.report.service.ReportService;
import coffeemeet.server.report.service.dto.GroupReportDto;
import coffeemeet.server.report.service.dto.ReportDetailDto;
import coffeemeet.server.report.service.dto.ReportListDto;
import coffeemeet.server.report.service.dto.ReportSummary;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
Expand Down Expand Up @@ -128,7 +127,7 @@ public ResponseEntity<Void> dismissReport(
}

@GetMapping("/reports")
public ResponseEntity<AdminCustomSlice<ReportListHTTP.Response>> findAllReports(
public ResponseEntity<AdminCustomSlice<ReportSummary>> findAllReports(
@SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId,
@RequestParam(defaultValue = "0") Long lastReportId,
@RequestParam(defaultValue = "10") int pageSize
Expand All @@ -137,22 +136,20 @@ public ResponseEntity<AdminCustomSlice<ReportListHTTP.Response>> findAllReports(
// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE);
// }
ReportListDto reportListDto = reportService.findAllReports(lastReportId, pageSize);
List<ReportListHTTP.Response> responses = reportListDto.contents().stream()
.map(Response::from)
.toList();
return ResponseEntity.ok(AdminCustomSlice.of(responses, reportListDto.hasNext()));
return ResponseEntity.ok(
AdminCustomSlice.of(reportListDto.contents(), reportListDto.hasNext()));
}

@GetMapping("/reports/group")
public ResponseEntity<GroupReportHTTP.Response> findReportByTargetIdAndChattingRoomId(
@SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId,
@ModelAttribute FindGroupReports findGroupReports
@ModelAttribute FindGroupReportsParam findGroupReportsParam
) {
// if (adminId == null) {
// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE);
// }
List<GroupReportDto> responses = reportService.findReportByTargetIdAndChattingRoomId(
findGroupReports.targetedId(), findGroupReports.chattingRoomId());
findGroupReportsParam.targetedId(), findGroupReportsParam.chattingRoomId());
return ResponseEntity.ok(GroupReportHTTP.Response.from(responses));
}

Expand All @@ -176,7 +173,7 @@ public ResponseEntity<AdminCustomSlice<InquirySummary>> searchInquiries(
// if (adminId == null) {
// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE);
// }
InquirySearchResponse inquiries = inquiryService.searchInquiries(lastInquiryId, pageSize);
InquirySearchDto inquiries = inquiryService.searchInquiries(lastInquiryId, pageSize);
return ResponseEntity.ok(AdminCustomSlice.of(inquiries.contents(), inquiries.hasNext()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package coffeemeet.server.report.presentation.dto;
package coffeemeet.server.admin.presentation.dto;

import jakarta.validation.constraints.NotNull;

public record FindGroupReports(
public record FindGroupReportsParam(
@NotNull
Long chattingRoomId,
@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package coffeemeet.server.admin.presentation.dto;

import static lombok.AccessLevel.PRIVATE;

import coffeemeet.server.report.service.dto.GroupReportDto;
import java.util.List;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = PRIVATE)
public final class GroupReportHTTP {

public record Response(List<GroupReportDto> groupReports) {

public static Response from(List<GroupReportDto> responses) {
return new Response(responses);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package coffeemeet.server.report.presentation.dto;
package coffeemeet.server.admin.presentation.dto;

import static lombok.AccessLevel.PRIVATE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class AuthTokensGenerator {

private static final String BEARER_TYPE = "Bearer ";

private final JwtTokenProvider jwtTokenProvider;
private final Long accessTokenExpireTime;
private final Long refreshTokenExpireTime;
private final JwtTokenProvider jwtTokenProvider;
private final RefreshTokenCommand refreshTokenCommand;

public AuthTokensGenerator(JwtTokenProvider jwtTokenProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ public class CertificationService {
private final EmailVerificationCommand emailVerificationCommand;
private final EmailVerificationQuery emailVerificationQuery;

public void registerCertification(long userId, String companyName, String email,
public void registerCertification(Long userId, String companyName, String email,
String departmentName, File businessCardImage) {
processCertification(userId, companyName, email, departmentName, businessCardImage, false);
}

public void updateCertification(long userId, String companyName, String email,
public void updateCertification(Long userId, String companyName, String email,
String departmentName, File businessCardImage) {
processCertification(userId, companyName, email, departmentName, businessCardImage, true);
}

private void processCertification(long userId, String companyName, String email,
private void processCertification(Long userId, String companyName, String email,
String departmentName, File businessCardImage, boolean isUpdate) {
String key = mediaManager.generateKey(BUSINESS_CARD);
uploadBusinessCard(userId, key, businessCardImage);
Expand All @@ -67,7 +67,7 @@ private void processCertification(long userId, String companyName, String email,
businessCardUrl);
}

private void uploadBusinessCard(long userId, String key, File businessCardUrl) {
private void uploadBusinessCard(Long userId, String key, File businessCardUrl) {
certificationCommand.applyIfCertifiedUser(userId, certification -> {
String oldKey = mediaManager.extractKey(certification.getBusinessCardUrl(), BUSINESS_CARD);
mediaManager.delete(oldKey);
Expand Down Expand Up @@ -103,7 +103,7 @@ public PendingCertificationPageDto getUncertifiedUserRequests(Pageable pageable)
certificationQuery.getPendingCertification(pageable);
Page<PendingCertification> pendingCertificationPage = pendingCertification.map(
PendingCertification::from);
return new PendingCertificationPageDto(pendingCertificationPage);
return PendingCertificationPageDto.from(pendingCertificationPage);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ public record PendingCertificationPageDto(
Page<PendingCertification> page
) {

public static PendingCertificationPageDto from(Page<PendingCertification> page) {
return new PendingCertificationPageDto(page);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package coffeemeet.server.chatting.current.presentation;

import coffeemeet.server.chatting.current.presentation.dto.ChatStomp;
import coffeemeet.server.chatting.current.presentation.dto.ChattingStomp;
import coffeemeet.server.chatting.current.service.ChattingMessageService;
import coffeemeet.server.chatting.current.service.dto.ChattingDto;
import coffeemeet.server.common.annotation.PerformanceMeasurement;
Expand Down Expand Up @@ -41,14 +41,14 @@ public void onDisconnect(SessionDisconnectEvent event) {
}

@MessageMapping("/chatting/messages")
public void message(@Valid ChatStomp.Request request, SimpMessageHeaderAccessor accessor) {
ChattingDto.Response response = chattingMessageService.chatting(
public void message(@Valid ChattingStomp.Request request, SimpMessageHeaderAccessor accessor) {
ChattingDto response = chattingMessageService.chat(
accessor.getSessionId(),
request.roomId(),
request.content()
);
simpMessageSendingOperations.convertAndSend("/sub/chatting/rooms/" + request.roomId(),
ChatStomp.Response.from(response));
ChattingStomp.Response.from(response));
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package coffeemeet.server.chatting.current.presentation;

import coffeemeet.server.chatting.current.presentation.dto.ChatRoomStatusHTTP;
import coffeemeet.server.chatting.current.presentation.dto.ChatsHTTP;
import coffeemeet.server.chatting.current.presentation.dto.ChattingCustomSlice;
import coffeemeet.server.chatting.current.presentation.dto.ChattingRoomStatusHTTP;
import coffeemeet.server.chatting.current.service.ChattingRoomService;
import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto;
import coffeemeet.server.chatting.current.service.dto.ChattingDto.Response;
import java.util.List;
import coffeemeet.server.chatting.current.service.dto.ChattingListDto;
import coffeemeet.server.chatting.current.service.dto.ChattingRoomStatusDto;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -23,12 +22,13 @@ public class ChattingRoomController {
private final ChattingRoomService chattingRoomService;

@GetMapping("/{roomId}")
public ResponseEntity<ChatsHTTP.Response> viewChattingRoomMessages(
public ResponseEntity<ChattingCustomSlice.Response> viewChattingRoomMessages(
@PathVariable Long roomId,
@RequestParam(defaultValue = "0") Long firstMessageId,
@RequestParam(defaultValue = "50") int pageSize) {
List<Response> responses = chattingRoomService.searchMessages(roomId, firstMessageId, pageSize);
return ResponseEntity.ok(ChatsHTTP.Response.from(responses));
ChattingListDto responses = chattingRoomService.searchMessages(roomId, firstMessageId,
pageSize);
return ResponseEntity.ok(ChattingCustomSlice.Response.from(responses));
}

@DeleteMapping("/{roomId}")
Expand All @@ -38,9 +38,11 @@ public ResponseEntity<Void> exitChattingRoom(@PathVariable Long roomId) {
}

@GetMapping("/{roomId}/exist")
public ResponseEntity<ChatRoomStatusHTTP.Response> checkChattingRoom(@PathVariable Long roomId) {
ChatRoomStatusDto chatRoomStatusDto = chattingRoomService.checkChattingRoomStatus(roomId);
return ResponseEntity.ok(ChatRoomStatusHTTP.Response.from(chatRoomStatusDto));
public ResponseEntity<ChattingRoomStatusHTTP.Response> checkChattingRoom(
@PathVariable Long roomId) {
ChattingRoomStatusDto chattingRoomStatusDto = chattingRoomService.checkChattingRoomStatus(
roomId);
return ResponseEntity.ok(ChattingRoomStatusHTTP.Response.from(chattingRoomStatusDto));
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package coffeemeet.server.chatting.current.presentation.dto;

import static lombok.AccessLevel.PRIVATE;

import coffeemeet.server.chatting.current.service.dto.Chatting;
import coffeemeet.server.chatting.current.service.dto.ChattingListDto;
import java.util.List;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = PRIVATE)
public final class ChattingCustomSlice {

public record Response(
List<Chatting> chats,
boolean hasNext
) {

public static Response from(ChattingListDto chattingListDto) {
return new Response(chattingListDto.contents(), chattingListDto.hasNext());
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package coffeemeet.server.chatting.current.presentation.dto;

import static lombok.AccessLevel.PRIVATE;

import coffeemeet.server.chatting.current.service.dto.ChattingRoomStatusDto;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = PRIVATE)
public final class ChattingRoomStatusHTTP {

public record Response(
boolean isExisted
) {

public static ChattingRoomStatusHTTP.Response from(
ChattingRoomStatusDto chattingRoomStatusDto) {
return new Response(chattingRoomStatusDto.isExisted());
}

}

}
Loading