Skip to content

Commit 21ac449

Browse files
authored
Merge branch 'code-differently:main' into feature/lesson_17
2 parents efc3061 + dbd7c3b commit 21ac449

File tree

123 files changed

+14617
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+14617
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Check Lesson 26 Java Pull Request
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
paths:
7+
- "lesson_26/api/java/**"
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up JDK 17
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '17'
24+
distribution: 'temurin'
25+
26+
- name: Build Lesson 26 with Java
27+
working-directory: ./lesson_26/api/java
28+
run: ./gradlew check
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Check Lesson 26 TS Pull Request
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
paths:
7+
- "lesson_26/api/javascript/api_app/**"
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Use Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20.x'
23+
24+
- name: Build Lesson 26 with Node.js
25+
working-directory: ./lesson_26/api/javascript/api_app
26+
run: |
27+
npm ci
28+
npm run check

lesson_26/README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,35 @@ Please review the following resources before lecture:
1919

2020
## Homework
2121

22-
TODO(anthonydmays): Add details
22+
- [ ] Complete the [Creating a Library API](#creating-a-library-api) assignment.
23+
- [ ] Do pre-work for [lesson 27](/lesson_27/).
24+
25+
### Creating a Library API
26+
27+
We are continuing to build atop the foundation of our library app. For this assignment, you will help implement the API that will be used by a yet-to-come front-end app.
28+
29+
* You will implement the [MediaItemsController][controller-file] to enable the following API:
30+
* `GET /items` - Retrieves a list of media items
31+
* `POST /items` - Creates a new media item
32+
* `GET /items/:id` - Retrieves a single media item with the given ID.
33+
* `DELETE /items/:id` - Deletes a single media item with the given ID.
34+
* Study the tests in [MediaItemsControllerTest][controller-test-file] to understand what you should accept and return in the API.
35+
* You should not need to make any code changes outside of the `com.codedifferently.lesson26.web` package.
36+
37+
#### Running the API
38+
39+
You can run the server using the usual `./gradlew run` command from the `api/java` directory. If you want to test that the server is running correctly, you can use `curl` like so:
40+
41+
```bash
42+
curl http://localhost:5000/items | json_pp
43+
```
44+
45+
Alternatively, you can test the API using the tool [Postman][postman-link]. I recommend installing this tool to make it easier to test things.
46+
47+
## Additional resources
48+
49+
* [gRPC vs REST: Comparing API Styles in Practice (Article)](https://dev.to/anthonydmays/grpc-vs-rest-comparing-api-styles-in-practice-4bl): This article explains why the stuff most people call REST isn't actually.
50+
51+
[controller-file]: ./api/java/api_app/src/main/java/com/codedifferently/lesson26/web/MediaItemsController.java
52+
[controller-test-file]: ./api/java/api_app/src/test/java/com/codedifferently/lesson26/web/MediaItemsControllerTest.java
53+
[postman-link]: https://www.postman.com/downloads/

lesson_26/api/java/.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+

lesson_26/api/java/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
plugins {
2+
// Apply the application plugin to add support for building a CLI application in Java.
3+
application
4+
eclipse
5+
id("com.diffplug.spotless") version "6.25.0"
6+
id("org.springframework.boot") version "3.2.2"
7+
id("com.adarshr.test-logger") version "4.0.0"
8+
id("io.freefair.lombok") version "8.6"
9+
}
10+
11+
apply(plugin = "io.spring.dependency-management")
12+
13+
repositories {
14+
// Use Maven Central for resolving dependencies.
15+
mavenCentral()
16+
}
17+
18+
dependencies {
19+
// Use JUnit Jupiter for testing.
20+
testImplementation("com.codedifferently.instructional:instructional-lib")
21+
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
22+
testImplementation("org.springframework.boot:spring-boot-starter-test")
23+
testImplementation("org.assertj:assertj-core:3.25.1")
24+
testImplementation("at.favre.lib:bcrypt:0.10.2")
25+
testImplementation("org.springframework.boot:spring-boot-starter-test")
26+
27+
// This dependency is used by the application.
28+
implementation("com.codedifferently.instructional:instructional-lib")
29+
implementation("com.google.guava:guava:31.1-jre")
30+
implementation("com.google.code.gson:gson:2.10.1")
31+
implementation("commons-cli:commons-cli:1.6.0")
32+
implementation("org.springframework.boot:spring-boot-starter")
33+
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
34+
implementation("org.springframework.boot:spring-boot-starter-validation")
35+
implementation("org.springframework.boot:spring-boot-starter-web")
36+
compileOnly("org.springframework.boot:spring-boot-devtools")
37+
implementation("com.opencsv:opencsv:5.9")
38+
implementation("org.apache.commons:commons-csv:1.10.0")
39+
implementation("org.xerial:sqlite-jdbc:3.36.0")
40+
implementation("org.hibernate.orm:hibernate-community-dialects:6.2.7.Final")
41+
}
42+
43+
application {
44+
// Define the main class for the application.
45+
mainClass.set("com.codedifferently.lesson26.Lesson26")
46+
}
47+
48+
tasks.named<JavaExec>("run") {
49+
standardInput = System.`in`
50+
}
51+
52+
tasks.named<Test>("test") {
53+
// Use JUnit Platform for unit tests.
54+
useJUnitPlatform()
55+
}
56+
57+
58+
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
59+
60+
format("misc", {
61+
// define the files to apply `misc` to
62+
target("*.gradle", ".gitattributes", ".gitignore")
63+
64+
// define the steps to apply to those files
65+
trimTrailingWhitespace()
66+
indentWithTabs() // or spaces. Takes an integer argument if you don't like 4
67+
endWithNewline()
68+
})
69+
70+
java {
71+
// don't need to set target, it is inferred from java
72+
73+
// apply a specific flavor of google-java-format
74+
googleJavaFormat()
75+
// fix formatting of type annotations
76+
formatAnnotations()
77+
}
78+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file is generated by the 'io.freefair.lombok' Gradle plugin
2+
config.stopBubbling = true
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.codedifferently.lesson26;
2+
3+
import com.codedifferently.lesson26.cli.LibraryApp;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.CommandLineRunner;
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.context.annotation.Configuration;
9+
10+
@Configuration
11+
@SpringBootApplication(scanBasePackages = "com.codedifferently")
12+
public class Lesson26 implements CommandLineRunner {
13+
@Autowired private LibraryApp libraryApp;
14+
15+
public static void main(String[] args) {
16+
var application = new SpringApplication(Lesson26.class);
17+
application.run(args);
18+
}
19+
20+
@Override
21+
public void run(String... args) throws Exception {
22+
// Don't run as an app if we're running as a JUnit test.
23+
if (isJUnitTest()) {
24+
return;
25+
}
26+
27+
libraryApp.run(args);
28+
}
29+
30+
private static boolean isJUnitTest() {
31+
for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
32+
if (element.getClassName().startsWith("org.junit.")) {
33+
return true;
34+
}
35+
}
36+
return false;
37+
}
38+
}

0 commit comments

Comments
 (0)