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

Opened /api/catalog/books/{book_id} endpoint for deleting book #97

Merged
merged 18 commits into from
Mar 25, 2024

Conversation

NenadJeckovic
Copy link
Contributor

Added delete book functionality with tests.

@NenadJeckovic NenadJeckovic changed the title 96 admin portal delete book Admin portal delete book Mar 11, 2024
public void deleteBook(Long bookId) {
validate(bookId);
bookRepository.deleteById(bookId);
deleteBookMessagingOutPort.sendMessage(bookId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if sendMessage fails for some reason? Do we want to delete a book without notifying everyone else?
Any idea how to prevent this?

message = message.concat(status).concat(" by ").concat(userName).concat(". ");
}

return message;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will this message look like if the bookRentals has more than one element? Let's say we have two copies of the same book and both are rented.
My guess it would be something like:
"Book is rented by sinisa.tutus. rented by nenad.jeckovic"
I'm not saying it is bad, just is this what you wanted (assuming I recreated the message correctly 😄 )?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if this happens if (rental.status() == null || rental.user() == null) it will return Cannot read rental status. regardless of what we generated in the message before (also the case when we have more than one element in the list)

Comment on lines 1 to 8
package com.productdock.adapter.in.web.dto;

import com.productdock.domain.RentalStatus;

import java.util.Date;

public record BookRentalStateDto (UserProfileDto user, RentalStatus status, Date date){}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we have this record inside in package when it is used in out ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And does it need to be part of adapter layer or part of domain?

package com.productdock.adapter.in.web.dto;


public record UserProfileDto (String fullName, String image, String email) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@Override
@SneakyThrows
public void deleteBook(Long bookId) {
validate(bookId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give it a bit more context with naming of this method. Method is private so it's ok to have a longer name

Comment on lines 69 to 70
assertThatThrownBy(() -> deleteBookService.deleteBook(BOOK_ID))
.isInstanceOf(DeleteBookException.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here, for this type of exception you want to check the exception message also
You will have more test cases for that

Copy link

@NenadJeckovic NenadJeckovic changed the title Admin portal delete book Opened /api/catalog/books/{book_id} endpoint for deleting book Mar 25, 2024
@NenadJeckovic NenadJeckovic merged commit 85b21df into main Mar 25, 2024
2 checks passed
@NenadJeckovic NenadJeckovic deleted the feat/96-admin-portal-delete-book branch March 25, 2024 09:40
@NenadJeckovic NenadJeckovic linked an issue Mar 25, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Admin portal Delete book
4 participants