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

[FEAT] (이벤트)공지사항/프로젝트 문의 리스트 조회 기능 추가 #131

Merged
merged 10 commits into from
Nov 28, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ public ResponseEntity<EventNoticeResponse> createEventNotice(
// Get a list of eventNotices
@GetMapping
public ResponseEntity<Page<EventNoticeListElementResponse>> getEventNoticeList(
@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "terms", required = false) String searchTerm,
@RequestParam(value = "scope", defaultValue = "both") String searchScope,
@PageableDefault(page = 0, size = 10, sort = "createdAt", direction = Sort.Direction.ASC) Pageable pageable) {
Page<EventNoticeListElementResponse> eventNoticeList = eventNoticeService.getEventNoticeList(title, pageable);

// Enforce that searchScope is ignored if searchTerm is null
if (searchTerm == null || searchTerm.isEmpty()) {
searchScope = null; // Ignore search scope
}

Page<EventNoticeListElementResponse> eventNoticeList = eventNoticeService.getEventNoticeList(searchTerm, searchScope, pageable);
return ResponseEntity.status(HttpStatus.OK).body(eventNoticeList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,25 @@
public interface EventNoticeRepository extends JpaRepository<EventNotice, Long> {

@Query("SELECT n FROM EventNotice n " +
"WHERE (:title IS NULL OR n.title LIKE %:title%) AND n.fixed = false")
Page<EventNoticeListElementResponse> findNonFixedEventNotices(@Param("title") String title, Pageable pageable);
"WHERE (:searchScope IS NULL OR " +
"(:searchScope = 'content' AND (:searchTerm IS NULL OR n.content LIKE %:searchTerm%)) " +
"OR (:searchScope = 'title' AND (:searchTerm IS NULL OR n.title LIKE %:searchTerm%)) " +
"OR (:searchScope = 'both' AND (:searchTerm IS NULL OR n.title LIKE %:searchTerm% OR n.content LIKE %:searchTerm%))) " +
"AND n.fixed = false")
Page<EventNoticeListElementResponse> findNonFixedEventNotices(
@Param("searchTerm") String searchTerm,
@Param("searchScope") String searchScope,
Pageable pageable);


@Query("SELECT n FROM EventNotice n " +
"WHERE (:title IS NULL OR n.title LIKE %:title%) AND n.fixed = true")
List<EventNoticeListElementResponse> findFixedEventNotices(@Param("title") String title, Sort sort);
"WHERE (:searchScope IS NULL OR " +
"(:searchScope = 'content' AND (:searchTerm IS NULL OR n.content LIKE %:searchTerm%)) " +
"OR (:searchScope = 'title' AND (:searchTerm IS NULL OR n.title LIKE %:searchTerm%)) " +
"OR (:searchScope = 'both' AND (:searchTerm IS NULL OR n.title LIKE %:searchTerm% OR n.content LIKE %:searchTerm%))) " +
"AND n.fixed = true")
List<EventNoticeListElementResponse> findFixedEventNotices(
@Param("searchTerm") String searchTerm,
@Param("searchScope") String searchScope,
Sort sort);
}
14 changes: 10 additions & 4 deletions src/main/java/com/scg/stop/event/service/EventNoticeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,29 @@ public EventNoticeResponse createEventNotice(EventNoticeRequest request) {
/**
* Get a list of event notices.
*
* @param title Title of the event notice (optional)
* @param searchTerm Search term to filter notices (optional)
* @param searchScope Search scope to filter notices (optional)
* @param pageable Pageable
* @return Paginated list of event notices
*/
@Transactional(readOnly = true)
public Page<EventNoticeListElementResponse> getEventNoticeList(String title, Pageable pageable) {
public Page<EventNoticeListElementResponse> getEventNoticeList(String searchTerm, String searchScope, Pageable pageable) {

// If no searchTerm is provided, set searchScope to null
if (searchTerm == null || searchTerm.isEmpty()) {
searchScope = null;
}

// Retrieve the sorting from the pageable
Sort sort = pageable.getSort();

// Find fixed notices with title and sorting
List<EventNoticeListElementResponse> fixedEventNotices = eventNoticeRepository.findFixedEventNotices(title, sort);
List<EventNoticeListElementResponse> fixedEventNotices = eventNoticeRepository.findFixedEventNotices(searchTerm, searchScope, sort);

// Find non-fixed notices with title and sorting
int nonFixedEventNoticesSize = pageable.getPageSize() - fixedEventNotices.size();
Pageable adjustedPageable = PageRequest.of(pageable.getPageNumber(), Math.max(nonFixedEventNoticesSize, 0), sort);
Page<EventNoticeListElementResponse> nonFixedEventNotices = eventNoticeRepository.findNonFixedEventNotices(title, adjustedPageable);
Page<EventNoticeListElementResponse> nonFixedEventNotices = eventNoticeRepository.findNonFixedEventNotices(searchTerm, searchScope, adjustedPageable);

// Combine fixed and non-fixed notices
List<EventNoticeListElementResponse> combinedEventNotices = new ArrayList<>(fixedEventNotices);
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/scg/stop/notice/controller/NoticeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ public ResponseEntity<NoticeResponse> createNotice(
// Get a list of notices
@GetMapping
public ResponseEntity<Page<NoticeListElementResponse>> getNoticeList(
@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "terms", required = false) String searchTerm,
@RequestParam(value = "scope", defaultValue = "both") String searchScope,
@PageableDefault(page = 0, size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) {
Page<NoticeListElementResponse> noticeList = noticeService.getNoticeList(title, pageable);

// Enforce that searchScope is ignored if searchTerm is null
if (searchTerm == null || searchTerm.isEmpty()) {
searchScope = null; // Ignore search scope
}

Page<NoticeListElementResponse> noticeList = noticeService.getNoticeList(searchTerm, searchScope, pageable);
return ResponseEntity.status(HttpStatus.OK).body(noticeList);
}


// Get a corresponding notice
@GetMapping("/{noticeId}")
public ResponseEntity<NoticeResponse> getNotice(
Expand Down
26 changes: 19 additions & 7 deletions src/main/java/com/scg/stop/notice/repository/NoticeRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@
public interface NoticeRepository extends JpaRepository<Notice, Long> {

@Query("SELECT n FROM Notice n " +
"WHERE (:title IS NULL OR n.title LIKE %:title%) AND n.fixed = false")
Page<NoticeListElementResponse> findNonFixedNotices(@Param("title") String title, Pageable pageable);

"WHERE (:searchScope IS NULL OR " +
"(:searchScope = 'content' AND (:searchTerm IS NULL OR n.content LIKE %:searchTerm%)) " +
"OR (:searchScope = 'title' AND (:searchTerm IS NULL OR n.title LIKE %:searchTerm%)) " +
"OR (:searchScope = 'both' AND (:searchTerm IS NULL OR n.title LIKE %:searchTerm% OR n.content LIKE %:searchTerm%))) " +
"AND n.fixed = false")
Page<NoticeListElementResponse> findNonFixedNotices(
@Param("searchTerm") String searchTerm,
@Param("searchScope") String searchScope,
Pageable pageable);

@Query("SELECT n FROM Notice n " +
"WHERE (:title IS NULL OR n.title LIKE %:title%) AND n.fixed = true")
List<NoticeListElementResponse> findFixedNotices(@Param("title") String title, Sort sort);

}
"WHERE (:searchScope IS NULL OR " +
"(:searchScope = 'content' AND (:searchTerm IS NULL OR n.content LIKE %:searchTerm%)) " +
"OR (:searchScope = 'title' AND (:searchTerm IS NULL OR n.title LIKE %:searchTerm%)) " +
"OR (:searchScope = 'both' AND (:searchTerm IS NULL OR n.title LIKE %:searchTerm% OR n.content LIKE %:searchTerm%))) " +
"AND n.fixed = true")
List<NoticeListElementResponse> findFixedNotices(
@Param("searchTerm") String searchTerm,
@Param("searchScope") String searchScope,
Sort sort);
}
18 changes: 12 additions & 6 deletions src/main/java/com/scg/stop/notice/service/NoticeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,29 @@ public NoticeResponse createNotice(NoticeRequest request) {
/**
* Get a list of notices with sorting
*
* @param title Title of the notice (optional)
* @param searchTerm Search term to filter notices (optional)
* @param searchScope Search scope to filter notices (optional)
* @param pageable Pageable containing sorting information
* @return List of notices
*/
@Transactional(readOnly = true)
public Page<NoticeListElementResponse> getNoticeList(String title, Pageable pageable) {
public Page<NoticeListElementResponse> getNoticeList(String searchTerm, String searchScope, Pageable pageable) {

// If no searchTerm is provided, set searchScope to null
if (searchTerm == null || searchTerm.isEmpty()) {
searchScope = null;
}

// Retrieve the sorting from the pageable
Sort sort = pageable.getSort();

// Find fixed notices with title and sorting
List<NoticeListElementResponse> fixedNotices = noticeRepository.findFixedNotices(title, sort);
// Find fixed notices based on the search criteria
List<NoticeListElementResponse> fixedNotices = noticeRepository.findFixedNotices(searchTerm, searchScope, sort);

// Find non-fixed notices with title and sorting
// Find non-fixed notices based on the search criteria
int nonFixedNoticesSize = pageable.getPageSize() - fixedNotices.size();
Pageable adjustedPageable = PageRequest.of(pageable.getPageNumber(), Math.max(nonFixedNoticesSize, 0), sort);
Page<NoticeListElementResponse> nonFixedNotices = noticeRepository.findNonFixedNotices(title, adjustedPageable);
Page<NoticeListElementResponse> nonFixedNotices = noticeRepository.findNonFixedNotices(searchTerm, searchScope, adjustedPageable);

// Combine fixed and non-fixed notices
List<NoticeListElementResponse> combinedNotices = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ public class InquiryController {
@GetMapping()
public ResponseEntity<Page<InquiryResponse>> getInquiries(
@AuthUser(accessType = {AccessType.COMPANY, AccessType.ADMIN}) User user,
@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "terms", required = false) String searchTerm,
@RequestParam(value = "scope", defaultValue = "both") String searchScope,
@PageableDefault(page = 0, size = 10) Pageable pageable) {

Page<InquiryResponse> inquiryList = inquiryService.getInquiryList(title, pageable);
// Enforce that searchScope is ignored if searchTerm is null
if (searchTerm == null || searchTerm.isEmpty()) {
searchScope = null; // Ignore search scope
}

Page<InquiryResponse> inquiryList = inquiryService.getInquiryList(searchTerm, searchScope, pageable);
return ResponseEntity.status(HttpStatus.OK).body(inquiryList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
import java.util.List;

public interface InquiryRepository extends JpaRepository<Inquiry, Long> {
@Query("SELECT i FROM Inquiry i WHERE :title IS NULL OR i.title LIKE %:title%")
Page<Inquiry> findInquiries(@Param("title") String title, Pageable pageable);
@Query("SELECT i FROM Inquiry i " +
"WHERE (:searchScope IS NULL OR " +
"(:searchScope = 'content' AND (:searchTerm IS NULL OR i.content LIKE %:searchTerm%)) " +
"OR (:searchScope = 'title' AND (:searchTerm IS NULL OR i.title LIKE %:searchTerm%)) " +
"OR (:searchScope = 'author' AND (:searchTerm IS NULL OR i.user.name LIKE %:searchTerm%)) " +
"OR (:searchScope = 'both' AND (:searchTerm IS NULL OR i.title LIKE %:searchTerm% OR i.content LIKE %:searchTerm%)))")
Page<Inquiry> findInquiries(
@Param("searchTerm") String searchTerm,
@Param("searchScope") String searchScope,
Pageable pageable);

List<Inquiry> findByUser(User user);
}
10 changes: 8 additions & 2 deletions src/main/java/com/scg/stop/project/service/InquiryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ public class InquiryService {

// 문의 목록 조회
@Transactional(readOnly = true)
public Page<InquiryResponse> getInquiryList(String title, Pageable pageable) {
Page<Inquiry> inquiries = inquiryRepository.findInquiries(title, pageable);
public Page<InquiryResponse> getInquiryList(String searchTerm, String searchScope, Pageable pageable) {

// If no searchTerm is provided, set searchScope to null
if (searchTerm == null || searchTerm.isEmpty()) {
searchScope = null;
}

Page<Inquiry> inquiries = inquiryRepository.findInquiries(searchTerm, searchScope, pageable);
return inquiries.map(inquiry ->
InquiryResponse.of(
inquiry.getId(),
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/static/docs/aihub-controller-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ <h4 id="_http_response">HTTP response</h4>
{
"totalPages" : 1,
"totalElements" : 2,
"first" : true,
"last" : true,
"size" : 10,
"content" : [ {
"title" : "title",
Expand Down Expand Up @@ -611,8 +613,6 @@ <h4 id="_http_response">HTTP response</h4>
"paged" : true,
"unpaged" : false
},
"first" : true,
"last" : true,
"empty" : false
}</code></pre>
</div>
Expand Down Expand Up @@ -946,6 +946,8 @@ <h4 id="_http_response">HTTP response</h4>
{
"totalPages" : 1,
"totalElements" : 2,
"first" : true,
"last" : true,
"size" : 10,
"content" : [ {
"title" : "title",
Expand Down Expand Up @@ -989,8 +991,6 @@ <h4 id="_http_response">HTTP response</h4>
"paged" : true,
"unpaged" : false
},
"first" : true,
"last" : true,
"empty" : false
}</code></pre>
</div>
Expand Down Expand Up @@ -1206,7 +1206,7 @@ <h4 id="_response_fields">Response fields</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2024-11-17 02:43:03 +0900
Last updated 2024-10-29 22:56:22 +0900
</div>
</div>
</body>
Expand Down
30 changes: 15 additions & 15 deletions src/main/resources/static/docs/application.html
Original file line number Diff line number Diff line change
Expand Up @@ -497,36 +497,38 @@ <h4 id="_http_response">HTTP response</h4>
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json
Content-Length: 1176
Content-Length: 1178

{
"totalPages" : 1,
"totalElements" : 3,
"first" : true,
"last" : true,
"size" : 10,
"content" : [ {
"id" : 1,
"name" : "김영한",
"division" : "배민",
"position" : null,
"userType" : "INACTIVE_COMPANY",
"createdAt" : "2024-11-28T19:20:48.377931",
"updatedAt" : "2024-11-28T19:20:48.377933"
"createdAt" : "2024-11-28T19:49:21.620883",
"updatedAt" : "2024-11-28T19:49:21.620885"
}, {
"id" : 2,
"name" : "김교수",
"division" : "솦융대",
"position" : "교수",
"userType" : "INACTIVE_PROFESSOR",
"createdAt" : "2024-11-28T19:20:48.377946",
"updatedAt" : "2024-11-28T19:20:48.377947"
"createdAt" : "2024-11-28T19:49:21.620894",
"updatedAt" : "2024-11-28T19:49:21.620895"
}, {
"id" : 3,
"name" : "박교수",
"division" : "정통대",
"position" : "교수",
"userType" : "INACTIVE_PROFESSOR",
"createdAt" : "2024-11-28T19:20:48.37795",
"updatedAt" : "2024-11-28T19:20:48.37795"
"createdAt" : "2024-11-28T19:49:21.620897",
"updatedAt" : "2024-11-28T19:49:21.620897"
} ],
"number" : 0,
"sort" : {
Expand All @@ -547,8 +549,6 @@ <h4 id="_http_response">HTTP response</h4>
"paged" : true,
"unpaged" : false
},
"first" : true,
"last" : true,
"empty" : false
}</code></pre>
</div>
Expand Down Expand Up @@ -796,8 +796,8 @@ <h4 id="_http_response">HTTP response</h4>
"division" : "배민",
"position" : "CEO",
"userType" : "INACTIVE_COMPANY",
"createdAt" : "2024-11-28T19:20:48.453106",
"updatedAt" : "2024-11-28T19:20:48.453109"
"createdAt" : "2024-11-28T19:49:21.643274",
"updatedAt" : "2024-11-28T19:49:21.643275"
}</code></pre>
</div>
</div>
Expand Down Expand Up @@ -926,7 +926,7 @@ <h4 id="_http_response">HTTP response</h4>
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json
Content-Length: 263
Content-Length: 262

{
"id" : 1,
Expand All @@ -936,8 +936,8 @@ <h4 id="_http_response">HTTP response</h4>
"division" : "배민",
"position" : "CEO",
"userType" : "COMPANY",
"createdAt" : "2024-11-28T19:20:48.433165",
"updatedAt" : "2024-11-28T19:20:48.433167"
"createdAt" : "2024-11-28T19:49:21.637588",
"updatedAt" : "2024-11-28T19:49:21.63759"
}</code></pre>
</div>
</div>
Expand Down Expand Up @@ -1077,7 +1077,7 @@ <h4 id="_http_response">HTTP response</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2024-11-17 02:43:03 +0900
Last updated 2024-10-28 21:44:55 +0900
</div>
</div>
</body>
Expand Down
Loading
Loading