Skip to content

Conversation

LeZhen1105
Copy link
Contributor

@LeZhen1105 LeZhen1105 commented Oct 12, 2025

Checklist

General

Server

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • I strictly followed the client coding and design guidelines.

Description

Added new DTOs:
CreateFaqDTO for creating FAQs.
UpdateFaqDTO for updating existing FAQs.
Refactored FaqResource:
POST /api/communication/courses/{courseId}/faqs → consumes CreateFaqDTO, returns FaqDTO.
PUT /api/communication/courses/{courseId}/faqs/{faqId} → consumes UpdateFaqDTO, returns FaqDTO.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 2 Students
  • 1 Programming Exercise with Complaints enabled
  1. Log in to Artemis
  2. Navigate to Course Administration
  3. ...

Testserver States

You can manage test servers using Helios. Check environment statuses in the environment list. To deploy to a test server, go to the CI/CD page, find your PR or branch, and trigger the deployment.

Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

  • Refactor
    • Switched FAQ create/update to use dedicated DTOs across backend and frontend for consistent request payloads.
  • Bug Fixes
    • Strengthened validation (IDs/course matching, required state/title), trim titles, omit empty optional fields, and standardized category formatting to prevent malformed submissions.
  • Tests
    • Updated unit and integration tests to exercise DTO-based flows, conversions, and related edge cases.

@github-project-automation github-project-automation bot moved this to Work In Progress in Artemis Development Oct 12, 2025
@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) client Pull requests that update TypeScript code. (Added Automatically!) communication Pull requests that affect the corresponding module labels Oct 12, 2025
@LeZhen1105 LeZhen1105 marked this pull request as ready for review October 12, 2025 10:17
@LeZhen1105 LeZhen1105 requested a review from a team as a code owner October 12, 2025 10:17
Copy link
Contributor

coderabbitai bot commented Oct 12, 2025

Walkthrough

Adds CreateFaqDTO and UpdateFaqDTO on backend and frontend; updates REST create/update endpoints to accept DTOs and validate path-vs-body IDs/courseIds; frontend builds/transforms DTOs before service calls; tests updated to use DTO payloads and assertions. DTOs include mapping helpers and category stringification.

Changes

