Skip to content

4 create taskentity#10

Merged
AnnaZiafar merged 19 commits intomainfrom
4-create-taskentity
Mar 30, 2026
Merged

4 create taskentity#10
AnnaZiafar merged 19 commits intomainfrom
4-create-taskentity

Conversation

@eraiicphu
Copy link
Copy Markdown
Contributor

@eraiicphu eraiicphu commented Mar 30, 2026

Summary by CodeRabbit

  • New Features
    • Task management with explicit statuses (Created, Assigned, In Progress, Review, Done, Overdue), titles, descriptions and deadlines.
    • Persistent storage and retrieval for tasks and users via repository interfaces.
    • User profiles with name, email, role (adds VISITOR) and persisted password; ability to fetch user details by ID with automatic DTO mapping.
  • Chores
    • Removed legacy employee entity.

@eraiicphu eraiicphu linked an issue Mar 30, 2026 that may be closed by this pull request
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds JPA entities and repos for tasks and users, a TaskStatus enum, ModelMapper dependency and bean, a UserService method for fetching users, extends Role enum with VISITOR, and removes EmployeeEntity.

Changes

Cohort / File(s) Summary
Task domain
src/main/java/demo/codeexample/enums/TaskStatus.java, src/main/java/demo/codeexample/task/TaskEntity.java, src/main/java/demo/codeexample/task/TaskRepository.java
Added TaskStatus enum; introduced JPA TaskEntity with ID, title, description, @Enumerated(EnumType.STRING) status, deadline, Lombok annotations, @ManyToOne user relation, constructor, Hibernate-aware equals/hashCode; added TaskRepository extends JpaRepository<TaskEntity, Long). Review: mapping annotations, enum persistence, relations, equals/hashCode.
User domain
src/main/java/demo/codeexample/user/UserEntity.java, src/main/java/demo/codeexample/user/UserDTO.java, src/main/java/demo/codeexample/user/UserRepository.java, src/main/java/demo/codeexample/user/UserService.java
Added UserEntity mapped to users (id, fullName, email unique, role as STRING, password), Lombok + constructor + equals/hashCode; added UserDTO (Lombok); UserRepository with findByEmail and findAllByRoleIgnoreCase; UserService with getUserById(Long) using ModelMapper. Review: repository queries, unique constraint, service error handling, mapping correctness.
Config & build
pom.xml, src/main/java/demo/codeexample/config/MapperConfig.java
Added ModelMapper dependency and a Spring @Configuration providing a ModelMapper bean. Review: dependency version and bean exposure.
Enums & removed file
src/main/java/demo/codeexample/enums/Role.java, src/main/java/demo/codeexample/employee/EmployeeEntity.java
Appended VISITOR to Role enum; removed EmployeeEntity file. Review: references to removed class and enum consumers needing updates.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Service as UserService
    participant Repo as UserRepository
    participant DB as Database
    participant Mapper as ModelMapper

    rect rgba(200,200,255,0.5)
    Client->>Service: getUserById(id)
    end
    Service->>Repo: findById(id)
    Repo->>DB: SELECT users WHERE id=?
    DB-->>Repo: row
    Repo-->>Service: Optional<UserEntity>
    alt found
      Service->>Mapper: map(UserEntity -> UserDTO)
      Mapper-->>Service: UserDTO
      Service-->>Client: UserDTO
    else not found
      Service-->>Client: throws RuntimeException("User not found")
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • AnnaZiafar

Poem

🐇 I hopped through code with nimble paws,

New statuses, users, mapping laws,
Entities planted in rows so neat,
Repos fetch carrots — what a treat!
A joyful rabbit celebrates this commit 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes creating TaskEntity, but the PR introduces significantly broader changes including TaskStatus enum, UserEntity, UserDTO, repositories, services, and MapperConfig. Revise title to reflect the full scope, e.g., 'Add user and task entities with supporting infrastructure' or 'Implement task management domain models and configuration'.
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 4-create-taskentity

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.

Copy link
Copy Markdown

@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: 3

🧹 Nitpick comments (1)
src/main/java/demo/codeexample/task/TaskEntity.java (1)

5-5: ProjectEntity is imported but unused; inconsistent relationship pattern.

ProjectEntity is imported on line 5 but never used. ProjectId is stored as a plain Long while Employee uses a proper @ManyToOne relationship. Consider either:

  • Using @ManyToOne for Project as well for consistency and referential integrity, or
  • Removing the unused import if the loose-coupling approach is intentional.

