-
Notifications
You must be signed in to change notification settings - Fork 29
feat: adds lesson_25 homework #777
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,28 @@ | ||
| name: Check Lesson 25 Java Pull Request | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ "main" ] | ||
| paths: | ||
| - "lesson_25/db/**" | ||
|
|
||
| jobs: | ||
| build: | ||
|
|
||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up JDK | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '21' | ||
| distribution: 'temurin' | ||
|
|
||
| - name: Build Lesson 26 with Java | ||
| working-directory: ./lesson_25/db | ||
| run: ./gradlew check |
This file contains hidden or 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 hidden or 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 @@ | ||||||||||||||||||
| import os | ||||||||||||||||||
| import pandas as pd | ||||||||||||||||||
| import numpy as np | ||||||||||||||||||
| import sqlite3 | ||||||||||||||||||
|
|
||||||||||||||||||
| # Step 1: Load the CSV file into a pandas DataFrame | ||||||||||||||||||
| media_items_df = pd.read_csv('/workspaces/code-society-25-2/lesson_12/io/io_app/src/main/resources/csv/media_items.csv') | ||||||||||||||||||
| guests_df = pd.read_csv('/workspaces/code-society-25-2/lesson_12/io/io_app/src/main/resources/csv/guests.csv') | ||||||||||||||||||
| checked_out_items_df = pd.read_csv('/workspaces/code-society-25-2/lesson_12/io/io_app/src/main/resources/csv/checked_out_items.csv') | ||||||||||||||||||
| checked_out_items_df['due_date'] = pd.to_datetime(checked_out_items_df['due_date']).values.astype(np.int64) | ||||||||||||||||||
|
|
||||||||||||||||||
| # Step 2: Create a connection to the SQLite database | ||||||||||||||||||
| # Note: This will create the database file if it doesn't exist already | ||||||||||||||||||
| os.makedirs('/workspaces/code-society-25-2/lesson_25/db/db_app/src/main/resources/sqlite/', exist_ok=True) | ||||||||||||||||||
| conn = sqlite3.connect('../db/db_app/src/main/resources/sqlite/data.db') | ||||||||||||||||||
|
Comment on lines
+14
to
+15
|
||||||||||||||||||
| os.makedirs('/workspaces/code-society-25-2/lesson_25/db/db_app/src/main/resources/sqlite/', exist_ok=True) | |
| conn = sqlite3.connect('../db/db_app/src/main/resources/sqlite/data.db') | |
| # Resolve the SQLite directory relative to this script's location | |
| script_dir = os.path.dirname(os.path.abspath(__file__)) | |
| sqlite_dir = os.path.join(script_dir, '../db/db_app/src/main/resources/sqlite/') | |
| os.makedirs(sqlite_dir, exist_ok=True) | |
| db_path = os.path.join(sqlite_dir, 'data.db') | |
| conn = sqlite3.connect(db_path) |
This file contains hidden or 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 @@ | ||
| pandas |
This file contains hidden or 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 @@ | ||
| # | ||
| # https://help.github.com/articles/dealing-with-line-endings/ | ||
| # | ||
| # Linux start script should use lf | ||
| /gradlew text eol=lf | ||
|
|
||
| # These are Windows script files and should use crlf | ||
| *.bat text eol=crlf | ||
|
|
This file contains hidden or 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,5 @@ | ||
| # Ignore Gradle project-specific cache directory | ||
| .gradle | ||
|
|
||
| # Ignore Gradle build output directory | ||
| build |
This file contains hidden or 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,79 @@ | ||
| plugins { | ||
| // Apply the application plugin to add support for building a CLI application in Java. | ||
| application | ||
| eclipse | ||
| id("com.diffplug.spotless") version "6.25.0" | ||
| id("org.springframework.boot") version "3.4.0" | ||
| id("com.adarshr.test-logger") version "4.0.0" | ||
| } | ||
|
|
||
| apply(plugin = "io.spring.dependency-management") | ||
|
|
||
| repositories { | ||
| // Use Maven Central for resolving dependencies. | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| // Use JUnit Jupiter for testing. | ||
| testImplementation("com.codedifferently.instructional:instructional-lib") | ||
| testImplementation("org.junit.jupiter:junit-jupiter:5.11.3") | ||
| testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
| testImplementation("org.assertj:assertj-core:3.26.3") | ||
| testImplementation("at.favre.lib:bcrypt:0.10.2") | ||
| testCompileOnly("org.projectlombok:lombok:1.18.38") | ||
| testAnnotationProcessor("org.projectlombok:lombok:1.18.38") | ||
|
|
||
| // This dependency is used by the application. | ||
| implementation("com.codedifferently.instructional:instructional-lib") | ||
| implementation("com.google.guava:guava:33.3.1-jre") | ||
| implementation("com.google.code.gson:gson:2.11.0") | ||
| implementation("commons-cli:commons-cli:1.6.0") | ||
| implementation("org.springframework.boot:spring-boot-starter") | ||
| implementation("org.springframework.boot:spring-boot-starter-data-jpa") | ||
| implementation("com.fasterxml.jackson.core:jackson-databind:2.13.0") | ||
| implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.3") | ||
| implementation("com.opencsv:opencsv:5.9") | ||
| implementation("org.apache.commons:commons-csv:1.10.0") | ||
| implementation("org.xerial:sqlite-jdbc:3.36.0") | ||
| implementation("org.hibernate.orm:hibernate-community-dialects:6.2.7.Final") | ||
| compileOnly("org.projectlombok:lombok:1.18.38") | ||
| annotationProcessor("org.projectlombok:lombok:1.18.38") | ||
| } | ||
|
|
||
| application { | ||
| // Define the main class for the application. | ||
| mainClass.set("com.codedifferently.lesson25.Lesson25") | ||
| } | ||
|
|
||
| tasks.named<JavaExec>("run") { | ||
| standardInput = System.`in` | ||
| } | ||
|
|
||
| tasks.named<Test>("test") { | ||
| // Use JUnit Platform for unit tests. | ||
| useJUnitPlatform() | ||
| } | ||
|
|
||
|
|
||
| configure<com.diffplug.gradle.spotless.SpotlessExtension> { | ||
|
|
||
| format("misc", { | ||
| // define the files to apply `misc` to | ||
| target("*.gradle", ".gitattributes", ".gitignore") | ||
|
|
||
| // define the steps to apply to those files | ||
| trimTrailingWhitespace() | ||
| indentWithTabs() // or spaces. Takes an integer argument if you don't like 4 | ||
| endWithNewline() | ||
| }) | ||
|
|
||
| java { | ||
| // don't need to set target, it is inferred from java | ||
|
|
||
| // apply a specific flavor of google-java-format | ||
| googleJavaFormat() | ||
| // fix formatting of type annotations | ||
| formatAnnotations() | ||
| } | ||
| } |
This file contains hidden or 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,2 @@ | ||
| # This file is generated by the 'io.freefair.lombok' Gradle plugin | ||
| config.stopBubbling = true |
39 changes: 39 additions & 0 deletions
39
lesson_25/db/db_app/src/main/java/com/codedifferently/lesson25/Lesson25.java
This file contains hidden or 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,39 @@ | ||
| package com.codedifferently.lesson25; | ||
|
|
||
| import com.codedifferently.lesson25.cli.LibraryApp; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.CommandLineRunner; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| @SpringBootApplication(scanBasePackages = "com.codedifferently") | ||
| public class Lesson25 implements CommandLineRunner { | ||
|
|
||
| @Autowired private LibraryApp libraryApp; | ||
|
|
||
| public static void main(String[] args) { | ||
| var application = new SpringApplication(Lesson25.class); | ||
| application.run(args); | ||
| } | ||
|
|
||
| @Override | ||
| public void run(String... args) throws Exception { | ||
| // Don't run as an app if we're running as a JUnit test. | ||
| if (isJUnitTest()) { | ||
| return; | ||
| } | ||
|
|
||
| libraryApp.run(args); | ||
| } | ||
|
|
||
| private static boolean isJUnitTest() { | ||
| for (StackTraceElement element : Thread.currentThread().getStackTrace()) { | ||
| if (element.getClassName().startsWith("org.junit.")) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } |
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.
Hard-coded absolute paths make the script non-portable. Consider using relative paths or environment variables to make the script work across different development environments.