Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import io.pillopl.library.lending.librarybranch.model.LibraryBranchId
import io.pillopl.library.lending.patron.model.PatronEvent
import io.pillopl.library.lending.patron.model.PatronId
import io.pillopl.library.lending.patron.model.PatronType
import io.pillopl.library.lending.patronprofile.model.Checkout
import io.pillopl.library.lending.patronprofile.model.Hold
import io.pillopl.library.lending.patronprofile.model.PatronProfile
import io.pillopl.library.lending.patronprofile.model.PatronProfiles
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -23,7 +25,6 @@ import static io.pillopl.library.catalogue.BookType.Restricted
import static io.pillopl.library.lending.book.model.BookFixture.anyBookId
import static io.pillopl.library.lending.librarybranch.model.LibraryBranchFixture.anyBranch
import static io.pillopl.library.lending.patron.model.PatronFixture.anyPatronId
import static io.vavr.Tuple.of
import static java.time.Instant.now

@SpringBootTest(classes = LendingTestContext.class)
Expand Down Expand Up @@ -83,14 +84,14 @@ class FindingPatronProfileInDatabaseIT extends Specification {

void thereIsOnlyOneHold(PatronProfile profile) {
assert profile.holdsView.currentHolds.size() == 1
assert profile.holdsView.currentHolds.get(0).equals(of(bookId, TOMORROW))
assert profile.holdsView.currentHolds.get(0) == new Hold(bookId, TOMORROW)
assert profile.currentCheckouts.currentCheckouts.size() == 0
}

void thereIsOnlyOneCheckout(PatronProfile profile) {
assert profile.holdsView.currentHolds.size() == 0
assert profile.currentCheckouts.currentCheckouts.size() == 1
assert profile.currentCheckouts.currentCheckouts.get(0).equals(of(bookId, TOMORROW))
assert profile.currentCheckouts.currentCheckouts.get(0) == new Checkout(bookId, TOMORROW)
}

void thereIsZeroHoldsAndZeroCheckouts(PatronProfile profile) {
Expand All @@ -99,7 +100,7 @@ class FindingPatronProfileInDatabaseIT extends Specification {

}

PatronEvent.BookCheckedOut bookCheckedOutTill(Instant till) {
PatronEvent.BookCheckedOut bookCheckedOutTill(Instant till) {
return new PatronEvent.BookCheckedOut(
now(),
patronId.getPatronId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import io.pillopl.library.lending.patron.application.hold.CancelingHold;
import io.pillopl.library.lending.patron.model.PatronFixture;
import io.pillopl.library.lending.patron.model.PatronId;
import io.pillopl.library.lending.patronprofile.model.Checkout;
import io.pillopl.library.lending.patronprofile.model.CheckoutsView;
import io.pillopl.library.lending.patronprofile.model.Hold;
import io.pillopl.library.lending.patronprofile.model.HoldsView;
import io.pillopl.library.lending.patronprofile.model.PatronProfile;
import io.pillopl.library.lending.patronprofile.model.PatronProfiles;
import io.vavr.Tuple;
import io.vavr.control.Try;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -191,7 +192,7 @@ public void shouldReturn500IfSomethingFailedWhileCanceling() throws Exception {

PatronProfile profiles() {
return new PatronProfile(
new HoldsView(of(Tuple.of(bookId, anyDate))),
new CheckoutsView(of(Tuple.of(anotherBook, anotherDate))));
new HoldsView(of(new Hold(bookId, anyDate))),
new CheckoutsView(of(new Checkout(anotherBook, anotherDate))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import io.pillopl.library.catalogue.BookId;
import io.pillopl.library.lending.dailysheet.model.CheckoutsToOverdueSheet;
import io.pillopl.library.lending.dailysheet.model.DailySheet;
import io.pillopl.library.lending.dailysheet.model.ExpiredHold;
import io.pillopl.library.lending.dailysheet.model.HoldsToExpireSheet;
import io.pillopl.library.lending.dailysheet.model.OverdueCheckout;
import io.pillopl.library.lending.librarybranch.model.LibraryBranchId;
import io.pillopl.library.lending.patron.model.PatronEvent.*;
import io.pillopl.library.lending.patron.model.PatronEvent.BookCheckedOut;
import io.pillopl.library.lending.patron.model.PatronEvent.BookHoldCanceled;
import io.pillopl.library.lending.patron.model.PatronEvent.BookHoldExpired;
import io.pillopl.library.lending.patron.model.PatronEvent.BookPlacedOnHold;
import io.pillopl.library.lending.patron.model.PatronEvent.BookReturned;
import io.pillopl.library.lending.patron.model.PatronId;
import io.vavr.Tuple3;
import io.vavr.control.Option;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
Expand All @@ -23,7 +28,6 @@
import java.util.Map;
import java.util.UUID;

import static io.vavr.Tuple.of;
import static io.vavr.collection.List.ofAll;
import static java.sql.Timestamp.from;
import static java.util.stream.Collectors.toList;
Expand All @@ -39,7 +43,7 @@ public HoldsToExpireSheet queryForHoldsToExpireSheet() {
return new HoldsToExpireSheet(ofAll(
findHoldsToExpire()
.stream()
.map(this::toExpiredHoldsTuple)
.map(this::toExpiredHold)
.collect(toList())));
}

Expand All @@ -50,8 +54,8 @@ private List<Map<String, Object>> findHoldsToExpire() {
new ColumnMapRowMapper());
}

private Tuple3<BookId, PatronId, LibraryBranchId> toExpiredHoldsTuple(Map<String, Object> map) {
return of(
private ExpiredHold toExpiredHold(Map<String, Object> map) {
return new ExpiredHold(
new BookId((UUID) map.get("BOOK_ID")),
new PatronId((UUID) map.get("HOLD_BY_PATRON_ID")),
new LibraryBranchId((UUID) map.get("HOLD_AT_BRANCH")));
Expand All @@ -62,7 +66,7 @@ public CheckoutsToOverdueSheet queryForCheckoutsToOverdue() {
return new CheckoutsToOverdueSheet(ofAll(
findCheckoutsToOverdue()
.stream()
.map(this::toOverdueCheckoutsTuple)
.map(this::toOverdueCheckout)
.collect(toList())));
}

Expand All @@ -73,8 +77,8 @@ private List<Map<String, Object>> findCheckoutsToOverdue() {
new ColumnMapRowMapper());
}

private Tuple3<BookId, PatronId, LibraryBranchId> toOverdueCheckoutsTuple(Map<String, Object> map) {
return of(
private OverdueCheckout toOverdueCheckout(Map<String, Object> map) {
return new OverdueCheckout(
new BookId((UUID) map.get("BOOK_ID")),
new PatronId((UUID) map.get("CHECKED_OUT_BY_PATRON_ID")),
new LibraryBranchId((UUID) map.get("CHECKED_OUT_AT_BRANCH")));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package io.pillopl.library.lending.dailysheet.model;

import io.pillopl.library.catalogue.BookId;
import io.pillopl.library.lending.librarybranch.model.LibraryBranchId;
import io.pillopl.library.lending.patron.model.PatronEvent.OverdueCheckoutRegistered;
import io.pillopl.library.lending.patron.model.PatronId;
import io.vavr.Tuple3;
import io.vavr.collection.List;
import io.vavr.collection.Stream;
import lombok.NonNull;
Expand All @@ -14,21 +10,15 @@
public class CheckoutsToOverdueSheet {

@NonNull
List<Tuple3<BookId, PatronId, LibraryBranchId>> checkouts;
List<OverdueCheckout> checkouts;

public Stream<OverdueCheckoutRegistered> toStreamOfEvents() {
return checkouts
.toStream()
.map(this::tupleToEvent);
return checkouts.toStream()
.map(OverdueCheckout::toEvent);
}

public int count() {
return checkouts.size();
}

private OverdueCheckoutRegistered tupleToEvent(Tuple3<BookId, PatronId, LibraryBranchId> overdueCheckouts) {
return OverdueCheckoutRegistered.now(overdueCheckouts._2, overdueCheckouts._1, overdueCheckouts._3);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.pillopl.library.lending.dailysheet.model;

import io.pillopl.library.catalogue.BookId;
import io.pillopl.library.lending.librarybranch.model.LibraryBranchId;
import io.pillopl.library.lending.patron.model.PatronEvent.BookHoldExpired;
import io.pillopl.library.lending.patron.model.PatronId;
import lombok.Value;

@Value
public class ExpiredHold {
private final BookId heldBook;
private final PatronId patron;
private final LibraryBranchId library;

BookHoldExpired toEvent() {
return BookHoldExpired.now(this.heldBook, this.patron, this.library);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package io.pillopl.library.lending.dailysheet.model;

import io.pillopl.library.catalogue.BookId;
import io.pillopl.library.lending.librarybranch.model.LibraryBranchId;
import io.pillopl.library.lending.patron.model.PatronEvent;
import io.pillopl.library.lending.patron.model.PatronId;
import io.vavr.Tuple3;
import io.vavr.collection.List;
import io.vavr.collection.Stream;
import lombok.NonNull;
Expand All @@ -15,22 +11,17 @@
public class HoldsToExpireSheet {

@NonNull
List<Tuple3<BookId, PatronId, LibraryBranchId>> expiredHolds;
List<ExpiredHold> expiredHolds;

@EventListener
public Stream<PatronEvent.BookHoldExpired> toStreamOfEvents() {
return expiredHolds
.toStream()
.map(this::tupleToEvent);
.map(ExpiredHold::toEvent);
}

public int count() {
return expiredHolds.size();
}

private PatronEvent.BookHoldExpired tupleToEvent(Tuple3<BookId, PatronId, LibraryBranchId> expiredHold) {
return PatronEvent.BookHoldExpired.now(expiredHold._1, expiredHold._2, expiredHold._3);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.pillopl.library.lending.dailysheet.model;

import io.pillopl.library.catalogue.BookId;
import io.pillopl.library.lending.librarybranch.model.LibraryBranchId;
import io.pillopl.library.lending.patron.model.PatronEvent.OverdueCheckoutRegistered;
import io.pillopl.library.lending.patron.model.PatronId;
import lombok.Value;

@Value
public class OverdueCheckout {
private final BookId checkedOutBook;
private final PatronId patron;
private final LibraryBranchId library;

OverdueCheckoutRegistered toEvent() {
return OverdueCheckoutRegistered.now(this.patron, this.checkedOutBook, this.library);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import io.pillopl.library.catalogue.BookId;
import io.pillopl.library.lending.patron.model.PatronId;
import io.pillopl.library.lending.patronprofile.model.Checkout;
import io.pillopl.library.lending.patronprofile.model.CheckoutsView;
import io.pillopl.library.lending.patronprofile.model.Hold;
import io.pillopl.library.lending.patronprofile.model.HoldsView;
import io.pillopl.library.lending.patronprofile.model.PatronProfile;
import io.pillopl.library.lending.patronprofile.model.PatronProfiles;
import io.vavr.Tuple;
import io.vavr.Tuple2;
import lombok.AllArgsConstructor;
import org.springframework.jdbc.core.ColumnMapRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Timestamp;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand All @@ -31,12 +30,12 @@ public PatronProfile fetchFor(PatronId patronId) {
HoldsView holdsView = new HoldsView(
ofAll(findCurrentHoldsFor(patronId)
.stream()
.map(this::toHoldViewTuple)
.map(this::toHold)
.collect(toList())));
CheckoutsView checkoutsView = new CheckoutsView(
ofAll(findCurrentCheckoutsFor(patronId)
.stream()
.map(this::toCheckoutsViewTuple)
.map(this::toCheckout)
.collect(toList())));
return new PatronProfile(holdsView, checkoutsView);
}
Expand All @@ -48,8 +47,8 @@ private List<Map<String, Object>> findCurrentHoldsFor(PatronId patronId) {
new ColumnMapRowMapper());
}

private Tuple2<BookId, Instant> toHoldViewTuple(Map<String, Object> map) {
return Tuple.of(new BookId((UUID) map.get("BOOK_ID")),
private Hold toHold(Map<String, Object> map) {
return new Hold(new BookId((UUID) map.get("BOOK_ID")),
((Timestamp) map.get("HOLD_TILL")).toInstant());
}

Expand All @@ -60,8 +59,8 @@ private List<Map<String, Object>> findCurrentCheckoutsFor(PatronId patronId) {
new ColumnMapRowMapper());
}

private Tuple2<BookId, Instant> toCheckoutsViewTuple(Map<String, Object> map) {
return Tuple.of(new BookId((UUID) map.get("BOOK_ID")),
private Checkout toCheckout(Map<String, Object> map) {
return new Checkout(new BookId((UUID) map.get("BOOK_ID")),
((Timestamp) map.get("CHECKOUT_TILL")).toInstant());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.pillopl.library.lending.patronprofile.model;

import io.pillopl.library.catalogue.BookId;
import lombok.Value;

import java.time.Instant;

@Value
public class Checkout {

private final BookId book;

private final Instant till;

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package io.pillopl.library.lending.patronprofile.model;

import io.pillopl.library.catalogue.BookId;
import io.vavr.Tuple2;
import io.vavr.collection.List;
import lombok.NonNull;
import lombok.Value;

import java.time.Instant;

@Value
public class CheckoutsView {

@NonNull
List<Tuple2<BookId, Instant>> currentCheckouts;
List<Checkout> currentCheckouts;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.pillopl.library.lending.patronprofile.model;

import io.pillopl.library.catalogue.BookId;
import lombok.Value;

import java.time.Instant;

@Value
public class Hold {

private final BookId book;

private final Instant till;

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package io.pillopl.library.lending.patronprofile.model;

import io.pillopl.library.catalogue.BookId;
Copy link
Member

Choose a reason for hiding this comment

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

Can you revert changes in imports? In all of the files?

import io.vavr.Tuple2;
import io.vavr.collection.List;
import lombok.NonNull;
import lombok.Value;

import java.time.Instant;

@Value
public class HoldsView {

@NonNull
List<Tuple2<BookId, Instant>> currentHolds;
List<Hold> currentHolds;

}
Loading