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

[Fix] getProjects 필터링 기능 추가 #100

Merged
merged 3 commits into from
Sep 20, 2024
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,6 +3,7 @@

import com.scg.stop.auth.annotation.AuthUser;
import com.scg.stop.project.domain.ProjectCategory;
import com.scg.stop.project.domain.ProjectType;
import com.scg.stop.project.dto.request.CommentRequest;
import com.scg.stop.project.dto.request.ProjectRequest;
import com.scg.stop.project.dto.response.CommentResponse;
Expand All @@ -20,6 +21,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/projects")
Expand All @@ -30,12 +33,13 @@ public class ProjectController {
@GetMapping
public ResponseEntity<Page<ProjectResponse>> getProjects(
@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "year", required = false) Integer year,
@RequestParam(value = "category", required = false) ProjectCategory category,
@RequestParam(value = "year", required = false) List<Integer> year,
@RequestParam(value = "category", required = false) List<ProjectCategory> category,
@RequestParam(value = "type", required = false) List<ProjectType> type,
@PageableDefault(page = 0, size = 10) Pageable pageable,
@AuthUser(accessType = {AccessType.OPTIONAL}) User user
){
Page<ProjectResponse> pageProjectResponse = projectService.getProjects(title, year, category, pageable, user);
Page<ProjectResponse> pageProjectResponse = projectService.getProjects(title, year, category, type, pageable, user);
return ResponseEntity.status(HttpStatus.OK).body(pageProjectResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@

import com.scg.stop.project.domain.Project;
import com.scg.stop.project.domain.ProjectCategory;
import com.scg.stop.project.domain.ProjectType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ProjectRepository extends JpaRepository<Project, Long> {
// @EntityGraph(attributePaths = {"thumbnail", "members"})
@Query("SELECT p FROM Project p " +
"WHERE (:title IS NULL OR p.name LIKE %:title%) " +
"AND (:year IS NULL OR p.year = :year) " +
"AND (:category IS NULL OR p.category = :category)")
"AND (:year IS NULL OR p.year IN :year) " +
"AND (:category IS NULL OR p.category IN :category)" +
"AND (:type IS NULL OR p.type IN :type)")
Page<Project> findProjects(
@Param("title") String title,
@Param("year") Integer year,
@Param("category") ProjectCategory category,
@Param("year") List<Integer> year,
@Param("category") List<ProjectCategory> category,
@Param("type") List<ProjectType> type,
Pageable pageable
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public class ProjectService {
private EntityManager entityManager;

@Transactional(readOnly = true)
public Page<ProjectResponse> getProjects(String title, Integer year, ProjectCategory category, Pageable pageable, User user){
Page<Project> projects = projectRepository.findProjects(title, year, category, pageable);
public Page<ProjectResponse> getProjects(String title, List<Integer> year, List<ProjectCategory> category, List<ProjectType> type, Pageable pageable, User user){
Page<Project> projects = projectRepository.findProjects(title, year, category, type, pageable);
Page<ProjectResponse> projectResponses = projects.map(project -> ProjectResponse.of(user, project));
return projectResponses;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/aiHub-controller-test.html
Original file line number Diff line number Diff line change
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-09-08 17:36:39 +0900
Last updated 2024-09-19 14:45:10 +0900
</div>
</div>
</body>
Expand Down
36 changes: 18 additions & 18 deletions src/main/resources/static/docs/application.html
Original file line number Diff line number Diff line change
Expand Up @@ -502,53 +502,53 @@ <h4 id="_http_response">HTTP response</h4>
{
"totalPages" : 1,
"totalElements" : 3,
"first" : true,
"last" : true,
"size" : 10,
"content" : [ {
"id" : 1,
"name" : "김영한",
"division" : "배민",
"position" : null,
"userType" : "INACTIVE_COMPANY",
"createdAt" : "2024-09-12T15:40:13.640315",
"updatedAt" : "2024-09-12T15:40:13.640318"
"createdAt" : "2024-09-19T19:31:37.360136",
"updatedAt" : "2024-09-19T19:31:37.360138"
}, {
"id" : 2,
"name" : "김교수",
"division" : "솦융대",
"position" : "교수",
"userType" : "INACTIVE_PROFESSOR",
"createdAt" : "2024-09-12T15:40:13.640334",
"updatedAt" : "2024-09-12T15:40:13.640335"
"createdAt" : "2024-09-19T19:31:37.360152",
"updatedAt" : "2024-09-19T19:31:37.360153"
}, {
"id" : 3,
"name" : "박교수",
"division" : "정통대",
"position" : "교수",
"userType" : "INACTIVE_PROFESSOR",
"createdAt" : "2024-09-12T15:40:13.640338",
"updatedAt" : "2024-09-12T15:40:13.640341"
"createdAt" : "2024-09-19T19:31:37.360155",
"updatedAt" : "2024-09-19T19:31:37.360156"
} ],
"number" : 0,
"sort" : {
"empty" : true,
"unsorted" : true,
"sorted" : false
"sorted" : false,
"unsorted" : true
},
"numberOfElements" : 3,
"pageable" : {
"pageNumber" : 0,
"pageSize" : 10,
"sort" : {
"empty" : true,
"unsorted" : true,
"sorted" : false
"sorted" : false,
"unsorted" : true
},
"offset" : 0,
"paged" : true,
"unpaged" : false
},
"numberOfElements" : 3,
"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-09-12T15:40:13.738394",
"updatedAt" : "2024-09-12T15:40:13.738396"
"createdAt" : "2024-09-19T19:31:37.383434",
"updatedAt" : "2024-09-19T19:31:37.383435"
}</code></pre>
</div>
</div>
Expand Down Expand Up @@ -936,8 +936,8 @@ <h4 id="_http_response">HTTP response</h4>
"division" : "배민",
"position" : "CEO",
"userType" : "COMPANY",
"createdAt" : "2024-09-12T15:40:13.718577",
"updatedAt" : "2024-09-12T15:40:13.718581"
"createdAt" : "2024-09-19T19:31:37.377496",
"updatedAt" : "2024-09-19T19:31:37.377497"
}</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-08-31 17:36:52 +0900
Last updated 2024-08-21 14:06:52 +0900
</div>
</div>
</body>
Expand Down
17 changes: 10 additions & 7 deletions src/main/resources/static/docs/auth-controller-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ <h4 id="_http_response">HTTP response</h4>
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Set-Cookie: refresh-token=refresh_token; Path=/; Max-Age=604800; Expires=Thu, 19 Sep 2024 06:40:08 GMT; Secure; HttpOnly; SameSite=None
Set-Cookie: access-token=access_token; Path=/; Max-Age=604800; Expires=Thu, 19 Sep 2024 06:40:08 GMT; Secure; SameSite=None
Set-Cookie: refresh-token=refresh_token; Path=/; Max-Age=604800; Expires=Thu, 26 Sep 2024 10:31:35 GMT; Secure; HttpOnly; SameSite=None
Set-Cookie: access-token=access_token; Path=/; Max-Age=604800; Expires=Thu, 26 Sep 2024 10:31:35 GMT; Secure; SameSite=None
Location: https://localhost:3000/login/kakao</code></pre>
</div>
</div>
Expand All @@ -499,21 +499,24 @@ <h4 id="_http_response">HTTP response</h4>
<h4 id="_response_fields">Response fields</h4>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Path</th>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Type</th>
<th class="tableblock halign-left valign-top">Required</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>accessToken</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">true</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">access token</p></td>
</tr>
</tbody>
Expand Down Expand Up @@ -803,7 +806,7 @@ <h4 id="_http_response">HTTP response</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2024-08-09 18:08:28 +0900
Last updated 2024-08-21 14:06:52 +0900
</div>
</div>
</body>
Expand Down
Loading
Loading