-
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.
#33 - Feat: GET /api/v1/myBooks (내 도서 리스트 조회) 구현, response.MyBookDto,…
… ProductDto 추가
- Loading branch information
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...ion/mutbooks/src/main/java/com/example/mutbooks/app/api/myBooks/MyBooksApiController.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,34 @@ | ||
package com.example.mutbooks.app.api.myBooks; | ||
|
||
import com.example.mutbooks.app.base.dto.RsData; | ||
import com.example.mutbooks.app.member.entity.Member; | ||
import com.example.mutbooks.app.mybook.dto.response.MyBookDto; | ||
import com.example.mutbooks.app.mybook.service.MyBookService; | ||
import com.example.mutbooks.app.security.dto.MemberContext; | ||
import com.example.mutbooks.util.Ut; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/myBooks") | ||
@RequiredArgsConstructor | ||
public class MyBooksApiController { | ||
private final MyBookService myBookService; | ||
|
||
// 내 도서 리스트 | ||
@GetMapping("") | ||
public ResponseEntity<RsData> list(@AuthenticationPrincipal MemberContext memberContext) { | ||
Member member = memberContext.getMember(); | ||
List<MyBookDto> myBookDtos = myBookService.findAllByOwner(member); | ||
|
||
return Ut.spring.responseEntityOf( | ||
RsData.successOf(Ut.mapOf("myBooks", myBookDtos)) | ||
); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ission/mutbooks/src/main/java/com/example/mutbooks/app/mybook/dto/response/MyBookDto.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,34 @@ | ||
package com.example.mutbooks.app.mybook.dto.response; | ||
|
||
import com.example.mutbooks.app.mybook.entity.MyBook; | ||
import com.example.mutbooks.app.product.dto.response.ProductDto; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@AllArgsConstructor | ||
public class MyBookDto { | ||
private Long id; | ||
private LocalDateTime createDate; | ||
private LocalDateTime modifyDate; | ||
private Long ownerId; | ||
private ProductDto product; | ||
|
||
public static MyBookDto toDto(MyBook myBook) { | ||
ProductDto productDto = ProductDto.toDto(myBook.getProduct()); | ||
|
||
return MyBookDto.builder() | ||
.id(myBook.getId()) | ||
.createDate(myBook.getCreateDate()) | ||
.modifyDate(myBook.getUpdateDate()) | ||
.ownerId(myBook.getOwner().getId()) | ||
.product(productDto) | ||
.build(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...n/mutbooks/src/main/java/com/example/mutbooks/app/mybook/repository/MyBookRepository.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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
package com.example.mutbooks.app.mybook.repository; | ||
|
||
import com.example.mutbooks.app.member.entity.Member; | ||
import com.example.mutbooks.app.mybook.entity.MyBook; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface MyBookRepository extends JpaRepository<MyBook, Long> { | ||
Optional<MyBook> findByProductIdAndOwnerId(Long productId, Long ownerId); | ||
|
||
void deleteByProductIdAndOwnerId(Long productId, Long ownerId); | ||
|
||
List<MyBook> findByOwner(Member owner); | ||
} |
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
33 changes: 33 additions & 0 deletions
33
...sion/mutbooks/src/main/java/com/example/mutbooks/app/product/dto/response/ProductDto.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,33 @@ | ||
package com.example.mutbooks.app.product.dto.response; | ||
|
||
import com.example.mutbooks.app.product.entity.Product; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@AllArgsConstructor | ||
public class ProductDto { | ||
private Long id; | ||
private LocalDateTime createDate; | ||
private LocalDateTime modifyDate; | ||
private Long authorId; | ||
private String authorName; | ||
private String subject; | ||
|
||
public static ProductDto toDto(Product product) { | ||
return ProductDto.builder() | ||
.id(product.getId()) | ||
.createDate(product.getCreateDate()) | ||
.modifyDate(product.getUpdateDate()) | ||
.authorId(product.getAuthor().getId()) | ||
.authorName(product.getAuthor().getNickname()) | ||
.subject(product.getSubject()) | ||
.build(); | ||
} | ||
} |