Skip to content

Commit

Permalink
[WHD-291] Feat: inquiry list by category
Browse files Browse the repository at this point in the history
  • Loading branch information
juy4844 committed Dec 3, 2024
1 parent e73eba2 commit f5aa3a3
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ClubPaymentResponse getClubPaymentByTerm(@RequestParam(required = false)
}

@GetMapping("/inquiry")
public InquiryListResponse getInquiry() {
public ListWrapperResponse<InquiryListResponse> getInquiry(@RequestParam(required = false) String category) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import woohakdong.server.api.controller.ListWrapperResponse;
import woohakdong.server.api.controller.admin.overall.dto.ClubListResponse;
import woohakdong.server.api.controller.admin.overall.dto.ClubPaymentResponse;
import woohakdong.server.api.controller.admin.overall.dto.CountResponse;
import woohakdong.server.api.controller.admin.overall.dto.SchoolListResponse;
import woohakdong.server.api.controller.admin.overall.dto.*;

import java.time.LocalDate;

Expand Down Expand Up @@ -52,4 +49,9 @@ public CountResponse getTotalMemberCount(@RequestParam(required = false)
@ApiResponse(responseCode = "200", description = "분기별 동아리 결제금액 반환 성공", useReturnTypeSchema = true)
ClubPaymentResponse getClubPaymentByTerm(@RequestParam(required = false)
LocalDate assignedTerm);

@SecurityRequirement(name = "accessToken")
@Operation(summary = "문의 내역 반환", description = "문의 내역을 카테고리별로 반환합니다.")
@ApiResponse(responseCode = "200", description = "문의 내역을 카테고리별 반환 성공", useReturnTypeSchema = true)
ListWrapperResponse<InquiryListResponse> getInquiry(@RequestParam(required = false) String category);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public record InquiryListResponse(
String memberEmail,
LocalDateTime creatDate
) {
static InquiryListResponse from(Inquiry inquiry, String memberEmail) {
static public InquiryListResponse from(Inquiry inquiry, String memberEmail) {
return InquiryListResponse.builder()
.inquiryId(inquiry.getInquiryId())
.inquiryContent(inquiry.getInquiryContent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import woohakdong.server.api.controller.admin.overall.dto.ClubListResponse;
import woohakdong.server.api.controller.admin.overall.dto.ClubPaymentResponse;
import woohakdong.server.api.controller.admin.overall.dto.CountResponse;
import woohakdong.server.api.controller.admin.overall.dto.SchoolListResponse;
import woohakdong.server.api.controller.admin.overall.dto.*;
import woohakdong.server.domain.club.Club;
import woohakdong.server.domain.club.ClubRepository;
import woohakdong.server.domain.clubHistory.ClubHistoryRepository;
import woohakdong.server.domain.clubmember.ClubMemberRepository;
import woohakdong.server.domain.inquiry.Inquiry;
import woohakdong.server.domain.inquiry.InquiryCategory;
import woohakdong.server.domain.inquiry.InquiryRepository;
import woohakdong.server.domain.member.MemberRepository;
import woohakdong.server.domain.school.School;
import woohakdong.server.domain.school.SchoolRepository;
Expand All @@ -32,6 +32,7 @@ public class AdminOverallService {
private final MemberRepository memberRepository;
private final ClubHistoryRepository clubHistoryRepository;
private final ClubMemberRepository clubMemberRepository;
private final InquiryRepository inquiryRepository;

public CountResponse getTotalSchoolCount(LocalDate assignedTerm) {
if (assignedTerm == null) {
Expand Down Expand Up @@ -95,4 +96,14 @@ public ClubPaymentResponse getClubPaymentByTerm(LocalDate assignedTerm) {
return ClubPaymentResponse.from(totalPayment);

}

public List<InquiryListResponse> getInquiry(String category) {
InquiryCategory inquiryCategory = category != null ? InquiryCategory.valueOf(category.toUpperCase()) : null;

List<Inquiry> inquiries = inquiryRepository.getByCategoryOrderByCreatedAtDesc(inquiryCategory);

return inquiries.stream()
.map(inquiry -> InquiryListResponse.from(inquiry, inquiry.getMember().getMemberEmail()))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package woohakdong.server.domain.inquiry;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import woohakdong.server.domain.member.Member;

import java.util.List;

public interface InquiryJpaRepository extends JpaRepository<Inquiry, Long> {
List<Inquiry> findByMember(Member member);

@Query("SELECT i FROM Inquiry i " +
"WHERE (:category IS NULL OR i.inquiryCategory = :category) " +
"ORDER BY i.createdAt DESC")
List<Inquiry> findByCategoryOrderByCreatedAtDesc(@Param("category") InquiryCategory category);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package woohakdong.server.domain.inquiry;

import org.springframework.data.repository.query.Param;
import woohakdong.server.domain.member.Member;

import java.util.List;
Expand All @@ -9,4 +10,5 @@ public interface InquiryRepository {
Inquiry save(Inquiry inquiry);
List<Inquiry> getByMember(Member member);
List<Inquiry> getAll();
List<Inquiry> getByCategoryOrderByCreatedAtDesc(@Param("category") InquiryCategory category);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package woohakdong.server.domain.inquiry;

import lombok.RequiredArgsConstructor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import woohakdong.server.domain.member.Member;

Expand All @@ -26,4 +27,9 @@ public List<Inquiry> getByMember(Member member) {
public List<Inquiry> getAll() {
return inquiryJpaRepository.findAll();
}

@Override
public List<Inquiry> getByCategoryOrderByCreatedAtDesc(@Param("category") InquiryCategory category){
return inquiryJpaRepository.findByCategoryOrderByCreatedAtDesc(category);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;
import woohakdong.server.api.controller.admin.overall.dto.ClubListResponse;
import woohakdong.server.api.controller.admin.overall.dto.ClubPaymentResponse;
import woohakdong.server.api.controller.admin.overall.dto.CountResponse;
import woohakdong.server.api.controller.admin.overall.dto.SchoolListResponse;
import woohakdong.server.api.controller.admin.overall.dto.*;
import woohakdong.server.domain.club.Club;
import woohakdong.server.domain.club.ClubRepository;
import woohakdong.server.domain.clubHistory.ClubHistory;
import woohakdong.server.domain.clubHistory.ClubHistoryRepository;
import woohakdong.server.domain.clubmember.ClubMember;
import woohakdong.server.domain.clubmember.ClubMemberRepository;
import woohakdong.server.domain.clubmember.ClubMemberRole;
import woohakdong.server.domain.inquiry.Inquiry;
import woohakdong.server.domain.inquiry.InquiryCategory;
import woohakdong.server.domain.inquiry.InquiryRepository;
import woohakdong.server.domain.member.Member;
import woohakdong.server.domain.member.MemberRepository;
import woohakdong.server.domain.school.School;
Expand Down Expand Up @@ -53,6 +53,9 @@ class AdminOverallServiceTest {
@Autowired
private ClubHistoryRepository clubHistoryRepository;

@Autowired
private InquiryRepository inquiryRepository;

@BeforeEach
void setup() {
// 초기 데이터 삽입 예시
Expand Down Expand Up @@ -208,6 +211,22 @@ void getClubPaymentWithAssignedTerm() {
assertThat(response.clubPayment()).isEqualTo(30000 + (2 * 500) + 30500);
}

@Test
void findByCategoryOrderByCreatedAtDesc() {
// Given
School school = createSchool("ajou.ac.kr");
Member member1 = createMember(school, "testProvideId2", "박상준", "[email protected]");
Inquiry inquiry1 = Inquiry.create("Content1", InquiryCategory.INQUIRY, member1);
Inquiry inquiry2 = Inquiry.create("Content2", InquiryCategory.ETC, member1);
inquiryRepository.save(inquiry1);
inquiryRepository.save(inquiry2);

// When
List<InquiryListResponse> result = adminOverallService.getInquiry("INQUIRY");

// Then
assertThat(result.get(0).inquiryContent()).isEqualTo("Content1");
}

private Club createClub(School school1, String name, String englishName) {
Club club = Club.builder()
Expand Down Expand Up @@ -258,4 +277,13 @@ private ClubHistory createClubHistory(Club club, LocalDate date) {
ClubHistory clubHistory = ClubHistory.create(club, date);
return clubHistoryRepository.save(clubHistory);
}

private School createSchool(String domain) {
School school = School.builder()
.schoolDomain(domain)
.schoolName("아주대학교")
.build();
return schoolRepository.save(school);
}

}

0 comments on commit f5aa3a3

Please sign in to comment.