Also applies to: 31-31

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/demo/codeexample/task/TaskEntity.java` at line 5, TaskEntity
currently imports ProjectEntity but stores projectId as a plain Long while
employee uses a `@ManyToOne` relationship; either remove the unused import or
convert to a proper association. If you want referential integrity and
consistency with the employee mapping, replace the Long projectId field in
TaskEntity with a ProjectEntity-typed field annotated `@ManyToOne` (and update
getters/setters and any constructors/usages), otherwise remove the unused import
of ProjectEntity and keep the loose-coupling approach.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/demo/codeexample/task/TaskEntity.java`:
- Line 27: The TaskEntity field "Status" is currently persisted as an ordinal
which can corrupt data if enum order changes; update the TaskEntity class to
annotate the Status field with `@Enumerated`(EnumType.STRING) (and add the
necessary javax.persistence or jakarta.persistence imports) so the enum is
stored by name, not ordinal, ensuring stable DB values for TaskStatus.
- Around line 33-35: The TaskEntity's `@ManyToOne` field references EmployeeEntity
which is currently not a JPA entity; either implement EmployeeEntity as a proper
JPA entity or remove the relationship until ready. Fix by creating or updating
the EmployeeEntity class to include `@Entity`, a primary key field annotated with
`@Id` (and `@GeneratedValue` if applicable), any required fields, and
getters/setters (and optional `@Table` or relationship mappings), and ensure
TaskEntity's field private EmployeeEntity Employee remains consistent with the
implemented entity; alternatively remove the `@ManyToOne/`@JoinColumn on
TaskEntity (or comment it out) until EmployeeEntity is fully implemented.
- Around line 17-35: Rename all PascalCase instance fields in TaskEntity to
camelCase (TaskId -> taskId, Title -> title, Description -> description, Status
-> status, Deadline -> deadline, ProjectId -> projectId, Employee -> employee)
and update any getters, setters, constructors, equals/hashCode/toString, and
usages accordingly (e.g., methods referencing getTaskId, setTaskId, getEmployee,
etc.). Keep JPA annotations (`@Id`, `@GeneratedValue`, `@Column`(name = "Task_id"),
`@JoinColumn`(name = "Employee_id")) as needed but ensure `@Column` names remain
mapped to the existing DB columns while the field names change; if any JSON or
serialization annotations exist, update them to match the new field names or add
`@JsonProperty` to preserve external contracts. Run a project-wide search/replace
for the old field names and run tests/compile to catch remaining references.

---

Nitpick comments:
In `@src/main/java/demo/codeexample/task/TaskEntity.java`:
- Line 5: TaskEntity currently imports ProjectEntity but stores projectId as a
plain Long while employee uses a `@ManyToOne` relationship; either remove the
unused import or convert to a proper association. If you want referential
integrity and consistency with the employee mapping, replace the Long projectId
field in TaskEntity with a ProjectEntity-typed field annotated `@ManyToOne` (and
update getters/setters and any constructors/usages), otherwise remove the unused
import of ProjectEntity and keep the loose-coupling approach.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dfccdcac-e83c-4cb2-9044-a22973a839be

📥 Commits

Reviewing files that changed from the base of the PR and between ef58115 and 94d6fc8.

📒 Files selected for processing (3)
  • src/main/java/demo/codeexample/enums/TaskStatus.java
  • src/main/java/demo/codeexample/task/TaskEntity.java
  • src/main/java/demo/codeexample/task/TaskRepository.java

Copy link
Copy Markdown

@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: 2

🧹 Nitpick comments (3)
src/main/java/demo/codeexample/user/UserService.java (2)

17-18: Use a specific exception instead of generic RuntimeException.

Throwing a generic RuntimeException makes it difficult for callers to handle this error case appropriately. Consider using a domain-specific exception or a standard Spring exception like EntityNotFoundException.

