Skip to content

Update Code

Method

REST method is adopted.

HTTP Method

PUT: Update code information

Naming Convention

To unify the naming of query parameters and nodes and improve readability, snake_case is used for URIs and JSON nodes in requests.

Request and Response

Headers

Meta information is set in HTTP headers, not in the response body.

Request Headers

  • Authorization
  • Content-Type: multipart/form-data
  • Accept
  • Accept-language

Response Headers

  • Content-Type

Update Code Information

URI

PUT /v1/organizations/{organization_id}/projects/{project_id}/code/{code_id}

Path Parameters

Name Type Required Description
organization_id number Required Backend PostgreSQL organization ID
project_id number Required Backend PostgreSQL project ID
code_id string Required Code UUID

Request Body

The request body is multipart/form-data (all fields are optional).

Form Fields

Name Type Required Description
name string Optional Code name (1-255 characters)
source_code string Optional Code source code
css_code string Optional Code CSS code
status number Optional Processing status (0-3)
file File Optional Preview image (PNG/JPG/JPEG/GIF, max 5MB)

Response

The response is JSON.

{
  "id": "0192a3b4-c5d6-4e8f-9a0b-1c2d3e4f5a6b",
  "projectId": 42,
  "name": "Updated Button",
  "s3Key": "code/0192a3b4-c5d6-4e8f-9a0b-1c2d3e4f5a6b.png",
  "sourceCode": "const UpdatedButton = () => { ... }",
  "cssCode": ".updated-button { ... }",
  "status": 2,
  "createdAt": 1234567890000,
  "updatedAt": 1234567899999,
  "deletedAt": null,
  "createdBy": "user-id",
  "updatedBy": "updater-id",
  "deletedBy": null
}

Authentication

Authentication is performed using JSON Web Tokens (JWT) issued by Amazon Cognito.

Error Handling

The status codes for error handling are as follows.

Description Status Code Status Name
Invalid data 400 Bad Request
Missing credentials 401 Unauthorized
Insufficient permissions 403 Forbidden
Code, project, or organization not found 404 Not Found
File size exceeds limit 413 Payload Too Large
Internal server error 500 Internal Server Error

Processing Flow

  1. Extract organization ID, project ID, and code ID from path parameters
  2. Extract update fields from form data
  3. Verify the user has access to the project
  4. Upload to S3 if a file is provided
  5. Update the code in the database
  6. Return updated code information

Detailed Flowchart

flowchart TD
    Start([PUT Request]) --> Route[Route Handler]
    Route --> Auth[Auth & Parameter Extraction]
    Auth --> Service[Service Layer]

    Service --> AccessCheck[Access Check]
    AccessCheck --> HasAccess{Write permission?}
    HasAccess -->|No| Err404[404 Not Found]
    HasAccess -->|Yes| ValidateFields

    ValidateFields[Validate Update Fields] --> AtLeastOne{At least 1 field?}
    AtLeastOne -->|No| Err400[400 Bad Request]
    AtLeastOne -->|Yes| ValidateEach[Validate each field]

    ValidateEach --> ValidName{name validation}
    ValidName -->|NG| Err400
    ValidName -->|OK| ValidCode{sourceCode validation}
    ValidCode -->|NG| Err400
    ValidCode -->|OK| ValidImg{image validation}
    ValidImg -->|NG| Err400
    ValidImg -->|OK| CheckExist

    CheckExist[Check Existing Code] --> Exists{Exists?}
    Exists -->|No| Err404
    Exists -->|Yes| ImageUpdate{Image update?}

    ImageUpdate -->|Yes| S3Upload[S3 Upload]
    ImageUpdate -->|No| PrepareSQS
    S3Upload --> S3OK{Successful?}
    S3OK -->|NG| Err400
    S3OK -->|OK| PrepareSQS

    PrepareSQS[Prepare SQS Message] --> SQSSend[Send SQS Message<br/>Fail-Fast Pattern]
    SQSSend --> SQSOK{Successful?}
    SQSOK -->|NG| Err500[500 SQS Unavailable<br/>DB operation aborted]
    SQSOK -->|OK| DBUpdate

    DBUpdate[DB Update<br/>Transaction] --> UpdateSuccess{Successful?}
    UpdateSuccess -->|NG| Err500
    UpdateSuccess -->|OK| Success[200 OK]