Cohort / File(s) Summary of changes
Backend DTOs
src/main/java/.../communication/dto/CreateFaqDTO.java, src/main/java/.../communication/dto/UpdateFaqDTO.java
Added record DTOs with validation and @JsonInclude; each exposes toEntity() to map to a Faq entity.
Backend Resource
src/main/java/.../communication/web/FaqResource.java
create/update endpoints now accept @Valid DTOs (CreateFaqDTO / UpdateFaqDTO); added path vs body id/courseId checks; DTO→entity mapping and course association before persist.
Frontend Models (DTOs)
src/main/webapp/app/communication/shared/entities/faq.model.ts
Added exported CreateFaqDTO and UpdateFaqDTO classes with constructors and static toCreateFaqDto / toUpdateDto mappers; include basic validation and trimming.
Frontend Service
src/main/webapp/app/communication/faq/faq.service.ts
create / update signatures now accept DTOs; added convertCreateFaqFromClient and convertUpdateFaqFromClient; stringifyFaqCategories updated to accept DTOs; update URL uses DTO id.
Frontend Components
src/main/webapp/app/communication/faq/faq-update.component.ts, src/main/webapp/app/communication/faq/faq.component.ts
Save/update flows now transform FaqCreateFaqDTO / UpdateFaqDTO before calling service; imports adjusted.
Frontend Service Tests
src/main/webapp/app/communication/faq/faq.service.spec.ts
Tests updated to construct and use DTOs for create/update; added DTO conversion and category stringification tests; updated defaults and expectations.
Frontend Component Tests
src/main/webapp/app/communication/faq/faq.component.spec.ts
Assertions updated to expect objectContaining DTO-like payloads instead of exact entity objects.
Backend Tests
src/test/java/.../communication/FaqIntegrationTest.java, src/test/java/.../iris/PyrisFaqIngestionTest.java
Tests migrated to send/receive DTOs (CreateFaqDTO / UpdateFaqDTO / FaqDTO); assertions and imports adapted; ID accessors updated to record style.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as Frontend (Components)
  participant FS as FaqService (FE)
  participant API as FaqResource (BE)
  participant Repo as Repository

  rect rgb(235,245,255)
  note over UI,FS: Create FAQ (DTO-based)
  User->>UI: Submit new FAQ
  UI->>FS: CreateFaqDTO.toCreateFaqDto(faq)
  FS->>FS: convertCreateFaqFromClient(dto)\nstringify categories
  FS->>API: POST /courses/{courseId}/faqs\nBody: CreateFaqDTO
  API->>API: validate path vs dto.courseId\nmap dto to Faq, load Course
  API->>Repo: persist Faq
  Repo-->>API: saved Faq
  API-->>FS: 201 Created (FaqDTO)
  FS-->>UI: return FaqDTO
  end

  rect rgb(245,235,245)
  note over UI,FS: Update FAQ (DTO-based)
  User->>UI: Update existing FAQ
  UI->>FS: UpdateFaqDTO.toUpdateDto(faq)
  FS->>FS: convertUpdateFaqFromClient(dto)\nstringify categories
  FS->>API: PUT /courses/{courseId}/faqs/{faqId}\nBody: UpdateFaqDTO
  API->>API: validate path vs dto.id and dto.courseId\nmap dto to Faq, load Course
  API->>Repo: update Faq
  Repo-->>API: updated Faq
  API-->>FS: 200 OK (FaqDTO)
  FS-->>UI: return FaqDTO
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly summarizes the primary change of migrating the FAQ service to use DTOs and directly reflects the scope of the changeset without including unnecessary details. It remains concise and specific, making it easy for reviewers to understand the main purpose at a glance.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/communication/faq-endpoints-dto

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

@github-project-automation github-project-automation bot moved this from Work In Progress to Ready For Review in Artemis Development Oct 12, 2025
Copy link
Contributor

coderabbitai bot commented Oct 12, 2025

Walkthrough

Introduces CreateFaqDTO and UpdateFaqDTO on backend and frontend. Refactors REST endpoints and Angular service/components to use DTOs for create/update. Adds conversion helpers and validation. Updates tests accordingly. Removes prior Faq-based client/server payload handling and related helpers. Response bodies standardized to FaqDTO in integration tests.

Changes

