diff --git a/src/main/java/com/umc/StudyFlexBE/controller/InquiryController.java b/src/main/java/com/umc/StudyFlexBE/controller/InquiryController.java index f8a1f2c..a6bfdec 100644 --- a/src/main/java/com/umc/StudyFlexBE/controller/InquiryController.java +++ b/src/main/java/com/umc/StudyFlexBE/controller/InquiryController.java @@ -39,6 +39,7 @@ public ResponseEntity> postInquiry( try { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String email = authentication.getName(); + System.out.println(email); Inquiry inquiry = inquiryService.createInquiry(email, request); return ResponseEntity.ok(new BaseResponse<>(BaseResponseStatus.SUCCESS, new InquiryUploadResponseDto(inquiry.getId()))); } catch (Exception e) { @@ -58,7 +59,7 @@ public ResponseEntity> getInquiries( } } - @PostMapping("/{inquiryId}") + @GetMapping("/{inquiryId}") public ResponseEntity> getInquiryDetail(@PathVariable Long inquiryId) { try { InquiryResponseDto inquiryDetail = inquiryService.getInquiryDetail(inquiryId); diff --git a/src/main/java/com/umc/StudyFlexBE/dto/request/StudyFlexNoticeUploadDto.java b/src/main/java/com/umc/StudyFlexBE/dto/request/StudyFlexNoticeUploadDto.java index bfc0b57..845e6d2 100644 --- a/src/main/java/com/umc/StudyFlexBE/dto/request/StudyFlexNoticeUploadDto.java +++ b/src/main/java/com/umc/StudyFlexBE/dto/request/StudyFlexNoticeUploadDto.java @@ -1,13 +1,9 @@ package com.umc.StudyFlexBE.dto.request; public class StudyFlexNoticeUploadDto { - private Long member_id; private String title; private String content; - public Long getMemberId() { - return member_id; - } public String getTitle() { return title; diff --git a/src/main/java/com/umc/StudyFlexBE/dto/response/StudyFlexNotice/StudyFlexNoticeListResponseDto.java b/src/main/java/com/umc/StudyFlexBE/dto/response/StudyFlexNotice/StudyFlexNoticeListResponseDto.java index 1faefae..5e2eaed 100644 --- a/src/main/java/com/umc/StudyFlexBE/dto/response/StudyFlexNotice/StudyFlexNoticeListResponseDto.java +++ b/src/main/java/com/umc/StudyFlexBE/dto/response/StudyFlexNotice/StudyFlexNoticeListResponseDto.java @@ -19,7 +19,6 @@ public class StudyFlexNoticeListResponseDto { public static class NoticeSummary { private Long id; private String title; - private String writer; private int views; } } diff --git a/src/main/java/com/umc/StudyFlexBE/dto/response/StudyFlexNotice/StudyFlexNoticeResponseDto.java b/src/main/java/com/umc/StudyFlexBE/dto/response/StudyFlexNotice/StudyFlexNoticeResponseDto.java index 44dc666..6512513 100644 --- a/src/main/java/com/umc/StudyFlexBE/dto/response/StudyFlexNotice/StudyFlexNoticeResponseDto.java +++ b/src/main/java/com/umc/StudyFlexBE/dto/response/StudyFlexNotice/StudyFlexNoticeResponseDto.java @@ -11,7 +11,6 @@ public class StudyFlexNoticeResponseDto { private Long id; private Integer view; private String title; - private Long writer; private String content; private Timestamp createdAt; private Timestamp updatedAt; diff --git a/src/main/java/com/umc/StudyFlexBE/entity/Notice.java b/src/main/java/com/umc/StudyFlexBE/entity/Notice.java index 7e1554d..c76256e 100644 --- a/src/main/java/com/umc/StudyFlexBE/entity/Notice.java +++ b/src/main/java/com/umc/StudyFlexBE/entity/Notice.java @@ -20,7 +20,7 @@ public class Notice { private Long id; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "member_id", referencedColumnName = "member_id", nullable = false) + @JoinColumn(name = "member_id", referencedColumnName = "member_id") private Member member; @Column(name = "title", length = 100, nullable = false) diff --git a/src/main/java/com/umc/StudyFlexBE/service/InquiryService.java b/src/main/java/com/umc/StudyFlexBE/service/InquiryService.java index 64aec29..5001054 100644 --- a/src/main/java/com/umc/StudyFlexBE/service/InquiryService.java +++ b/src/main/java/com/umc/StudyFlexBE/service/InquiryService.java @@ -43,6 +43,9 @@ public Inquiry createInquiry(String email, InquiryUploadRequestDto request) { inquiry.setMember_id(member); inquiry.setTitle(request.getTitle()); inquiry.setContent(request.getContent()); + inquiry.setIs_answered(false); + inquiry.setCreated_at(new Timestamp(System.currentTimeMillis())); + inquiry.setUpdated_at(new Timestamp(System.currentTimeMillis())); inquiry.setIs_opened(true); inquiry.setView(0); @@ -75,6 +78,9 @@ public InquiryResponseDto getInquiryDetail(Long inquiryId) { Inquiry inquiry = inquiryRepository.findById(inquiryId) .orElseThrow(() -> new RuntimeException("Inquiry not found")); + inquiry.setView(inquiry.getView() + 1); + inquiryRepository.save(inquiry); + InquiryResponseDto.AnswerResponse answerResponse = null; boolean isAnswered = inquiryAnswerRepository.findByInquiry(inquiry).isPresent(); if (isAnswered) { diff --git a/src/main/java/com/umc/StudyFlexBE/service/StudyFlexNoticeService.java b/src/main/java/com/umc/StudyFlexBE/service/StudyFlexNoticeService.java index 6e84487..3c97a1f 100644 --- a/src/main/java/com/umc/StudyFlexBE/service/StudyFlexNoticeService.java +++ b/src/main/java/com/umc/StudyFlexBE/service/StudyFlexNoticeService.java @@ -13,6 +13,7 @@ import org.springframework.data.domain.*; import org.springframework.stereotype.Service; +import java.sql.Timestamp; import java.util.List; import java.util.stream.Collectors; @@ -28,13 +29,12 @@ public StudyFlexNoticeService(StudyFlexNoticeRepository StudyFlexNoticeRepositor } public Notice createNotice(StudyFlexNoticeUploadDto request) throws BaseException { - Member member = memberRepository.findById(request.getMemberId()) - .orElseThrow(() -> new BaseException(BaseResponseStatus.NO_SUCH_EMAIL)); Notice notice = new Notice(); - notice.setMember(member); notice.setTitle(request.getTitle()); notice.setContent(request.getContent()); + notice.setCreated_at(new Timestamp(System.currentTimeMillis())); + notice.setUpdated_at(new Timestamp(System.currentTimeMillis())); notice.setView(0); return StudyFlexNoticeRepository.save(notice); @@ -42,13 +42,15 @@ public Notice createNotice(StudyFlexNoticeUploadDto request) throws BaseExceptio public StudyFlexNoticeResponseDto getNotice(Long noticeId) throws BaseException { Notice notice = StudyFlexNoticeRepository.findById(noticeId) - .orElseThrow(() -> new BaseException(BaseResponseStatus.BAD_REQUEST)); //need to change err code + .orElseThrow(() -> new BaseException(BaseResponseStatus.BAD_REQUEST)); + + notice.setView(notice.getView() + 1); + StudyFlexNoticeRepository.save(notice); return new StudyFlexNoticeResponseDto( notice.getId(), notice.getView(), notice.getTitle(), - notice.getMember().getMember_id(), notice.getContent(), notice.getCreated_at(), notice.getUpdated_at() @@ -63,7 +65,6 @@ public StudyFlexNoticeListResponseDto getNoticeList(int page, int itemSize) { .map(notice -> new StudyFlexNoticeListResponseDto.NoticeSummary( notice.getId(), notice.getTitle(), - notice.getMember().getName(), notice.getView() )) .collect(Collectors.toList()); @@ -84,7 +85,6 @@ public StudyFlexNoticeListResponseDto searchNotices(String searchTerm, int page, .map(notice -> new StudyFlexNoticeListResponseDto.NoticeSummary( notice.getId(), notice.getTitle(), - notice.getMember().getName(), notice.getView() )) .collect(Collectors.toList());