From 8b8bc9a966d89d9abc4ebf595a88d6d15a4e1521 Mon Sep 17 00:00:00 2001 From: Michelle Date: Fri, 17 Apr 2026 08:57:54 +0800 Subject: [PATCH 1/9] mich changes --- src/main/java/com/libraryman_api/book/BookController.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/libraryman_api/book/BookController.java b/src/main/java/com/libraryman_api/book/BookController.java index 803e0e9..7924175 100644 --- a/src/main/java/com/libraryman_api/book/BookController.java +++ b/src/main/java/com/libraryman_api/book/BookController.java @@ -17,9 +17,10 @@ * This controller provides endpoints for performing CRUD operations on books, * including retrieving all books, getting a book by its ID, adding a new book, * updating an existing book, and deleting a book. + * * Version: 1.1 */ @RestController -@RequestMapping("/api") +@RequestMapping("/api/v1/books") //Versioning API path -> provide more context public class BookController { @Autowired @@ -80,7 +81,8 @@ public BookDto addBook(@Valid @RequestBody BookDto bookDto) { /** * Updates an existing book in the library. - * + * This operation is restricted to LIBRARIAN and ADMIN roles. + * * @param id the ID of the book to update. * @param bookDtoDetails the {@link Book} object containing the updated book details. * @return the updated {@link Book} object. @@ -93,6 +95,7 @@ public BookDto updateBook(@PathVariable int id, @Valid @RequestBody BookDto book /** * Deletes a book from the library by its ID. + * Provides confirmation message upon successful deletion. * * @param id the ID of the book to delete. */ @@ -100,6 +103,7 @@ public BookDto updateBook(@PathVariable int id, @Valid @RequestBody BookDto book @PreAuthorize("hasRole('LIBRARIAN') or hasRole('ADMIN')") public void deleteBook(@PathVariable int id) { bookService.deleteBook(id); + return ResponseEntity.ok("Book with ID " + id + " has been successfully deleted from the system."); } /** From fad75ce6cb7cbb10ca660c0dac0ea4d3b22b1765 Mon Sep 17 00:00:00 2001 From: Michelle Date: Fri, 17 Apr 2026 09:34:25 +0800 Subject: [PATCH 2/9] new mich changes --- pom.xml | 2 +- src/main/java/com/libraryman_api/book/BookController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6dfee89..a48b762 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ io.jsonwebtoken jjwt-jackson - 0.12.0 + 0.11.5 runtime diff --git a/src/main/java/com/libraryman_api/book/BookController.java b/src/main/java/com/libraryman_api/book/BookController.java index 7924175..3784db3 100644 --- a/src/main/java/com/libraryman_api/book/BookController.java +++ b/src/main/java/com/libraryman_api/book/BookController.java @@ -101,7 +101,7 @@ public BookDto updateBook(@PathVariable int id, @Valid @RequestBody BookDto book */ @DeleteMapping("delete-book/{id}") @PreAuthorize("hasRole('LIBRARIAN') or hasRole('ADMIN')") - public void deleteBook(@PathVariable int id) { + public ResponseEntity deleteBook(@PathVariable int id) { bookService.deleteBook(id); return ResponseEntity.ok("Book with ID " + id + " has been successfully deleted from the system."); } From 9a2e51f76fc24e9881050af5cc05067f9f47c407 Mon Sep 17 00:00:00 2001 From: yanzhi Date: Fri, 17 Apr 2026 18:58:10 +0800 Subject: [PATCH 3/9] Test running --- pom.xml | 50 +++++++++++++++++++---- src/test/resources/application.properties | 6 +++ 2 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/application.properties diff --git a/pom.xml b/pom.xml index 6dfee89..8c3bb46 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,12 @@ spring-boot-starter-web + + com.h2database + h2 + test + + org.springframework.boot spring-boot-devtools @@ -68,7 +74,7 @@ io.jsonwebtoken jjwt-jackson - 0.12.0 + 0.11.5 runtime @@ -124,12 +130,40 @@ - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + org.jacoco + jacoco-maven-plugin + 0.8.11 + + + + + + prepare-agent + + + + + + report + test + + report + + + + + + + + diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties new file mode 100644 index 0000000..f79b07c --- /dev/null +++ b/src/test/resources/application.properties @@ -0,0 +1,6 @@ +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= + +spring.jpa.hibernate.ddl-auto=create-drop \ No newline at end of file From ef2b311d3180b575c5c7b23d2112818c206ae116 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 18 Apr 2026 02:44:30 +0000 Subject: [PATCH 4/9] Upgrade CI workflow: actions v4, Maven caching, JaCoCo reports, artifact upload Agent-Logs-Url: https://github.com/WeiXuChong/LibraryMan-API/sessions/8aa7cee4-8b55-4ec9-b75b-e8fc9bf40baa Co-authored-by: achanhalt <199769577+achanhalt@users.noreply.github.com> --- .github/workflows/build-test-lint-format.yml | 38 ++++++++++---------- pom.xml | 19 ++++++++++ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build-test-lint-format.yml b/.github/workflows/build-test-lint-format.yml index 03f928c..d941091 100644 --- a/.github/workflows/build-test-lint-format.yml +++ b/.github/workflows/build-test-lint-format.yml @@ -13,27 +13,20 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' - -# - name: Cache Maven dependencies -# uses: actions/cache@v3 -# with: -# path: ~/.m2/repository -# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} -# restore-keys: | -# ${{ runner.os }}-maven- + cache: 'maven' - name: Install dependencies - run: mvn clean install -DskipTests + run: chmod +x mvnw && ./mvnw clean install -DskipTests - name: Run Tests - run: mvn test + run: ./mvnw clean test env: ENV: production DATABASE_URL: ${{ secrets.DATABASE_URL }} @@ -49,27 +42,36 @@ jobs: MAIL_SERVICE_STARTTLS: ${{ secrets.MAIL_SERVICE_STARTTLS }} MAIL_SERVICE_DOMAIN_NAME: ${{ secrets.MAIL_SERVICE_DOMAIN_NAME }} + - name: Upload test reports + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-reports + path: | + target/surefire-reports/ + target/site/jacoco/ + # lint-and-format: # runs-on: ubuntu-latest # needs: build-and-test # steps: # - name: Checkout code -# uses: actions/checkout@v3 +# uses: actions/checkout@v4 # # - name: Set up JDK 17 -# uses: actions/setup-java@v3 +# uses: actions/setup-java@v4 # with: # java-version: '17' # distribution: 'temurin' # # - name: Run Checkstyle -# run: mvn checkstyle:check +# run: ./mvnw checkstyle:check # # - name: Run PMD -# run: mvn pmd:check +# run: ./mvnw pmd:check # # - name: Run SpotBugs -# run: mvn spotbugs:check +# run: ./mvnw spotbugs:check # - name: Verify code formatting with Spotless (excluding Javadocs) -# run: mvn spotless:check -Dspotless.apply.skip +# run: ./mvnw spotless:check -Dspotless.apply.skip diff --git a/pom.xml b/pom.xml index a48b762..3998097 100644 --- a/pom.xml +++ b/pom.xml @@ -129,6 +129,25 @@ org.springframework.boot spring-boot-maven-plugin + + org.jacoco + jacoco-maven-plugin + 0.8.12 + + + + prepare-agent + + + + report + test + + report + + + + From 9ca722d81457d28cd9847910a5a2f82f18b62409 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 18 Apr 2026 02:45:08 +0000 Subject: [PATCH 5/9] Remove redundant clean goal from test step to avoid unnecessary rebuild Agent-Logs-Url: https://github.com/WeiXuChong/LibraryMan-API/sessions/8aa7cee4-8b55-4ec9-b75b-e8fc9bf40baa Co-authored-by: achanhalt <199769577+achanhalt@users.noreply.github.com> --- .github/workflows/build-test-lint-format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test-lint-format.yml b/.github/workflows/build-test-lint-format.yml index d941091..882d670 100644 --- a/.github/workflows/build-test-lint-format.yml +++ b/.github/workflows/build-test-lint-format.yml @@ -26,7 +26,7 @@ jobs: run: chmod +x mvnw && ./mvnw clean install -DskipTests - name: Run Tests - run: ./mvnw clean test + run: ./mvnw test env: ENV: production DATABASE_URL: ${{ secrets.DATABASE_URL }} From 356c15bb8952701d111a3436475f9983789018c1 Mon Sep 17 00:00:00 2001 From: Chin Chia Poh Date: Sat, 18 Apr 2026 10:49:15 +0800 Subject: [PATCH 6/9] Update PR #2 description to include 'Fixes #1' --- pulls/2/description | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 pulls/2/description diff --git a/pulls/2/description b/pulls/2/description new file mode 100644 index 0000000..d761cf5 --- /dev/null +++ b/pulls/2/description @@ -0,0 +1,14 @@ +Fixes #1 + +Modernize the CI pipeline to produce accessible test and coverage reports as downloadable artifacts. + +### Workflow (`build-test-lint-format.yml`) +- Upgrade `actions/checkout`, `actions/setup-java`, to **v4** +- Replace commented-out `actions/cache@v3` with `setup-java`'s built-in `cache: 'maven'` +- Switch from `mvn` to `./mvnw` for reproducible builds via the Maven wrapper +- Add `actions/upload-artifact@v4` (`if: always()`) to archive Surefire + JaCoCo reports + +### Build (`pom.xml`) +- Add `jacoco-maven-plugin` 0.8.12 with `prepare-agent` and `report` goals bound to the `test` phase + +After this, every push/PR run will produce a downloadable `test-reports` artifact containing `target/surefire-reports/` and `target/site/jacoco/. \ No newline at end of file From 5172a973504d3a2bb5e0fa40efe908542c0caa82 Mon Sep 17 00:00:00 2001 From: Chin Chia Poh Date: Sat, 18 Apr 2026 11:03:40 +0800 Subject: [PATCH 7/9] Create main.yml --- .github/workloads/main.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/workloads/main.yml diff --git a/.github/workloads/main.yml b/.github/workloads/main.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.github/workloads/main.yml @@ -0,0 +1 @@ + From ae2cfa1f70b8f36f3969435d424babcbfe0ecb05 Mon Sep 17 00:00:00 2001 From: Chin Chia Poh Date: Sat, 18 Apr 2026 11:04:26 +0800 Subject: [PATCH 8/9] Add CI pipeline configuration for LibraryMan-API This CI pipeline triggers on pushes and pull requests to specified branches, sets up JDK 17, builds the project, runs tests, generates a coverage report, and archives the reports. --- .github/workloads/main.yml | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/.github/workloads/main.yml b/.github/workloads/main.yml index 8b13789..ff0a4ed 100644 --- a/.github/workloads/main.yml +++ b/.github/workloads/main.yml @@ -1 +1,46 @@ +name: LibraryMan-API CI Pipeline +# 1. Automated Triggers: Triggers on every push or PR to key branches +on: + push: + branches: [ "main", "Build", "Test", "Deploy", "CI" ] + pull_request: + branches: [ "main" ] + +jobs: + pipeline: + runs-on: ubuntu-latest + + steps: + # 2. Setup Phase + - name: Checkout Repository Code + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + # 3. Automation Phase + - name: Make Maven Wrapper Executable + run: chmod +x mvnw + + - name: Build and Execute 111 Unit Tests + # This automates the build and test process within the pipeline + run: ./mvnw clean test + + - name: Generate JaCoCo Coverage Report + # This generates the report for the "Accessible Reports" requirement + run: ./mvnw jacoco:report + + # 4. Reporting Phase (Deliverables) + - name: Archive Test & Coverage Reports + if: always() # Ensures reports are uploaded even if tests fail + uses: actions/upload-artifact@v4 + with: + name: assignment-reports + path: | + target/surefire-reports/ + target/site/jacoco/ From b0ce0760290fccb9a28671c70eb19c1c69ddbd91 Mon Sep 17 00:00:00 2001 From: yanzhi Date: Fri, 17 Apr 2026 18:58:10 +0800 Subject: [PATCH 9/9] Test running --- pom.xml | 25 ++++++----------------- src/test/resources/application.properties | 6 ++++++ 2 files changed, 12 insertions(+), 19 deletions(-) create mode 100644 src/test/resources/application.properties diff --git a/pom.xml b/pom.xml index 3998097..26795d8 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,12 @@ spring-boot-starter-web + + com.h2database + h2 + test + + org.springframework.boot spring-boot-devtools @@ -129,25 +135,6 @@ org.springframework.boot spring-boot-maven-plugin - - org.jacoco - jacoco-maven-plugin - 0.8.12 - - - - prepare-agent - - - - report - test - - report - - - - diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties new file mode 100644 index 0000000..f79b07c --- /dev/null +++ b/src/test/resources/application.properties @@ -0,0 +1,6 @@ +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= + +spring.jpa.hibernate.ddl-auto=create-drop \ No newline at end of file