BLOG-133 Unique label name and semantic ID #135

Merged
squid merged 4 commits from BLOG-133_unique_label_name into main 2025-10-12 21:16:36 +08:00
Owner

Description

  • It returns status 409 CONFLICT if there is already a label with same name or a post with same semantic ID.

Package Changes

No response

Screenshots

No response

Reference

Resolves #133.

Checklist

  • A milestone is set
  • The related issuse has been linked to this branch
### Description - It returns status `409 CONFLICT` if there is already a label with same name or a post with same semantic ID. ### Package Changes _No response_ ### Screenshots _No response_ ### Reference Resolves #133. ### Checklist - [x] A milestone is set - [x] The related issuse has been linked to this branch
squid added this to the 0.4 milestone 2025-10-12 21:11:53 +08:00
squid added 4 commits 2025-10-12 21:11:53 +08:00
feat: update sqlx
All checks were successful
Frontend CI / build (push) Successful in 1m23s
f900c2dc2b
feat: add unique index to label name column
All checks were successful
Frontend CI / build (push) Successful in 1m22s
88aceb3a51
feat: add error handling for duplicated semantic ID and label name
All checks were successful
Frontend CI / build (push) Successful in 1m21s
9f17f45862
feat: add error handling for duplicated semantic ID and label name in database operations
All checks were successful
Frontend CI / build (push) Successful in 1m22s
Auto Comment On PR / add_improve_comment (pull_request) Successful in 17s
PR Title Check / pr-title-check (pull_request) Successful in 17s
78dfca41e6
Collaborator

/improve

/improve
Collaborator

PR Code Suggestions

CategorySuggestion                                                                                                                                    Impact
Possible issue
Return 409 for duplicate semantic ID

The PostError::DuplicatedSemanticId error indicates a client-side conflict, not a
server-side issue. It should return an HttpResponse::Conflict() (409 status code)
instead of HttpResponse::InternalServerError() (500 status code). This provides a
more accurate and actionable response to the client.

backend/feature/post/src/framework/web/create_label_handler.rs [38-43]

-PostError::NotFound
-| PostError::InvalidSemanticId
-| PostError::DuplicatedSemanticId => {
+PostError::DuplicatedSemanticId => HttpResponse::Conflict().finish(),
+PostError::NotFound | PostError::InvalidSemanticId => {
     capture_anyhow(&anyhow!(e));
     HttpResponse::InternalServerError().finish()
 }
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies that PostError::DuplicatedSemanticId should result in an HttpResponse::Conflict() (409) as it's a client-side data conflict, not an internal server error. This improves the API's error reporting accuracy.

High
Return 409 for duplicate label name

The PostError::DuplicatedLabelName error signifies a client-side conflict when
creating a post, not an internal server error. It should return an
HttpResponse::Conflict() (409 status code) to correctly inform the client about the
duplicate resource.

backend/feature/post/src/framework/web/create_post_handler.rs [41-44]

-PostError::NotFound | PostError::DuplicatedLabelName => {
+PostError::DuplicatedLabelName => HttpResponse::Conflict().finish(),
+PostError::NotFound => {
     capture_anyhow(&anyhow!(e));
     HttpResponse::InternalServerError().finish()
 }
Suggestion importance[1-10]: 9

__

Why: Similar to the previous suggestion, PostError::DuplicatedLabelName indicates a client-side conflict, making HttpResponse::Conflict() (409) the appropriate response. This enhances the API's semantic correctness for error handling.

High
## PR Code Suggestions ✨ <!-- --> <table><thead><tr><td><strong>Category</strong></td><td align=left><strong>Suggestion&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong></td><td align=center><strong>Impact</strong></td></tr><tbody><tr><td rowspan=2>Possible issue</td> <td> <details><summary>Return 409 for duplicate semantic ID</summary> ___ **The <code>PostError::DuplicatedSemanticId</code> error indicates a client-side conflict, not a <br>server-side issue. It should return an <code>HttpResponse::Conflict()</code> (409 status code) <br>instead of <code>HttpResponse::InternalServerError()</code> (500 status code). This provides a <br>more accurate and actionable response to the client.** [backend/feature/post/src/framework/web/create_label_handler.rs [38-43]](https://git.squidspirit.com/squid/blog/src/branch/BLOG-133_unique_label_name/backend/feature/post/src/framework/web/create_label_handler.rs#L38-L43) ```diff -PostError::NotFound -| PostError::InvalidSemanticId -| PostError::DuplicatedSemanticId => { +PostError::DuplicatedSemanticId => HttpResponse::Conflict().finish(), +PostError::NotFound | PostError::InvalidSemanticId => { capture_anyhow(&anyhow!(e)); HttpResponse::InternalServerError().finish() } ``` <details><summary>Suggestion importance[1-10]: 9</summary> __ Why: The suggestion correctly identifies that `PostError::DuplicatedSemanticId` should result in an `HttpResponse::Conflict()` (409) as it's a client-side data conflict, not an internal server error. This improves the API's error reporting accuracy. </details></details></td><td align=center>High </td></tr><tr><td> <details><summary>Return 409 for duplicate label name</summary> ___ **The <code>PostError::DuplicatedLabelName</code> error signifies a client-side conflict when <br>creating a post, not an internal server error. It should return an <br><code>HttpResponse::Conflict()</code> (409 status code) to correctly inform the client about the <br>duplicate resource.** [backend/feature/post/src/framework/web/create_post_handler.rs [41-44]](https://git.squidspirit.com/squid/blog/src/branch/BLOG-133_unique_label_name/backend/feature/post/src/framework/web/create_post_handler.rs#L41-L44) ```diff -PostError::NotFound | PostError::DuplicatedLabelName => { +PostError::DuplicatedLabelName => HttpResponse::Conflict().finish(), +PostError::NotFound => { capture_anyhow(&anyhow!(e)); HttpResponse::InternalServerError().finish() } ``` <details><summary>Suggestion importance[1-10]: 9</summary> __ Why: Similar to the previous suggestion, `PostError::DuplicatedLabelName` indicates a client-side conflict, making `HttpResponse::Conflict()` (409) the appropriate response. This enhances the API's semantic correctness for error handling. </details></details></td><td align=center>High </td></tr></tr></tbody></table>
squid merged commit 1ae104cd56 into main 2025-10-12 21:16:36 +08:00
squid deleted branch BLOG-133_unique_label_name 2025-10-12 21:16:36 +08:00
Sign in to join this conversation.
No description provided.