forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 1
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
#39 feat: db에 없는 책 추가
- Loading branch information
Showing
7 changed files
with
68 additions
and
27 deletions.
There are no files selected for viewing
28 changes: 13 additions & 15 deletions
28
...mber/controller/dto/AddMyBookRequest.java → ...stone/book/controller/AddBookRequest.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,15 +1,13 @@ | ||
package com.project.capstone.member.controller.dto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record AddMyBookRequest ( | ||
String isbn, | ||
String title, | ||
String category1d, | ||
String category2d, | ||
String category3d, | ||
String author, | ||
String publisher, | ||
String publishDate | ||
) { | ||
} | ||
package com.project.capstone.book.controller; | ||
|
||
public record AddBookRequest( | ||
String isbn, | ||
String title, | ||
String category1d, | ||
String category2d, | ||
String category3d, | ||
String author, | ||
String publisher, | ||
String publishDate | ||
) { | ||
} |
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/com/project/capstone/book/controller/BookController.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,21 @@ | ||
package com.project.capstone.book.controller; | ||
|
||
import com.project.capstone.book.service.BookService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/book") | ||
@RequiredArgsConstructor | ||
public class BookController { | ||
|
||
private final BookService bookService; | ||
|
||
// 책 추가하기 | ||
@PostMapping("/add") | ||
public ResponseEntity<?> addBook(@RequestBody AddBookRequest request) { | ||
bookService.addBook(request); | ||
return ResponseEntity.ok().body("도서 추가 완료"); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/com/project/capstone/book/service/BookService.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.project.capstone.book.service; | ||
|
||
import com.project.capstone.book.controller.AddBookRequest; | ||
import com.project.capstone.book.domain.Book; | ||
import com.project.capstone.book.domain.BookRepository; | ||
import com.project.capstone.book.exception.BookException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import static com.project.capstone.book.exception.BookExceptionType.ALREADY_EXIST_BOOK; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class BookService { | ||
private final BookRepository bookRepository; | ||
public void addBook(AddBookRequest request) { | ||
if (bookRepository.findBookByIsbn(request.isbn()).isPresent()) { | ||
throw new BookException(ALREADY_EXIST_BOOK); | ||
} | ||
bookRepository.save(new Book(request)); | ||
} | ||
} |
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