-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix/#63 Post, User 엔티티 수정
- Loading branch information
Showing
16 changed files
with
377 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
backend/src/main/java/com/hjjang/backend/domain/post/domain/entity/PostDefaultValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
backend/src/main/java/com/hjjang/backend/domain/search/controller/SearchController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.hjjang.backend.domain.search.controller; | ||
|
||
import com.hjjang.backend.domain.post.dto.PostMapper; | ||
import com.hjjang.backend.domain.search.service.SearchServiceImpl; | ||
import com.hjjang.backend.global.dto.ApiResponse; | ||
import com.hjjang.backend.global.util.UserUtil; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort.Direction; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/searches") | ||
public class SearchController { | ||
|
||
private final SearchServiceImpl searchService; | ||
private final PostMapper postMapper; | ||
private final UserUtil userUtil; | ||
|
||
@GetMapping("/all") | ||
public ResponseEntity<ApiResponse> searchPosts( | ||
@RequestParam(required = false) String filter, | ||
@PageableDefault(sort = "time", direction = Direction.DESC) Pageable pageable) { | ||
return ResponseEntity.ok( | ||
ApiResponse.success( | ||
"searchPosts", | ||
searchService.findAll(filter, pageable, userUtil.getLoginUserByToken()) | ||
.stream() | ||
.map(postMapper::fromEntity) | ||
.collect(Collectors.toList())) | ||
); | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<ApiResponse> searchPostsByKeyword( | ||
@RequestParam String keyword, | ||
@RequestParam(required = false) String filter, | ||
@PageableDefault(sort = "time", direction = Direction.DESC) Pageable pageable) { | ||
return ResponseEntity.ok( | ||
ApiResponse.success( | ||
"searchPostsByKeyword", | ||
searchService.findByKeyword(keyword, filter, pageable, userUtil.getLoginUserByToken()) | ||
.stream() | ||
.map(postMapper::fromEntity) | ||
.collect(Collectors.toList()) | ||
) | ||
); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/com/hjjang/backend/domain/search/repository/SearchRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.hjjang.backend.domain.search.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.hjjang.backend.domain.post.domain.entity.Post; | ||
import com.hjjang.backend.domain.university.entity.University; | ||
|
||
public interface SearchRepository extends JpaRepository<Post, Long> { | ||
|
||
List<Post> findByIsSaleCompletion(String IsSaleCompletion, Pageable pageable); | ||
|
||
Page<Post> findAllByIsSaleCompletion(String IsSaleCompletion, Pageable pageable); | ||
|
||
List<Post> findByTitleContaining(String keyword, Pageable pageable); | ||
|
||
Page<Post> findByUniversity(University university, Pageable pageable); | ||
|
||
List<Post> findByIsSaleCompletionAndUniversity(String IsSaleCompletion, University university, Pageable pageable); | ||
Page<Post> findAllByIsSaleCompletionAndUniversity(String IsSaleCompletion, University university, Pageable pageable); | ||
} |
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/com/hjjang/backend/domain/search/service/SearchService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.hjjang.backend.domain.search.service; | ||
|
||
import com.hjjang.backend.domain.post.domain.entity.Post; | ||
import com.hjjang.backend.domain.user.entity.User; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public interface SearchService { | ||
|
||
Page<Post> findAll(String filter, Pageable pageable, User user); | ||
|
||
Page<Post> findByKeyword(String keyword, String filter, Pageable pageable, User user); | ||
} |
Oops, something went wrong.