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
Feat: Updated CvsDataLoader file #312
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8f1b698
Feat: Updated Library with Dvd, Madazine, Newspaper, and Media files
CD-Jamira e88b578
Feat: Updated Library with Media, Newspaper, DVD, and Librarian class
CD-Jamira 03ea474
Merge branch 'lesson10' of https://github.com/CD-Jamira/code-differen…
CD-Jamira 276cf36
Merge branch 'code-differently:main' into lesson10
CD-Jamira f1feea4
lsMerge branch 'main' of https://github.com/CD-Jamira/code-differentl…
CD-Jamira 59dfb10
Feat: updated CsvDataLoader
CD-Jamira File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
lesson_10/solid/solid_app/src/main/java/com/codedifferently/lesson10/library/DVD.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,27 @@ | ||
package com.codedifferently.lesson10.library; | ||
|
||
public class DVD implements Media { | ||
private String title; | ||
private String type; | ||
|
||
public DVD(String title) { | ||
this.title = title; | ||
this.type = "DVD"; | ||
} | ||
|
||
@Override | ||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public boolean canBeCheckedOutBy(Patron patron) { | ||
// Implement logic for checking if a DVD can be checked out by a patron | ||
return true; // For example, DVDs can be checked out by anyone | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
lesson_10/solid/solid_app/src/main/java/com/codedifferently/lesson10/library/Librarian.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,23 @@ | ||
package com.codedifferently.lesson10.library; | ||
|
||
import com.codedifferently.lesson10.library.exceptions.BookCheckedOutException; | ||
|
||
public class Librarian { | ||
|
||
public void checkOutBook(Book book, Patron patron) throws BookCheckedOutException { | ||
if (book.isCheckedOut()) { | ||
throw new BookCheckedOutException("Book is already checked out."); | ||
} | ||
book.setLibrary(null); | ||
book.setLibrary(patron.getLibrary()); | ||
patron.getLibrary().checkOutBook(book, patron); | ||
} | ||
|
||
public void checkInBook(Book book, Patron patron) throws BookCheckedOutException { | ||
if (!patron.getLibrary().isCheckedOut(book)) { | ||
throw new BookCheckedOutException("Book is not checked out."); | ||
} | ||
patron.getLibrary().checkInBook(book, patron); | ||
book.setLibrary(null); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
lesson_10/solid/solid_app/src/main/java/com/codedifferently/lesson10/library/Magazine.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,27 @@ | ||
package com.codedifferently.lesson10.library; | ||
|
||
public class Magazine implements Media { | ||
private String title; | ||
private String type; | ||
|
||
public Magazine(String title) { | ||
this.title = title; | ||
this.type = "Magazine"; | ||
} | ||
|
||
@Override | ||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public boolean canBeCheckedOutBy(Patron patron) { | ||
// Implement logic for checking if a magazine can be checked out by a patron | ||
return false; // Magazines cannot be checked out | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
lesson_10/solid/solid_app/src/main/java/com/codedifferently/lesson10/library/Media.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,9 @@ | ||
package com.codedifferently.lesson10.library; | ||
|
||
public interface Media { | ||
String getTitle(); | ||
|
||
String getType(); | ||
|
||
boolean canBeCheckedOutBy(Patron patron); | ||
} |
27 changes: 27 additions & 0 deletions
27
lesson_10/solid/solid_app/src/main/java/com/codedifferently/lesson10/library/Newspaper.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,27 @@ | ||
package com.codedifferently.lesson10.library; | ||
|
||
public class Newspaper implements Media { | ||
private String title; | ||
private String type; | ||
|
||
public Newspaper(String title) { | ||
this.title = title; | ||
this.type = "Newspaper"; | ||
} | ||
|
||
@Override | ||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public boolean canBeCheckedOutBy(Patron patron) { | ||
// Implement logic for checking if a newspaper can be checked out by a patron | ||
return false; // Newspapers cannot be checked out | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
...io_app/src/test/java/com/codedifferently/lesson12/factory/jamirabailey/CsvDateLoader.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,61 @@ | ||
package com.codedifferently.lesson12.factory.jamirabailey; | ||
|
||
import com.codedifferently.lesson12.factory.LibraryCsvDataLoader; | ||
import com.codedifferently.lesson12.models.CheckoutModel; | ||
import com.codedifferently.lesson12.models.LibraryDataModel; | ||
import com.codedifferently.lesson12.models.LibraryGuestModel; | ||
import com.codedifferently.lesson12.models.MediaItemModel; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
@Service | ||
public class CsvDataLoader implements LibraryCsvDataLoader { | ||
|
||
@Override | ||
public LibraryDataModel loadData() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you're making progress, so feel free to submit an updated version if you'd like more credit for this assignment. |
||
LibraryDataModel model = new LibraryDataModel(); | ||
model.mediaItems = readMediaItems("/workspaces/code-differently-24-q1/lesson_12/io/io_app/src/main/resources/csv/media_items.csv"); | ||
model.guests = readGuests("/workspaces/code-differently-24-q1/lesson_12/io/io_app/src/main/resources/csv/guests.csv"); | ||
model.checkoutsByGuestEmail = readCheckoutsByGuestEmail("/workspaces/code-differently-24-q1/lesson_12/io/io_app/src/main/resources/csv/checkouts_by_guest_email.csv"); | ||
return model; | ||
} | ||
|
||
private List<MediaItemModel> readMediaItems(String filePath) { | ||
List<MediaItemModel> mediaItems = new ArrayList<>(); | ||
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) { | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
String[] parts = line.split(","); | ||
MediaItemModel item = new MediaItemModel(); | ||
item.setType(parts[0]); | ||
item.setId(UUID.fromString(parts[1])); | ||
item.setTitle(parts[2]); | ||
item.setType(parts[3]); | ||
mediaItems.add(item); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to read media items", e); | ||
} | ||
return mediaItems; | ||
} | ||
|
||
private List<LibraryGuestModel> readGuests(String filePath) { | ||
List<LibraryGuestModel> guests = new ArrayList<>(); | ||
// Implement reading guests from CSV file | ||
return guests; | ||
} | ||
|
||
private Map<String, List<CheckoutModel>> readCheckoutsByGuestEmail(String filePath) { | ||
Map<String, List<CheckoutModel>> checkoutsByGuestEmail = new HashMap<>(); | ||
// Implement reading checkouts from CSV file | ||
return checkoutsByGuestEmail; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to remove the library files from this PR.