♻️ Proposed fix using a custom exception
+import jakarta.persistence.EntityNotFoundException;
+
 // ...
 
     public UserDTO getUserById(Long id) {
         UserEntity userEntity = userRepository.findById(id)
-                .orElseThrow(() -> new RuntimeException("User not found"));
+                .orElseThrow(() -> new EntityNotFoundException("User not found with id: " + id));
 
         return modelMapper.map(userEntity, UserDTO.class);
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/demo/codeexample/user/UserService.java` around lines 17 - 18,
Replace the generic RuntimeException thrown in the userRepository.findById(...)
call with a specific exception so callers can handle "user not found" cases;
create and throw a domain-specific UserNotFoundException (or use
javax.persistence.EntityNotFoundException) instead of RuntimeException in
UserService where UserEntity is retrieved, and update any controllers/services
that catch this to handle the new exception type appropriately.

5-5: Remove unused import.

PasswordEncoder is imported but not used in this class.

🧹 Proposed fix
 import lombok.RequiredArgsConstructor;
 import org.modelmapper.ModelMapper;
-import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/demo/codeexample/user/UserService.java` at line 5, The import
of PasswordEncoder in UserService is unused; remove the line importing
org.springframework.security.crypto.password.PasswordEncoder from
UserService.java so the class no longer has an unnecessary unused import (no
other code changes required).
src/main/java/demo/codeexample/task/TaskEntity.java (1)

36-36: Add private access modifier to the project field.

The project field lacks an explicit access modifier, making it package-private. For consistency with other fields and encapsulation, it should be private.

🔧 Proposed fix
     `@ManyToOne`
     `@JoinColumn` (name = "projectId")
-    ProjectEntity project;
+    private ProjectEntity project;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/demo/codeexample/task/TaskEntity.java` at line 36, The field
"project" in TaskEntity is package-private and should be made private for
encapsulation; update the declaration of the project field in the TaskEntity
class (symbol: ProjectEntity project) to include the private modifier so it
matches the other fields and access patterns, then rebuild and run tests to
ensure any direct package access sites (if any) are updated to use existing
getters/setters on TaskEntity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/demo/codeexample/task/TaskEntity.java`:
- Around line 34-36: TaskEntity defines a `@ManyToOne` relationship to
ProjectEntity but ProjectEntity is not a valid JPA entity; implement
ProjectEntity as a JPA entity by annotating the class with `@Entity`, adding a
primary key field annotated with `@Id` (and `@GeneratedValue` if appropriate), and
include any needed getters/setters and basic fields, or remove the ProjectEntity
reference from TaskEntity (the `@ManyToOne` and `@JoinColumn`(name = "projectId") on
field project) until ProjectEntity is implemented so the JPA mapping can
initialize correctly.

In `@src/main/java/demo/codeexample/user/UserRepository.java`:
- Line 16: The repository method findAllByRoleIgnoreCase uses the IgnoreCase
suffix with an enum parameter (Role), which is invalid; replace it with a plain
enum-based finder by renaming the method to findAllByRole(Role role) in
UserRepository (returning List<UserEntity>), remove the IgnoreCase suffix, and
update any callers to pass the Role enum instead of strings so queries use the
enum mapping properly.

---

Nitpick comments:
In `@src/main/java/demo/codeexample/task/TaskEntity.java`:
- Line 36: The field "project" in TaskEntity is package-private and should be
made private for encapsulation; update the declaration of the project field in
the TaskEntity class (symbol: ProjectEntity project) to include the private
modifier so it matches the other fields and access patterns, then rebuild and
run tests to ensure any direct package access sites (if any) are updated to use
existing getters/setters on TaskEntity.

In `@src/main/java/demo/codeexample/user/UserService.java`:
- Around line 17-18: Replace the generic RuntimeException thrown in the
userRepository.findById(...) call with a specific exception so callers can
handle "user not found" cases; create and throw a domain-specific
UserNotFoundException (or use javax.persistence.EntityNotFoundException) instead
of RuntimeException in UserService where UserEntity is retrieved, and update any
controllers/services that catch this to handle the new exception type
appropriately.
- Line 5: The import of PasswordEncoder in UserService is unused; remove the
line importing org.springframework.security.crypto.password.PasswordEncoder from
UserService.java so the class no longer has an unnecessary unused import (no
other code changes required).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 28e311d0-dda5-4a9a-ace5-221e66bd33d8

📥 Commits

Reviewing files that changed from the base of the PR and between b11f479 and 808bc82.

📒 Files selected for processing (9)
  • pom.xml
  • src/main/java/demo/codeexample/config/MapperConfig.java
  • src/main/java/demo/codeexample/employee/EmployeeEntity.java
  • src/main/java/demo/codeexample/enums/Role.java
  • src/main/java/demo/codeexample/task/TaskEntity.java
  • src/main/java/demo/codeexample/user/UserDTO.java
  • src/main/java/demo/codeexample/user/UserEntity.java
  • src/main/java/demo/codeexample/user/UserRepository.java
  • src/main/java/demo/codeexample/user/UserService.java
💤 Files with no reviewable changes (1)
  • src/main/java/demo/codeexample/employee/EmployeeEntity.java
✅ Files skipped from review due to trivial changes (4)
  • pom.xml
  • src/main/java/demo/codeexample/config/MapperConfig.java
  • src/main/java/demo/codeexample/user/UserDTO.java
  • src/main/java/demo/codeexample/enums/Role.java

@AnnaZiafar AnnaZiafar merged commit 304e7d7 into main Mar 30, 2026
1 check was pending
This was referenced Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create TaskEntity

3 participants