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

Be #159

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ public static BookDetail toBookDetail(Book book){
.book(book)
.build();
}

public void setImageURL(String imageURL) {
this.imageURL = imageURL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class BookApproveDTO {
private String publishYear;
private String publisher;
private String bookApplicant;
private String information;
private String imageURL;

public static BookApproveDTO of(BookApprove bookApprove, User user){
Expand All @@ -31,6 +32,7 @@ public static BookApproveDTO of(BookApprove bookApprove, User user){
.publisher(bookApprove.getPublisher())
.publishYear(bookApprove.getPublishYear())
.bookApplicant(user.getName())
.information(bookApprove.getInformation())
.imageURL(bookApprove.getImageURL())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@AllArgsConstructor
public class FullBookDTO extends BookDTO{
private String publishYear;
private String information;

public static FullBookDTO of(Book book){
return FullBookDTO.builder()
Expand All @@ -22,6 +23,7 @@ public static FullBookDTO of(Book book){
.author(book.getAuthor())
.publisher(book.getPublisher())
.publishYear(book.getPublishYear())
.information(book.getInformation())
.imageURL(book.getImageURL())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -33,6 +34,9 @@ public class BookService {
private final BookApproveRepository bookApproveRepository;
private final BookCategoryRepository bookCategoryRepository;

@Value("${cloud.aws.s3.default.image.url}")
private String defaultImageUrl;

public Book getOneBook(Long id) {
return getBook.getOneEntity(id);
}
Expand Down Expand Up @@ -76,7 +80,13 @@ public Page<BookDetail> getAllBookDetails(int page){
}

public Long createBookApprove(CreateBookApproveRequest createBookApproveRequest, Long userId){
String url = createBookApproveRequest.getImageURL();
if (url == null) {
url = defaultImageUrl;
}

BookApprove bookApprove = CreateBookApproveRequest.toEntity(createBookApproveRequest, userId);
bookApprove.setImageURL(url);
return postBook.saveBookApprove(bookApprove);
}

Expand All @@ -91,7 +101,7 @@ public void createBook(CreateBookRequest createBookRequest) {
bookApproveList.stream()
.map(bookApprove -> {
BookWithCategories bookWithCategories = BookApprove.toBookWithCategories(
getOrCreateBook(bookApprove), bookApprove.getCategories()
getOrCreateBook(bookApprove), bookApprove.getCategories().toUpperCase()
);

bookApproveRepository.deleteById(bookApprove.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public ApiResponse<SuccessBody<UserResponse>> findUser(@AuthenticationPrincipal

// 회원가입
@PostMapping("/users")
public ApiResponse<SuccessBody<Void>> signup(@RequestBody AddUserRequest request) {
userService.save(request);
public ApiResponse<SuccessBody<Void>> signup(@RequestBody List<AddUserRequest> requests) {
userService.save(requests);
return ApiResponseGenerator.success(HttpStatus.CREATED, SuccessMessage.CREATE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ public User findById(Long Id) {
.orElseThrow(() -> new IllegalArgumentException("not found: " + Id));
}

public Long save(AddUserRequest dto) {
return userRepository.save(User.builder()
.loginId(dto.getLoginId())
.password(passwordEncoder.encode(dto.getPassword()))
.name(dto.getName())
.grade(dto.getGrade())
.build()).getId();
public void save(List<AddUserRequest> dto) {

dto.stream().forEach(
addUserRequest -> userRepository.save(User.builder()
.loginId(addUserRequest.getLoginId())
.password(passwordEncoder.encode(addUserRequest.getPassword()))
.name(addUserRequest.getName())
.grade(addUserRequest.getGrade())
.build())
);
}

public Page<User> getUserPage(int page){
Expand Down