Skip to content
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 @@ -3,7 +3,7 @@
import java.time.Duration;
import java.util.List;
import life.mosu.mosuserver.domain.faq.FaqAttachmentJpaEntity;
import life.mosu.mosuserver.domain.faq.FaqAttachmentRepository;
import life.mosu.mosuserver.domain.faq.FaqAttachmentJpaRepository;
import life.mosu.mosuserver.domain.faq.FaqJpaEntity;
import life.mosu.mosuserver.global.util.FileRequest;
import life.mosu.mosuserver.infra.property.S3Properties;
Expand All @@ -20,7 +20,7 @@
@RequiredArgsConstructor
public class FaqAttachmentService implements AttachmentService<FaqJpaEntity, FileRequest> {

private final FaqAttachmentRepository faqAttachmentRepository;
private final FaqAttachmentJpaRepository faqAttachmentJpaRepository;
private final FileUploadHelper fileUploadHelper;
private final S3Service s3Service;
private final S3Properties s3Properties;
Expand All @@ -31,7 +31,7 @@ public void createAttachment(List<FileRequest> requests, FaqJpaEntity faqEntity)
fileUploadHelper.saveAttachments(
requests,
faqEntity.getId(),
faqAttachmentRepository,
faqAttachmentJpaRepository,
(req, id) -> req.toFaqAttachmentEntity(
req.fileName(),
req.s3Key(),
Expand All @@ -43,15 +43,15 @@ public void createAttachment(List<FileRequest> requests, FaqJpaEntity faqEntity)

@Override
public void deleteAttachment(FaqJpaEntity entity) {
List<FaqAttachmentJpaEntity> attachments = faqAttachmentRepository.findAllByFaqId(
List<FaqAttachmentJpaEntity> attachments = faqAttachmentJpaRepository.findAllByFaqId(
entity.getId());
faqAttachmentRepository.deleteAll(attachments);
faqAttachmentJpaRepository.deleteAll(attachments);
}


public List<FaqResponse.AttachmentResponse> toAttachmentResponses(FaqJpaEntity faq) {

List<FaqAttachmentJpaEntity> attachments = faqAttachmentRepository.findAllByFaqId(
List<FaqAttachmentJpaEntity> attachments = faqAttachmentJpaRepository.findAllByFaqId(
faq.getId());

return attachments.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;
import life.mosu.mosuserver.domain.faq.FaqJpaEntity;
import life.mosu.mosuserver.domain.faq.FaqRepository;
import life.mosu.mosuserver.domain.faq.FaqJpaRepository;
import life.mosu.mosuserver.global.exception.CustomRuntimeException;
import life.mosu.mosuserver.global.exception.ErrorCode;
import life.mosu.mosuserver.presentation.faq.dto.FaqCreateRequest;
Expand All @@ -21,21 +21,21 @@
@RequiredArgsConstructor
public class FaqService {

private final FaqRepository faqRepository;
private final FaqJpaRepository faqJpaRepository;
private final FaqAttachmentService attachmentService;


@Transactional
public void createFaq(FaqCreateRequest request) {
FaqJpaEntity faqEntity = faqRepository.save(request.toEntity());
FaqJpaEntity faqEntity = faqJpaRepository.save(request.toEntity());

attachmentService.createAttachment(request.attachments(), faqEntity);
}

@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<FaqResponse> getFaqWithAttachments(int page, int size) {
Pageable pageable = PageRequest.of(page, size, Sort.by("id"));
Page<FaqJpaEntity> faqPage = faqRepository.findAll(pageable);
Page<FaqJpaEntity> faqPage = faqJpaRepository.findAll(pageable);

return faqPage.stream()
.map(this::toFaqResponse)
Expand All @@ -44,19 +44,19 @@ public List<FaqResponse> getFaqWithAttachments(int page, int size) {

@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public FaqResponse getFaqDetail(Long faqId) {
FaqJpaEntity faq = faqRepository.findById(faqId)
FaqJpaEntity faq = faqJpaRepository.findById(faqId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.FAQ_NOT_FOUND));

return toFaqResponse(faq);
}

@Transactional
public void update(FaqUpdateRequest request, Long faqId) {
FaqJpaEntity faqEntity = faqRepository.findById(faqId)
FaqJpaEntity faqEntity = faqJpaRepository.findById(faqId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.FAQ_NOT_FOUND));

faqEntity.update(request.question(), request.answer(), request.author());
faqRepository.save(faqEntity);
faqJpaRepository.save(faqEntity);

attachmentService.deleteAttachment(faqEntity);
attachmentService.createAttachment(request.attachments(), faqEntity);
Expand All @@ -65,9 +65,9 @@ public void update(FaqUpdateRequest request, Long faqId) {

@Transactional
public void deleteFaq(Long faqId) {
FaqJpaEntity faqEntity = faqRepository.findById(faqId)
FaqJpaEntity faqEntity = faqJpaRepository.findById(faqId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.FILE_NOT_FOUND));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error code ErrorCode.FILE_NOT_FOUND seems incorrect. Using ErrorCode.FAQ_NOT_FOUND would be clearer, as in getFaqDetail and update.

Suggested change
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.FILE_NOT_FOUND));
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.FAQ_NOT_FOUND));

Comment on lines +68 to 69
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix inconsistent error code usage.

The error code should be FAQ_NOT_FOUND instead of FILE_NOT_FOUND to be consistent with other methods in this service that use the correct FAQ-specific error code.

-        FaqJpaEntity faqEntity = faqJpaRepository.findById(faqId)
-                .orElseThrow(() -> new CustomRuntimeException(ErrorCode.FILE_NOT_FOUND));
+        FaqJpaEntity faqEntity = faqJpaRepository.findById(faqId)
+                .orElseThrow(() -> new CustomRuntimeException(ErrorCode.FAQ_NOT_FOUND));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
FaqJpaEntity faqEntity = faqJpaRepository.findById(faqId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.FILE_NOT_FOUND));
FaqJpaEntity faqEntity = faqJpaRepository.findById(faqId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.FAQ_NOT_FOUND));
🤖 Prompt for AI Agents
In src/main/java/life/mosu/mosuserver/application/faq/FaqService.java at lines
68-69, the error code used when throwing the exception for a missing FAQ is
incorrectly set to FILE_NOT_FOUND. Change this error code to FAQ_NOT_FOUND to
maintain consistency with other methods in the service that handle FAQ-related
errors.

faqRepository.delete(faqEntity);
faqJpaRepository.delete(faqEntity);
attachmentService.deleteAttachment(faqEntity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.Duration;
import java.util.List;
import life.mosu.mosuserver.domain.inquiryAnswer.InquiryAnswerAttachmentEntity;
import life.mosu.mosuserver.domain.inquiryAnswer.InquiryAnswerAttachmentRepository;
import life.mosu.mosuserver.domain.inquiryAnswer.InquiryAnswerAttachmentJpaRepository;
import life.mosu.mosuserver.domain.inquiryAnswer.InquiryAnswerJpaEntity;
import life.mosu.mosuserver.global.util.FileRequest;
import life.mosu.mosuserver.infra.property.S3Properties;
Expand All @@ -20,7 +20,7 @@ public class InquiryAnswerAttachmentService implements
AttachmentService<InquiryAnswerJpaEntity, FileRequest> {

private final S3Properties s3Properties;
private final InquiryAnswerAttachmentRepository attachmentRepository;
private final InquiryAnswerAttachmentJpaRepository attachmentRepository;
private final FileUploadHelper fileUploadHelper;
private final S3Service s3Service;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package life.mosu.mosuserver.application.inquiry;

import life.mosu.mosuserver.domain.inquiry.InquiryJpaEntity;
import life.mosu.mosuserver.domain.inquiry.InquiryRepository;
import life.mosu.mosuserver.domain.inquiry.InquiryJpaRepository;
import life.mosu.mosuserver.domain.inquiryAnswer.InquiryAnswerJpaEntity;
import life.mosu.mosuserver.domain.inquiryAnswer.InquiryAnswerRepository;
import life.mosu.mosuserver.domain.inquiryAnswer.InquiryAnswerJpaRepository;
import life.mosu.mosuserver.global.exception.CustomRuntimeException;
import life.mosu.mosuserver.global.exception.ErrorCode;
import life.mosu.mosuserver.presentation.inquiry.dto.InquiryAnswerRequest;
Expand All @@ -20,18 +20,18 @@
public class InquiryAnswerService {

private final InquiryAnswerAttachmentService answerAttachmentService;
private final InquiryAnswerRepository inquiryAnswerRepository;
private final InquiryRepository inquiryRepository;
private final InquiryAnswerJpaRepository inquiryAnswerJpaRepository;
private final InquiryJpaRepository inquiryJpaRepository;

@Transactional
public void createInquiryAnswer(Long postId, InquiryAnswerRequest request) {
InquiryJpaEntity inquiryEntity = getInquiryOrThrow(postId);

if (inquiryAnswerRepository.findByInquiryId(postId).isPresent()) {
if (inquiryAnswerJpaRepository.findByInquiryId(postId).isPresent()) {
throw new CustomRuntimeException(ErrorCode.INQUIRY_ANSWER_ALREADY_EXISTS);
}

InquiryAnswerJpaEntity answerEntity = inquiryAnswerRepository.save(
InquiryAnswerJpaEntity answerEntity = inquiryAnswerJpaRepository.save(
request.toEntity(postId));

answerAttachmentService.createAttachment(request.attachments(), answerEntity);
Expand All @@ -42,18 +42,18 @@ public void createInquiryAnswer(Long postId, InquiryAnswerRequest request) {
public void deleteInquiryAnswer(Long postId) {
InquiryJpaEntity inquiryEntity = getInquiryOrThrow(postId);

InquiryAnswerJpaEntity answerEntity = inquiryAnswerRepository.findByInquiryId(postId)
InquiryAnswerJpaEntity answerEntity = inquiryAnswerJpaRepository.findByInquiryId(postId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.INQUIRY_ANSWER_NOT_FOUND));

inquiryAnswerRepository.delete(answerEntity);
inquiryAnswerJpaRepository.delete(answerEntity);
answerAttachmentService.deleteAttachment(answerEntity);
inquiryEntity.updateStatusToPending();
}

@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public InquiryDetailResponse.InquiryAnswerDetailResponse getInquiryAnswerDetail(
Long inquiryId) {
return inquiryAnswerRepository.findByInquiryId(inquiryId)
return inquiryAnswerJpaRepository.findByInquiryId(inquiryId)
.map(answer -> InquiryAnswerDetailResponse.of(
answer,
answerAttachmentService.toAttachmentResponses(answer)
Expand All @@ -65,18 +65,18 @@ public InquiryDetailResponse.InquiryAnswerDetailResponse getInquiryAnswerDetail(
public void updateInquiryAnswer(Long postId, InquiryAnswerUpdateRequest request) {
InquiryJpaEntity inquiryEntity = getInquiryOrThrow(postId);

InquiryAnswerJpaEntity answerEntity = inquiryAnswerRepository.findByInquiryId(postId)
InquiryAnswerJpaEntity answerEntity = inquiryAnswerJpaRepository.findByInquiryId(postId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.INQUIRY_ANSWER_NOT_FOUND));

answerEntity.update(request.title(), request.content());
inquiryAnswerRepository.save(answerEntity);
inquiryAnswerJpaRepository.save(answerEntity);

answerAttachmentService.deleteAttachment(answerEntity);
answerAttachmentService.createAttachment(request.attachments(), answerEntity);
}

private InquiryJpaEntity getInquiryOrThrow(Long postId) {
return inquiryRepository.findById(postId)
return inquiryJpaRepository.findById(postId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.INQUIRY_NOT_FOUND));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.Duration;
import java.util.List;
import life.mosu.mosuserver.domain.inquiry.InquiryAttachmentJpaEntity;
import life.mosu.mosuserver.domain.inquiry.InquiryAttachmentRepository;
import life.mosu.mosuserver.domain.inquiry.InquiryAttachmentJpaRepository;
import life.mosu.mosuserver.domain.inquiry.InquiryJpaEntity;
import life.mosu.mosuserver.global.util.FileRequest;
import life.mosu.mosuserver.infra.property.S3Properties;
Expand All @@ -18,7 +18,7 @@
@RequiredArgsConstructor
public class InquiryAttachmentService implements AttachmentService<InquiryJpaEntity, FileRequest> {

private final InquiryAttachmentRepository inquiryAttachmentRepository;
private final InquiryAttachmentJpaRepository inquiryAttachmentJpaRepository;
private final FileUploadHelper fileUploadHelper;
private final S3Service s3Service;
private final S3Properties s3Properties;
Expand All @@ -28,7 +28,7 @@ public void createAttachment(List<FileRequest> requests, InquiryJpaEntity inquir
fileUploadHelper.saveAttachments(
requests,
inquiryEntity.getId(),
inquiryAttachmentRepository,
inquiryAttachmentJpaRepository,
(req, id) -> req.toInquiryAttachmentEntity(
req.fileName(),
req.s3Key(),
Expand All @@ -40,15 +40,15 @@ public void createAttachment(List<FileRequest> requests, InquiryJpaEntity inquir

@Override
public void deleteAttachment(InquiryJpaEntity entity) {
List<InquiryAttachmentJpaEntity> attachments = inquiryAttachmentRepository.findAllByInquiryId(
List<InquiryAttachmentJpaEntity> attachments = inquiryAttachmentJpaRepository.findAllByInquiryId(
entity.getId());
inquiryAttachmentRepository.deleteAll(attachments);
inquiryAttachmentJpaRepository.deleteAll(attachments);
}


public List<InquiryDetailResponse.AttachmentDetailResponse> toAttachmentResponses(
InquiryJpaEntity inquiry) {
List<InquiryAttachmentJpaEntity> attachments = inquiryAttachmentRepository.findAllByInquiryId(
List<InquiryAttachmentJpaEntity> attachments = inquiryAttachmentJpaRepository.findAllByInquiryId(
inquiry.getId());

return attachments.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package life.mosu.mosuserver.application.inquiry;

import life.mosu.mosuserver.domain.inquiry.InquiryJpaEntity;
import life.mosu.mosuserver.domain.inquiry.InquiryRepository;
import life.mosu.mosuserver.domain.inquiry.InquiryJpaRepository;
import life.mosu.mosuserver.domain.inquiry.InquiryStatus;
import life.mosu.mosuserver.domain.inquiryAnswer.InquiryAnswerRepository;
import life.mosu.mosuserver.domain.inquiryAnswer.InquiryAnswerJpaRepository;
import life.mosu.mosuserver.global.exception.CustomRuntimeException;
import life.mosu.mosuserver.global.exception.ErrorCode;
import life.mosu.mosuserver.presentation.inquiry.dto.InquiryCreateRequest;
Expand All @@ -22,13 +22,13 @@
public class InquiryService {

private final InquiryAttachmentService inquiryAttachmentService;
private final InquiryRepository inquiryRepository;
private final InquiryJpaRepository inquiryJpaRepository;
private final InquiryAnswerService inquiryAnswerService;
private final InquiryAnswerRepository inquiryAnswerRepository;
private final InquiryAnswerJpaRepository inquiryAnswerJpaRepository;

Comment on lines 24 to 28
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid mixing service & repository layers for the same aggregate

Injecting both InquiryAnswerService and InquiryAnswerJpaRepository in the same service breaks layer isolation and makes future refactors harder.
deleteInquiry only needs a presence-check before delegating to InquiryAnswerService. Expose that check via the service (or let the delete method be idempotent) and drop the direct repository dependency here.

🤖 Prompt for AI Agents
In src/main/java/life/mosu/mosuserver/application/inquiry/InquiryService.java
around lines 24 to 28, avoid injecting both InquiryAnswerService and
InquiryAnswerJpaRepository to maintain layer isolation. Remove the direct
dependency on InquiryAnswerJpaRepository and instead expose a presence-check
method in InquiryAnswerService or make the deleteInquiry method idempotent so
that the repository is only accessed through the service layer.

@Transactional
public void createInquiry(InquiryCreateRequest request) {
InquiryJpaEntity inquiryEntity = inquiryRepository.save(request.toEntity());
InquiryJpaEntity inquiryEntity = inquiryJpaRepository.save(request.toEntity());
inquiryAttachmentService.createAttachment(request.attachments(), inquiryEntity);
}

Expand All @@ -39,7 +39,7 @@ public Page<InquiryResponse> getInquiries(
boolean asc,
Pageable pageable) {

return inquiryRepository.searchInquiries(status, sortField, asc, pageable);
return inquiryJpaRepository.searchInquiries(status, sortField, asc, pageable);

}

Expand All @@ -54,13 +54,13 @@ public InquiryDetailResponse getInquiryDetail(Long postId) {
public void deleteInquiry(Long postId) {
InquiryJpaEntity inquiryEntity = getInquiryOrThrow(postId);

inquiryAnswerRepository.findByInquiryId(postId).ifPresent(answer -> {
inquiryAnswerJpaRepository.findByInquiryId(postId).ifPresent(answer -> {
inquiryAnswerService.deleteInquiryAnswer(postId);
});

inquiryAttachmentService.deleteAttachment(inquiryEntity);

inquiryRepository.delete(inquiryEntity);
inquiryJpaRepository.delete(inquiryEntity);
}


Expand All @@ -77,7 +77,7 @@ private InquiryDetailResponse toInquiryDetailResponse(InquiryJpaEntity inquiry)
}

private InquiryJpaEntity getInquiryOrThrow(Long postId) {
return inquiryRepository.findById(postId)
return inquiryJpaRepository.findById(postId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.INQUIRY_NOT_FOUND));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.Duration;
import java.util.List;
import life.mosu.mosuserver.domain.notice.NoticeAttachmentJpaEntity;
import life.mosu.mosuserver.domain.notice.NoticeAttachmentRepository;
import life.mosu.mosuserver.domain.notice.NoticeAttachmentJpaRepository;
import life.mosu.mosuserver.domain.notice.NoticeJpaEntity;
import life.mosu.mosuserver.global.util.FileRequest;
import life.mosu.mosuserver.infra.property.S3Properties;
Expand All @@ -21,7 +21,7 @@
@RequiredArgsConstructor
public class NoticeAttachmentService implements AttachmentService<NoticeJpaEntity, FileRequest> {

private final NoticeAttachmentRepository noticeAttachmentRepository;
private final NoticeAttachmentJpaRepository noticeAttachmentJpaRepository;
private final FileUploadHelper fileUploadHelper;
private final S3Service s3Service;
private final S3Properties s3Properties;
Expand All @@ -31,7 +31,7 @@ public void createAttachment(List<FileRequest> requests, NoticeJpaEntity noticeE
fileUploadHelper.saveAttachments(
requests,
noticeEntity.getId(),
noticeAttachmentRepository,
noticeAttachmentJpaRepository,
(req, id) -> req.toNoticeAttachmentEntity(
req.fileName(),
req.s3Key(),
Expand All @@ -43,14 +43,14 @@ public void createAttachment(List<FileRequest> requests, NoticeJpaEntity noticeE

@Override
public void deleteAttachment(NoticeJpaEntity entity) {
List<NoticeAttachmentJpaEntity> attachments = noticeAttachmentRepository.findAllByNoticeId(
List<NoticeAttachmentJpaEntity> attachments = noticeAttachmentJpaRepository.findAllByNoticeId(
entity.getId());
noticeAttachmentRepository.deleteAll(attachments);
noticeAttachmentJpaRepository.deleteAll(attachments);
}

public List<NoticeResponse.AttachmentResponse> toAttachmentResponses(NoticeJpaEntity notice) {

List<NoticeAttachmentJpaEntity> attachments = noticeAttachmentRepository.findAllByNoticeId(
List<NoticeAttachmentJpaEntity> attachments = noticeAttachmentJpaRepository.findAllByNoticeId(
notice.getId());

return attachments.stream()
Expand All @@ -64,7 +64,7 @@ public List<NoticeResponse.AttachmentResponse> toAttachmentResponses(NoticeJpaEn
public List<NoticeDetailResponse.AttachmentDetailResponse> toDetailAttResponses(
NoticeJpaEntity notice) {

List<NoticeAttachmentJpaEntity> attachments = noticeAttachmentRepository.findAllByNoticeId(
List<NoticeAttachmentJpaEntity> attachments = noticeAttachmentJpaRepository.findAllByNoticeId(
notice.getId());

return attachments.stream()
Expand Down
Loading