Cohort / File(s) Summary of Changes
Backend DTO introduction
src/main/java/de/tum/cit/aet/artemis/communication/dto/CreateFaqDTO.java, src/main/java/de/tum/cit/aet/artemis/communication/dto/UpdateFaqDTO.java
Added new record DTOs with validation and JsonInclude. Provided toEntity() builders for Faq, including id (update) and fields (state, categories, title, answer).
Backend REST adjustments
src/main/java/de/tum/cit/aet/artemis/communication/web/FaqResource.java
Endpoints now accept @Valid CreateFaqDTO/UpdateFaqDTO; ensure path/body ID alignment; convert DTOs to entities; look up Course; persist; updated imports and method signatures.
Frontend model and DTOs
src/main/webapp/app/communication/shared/entities/faq.model.ts
Added CreateFaqDTO and UpdateFaqDTO classes; UpdateFaqDTO.toUpdateDto(Faq) helper to construct DTO from entity.
Frontend service refactor
src/main/webapp/app/communication/faq/faq.service.ts
Changed public API: create/update now take DTOs. Added DTO-based converters and category stringification helpers; removed Faq-based helpers; updated imports and URL construction using DTO id.
Frontend components updates
src/main/webapp/app/communication/faq/faq.component.ts, src/main/webapp/app/communication/faq/faq-update.component.ts
Switched to pass UpdateFaqDTO (via toUpdateDto) for updates and creates. Error handling and state restoration preserved.
Frontend tests updates
src/main/webapp/app/communication/faq/faq.service.spec.ts, src/main/webapp/app/communication/faq/faq.component.spec.ts
Service tests use Create/Update DTOs and new defaults; removed stringifyFaqCategories test. Component specs adjusted to use stored spies for update assertions.
Backend integration tests
src/test/java/de/tum/cit/aet/artemis/communication/FaqIntegrationTest.java
Tests now send DTOs and expect FaqDTO responses; updated assertions, status expectations, and forbidden checks; removed entity-centric assumptions.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as Angular Component
  participant Svc as FaqService (client)
  participant API as FaqResource (server)
  participant Repo as Persistence

  rect rgba(230,245,255,0.6)
  note over UI,Svc: Create FAQ (DTO-based)
  User->>UI: Submit create form
  UI->>Svc: create(courseId, CreateFaqDTO)
  Svc->>Svc: convertCreateFaqFromClient<br/>(stringify categories)
  Svc->>API: POST /api/courses/{courseId}/faqs<br/>body: CreateFaqDTO
  API->>API: validate @Valid DTO<br/>toEntity()
  API->>Repo: save(Faq)
  Repo-->>API: Faq saved
  API-->>Svc: 201 Created + FaqDTO
  Svc-->>UI: FaqDTO
  end

  rect rgba(240,255,230,0.6)
  note over UI,Svc: Update FAQ (DTO-based)
  User->>UI: Change state/title/answer
  UI->>UI: UpdateFaqDTO.toUpdateDto(Faq)
  UI->>Svc: update(courseId, UpdateFaqDTO)
  Svc->>Svc: convertUpdateFaqFromClient<br/>(stringify categories)
  Svc->>API: PUT /api/courses/{courseId}/faqs/{id}<br/>body: UpdateFaqDTO
  API->>API: validate @Valid, check path/id match<br/>toEntity()
  API->>Repo: save(Faq)
  Repo-->>API: Faq updated
  API-->>Svc: 200 OK + FaqDTO
  Svc-->>UI: FaqDTO
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary change—migrating the FAQ service to use DTOs—so it accurately reflects the main focus of the pull request without including unnecessary details.
✨ Finishing touches
  • 📝 Docstrings were successfully generated.
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/communication/faq-endpoints-dto

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PMD (7.17.0)
src/main/java/de/tum/cit/aet/artemis/communication/dto/UpdateFaqDTO.java

