Skip to content

Commit

Permalink
Merge pull request #18 from StudyFlexUMC5th/yeeun2
Browse files Browse the repository at this point in the history
Yeeun2
  • Loading branch information
Yeeun411 authored Jan 8, 2024
2 parents dc81daf + 36088ff commit 241623e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public ResponseEntity<BaseResponse<InquiryUploadResponseDto>> 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) {
Expand All @@ -58,7 +59,7 @@ public ResponseEntity<BaseResponse<InquiryListResponseDto>> getInquiries(
}
}

@PostMapping("/{inquiryId}")
@GetMapping("/{inquiryId}")
public ResponseEntity<BaseResponse<InquiryResponseDto>> getInquiryDetail(@PathVariable Long inquiryId) {
try {
InquiryResponseDto inquiryDetail = inquiryService.getInquiryDetail(inquiryId);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class StudyFlexNoticeListResponseDto {
public static class NoticeSummary {
private Long id;
private String title;
private String writer;
private int views;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/umc/StudyFlexBE/entity/Notice.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/umc/StudyFlexBE/service/InquiryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -28,27 +29,28 @@ 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);
}

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()
Expand All @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit 241623e

Please sign in to comment.