Solidify MVP-critical domain relationships: Issue <=> Comment, PullRequest <=> reviewers (SZ-27)
rk@tigase.net opened 3 weeks ago

Issue: Solidify MVP-critical domain relationships – Issue <=> Comment, PullRequest <=> reviewers

Goal

Finalize the key domain relationships needed to support Issue discussions and Pull Request review workflows in the MVP. These associations are required for REST APIs and UI display logic (e.g., showing comments under an issue, or listing reviewers for a PR).


Acceptance Criteria

Issue <=> Comment

  • Add @OneToMany(mappedBy = "issue", cascade = CascadeType.ALL, orphanRemoval = true) in Issue
  • Add List<Comment> comments in Issue
  • Add @ManyToOne(fetch = FetchType.LAZY) in Comment linking back to Issue
  • Avoid cyclic serialization using @JsonIgnore, @JsonManagedReference, or switch to DTOs for REST

PullRequest <=> reviewers

  • Add @ManyToMany in PullRequest:
    @ManyToMany
    @JoinTable(name = "pull_request_reviewers",
               joinColumns = @JoinColumn(name = "pull_request_id"),
               inverseJoinColumns = @JoinColumn(name = "user_id"))
    private Set<User> reviewers = new HashSet<>();
    
  • No inverse field in User needed yet

Worklog

  • Decided to split this off from the broader domain audit task to allow focused implementation of relationships needed for MVP
  • These associations are crucial to:
    • enable REST endpoints like GET /api/issues/{id}/comments
    • allow PR UI to show assigned reviewers
  • Will test with:
    • inline setup in integration tests
    • cascade + orphanRemoval behavior
    • serialization checks
  • Future enhancements (e.g., comment edit history, reviewer decision status) will build on this foundation
  • rk@tigase.net commented 3 weeks ago

    Tasks & Estimates

    TaskEst. Time
    Implement Issue ↔ Comment relationship with cascade + orphanRem1.0 h
    Implement PullRequest ↔ reviewers relationship with join table0.5 h
    Add serialization annotations or DTO mapping0.5 h
    Write integration test for Issue comment cascade0.5 h
    Write integration test for PullRequest reviewer persistence0.5 h

    Total estimate: 3.0 hours


  • rk@tigase.net changed title 3 weeks ago
    Previous Value Current Value
    Solidify MVP-critical domain relationships: Issue ↔ Comment, PullRequest ↔ reviewers
    Solidify MVP-critical domain relationships: Issue <=> Comment, PullRequest <=> reviewers
  • rk@tigase.net commented 3 weeks ago

    Comment: Entity vs Value Object

    TL;DR

    Comment should be modeled as an Entity, not a Value Object, because:

    • It has a distinct identity (@Id)
    • It can evolve independently over time
    • It may need to support auditing, authorization, or reply chaining in the future

    1. Identity Matters

    Each comment should be distinguishable from others, even if the content and author are the same:

    Comment A: "Looks good" — by Alice on 2025-10-01
    Comment B: "Looks good" — by Alice on 2025-10-02
    

    Without an ID, they would be indistinguishable. This violates domain semantics and auditability.


    2. Mutable Lifecycle

    A Comment might be:

    • Edited
    • Flagged
    • Deleted (soft-deleted for moderation)
    • Used in search queries (e.g., "all comments by X")

    Such behaviors require persistent identity and lifecycle management — classic signs of an Entity.


    3. Futureproofing: Threads, Reactions, Permissions

    Even if Comment seems simple now, making it a Value Object locks you out of future enhancements like:

    • Reply-to threading (parentCommentId)
    • Emoji reactions
    • Role-based visibility (e.g., internal vs public comments)
    • Fine-grained update tracking (edited timestamp, versioning)

    Modeling it as an entity allows us to evolve the design without data model breakage.


    4. Value Object Semantics Don’t Fit

    A Value Object is:

    • Immutable
    • Interchangeable based on value equality (e.g., new Money(100, "USD"))
    • Owned by its parent entity, not shared across entities

    But Comment:

    • Is not interchangeable (identity matters)
    • May be edited (mutable)
    • Is often queried directly

    5. JPA Constraint: Entities Must Have @Id

    If you annotate a class with @Entity, JPA requires a primary key. This aligns with the semantic idea that an entity must have identity — not just structure.


    Conclusion

    Even if we use KISS and MVP principles, making Comment an entity provides the right foundation for extensibility, traceability, and domain integrity.

issue 1 of 1
Type
Improvement
Priority
Major
Assignee
Version
1.0
Sprints
n/a
Customer
n/a
Issue Votes (0)
Watchers (3)
Reference
SZ-27
Please wait...
Page is in error, reload to recover