[0.001s][warning][perf,memops] Cannot use file /tmp/hsperfdata_jailuser/1 because it is locked by another process (errno = 11)
[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitc

... [truncated 11539 characters] ...

prone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

src/test/java/de/tum/cit/aet/artemis/communication/FaqIntegrationTest.java

[0.001s][warning][perf,memops] Cannot use file /tmp/hsperfdata_jailuser/1 because it is locked by another process (errno = 11)
[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitc

... [truncated 11539 characters] ...

prone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

src/main/java/de/tum/cit/aet/artemis/communication/dto/CreateFaqDTO.java

[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitch instead of the deprecated Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt. PMD 8.0.0 will remove su

... [truncated 11412 characters] ...

prone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

  • 1 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 12, 2025
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 12, 2025

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 12, 2025

This comment was marked as outdated.

@github-actions github-actions bot added the iris Pull requests that affect the corresponding module label Oct 12, 2025
coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 12, 2025
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed1s 605ms
TestResultTime ⏱
No test annotations available

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 12, 2025

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as resolved.

Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed1s 428ms
TestResultTime ⏱
No test annotations available

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 13, 2025
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 13, 2025
coderabbitai[bot]

This comment was marked as resolved.

Copy link
Contributor

coderabbitai bot commented Oct 13, 2025

✅ Actions performed

Initiated docstring generation; will generate only if new commits exist.

@ls1intum ls1intum deleted a comment from coderabbitai bot Oct 13, 2025
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report205 ran200 passed3 skipped2 failed1h 15m 16s 34ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/exam/test-exam/TestExamParticipation.spec.ts
ts.Test exam participation › Early Hand-in › Using exercise sidebar to navigate within exam❌ failure4m 36s 272ms
e2e/exercise/programming/ProgrammingExerciseStaticCodeAnalysis.spec.ts
ts.Static code analysis tests › Configures SCA grading and makes a successful submission with SCA errors❌ failure2m 35s 561ms

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f4e149 and dd73ffc.

📒 Files selected for processing (2)
  • src/main/webapp/app/communication/faq/faq.component.spec.ts (3 hunks)
  • src/main/webapp/app/communication/faq/faq.service.spec.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/webapp/app/communication/faq/faq.component.spec.ts
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/**/*.ts

⚙️ CodeRabbit configuration file

angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

Files:

  • src/main/webapp/app/communication/faq/faq.service.spec.ts
🧬 Code graph analysis (1)
src/main/webapp/app/communication/faq/faq.service.spec.ts (1)
src/main/webapp/app/communication/shared/entities/faq.model.ts (3)
  • CreateFaqDTO (20-36)
  • UpdateFaqDTO (38-58)
  • Faq (11-18)
🔇 Additional comments (6)
src/main/webapp/app/communication/faq/faq.service.spec.ts (6)

10-10: LGTM!

The imports and variable declarations are correct and follow the naming conventions.

Also applies to: 21-22


38-38: LGTM!

The initialization of default test data and DTOs using static helper methods is correct.

Also applies to: 41-42


54-54: LGTM!

The service method calls correctly use the new DTO parameters, aligning with the DTO migration.

Also applies to: 70-70


238-242: LGTM!

The test correctly verifies conversion of stringified categories from the server into FaqCategory objects.


274-303: LGTM!

These tests effectively verify immutability during DTO conversion and handle the edge case of undefined categories.


305-323: LGTM!

The error handling tests comprehensively verify that the DTO conversion methods throw appropriate errors when required fields are missing.

expect(() => CreateFaqDTO.toCreateFaqDto(f)).toThrow('The state should be present to create FAQ');
});

it('should throw if id is missing when converting to upDateFaqDto', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typo in test names.

The test names contain a typo: "upDateFaqDto" should be "UpdateFaqDTO" for consistency.

Apply this diff to fix the typo:

-    it('should throw if id is missing when converting to upDateFaqDto', () => {
+    it('should throw if id is missing when converting to UpdateFaqDTO', () => {
-    it('should throw if faqState is missing when converting to upDateFaqDto', () => {
+    it('should throw if faqState is missing when converting to UpdateFaqDTO', () => {

Also applies to: 318-318

🤖 Prompt for AI Agents
In src/main/webapp/app/communication/faq/faq.service.spec.ts around lines 311
and 318 the test names contain a typo: "upDateFaqDto" should be "UpdateFaqDTO";
update both it(...) descriptions to use the correct casing and spelling
"UpdateFaqDTO" to keep test names consistent and clear.

Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report205 ran199 passed3 skipped3 failed1h 14m 5s 710ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/exam/test-exam/TestExamParticipation.spec.ts
ts.Test exam participation › Early Hand-in › Using exercise sidebar to navigate within exam❌ failure3m 14s 93ms
ts.Test exam participation › Early Hand-in › Using exercise overview to navigate within exam❌ failure3m 34s 898ms
e2e/exercise/programming/ProgrammingExerciseStaticCodeAnalysis.spec.ts
ts.Static code analysis tests › Configures SCA grading and makes a successful submission with SCA errors❌ failure2m 39s 504ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client Pull requests that update TypeScript code. (Added Automatically!) communication Pull requests that affect the corresponding module iris Pull requests that affect the corresponding module ready for review server Pull requests that update Java code. (Added Automatically!) tests

Projects

Status: Ready For Review

Development

Successfully merging this pull request may close these issues.

1 participant