-
Notifications
You must be signed in to change notification settings - Fork 0
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
- Loading branch information
Showing
5 changed files
with
134 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package server.bookmark; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
import server.entity.BookMark; | ||
import server.entity.User; | ||
import server.oauth.user.UserRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import static server.enums.Values.HEADER_AUTHORIZATION; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/api/v1/bookmark") | ||
@RequiredArgsConstructor | ||
public class BookMarkController { | ||
private final UserRepository userRepository; | ||
private final BookMarkRepository bookMarkRepository; | ||
|
||
@GetMapping("/search") | ||
public List<BookMarkSearchResponse> searchBookMark(@RequestHeader(value = HEADER_AUTHORIZATION) String authorizationHeader, @RequestParam("ticketIds") List<Long> ticketIds) { | ||
//todo 헤더의 토큰을 통해 User 정보를 가져오는 로직 추가 필요 | ||
User user = userRepository.findById("1").get(); | ||
List<BookMark> bookMarks = bookMarkRepository.findAllByTicketIdInAndUserId(ticketIds, user); | ||
List<BookMarkSearchResponse> response = bookMarks.stream() | ||
.map(bookMark -> BookMarkSearchResponse.of(bookMark.getTicket().getId(), true)) | ||
.collect(Collectors.toList()); | ||
return response; | ||
} | ||
} |
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,16 @@ | ||
package server.bookmark; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
import server.entity.BookMark; | ||
import server.entity.User; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface BookMarkRepository extends JpaRepository<BookMark, Long> { | ||
@Query("SELECT b FROM BookMark b JOIN FETCH b.ticket WHERE b.ticket.id IN :ticketIds AND b.user= :user") | ||
List<BookMark> findAllByTicketIdInAndUserId(@Param("ticketIds") List<Long> ticketId, @Param("user") User user); | ||
} |
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,25 @@ | ||
package server.bookmark; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class BookMarkSearchResponse { | ||
private Long ticketId; | ||
private boolean isBookMarked; | ||
|
||
@Builder | ||
public BookMarkSearchResponse(Long ticketId, boolean isBookMarked) { | ||
this.ticketId = ticketId; | ||
this.isBookMarked = isBookMarked; | ||
} | ||
|
||
public static BookMarkSearchResponse of(Long ticketId, boolean isBookMarked) { | ||
return BookMarkSearchResponse.builder() | ||
.ticketId(ticketId) | ||
.isBookMarked(isBookMarked) | ||
.build(); | ||
} | ||
} |
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,8 @@ | ||
package server.enums; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class Values { | ||
public static final String HEADER_AUTHORIZATION = "Authorization"; | ||
} |
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