From fa735394f6ce073d521b3678f84c32433ff34a6c Mon Sep 17 00:00:00 2001 From: caichi <54824604+caichi-t@users.noreply.github.com> Date: Wed, 9 Oct 2024 14:46:29 +0900 Subject: [PATCH 1/9] fix(web): workspace name disappears when refreshing page (#1254) fix: workspace name disappearing when refreshing --- .../molecules/WorkspaceSettings/GeneralForm.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/web/src/components/molecules/WorkspaceSettings/GeneralForm.tsx b/web/src/components/molecules/WorkspaceSettings/GeneralForm.tsx index 1868fa7b2..1aa6eaf44 100644 --- a/web/src/components/molecules/WorkspaceSettings/GeneralForm.tsx +++ b/web/src/components/molecules/WorkspaceSettings/GeneralForm.tsx @@ -1,5 +1,5 @@ import styled from "@emotion/styled"; -import { useCallback, useState } from "react"; +import { useCallback, useState, useEffect } from "react"; import Button from "@reearth-cms/components/atoms/Button"; import Form, { ValidateErrorEntity } from "@reearth-cms/components/atoms/Form"; @@ -21,9 +21,13 @@ const WorkspaceGeneralForm: React.FC = ({ updateWorkspaceLoading, onWorkspaceUpdate, }) => { + const t = useT(); const [form] = Form.useForm(); const [isDisabled, setIsDisabled] = useState(true); - const t = useT(); + + useEffect(() => { + form.setFieldsValue({ name: workspaceName }); + }, [form, workspaceName]); const handleValuesChange = useCallback( async (_: unknown, values: FormType) => { @@ -53,7 +57,6 @@ const WorkspaceGeneralForm: React.FC = ({ return ( Date: Wed, 9 Oct 2024 13:14:30 +0200 Subject: [PATCH 2/9] feat(web): dockerize web application (#1253) * feat(web): dockerize the application Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> * Update web/vite.config.ts Co-authored-by: rot1024 * feat(web): revert commithash retrieval with git Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> * fix(web): json stringify commitHash in vite Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> --------- Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> Co-authored-by: rot1024 --- .github/workflows/ci_web.yml | 4 + .github/workflows/deploy_test.yml | 57 +++++++++-- .github/workflows/web_build.yml | 107 ++++++++++++++++++++ web/.dockerignore | 11 ++ web/Dockerfile | 43 ++++++++ web/docker/40-envsubst-on-reearth-config.sh | 8 ++ web/docker/nginx.conf.template | 35 +++++++ web/docker/reearth_config.json.template | 5 + web/vite.config.ts | 2 +- 9 files changed, 261 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/web_build.yml create mode 100644 web/.dockerignore create mode 100644 web/Dockerfile create mode 100755 web/docker/40-envsubst-on-reearth-config.sh create mode 100644 web/docker/nginx.conf.template create mode 100644 web/docker/reearth_config.json.template diff --git a/.github/workflows/ci_web.yml b/.github/workflows/ci_web.yml index b97bd93e2..d0d9ace00 100644 --- a/.github/workflows/ci_web.yml +++ b/.github/workflows/ci_web.yml @@ -53,9 +53,13 @@ jobs: run: yarn i18n --fail-on-update - name: Build run: yarn build + + # TODO: Remove after dockerizing the web. - name: Pack if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release' run: mv dist reearth-cms-web && tar -zcvf reearth-cms-web.tar.gz reearth-cms-web + + # TODO: Remove after dockerizing the web. - uses: actions/upload-artifact@v4 if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release' with: diff --git a/.github/workflows/deploy_test.yml b/.github/workflows/deploy_test.yml index 2b70d2a23..515b1481d 100644 --- a/.github/workflows/deploy_test.yml +++ b/.github/workflows/deploy_test.yml @@ -8,19 +8,29 @@ concurrency: group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}-${{github.event.workflow_run.name}} cancel-in-progress: true env: + GCP_REGION: us-central1 + + # TODO: Remove after dockerizing the web. + GCS_DEST: gs://cms.test.reearth.dev + # server - IMAGE: reearth/reearth-cms:nightly - IMAGE_NAME: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-cms:nightly - IMAGE_GCP: us-central1-docker.pkg.dev/reearth-oss/reearth/reearth-cms:nightly + SERVER_IMAGE: reearth/reearth-cms:nightly + SERVER_IMAGE_NAME: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-cms:nightly + SERVER_IMAGE_GCP: us-central1-docker.pkg.dev/reearth-oss/reearth/reearth-cms:nightly + + # web + WEB_IMAGE: reearth/reearth-cms-web:nightly + WEB_IMAGE_NAME: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-cms-worker:nightly + WEB_IMAGE_GCP: us-central1-docker.pkg.dev/reearth-oss/reearth/reearth-cms-worker:nightly + # worker WORKER_IMAGE: reearth/reearth-cms-worker:nightly WORKER_IMAGE_NAME: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-cms-worker:nightly WORKER_IMAGE_GCP: us-central1-docker.pkg.dev/reearth-oss/reearth/reearth-cms-worker:nightly - GCP_REGION: us-central1 - GCS_DEST: gs://cms.test.reearth.dev jobs: - deploy_web: + # TODO: Remove after dockerizing the web. + deploy_web_gcs: name: Deploy web to test env if: github.event.repository.full_name == 'reearth/reearth-cms' && github.event.workflow_run.name == 'ci-web' && github.event.workflow_run.conclusion != 'failure' && github.event.workflow_run.head_branch == 'main' runs-on: ubuntu-latest @@ -67,13 +77,40 @@ jobs: run: gcloud auth configure-docker us-central1-docker.pkg.dev --quiet - name: docker push run: | - docker pull $IMAGE - docker tag $IMAGE $IMAGE_GCP - docker push $IMAGE_GCP + docker pull $SERVER_IMAGE + docker tag $SERVER_IMAGE $SERVER_IMAGE_GCP + docker push $SERVER_IMAGE_GCP - name: Deploy to Cloud Run run: | gcloud run deploy reearth-cms-backend \ - --image $IMAGE_GCP \ + --image $SERVER_IMAGE_GCP \ + --region $GCP_REGION \ + --platform managed \ + --quiet + + deploy_web: + name: Deploy web to test env + runs-on: ubuntu-latest + if: github.event.repository.full_name == 'reearth/reearth-cms' && github.event.workflow_run.name == 'web-build' && github.event.workflow_run.conclusion != 'failure' && github.event.workflow_run.head_branch == 'main' + steps: + - uses: actions/checkout@v4 + + - uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ secrets.GCP_SA_KEY }} + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v2 + - name: Configure docker + run: gcloud auth configure-docker us-central1-docker.pkg.dev --quiet + - name: docker push + run: | + docker pull $WEB_IMAGE + docker tag $WEB_IMAGE $WEB_IMAGE_GCP + docker push $WEB_IMAGE_GCP + - name: Deploy to Cloud Run + run: | + gcloud run deploy reearth-cms-web \ + --image $WEB_IMAGE_GCP \ --region $GCP_REGION \ --platform managed \ --quiet diff --git a/.github/workflows/web_build.yml b/.github/workflows/web_build.yml new file mode 100644 index 000000000..b35646a6f --- /dev/null +++ b/.github/workflows/web_build.yml @@ -0,0 +1,107 @@ +name: web-build +on: + workflow_run: + workflows: [ci-web] + types: [completed] + branches: [main, release] +concurrency: + group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }} + cancel-in-progress: true + +jobs: + info: + name: Collect information + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion != 'failure' && github.event.repository.full_name == 'reearth/reearth-cms' && (github.event.workflow_run.head_branch == 'release' || !startsWith(github.event.head_commit.message, 'v')) + outputs: + sha_short: ${{ steps.info.outputs.sha_short }} + new_tag: ${{ steps.info.outputs.new_tag }} + new_tag_short: ${{ steps.info.outputs.new_tag_short }} + name: ${{ steps.info.outputs.name }} + steps: + - name: checkout + uses: actions/checkout@v4 + - name: Fetch tags + run: git fetch --prune --unshallow --tags + - name: Get info + id: info + # The tag name should be retrieved lazily, as tagging may be delayed. + env: + BRANCH: ${{ github.event.workflow_run.head_branch }} + run: | + echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + if [[ "$BRANCH" = "release" ]]; then + TAG=$(git tag --points-at HEAD) + if [[ ! -z "$TAG" ]]; then + echo "::set-output name=new_tag::$TAG" + echo "::set-output name=new_tag_short::${TAG#v}" + else + echo "::set-output name=name::rc" + fi + else + echo "::set-output name=name::nightly" + fi + - name: Show info + env: + SHA_SHORT: ${{ steps.info.outputs.sha_short }} + NEW_TAG: ${{ steps.info.outputs.new_tag }} + NEW_TAG_SHORT: ${{ steps.info.outputs.new_tag_short }} + NAME: ${{ steps.info.outputs.name }} + run: echo "sha_short=$SHA_SHORT, new_tag=$NEW_TAG, new_tag_short=$NEW_TAG_SHORT, name=$NAME" + + docker: + name: Build and push Docker image + runs-on: ubuntu-latest + needs: + - info + if: needs.info.outputs.name || needs.info.outputs.new_tag + env: + IMAGE_NAME: reearth/reearth-cms-web + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Get options + id: options + env: + TAG: ${{ needs.info.outputs.tag_short }} + NAME: ${{ needs.info.outputs.name }} + SHA: ${{ needs.info.outputs.sha_short }} + run: | + if [[ -n $TAG ]]; then + PLATFORMS=linux/amd64,linux/arm64 + VERSION=$TAG + TAGS=$IMAGE_NAME:$TAG + if [[ ! $TAG =~ '-' ]]; then + TAGS+=,${IMAGE_NAME}:${TAG%.*} + TAGS+=,${IMAGE_NAME}:${TAG%%.*} + TAGS+=,${IMAGE_NAME}:latest + fi + else + PLATFORMS=linux/amd64 + VERSION=$SHA + TAGS=$IMAGE_NAME:$NAME + fi + echo "::set-output name=platforms::$PLATFORMS" + echo "::set-output name=version::$VERSION" + echo "::set-output name=tags::$TAGS" + - name: Build and push docker image + uses: docker/build-push-action@v6 + with: + context: ./web + platforms: ${{ steps.options.outputs.platforms }} + push: true + build-args: | + GITHUB_SHA=${{ needs.info.outputs.sha_short }} + VERSION=${{ steps.options.outputs.version }} + tags: ${{ steps.options.outputs.tags }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/web/.dockerignore b/web/.dockerignore new file mode 100644 index 000000000..c497bd926 --- /dev/null +++ b/web/.dockerignore @@ -0,0 +1,11 @@ +* + +!docker/ +!src/ + +!index.html +!i18next-parser.config.js +!tsconfig.json +!package.json +!vite.config.ts +!yarn.lock diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 000000000..fb70c3f0c --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,43 @@ +FROM node:20.18.0-slim AS builder +WORKDIR /app + +ARG NODE_OPTIONS="--max-old-space-size=4096" +ARG GITHUB_SHA +ENV NODE_OPTIONS=$NODE_OPTIONS +ENV GITHUB_SHA=$GITHUB_SHA + +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=yarn.lock,target=yarn.lock \ + --mount=type=cache,target=/root/.yarn,sharing=locked \ + yarn install --frozen-lockfile --production=false + +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=yarn.lock,target=yarn.lock \ + --mount=type=bind,source=index.html,target=index.html \ + --mount=type=bind,source=tsconfig.json,target=tsconfig.json \ + --mount=type=bind,source=vite.config.ts,target=vite.config.ts \ + --mount=type=bind,source=src,target=src \ + --mount=type=cache,target=/root/.yarn,sharing=locked \ + yarn build + +FROM nginx:1.27-alpine +WORKDIR /app + +# Quite the Nginx startup logs. +ENV NGINX_ENTRYPOINT_QUIET_LOGS=true + +# Default to Cloud Run port. +# Ref: https://cloud.google.com/run/docs/reference/container-contract#port +ENV PORT=8080 + +# Defaults Google Cloud Load Balancer header. +# Ref: https://cloud.google.com/load-balancing/docs/https#target-proxies +ENV REAL_IP_HEADER=X-Forwarded-For + +COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html +COPY --chown=nginx:nginx docker/nginx.conf.template /etc/nginx/templates/nginx.conf.template +COPY --chown=nginx:nginx docker/40-envsubst-on-reearth-config.sh /docker-entrypoint.d +COPY --chown=nginx:nginx docker/reearth_config.json.template /opt/reearth-cms/reearth_config.json.template + +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["nginx", "-g", "daemon off;"] diff --git a/web/docker/40-envsubst-on-reearth-config.sh b/web/docker/40-envsubst-on-reearth-config.sh new file mode 100755 index 000000000..40a2097e7 --- /dev/null +++ b/web/docker/40-envsubst-on-reearth-config.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +set -e + +_REEARTH_CONFIG_TEMPLATE_FILE="/opt/reearth-cms/reearth_config.json.template" +_REEARTH_CONFIG_OUTPUT_FILE="/usr/share/nginx/html/reearth_config.json" + +envsubst < "$_REEARTH_CONFIG_TEMPLATE_FILE" > "$_REEARTH_CONFIG_OUTPUT_FILE" diff --git a/web/docker/nginx.conf.template b/web/docker/nginx.conf.template new file mode 100644 index 000000000..b2c19d256 --- /dev/null +++ b/web/docker/nginx.conf.template @@ -0,0 +1,35 @@ +log_format json escape=json '{' + '"body_bytes_sent": "$body_bytes_sent",' + '"http_referer": "$http_referer",' + '"http_user_agent": "$http_user_agent",' + '"remote_ip": "$remote_addr",' + '"remote_user": "$remote_user",' + '"request": "$request",' + '"request_id": "$request_id",' + '"request_method": "$request_method",' + '"request_time": "$request_time",' + '"request_uri": "$request_uri",' + '"server_name": "$server_name",' + '"status": "$status",' + '"time": "$time_iso8601"' +'}'; + +real_ip_header ${REAL_IP_HEADER}; + +server { + listen ${PORT}; + root /usr/share/nginx/html; + server_name _; + + access_log /dev/stdout json; + error_log /dev/stderr warn; + + location / { + try_files $uri /index.html =404; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} diff --git a/web/docker/reearth_config.json.template b/web/docker/reearth_config.json.template new file mode 100644 index 000000000..4803d085e --- /dev/null +++ b/web/docker/reearth_config.json.template @@ -0,0 +1,5 @@ +{ + "auth0Audience": "$AUTH0_AUDIENCE", + "auth0ClientId": "$AUTH0_CLIENT_ID", + "auth0Domain": "$AUTH0_DOMAIN" +} \ No newline at end of file diff --git a/web/vite.config.ts b/web/vite.config.ts index d844a0e63..e320600c0 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -35,7 +35,7 @@ export default defineConfig({ envPrefix: "REEARTH_CMS_", define: { __APP_VERSION__: JSON.stringify(pkg.version), - __REEARTH_COMMIT_HASH__: JSON.stringify(commitHash) + __REEARTH_COMMIT_HASH__: JSON.stringify(process.env.GITHUB_SHA || commitHash) }, plugins: [ react(), From d1b66c4d110d29ac06cbebd5074587955b54ffd6 Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Wed, 9 Oct 2024 14:20:56 +0200 Subject: [PATCH 3/9] ci: add `web-build` to deploy-test workflow's dependencies (#1255) Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> --- .github/workflows/deploy_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy_test.yml b/.github/workflows/deploy_test.yml index 515b1481d..d24653634 100644 --- a/.github/workflows/deploy_test.yml +++ b/.github/workflows/deploy_test.yml @@ -1,7 +1,7 @@ name: deploy-test on: workflow_run: - workflows: [server-build, ci-web, worker-build] + workflows: [server-build, ci-web, web-build, worker-build] types: [completed] branches: [main] concurrency: From c857db08f01f2b1f072b2e8f7332eff4603ad0fa Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Wed, 9 Oct 2024 14:45:27 +0200 Subject: [PATCH 4/9] ci: fix Docker image name for web image (#1256) ci: fix docker image name for web Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> --- .github/workflows/deploy_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy_test.yml b/.github/workflows/deploy_test.yml index d24653634..cf3c1126f 100644 --- a/.github/workflows/deploy_test.yml +++ b/.github/workflows/deploy_test.yml @@ -20,8 +20,8 @@ env: # web WEB_IMAGE: reearth/reearth-cms-web:nightly - WEB_IMAGE_NAME: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-cms-worker:nightly - WEB_IMAGE_GCP: us-central1-docker.pkg.dev/reearth-oss/reearth/reearth-cms-worker:nightly + WEB_IMAGE_NAME: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-cms-web:nightly + WEB_IMAGE_GCP: us-central1-docker.pkg.dev/reearth-oss/reearth/reearth-cms-web:nightly # worker WORKER_IMAGE: reearth/reearth-cms-worker:nightly From 25ecfe16d7653995d33e26974165e5cd94c38a25 Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Thu, 10 Oct 2024 22:29:57 +0200 Subject: [PATCH 5/9] feat(web): wrap environment variables with '""' for Re:Earth config (#1258) feat(web): wrap env var with "" Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> --- web/Dockerfile | 11 +++++++++++ web/docker/40-envsubst-on-reearth-config.sh | 9 +++++++++ web/docker/reearth_config.json.template | 14 ++++++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/web/Dockerfile b/web/Dockerfile index fb70c3f0c..7dd957c3f 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -34,6 +34,17 @@ ENV PORT=8080 # Ref: https://cloud.google.com/load-balancing/docs/https#target-proxies ENV REAL_IP_HEADER=X-Forwarded-For +# Default values. +# Cesium Ion access token is not a secret. +ENV REEARTH_CMS_CESIUM_ION_ACCESS_TOKEN=null + +# All values in reearth_config.json must have a default value. +ENV REEARTH_CMS_API=null +ENV REEARTH_CMS_COVER_IMAGE_URL=null +ENV REEARTH_CMS_EDITOR_URL=null +ENV REEARTH_CMS_LOGO_URL=null +ENV REEARTH_CMS_MULTI_TENANT=null + COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html COPY --chown=nginx:nginx docker/nginx.conf.template /etc/nginx/templates/nginx.conf.template COPY --chown=nginx:nginx docker/40-envsubst-on-reearth-config.sh /docker-entrypoint.d diff --git a/web/docker/40-envsubst-on-reearth-config.sh b/web/docker/40-envsubst-on-reearth-config.sh index 40a2097e7..1b116b416 100755 --- a/web/docker/40-envsubst-on-reearth-config.sh +++ b/web/docker/40-envsubst-on-reearth-config.sh @@ -5,4 +5,13 @@ set -e _REEARTH_CONFIG_TEMPLATE_FILE="/opt/reearth-cms/reearth_config.json.template" _REEARTH_CONFIG_OUTPUT_FILE="/usr/share/nginx/html/reearth_config.json" +# Wrap with "" if the value doesn't start with '{' and end with '}' (JSON) or "null". +wrap_reearth_cms_variables() { + for var in $(env | grep '^REEARTH_CMS_' | cut -d= -f1); do + value=$(printenv "$var") + [ "$value" != "null" ] && ! echo "$value" | grep -qE '^\{.*\}$' && export "$var=\"${value}\"" + done +} + +wrap_reearth_cms_variables $@ envsubst < "$_REEARTH_CONFIG_TEMPLATE_FILE" > "$_REEARTH_CONFIG_OUTPUT_FILE" diff --git a/web/docker/reearth_config.json.template b/web/docker/reearth_config.json.template index 4803d085e..75bc0a5fc 100644 --- a/web/docker/reearth_config.json.template +++ b/web/docker/reearth_config.json.template @@ -1,5 +1,11 @@ { - "auth0Audience": "$AUTH0_AUDIENCE", - "auth0ClientId": "$AUTH0_CLIENT_ID", - "auth0Domain": "$AUTH0_DOMAIN" -} \ No newline at end of file + "api": $REEARTH_CMS_API, + "auth0Audience": $REEARTH_CMS_AUTH0_AUDIENCE, + "auth0ClientId": $REEARTH_CMS_AUTH0_CLIENT_ID, + "auth0Domain": $REEARTH_CMS_AUTH0_DOMAIN, + "cesiumIonAccessToken": $REEARTH_CMS_CESIUM_ION_ACCESS_TOKEN, + "coverImageUrl": $REEARTH_CMS_COVER_IMAGE_URL, + "editorUrl": $REEARTH_CMS_EDITOR_URL, + "logoUrl": $REEARTH_CMS_LOGO_URL, + "multiTenant": $REEARTH_CMS_MULTI_TENANT +} From c7c79a43d69816823a285f2aef977296e7d6bd4a Mon Sep 17 00:00:00 2001 From: yk-eukarya <81808708+yk-eukarya@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:56:47 +0200 Subject: [PATCH 6/9] fix(server): integration api returns 404 when updating empty model (#1259) fix --- server/e2e/integration_item_test.go | 21 ++++++++++ server/e2e/integration_model_test.go | 40 +++++++++++++++++--- server/e2e/integration_schema_test.go | 18 +++++++-- server/internal/adapter/integration/model.go | 2 +- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/server/e2e/integration_item_test.go b/server/e2e/integration_item_test.go index 48eabba9b..f3edcd4ac 100644 --- a/server/e2e/integration_item_test.go +++ b/server/e2e/integration_item_test.go @@ -39,6 +39,7 @@ var ( wId0 = accountdomain.NewWorkspaceID() uId = accountdomain.NewUserID() iId = id.NewIntegrationID() + mId0 = id.NewModelID() mId1 = id.NewModelID() mId2 = id.NewModelID() mId3 = id.NewModelID() @@ -72,7 +73,9 @@ var ( ikey2 = key.Random() ikey3 = key.Random() ikey4 = key.Random() + ikey0 = id.RandomKey() pid = id.NewProjectID() + sid0 = id.NewSchemaID() sid1 = id.NewSchemaID() sid2 = id.NewSchemaID() sid3 = id.NewSchemaID() @@ -153,6 +156,11 @@ func baseSeeder(ctx context.Context, r *repo.Container) error { sf3 := schema.NewField(schema.NewReference(mId1, sid1, nil, nil).TypeProperty()).ID(fId3).Key(sfKey3).MustBuild() sf4 := schema.NewField(schema.NewBool().TypeProperty()).ID(fId4).Key(sfKey4).MustBuild() + s0 := schema.New().ID(sid0).Workspace(w.ID()).Project(p.ID()).Fields([]*schema.Field{}).MustBuild() + if err := r.Schema.Save(ctx, s0); err != nil { + return err + } + s1 := schema.New().ID(sid1).Workspace(w.ID()).Project(p.ID()).Fields([]*schema.Field{sf1, sf2}).TitleField(sf1.ID().Ref()).MustBuild() if err := r.Schema.Save(ctx, s1); err != nil { return err @@ -168,6 +176,19 @@ func baseSeeder(ctx context.Context, r *repo.Container) error { return err } + m0 := model.New(). + ID(mId0). + Name("m0"). + Description("m0 desc"). + Public(true). + Key(ikey0). + Project(p.ID()). + Schema(s0.ID()). + MustBuild() + if err := r.Model.Save(ctx, m0); err != nil { + return err + } + m1 := model.New(). ID(mId1). Name("m1"). diff --git a/server/e2e/integration_model_test.go b/server/e2e/integration_model_test.go index e00974020..818e03ae6 100644 --- a/server/e2e/integration_model_test.go +++ b/server/e2e/integration_model_test.go @@ -76,7 +76,27 @@ func TestIntegrationModelUpdateAPI(t *testing.T) { Expect(). Status(http.StatusUnauthorized) - obj := e.PATCH(endpoint, mId1). + // update empty model + obj := e.PATCH(endpoint, mId0). + WithHeader("authorization", "Bearer "+secret). + WithJSON(map[string]interface{}{ + "name": "M0 updated", + "description": "M0 desc updated", + "key": "M0KeyUpdated", + }). + Expect(). + Status(http.StatusOK). + JSON(). + Object() + obj. + ContainsKey("id"). + ContainsKey("schemaId"). + HasValue("projectId", pid). + HasValue("name", "M0 updated"). + HasValue("description", "M0 desc updated"). + HasValue("key", "M0KeyUpdated") + + obj = e.PATCH(endpoint, mId1). WithHeader("authorization", "Bearer "+secret). WithJSON(map[string]interface{}{ "name": "newM1 updated", @@ -187,12 +207,22 @@ func TestIntegrationModelFilterAPI(t *testing.T) { Object(). HasValue("page", 1). HasValue("perPage", 10). - HasValue("totalCount", 5). + HasValue("totalCount", 6). Value("models"). Array() - models.Length().IsEqual(5) + models.Length().IsEqual(6) + + obj0 := models.Value(0).Object() + obj0. + HasValue("id", mId0.String()). + HasValue("name", "m0"). + HasValue("description", "m0 desc"). + HasValue("public", true). + HasValue("key", ikey0.String()). + HasValue("projectId", pid). + HasValue("schemaId", sid0) - obj1 := models.Value(0).Object() + obj1 := models.Value(1).Object() obj1. HasValue("id", mId1.String()). HasValue("name", "m1"). @@ -206,7 +236,7 @@ func TestIntegrationModelFilterAPI(t *testing.T) { obj1.Value("updatedAt").NotNull() obj1.Value("lastModified").NotNull() - obj2 := models.Value(1).Object() + obj2 := models.Value(2).Object() obj2. HasValue("id", mId2.String()). HasValue("name", "m2"). diff --git a/server/e2e/integration_schema_test.go b/server/e2e/integration_schema_test.go index 8a37a2c55..6ecd14383 100644 --- a/server/e2e/integration_schema_test.go +++ b/server/e2e/integration_schema_test.go @@ -43,12 +43,22 @@ func TestIntegrationScemaFilterAPI(t *testing.T) { Object(). HasValue("page", 1). HasValue("perPage", 10). - HasValue("totalCount", 5). + HasValue("totalCount", 6). Value("models"). Array() - models.Length().IsEqual(5) + models.Length().IsEqual(6) - obj1 := models.Value(0).Object() + obj0 := models.Value(0).Object() + obj0. + HasValue("id", mId0.String()). + HasValue("name", "m0"). + HasValue("description", "m0 desc"). + HasValue("public", true). + HasValue("key", ikey0.String()). + HasValue("projectId", pid). + HasValue("schemaId", sid0) + + obj1 := models.Value(1).Object() obj1. HasValue("id", mId1.String()). HasValue("name", "m1"). @@ -62,7 +72,7 @@ func TestIntegrationScemaFilterAPI(t *testing.T) { obj1.Value("updatedAt").NotNull() obj1.Value("lastModified").NotNull() - obj2 := models.Value(1).Object() + obj2 := models.Value(2).Object() obj2. HasValue("id", mId2.String()). HasValue("name", "m2"). diff --git a/server/internal/adapter/integration/model.go b/server/internal/adapter/integration/model.go index d40581102..02b74afca 100644 --- a/server/internal/adapter/integration/model.go +++ b/server/internal/adapter/integration/model.go @@ -173,7 +173,7 @@ func (s *Server) ModelUpdate(ctx context.Context, request ModelUpdateRequestObje } lastModified, err := uc.Item.LastModifiedByModel(ctx, request.ModelId, op) - if err != nil { + if err != nil && !errors.Is(err, rerror.ErrNotFound) { return nil, err } From 08be04cf490f9faf84dfbd5bf1f50696571fce15 Mon Sep 17 00:00:00 2001 From: yk-eukarya <81808708+yk-eukarya@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:14:43 +0200 Subject: [PATCH 7/9] ci(server): enhance performance (#928) * imp * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * Update .github/workflows/ci.yml Co-authored-by: KeisukeYamashita <19yamashita15@gmail.com> * Update .github/workflows/ci.yml Co-authored-by: KeisukeYamashita <19yamashita15@gmail.com> * Update .github/workflows/ci.yml Co-authored-by: KeisukeYamashita <19yamashita15@gmail.com> * Update .github/workflows/ci.yml Co-authored-by: KeisukeYamashita <19yamashita15@gmail.com> * fix --------- Co-authored-by: KeisukeYamashita <19yamashita15@gmail.com> --- .../{server_build.yml => build_server.yml} | 0 .../{worker_build.yml => build_worker.yml} | 0 .github/workflows/ci.yml | 71 ++++++++++++++++ .github/workflows/ci_server.yml | 85 ++++++++++--------- .github/workflows/ci_web.yml | 32 +------ .github/workflows/ci_worker.yml | 71 +++++++--------- .github/workflows/{pr_title.yml => pr.yml} | 17 +++- 7 files changed, 162 insertions(+), 114 deletions(-) rename .github/workflows/{server_build.yml => build_server.yml} (100%) rename .github/workflows/{worker_build.yml => build_worker.yml} (100%) create mode 100644 .github/workflows/ci.yml rename .github/workflows/{pr_title.yml => pr.yml} (76%) diff --git a/.github/workflows/server_build.yml b/.github/workflows/build_server.yml similarity index 100% rename from .github/workflows/server_build.yml rename to .github/workflows/build_server.yml diff --git a/.github/workflows/worker_build.yml b/.github/workflows/build_worker.yml similarity index 100% rename from .github/workflows/worker_build.yml rename to .github/workflows/build_worker.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..5e70e71ec --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,71 @@ +name: ci +on: + push: + branches: [main, release] + pull_request: +jobs: + prepare: + runs-on: ubuntu-latest + outputs: + web: ${{ steps.web.outputs.any_modified }} + server: ${{ steps.server.outputs.any_modified }} + worker: ${{ steps.worker.outputs.any_modified }} + steps: + - name: checkout + uses: actions/checkout@v4 + - name: changed files for web + id: web + uses: tj-actions/changed-files@v45 + with: + files: | + web + .github/workflows/ci.yml + .github/workflows/ci_web.yml + + - name: changed files for server + id: server + uses: tj-actions/changed-files@v45 + with: + files: | + server + .github/workflows/ci.yml + .github/workflows/ci_server.yml + .github/workflows/build_server.yml + + - name: changed files for worker + id: worker + uses: tj-actions/changed-files@v45 + with: + files: | + worker + .github/workflows/ci.yml + .github/workflows/ci_worker.yml + .github/workflows/build_worker.yml + + ci-web: + name: web + needs: prepare + if: needs.prepare.outputs.web == 'true' + uses: ./.github/workflows/ci_web.yml + + ci-server: + name: server + needs: prepare + if: needs.prepare.outputs.server == 'true' + uses: ./.github/workflows/ci_server.yml + + ci-worker: + name: worker + needs: prepare + if: needs.prepare.outputs.worker == 'true' + uses: ./.github/workflows/ci_worker.yml + + ci: + runs-on: ubuntu-latest + needs: + - ci-web + - ci-server + - ci-worker + if: '!failure()' + steps: + - run: echo OK \ No newline at end of file diff --git a/.github/workflows/ci_server.yml b/.github/workflows/ci_server.yml index 0f92662ec..5041479b9 100644 --- a/.github/workflows/ci_server.yml +++ b/.github/workflows/ci_server.yml @@ -1,64 +1,65 @@ name: ci-server on: - push: - branches: [main, release] - paths: - - server/** - - .github/workflows/ci_server.yml - - .github/workflows/server_build.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml - - .github/workflows/server_build.yml - pull_request: - paths: - - server/** - - .github/workflows/ci_server.yml - - .github/workflows/server_build.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml + workflow_call: +env: + GO_VERSION: "1.23" + jobs: - ci: - name: ci + ci-server-lint: + name: lint + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + - name: go setup + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.61 + working-directory: server + args: --config=../.golangci.yml + skip-cache: true + ci-server-i18n: + name: i18n runs-on: ubuntu-latest defaults: run: working-directory: server + steps: + - name: checkout + uses: actions/checkout@v4 + - name: go setup + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: check forgotten translations + working-directory: server + run: make i18n-ci + ci-server-test: + name: test + runs-on: ubuntu-latest services: mongo: image: mongo:6-focal ports: - 27017:27017 steps: - - uses: actions/setup-go@v5 - with: - go-version: 1.23 - name: checkout uses: actions/checkout@v4 - - name: cache - uses: actions/cache@v4 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + - name: go setup + uses: actions/setup-go@v5 with: - version: v1.61 - working-directory: server - args: --config=../.golangci.yml + go-version: ${{ env.GO_VERSION }} - name: test - run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic + run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic -timeout 10m + working-directory: server env: REEARTH_CMS_DB: mongodb://localhost - - name: codecov + - name: Send coverage report uses: codecov/codecov-action@v4 with: flags: server - file: coverage.txt - - name: check forgotten translations - run: make i18n-ci + file: coverage.txt \ No newline at end of file diff --git a/.github/workflows/ci_web.yml b/.github/workflows/ci_web.yml index d0d9ace00..7009e3877 100644 --- a/.github/workflows/ci_web.yml +++ b/.github/workflows/ci_web.yml @@ -1,22 +1,6 @@ name: ci-web on: - push: - branches: [main, release] - paths: - - web/** - - .github/workflows/ci_web.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml - pull_request: - paths: - - web/** - - .github/workflows/ci_web.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml + workflow_call: jobs: ci: name: ci @@ -25,20 +9,12 @@ jobs: run: working-directory: web steps: + - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: lts/* - - uses: actions/checkout@v4 - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v4 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- + cache: yarn + cache-dependency-path: '**/yarn.lock' - name: Install run: yarn install - name: Lint diff --git a/.github/workflows/ci_worker.yml b/.github/workflows/ci_worker.yml index 00faf90ce..158faf18c 100644 --- a/.github/workflows/ci_worker.yml +++ b/.github/workflows/ci_worker.yml @@ -1,61 +1,48 @@ name: ci-worker on: - push: - branches: [main, release] - paths: - - worker/** - - .github/workflows/ci_worker.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml - - .github/workflows/decompressor_build.yml - - .github/workflows/worker_build.yml - pull_request: - paths: - - worker/** - - .github/workflows/ci_worker.yml - - .github/workflows/deploy_test.yml - - .github/workflows/pr_title.yml - - .github/workflows/stage.yml - - .github/workflows/release.yml + workflow_call: +env: + GO_VERSION: "1.23" jobs: - ci: - name: ci + ci-server-lint: + name: lint runs-on: ubuntu-latest - defaults: - run: - working-directory: worker - services: - mongo: - image: mongo:6-focal - ports: - - 27017:27017 steps: - - uses: actions/setup-go@v5 - with: - go-version: 1.23 - name: checkout uses: actions/checkout@v4 - - name: cache - uses: actions/cache@v4 + - name: go setup + uses: actions/setup-go@v5 with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- + go-version: ${{ env.GO_VERSION }} - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: version: v1.61 working-directory: worker args: --config=../.golangci.yml + skip-cache: true + ci-server-test: + name: test + runs-on: ubuntu-latest + services: + mongo: + image: mongo:6-focal + ports: + - 27017:27017 + steps: + - name: checkout + uses: actions/checkout@v4 + - name: go setup + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} - name: test - run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic + run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic -timeout 10m + working-directory: worker env: - REEARTH_CMS_WORKER_DB: mongodb://localhost - - name: codecov + REEARTH_CMS_DB: mongodb://localhost + - name: Send coverage report uses: codecov/codecov-action@v4 with: flags: worker - file: coverage.txt + file: coverage.txt \ No newline at end of file diff --git a/.github/workflows/pr_title.yml b/.github/workflows/pr.yml similarity index 76% rename from .github/workflows/pr_title.yml rename to .github/workflows/pr.yml index 06179c4f4..09bf18e61 100644 --- a/.github/workflows/pr_title.yml +++ b/.github/workflows/pr.yml @@ -1,4 +1,4 @@ -name: PR Title Checker +name: PR on: pull_request: types: @@ -8,12 +8,17 @@ on: - labeled - unlabeled jobs: - pr_title: + labeler: + name: labeler runs-on: ubuntu-latest steps: - uses: actions/labeler@v5 with: repo-token: ${{ secrets.GITHUB_TOKEN }} + title_check: + name: title check + runs-on: ubuntu-latest + steps: - uses: amannn/action-semantic-pull-request@v5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -27,3 +32,11 @@ jobs: The subject "{subject}" found in the pull request title "{title}" didn't match the configured pattern. Please ensure that the subject doesn't start with an uppercase character. + pr_title: + runs-on: ubuntu-latest + needs: + - labeler + - title_check + if: '!failure()' + steps: + - run: echo OK From 62d74d5bbb361bcb004942c67f505edcc6f37ce3 Mon Sep 17 00:00:00 2001 From: yk-eukarya <81808708+yk-eukarya@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:17:57 +0200 Subject: [PATCH 8/9] feat(server): support CJK in fields keys (#1261) * imp * rollback FE changes --- server/e2e/integration_item_test.go | 35 +++--- server/e2e/publicapi_test.go | 21 ++-- .../gql/gqlmodel/convert_group_test.go | 4 +- .../adapter/gql/gqlmodel/convert_item_test.go | 5 +- .../gql/gqlmodel/convert_model_test.go | 7 +- .../gql/gqlmodel/convert_schema_test.go | 5 +- .../internal/adapter/integration/convert.go | 5 +- .../adapter/integration/item_import.go | 5 +- .../internal/adapter/integration/item_test.go | 5 +- .../internal/adapter/publicapi/types_test.go | 18 +-- .../infrastructure/memory/group_test.go | 7 +- .../infrastructure/memory/model_test.go | 7 +- .../infrastructure/mongo/group_test.go | 7 +- .../infrastructure/mongo/model_test.go | 11 +- .../infrastructure/mongo/mongodoc/group.go | 3 +- .../mongo/mongodoc/group_test.go | 6 +- .../infrastructure/mongo/mongodoc/model.go | 6 +- .../mongo/mongodoc/model_test.go | 6 +- .../infrastructure/mongo/mongodoc/schema.go | 3 +- server/internal/usecase/interactor/group.go | 7 +- server/internal/usecase/interactor/item.go | 3 +- .../internal/usecase/interactor/item_test.go | 23 ++-- server/internal/usecase/interactor/model.go | 9 +- .../internal/usecase/interactor/model_test.go | 11 +- server/internal/usecase/interactor/schema.go | 5 +- server/internal/usecase/interfaces/item.go | 3 +- server/pkg/exporters/csv_test.go | 65 +++++----- server/pkg/exporters/geojson_test.go | 49 ++++---- server/pkg/group/builder.go | 3 +- server/pkg/group/builder_test.go | 47 ++++--- server/pkg/group/group.go | 9 +- server/pkg/group/group_test.go | 55 ++++----- server/pkg/group/list_test.go | 13 +- server/pkg/id/key.go | 16 +-- server/pkg/id/key_test.go | 11 +- server/pkg/item/item_test.go | 15 ++- server/pkg/item/reference_test.go | 7 +- server/pkg/key/key.go | 11 -- server/pkg/model/builder.go | 7 +- server/pkg/model/builder_test.go | 115 +++++++++--------- server/pkg/model/list_test.go | 21 ++-- server/pkg/model/model.go | 14 +-- server/pkg/model/model_test.go | 59 +++++---- server/pkg/schema/corresponding_field.go | 3 +- server/pkg/schema/corresponding_field_test.go | 5 +- server/pkg/schema/field.go | 8 +- server/pkg/schema/field_builder.go | 6 +- server/pkg/schema/field_builder_test.go | 11 +- server/pkg/schema/field_test.go | 7 +- server/pkg/schema/list_test.go | 9 +- server/pkg/schema/package_test.go | 37 +++--- server/pkg/schema/schema.go | 3 +- server/pkg/schema/schema_test.go | 17 ++- 53 files changed, 403 insertions(+), 447 deletions(-) delete mode 100644 server/pkg/key/key.go diff --git a/server/e2e/integration_item_test.go b/server/e2e/integration_item_test.go index f3edcd4ac..773baf649 100644 --- a/server/e2e/integration_item_test.go +++ b/server/e2e/integration_item_test.go @@ -18,7 +18,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/integration" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/operator" "github.com/reearth/reearth-cms/server/pkg/project" @@ -69,26 +68,26 @@ var ( thId4 = id.NewThreadID() thId5 = id.NewThreadID() icId = id.NewCommentID() - ikey1 = key.Random() - ikey2 = key.Random() - ikey3 = key.Random() - ikey4 = key.Random() ikey0 = id.RandomKey() + ikey1 = id.RandomKey() + ikey2 = id.RandomKey() + ikey3 = id.RandomKey() + ikey4 = id.RandomKey() pid = id.NewProjectID() sid0 = id.NewSchemaID() sid1 = id.NewSchemaID() sid2 = id.NewSchemaID() sid3 = id.NewSchemaID() palias = "PROJECT_ALIAS" - sfKey1 = key.Random() + sfKey1 = id.RandomKey() sfKey2 = id.NewKey("asset") - sfKey3 = key.Random() - sfKey4 = key.Random() + sfKey3 = id.RandomKey() + sfKey4 = id.RandomKey() sfKey5 = id.NewKey("asset-key") sfKey6 = id.NewKey("group-key") sfKey7 = id.NewKey("geometry-key") sfKey8 = id.NewKey("geometry-editor-key") - gKey1 = key.Random() + gKey1 = id.RandomKey() gId1 = id.NewItemGroupID() gId2 = id.NewItemGroupID() gId3 = id.NewItemGroupID() @@ -380,28 +379,28 @@ func baseSeeder(ctx context.Context, r *repo.Container) error { // endregion // Default value - msf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(key.Random()).DefaultValue(schema.NewBool().TypeProperty().Type().Value(true).AsMultiple()).MustBuild() + msf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(id.RandomKey()).DefaultValue(schema.NewBool().TypeProperty().Type().Value(true).AsMultiple()).MustBuild() sm := schema.New().NewID().Workspace(w.ID()).Project(pid).Fields([]*schema.Field{msf1}).MustBuild() if err := r.Schema.Save(ctx, sm); err != nil { return err } - gsf := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.Random()).DefaultValue(schema.NewText(nil).TypeProperty().Type().Value("default group").AsMultiple()).MustBuild() + gsf := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).DefaultValue(schema.NewText(nil).TypeProperty().Type().Value("default group").AsMultiple()).MustBuild() gs := schema.New().NewID().Workspace(w.ID()).Project(pid).Fields([]*schema.Field{gsf}).MustBuild() if err := r.Schema.Save(ctx, gs); err != nil { return err } - gp := group.New().NewID().Name("group2").Project(pid).Key(key.Random()).Schema(gs.ID()).MustBuild() + gp := group.New().NewID().Name("group2").Project(pid).Key(id.RandomKey()).Schema(gs.ID()).MustBuild() if err := r.Group.Save(ctx, gp); err != nil { return err } - dvsf1 := schema.NewField(schema.NewText(nil).TypeProperty()).ID(dvsfId).Key(key.Random()).MustBuild() - dvsf2 := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.Random()).DefaultValue(schema.NewText(nil).TypeProperty().Type().Value("default").AsMultiple()).MustBuild() - dvsf3 := schema.NewField(schema.NewGroup(gp.ID()).TypeProperty()).NewID().Key(key.Random()).MustBuild() + dvsf1 := schema.NewField(schema.NewText(nil).TypeProperty()).ID(dvsfId).Key(id.RandomKey()).MustBuild() + dvsf2 := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).DefaultValue(schema.NewText(nil).TypeProperty().Type().Value("default").AsMultiple()).MustBuild() + dvsf3 := schema.NewField(schema.NewGroup(gp.ID()).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() gst2 := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest2 := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} - dvsf4 := schema.NewField(schema.NewGeometryObject(gst2).TypeProperty()).NewID().Key(key.Random()).MustBuild() - dvsf5 := schema.NewField(schema.NewGeometryEditor(gest2).TypeProperty()).NewID().Key(key.Random()).MustBuild() + dvsf4 := schema.NewField(schema.NewGeometryObject(gst2).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + dvsf5 := schema.NewField(schema.NewGeometryEditor(gest2).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() dvs1 := schema.New().NewID().Workspace(w.ID()).Project(pid).Fields([]*schema.Field{dvsf1, dvsf2, dvsf3, dvsf4, dvsf5}).MustBuild() if err := r.Schema.Save(ctx, dvs1); err != nil { @@ -412,7 +411,7 @@ func baseSeeder(ctx context.Context, r *repo.Container) error { Name("dvm"). Description("dvm desc"). Public(true). - Key(key.Random()). + Key(id.RandomKey()). Project(pid). Schema(dvs1.ID()). Metadata(sm.ID().Ref()). diff --git a/server/e2e/publicapi_test.go b/server/e2e/publicapi_test.go index f5991d805..93705591f 100644 --- a/server/e2e/publicapi_test.go +++ b/server/e2e/publicapi_test.go @@ -12,7 +12,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/asset" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" @@ -361,22 +360,22 @@ func publicAPISeeder(ctx context.Context, r *repo.Container) error { gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} s := schema.New().NewID().Project(p1.ID()).Workspace(p1.Workspace()).Fields(schema.FieldList{ - schema.NewField(schema.NewText(nil).TypeProperty()).ID(fid).Name(publicAPIField1Key).Key(key.New(publicAPIField1Key)).MustBuild(), - schema.NewField(schema.NewAsset().TypeProperty()).NewID().Name(publicAPIField2Key).Key(key.New(publicAPIField2Key)).MustBuild(), - schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Name(publicAPIField3Key).Key(key.New(publicAPIField3Key)).Multiple(true).MustBuild(), - schema.NewField(schema.NewAsset().TypeProperty()).NewID().Name(publicAPIField4Key).Key(key.New(publicAPIField4Key)).Multiple(true).MustBuild(), - schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name(publicAPIField5Key).Key(key.New(publicAPIField5Key)).MustBuild(), - schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name(publicAPIField6Key).Key(key.New(publicAPIField6Key)).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).ID(fid).Name(publicAPIField1Key).Key(id.NewKey(publicAPIField1Key)).MustBuild(), + schema.NewField(schema.NewAsset().TypeProperty()).NewID().Name(publicAPIField2Key).Key(id.NewKey(publicAPIField2Key)).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Name(publicAPIField3Key).Key(id.NewKey(publicAPIField3Key)).Multiple(true).MustBuild(), + schema.NewField(schema.NewAsset().TypeProperty()).NewID().Name(publicAPIField4Key).Key(id.NewKey(publicAPIField4Key)).Multiple(true).MustBuild(), + schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name(publicAPIField5Key).Key(id.NewKey(publicAPIField5Key)).MustBuild(), + schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name(publicAPIField6Key).Key(id.NewKey(publicAPIField6Key)).MustBuild(), }).TitleField(fid.Ref()).MustBuild() s2 := schema.New().NewID().Project(p1.ID()).Workspace(p1.Workspace()).Fields(schema.FieldList{ - schema.NewField(schema.NewText(nil).TypeProperty()).ID(fid).Name(publicAPIField1Key).Key(key.New(publicAPIField1Key)).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).ID(fid).Name(publicAPIField1Key).Key(id.NewKey(publicAPIField1Key)).MustBuild(), }).MustBuild() - m := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s.ID()).Public(true).Key(key.New(publicAPIModelKey)).MustBuild() + m := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s.ID()).Public(true).Key(id.NewKey(publicAPIModelKey)).MustBuild() // m2 is not a public model - m2 := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s.ID()).Name(publicAPIModelKey2).Key(key.New(publicAPIModelKey2)).Public(false).MustBuild() - m3 := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s2.ID()).Name(publicAPIModelKey3).Key(key.New(publicAPIModelKey3)).Public(true).MustBuild() + m2 := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s.ID()).Name(publicAPIModelKey2).Key(id.NewKey(publicAPIModelKey2)).Public(false).MustBuild() + m3 := model.New().ID(publicAPIModelID).Project(p1.ID()).Schema(s2.ID()).Name(publicAPIModelKey3).Key(id.NewKey(publicAPIModelKey3)).Public(true).MustBuild() i1 := item.New().ID(publicAPIItem1ID).Model(m.ID()).Schema(s.ID()).Project(p1.ID()).Thread(id.NewThreadID()).User(uid).Fields([]*item.Field{ item.NewField(s.Fields()[0].ID(), value.TypeText.Value("aaa").AsMultiple(), nil), diff --git a/server/internal/adapter/gql/gqlmodel/convert_group_test.go b/server/internal/adapter/gql/gqlmodel/convert_group_test.go index 8313544c3..e408e9707 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_group_test.go +++ b/server/internal/adapter/gql/gqlmodel/convert_group_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/group" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/stretchr/testify/assert" @@ -14,7 +14,7 @@ func TestToGroup(t *testing.T) { mId := group.NewID() pId := project.NewID() sId := schema.NewID() - k := key.Random() + k := id.RandomKey() tests := []struct { name string group *group.Group diff --git a/server/internal/adapter/gql/gqlmodel/convert_item_test.go b/server/internal/adapter/gql/gqlmodel/convert_item_test.go index cd91bfc9d..5628201cc 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_item_test.go +++ b/server/internal/adapter/gql/gqlmodel/convert_item_test.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearth-cms/server/pkg/version" @@ -25,7 +24,7 @@ func TestToItem(t *testing.T) { nid := id.NewIntegrationID() tid := id.NewThreadID() pid := id.NewProjectID() - sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() sf := []*schema.Field{sf1} s := schema.New().ID(sid).Fields(sf).Workspace(accountdomain.NewWorkspaceID()).TitleField(sf1.ID().Ref()).Project(pid).MustBuild() i := item.New(). @@ -128,7 +127,7 @@ func TestToVersionedItem(t *testing.T) { iid := id.NewItemID() sid := id.NewSchemaID() ref := "a" - sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() sf := []*schema.Field{sf1} s := schema.New().ID(sid).Fields(sf).Workspace(accountdomain.NewWorkspaceID()).Project(pId).MustBuild() fs := []*item.Field{item.NewField(sf1.ID(), value.TypeBool.Value(true).AsMultiple(), nil)} diff --git a/server/internal/adapter/gql/gqlmodel/convert_model_test.go b/server/internal/adapter/gql/gqlmodel/convert_model_test.go index dde0e8b62..38eaeb645 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_model_test.go +++ b/server/internal/adapter/gql/gqlmodel/convert_model_test.go @@ -1,10 +1,11 @@ package gqlmodel import ( - "github.com/samber/lo" "testing" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" + "github.com/samber/lo" + "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" @@ -15,7 +16,7 @@ func TestToModel(t *testing.T) { mId := model.NewID() pId := project.NewID() sId := schema.NewID() - k := key.Random() + k := id.RandomKey() tests := []struct { name string model *model.Model diff --git a/server/internal/adapter/gql/gqlmodel/convert_schema_test.go b/server/internal/adapter/gql/gqlmodel/convert_schema_test.go index d02e7331e..b7b497835 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_schema_test.go +++ b/server/internal/adapter/gql/gqlmodel/convert_schema_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" @@ -17,7 +16,7 @@ func TestToSchema(t *testing.T) { pId := id.NewProjectID() sId := schema.NewID() fId := id.NewFieldID() - k := key.Random() + k := id.RandomKey() tests := []struct { name string schema *schema.Schema @@ -91,7 +90,7 @@ func TestToSchemaField(t *testing.T) { UpdatedAt(fid.Timestamp()). Name("N1"). Description("D1"). - Key(key.New("K123456")). + Key(id.NewKey("K123456")). Unique(true). Multiple(true). Required(true). diff --git a/server/internal/adapter/integration/convert.go b/server/internal/adapter/integration/convert.go index 0e32dfa56..304294451 100644 --- a/server/internal/adapter/integration/convert.go +++ b/server/internal/adapter/integration/convert.go @@ -6,7 +6,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/integrationapi" "github.com/reearth/reearth-cms/server/pkg/item" "github.com/reearth/reearth-cms/server/pkg/item/view" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/usecasex" @@ -53,9 +52,9 @@ func fromItemFieldParam(f integrationapi.Field, sf *schema.Field) interfaces.Ite v = *f.Value } - var k *key.Key + var k *id.Key if f.Key != nil { - k = key.New(*f.Key).Ref() + k = id.NewKey(*f.Key).Ref() } return interfaces.ItemFieldParam{ diff --git a/server/internal/adapter/integration/item_import.go b/server/internal/adapter/integration/item_import.go index d76036461..029656cf9 100644 --- a/server/internal/adapter/integration/item_import.go +++ b/server/internal/adapter/integration/item_import.go @@ -13,7 +13,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/integrationapi" - key2 "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/i18n" @@ -179,7 +178,7 @@ func itemsFromJson(r io.Reader, isGeoJson bool, geoField *string, sp schema.Pack return nil, nil, rerror.ErrInvalidParams } - geoFieldKey := key2.New(*geoField) + geoFieldKey := id.NewKey(*geoField) if !geoFieldKey.IsValid() { return nil, nil, rerror.ErrInvalidParams } @@ -211,7 +210,7 @@ func itemsFromJson(r io.Reader, isGeoJson bool, geoField *string, sp schema.Pack if v == nil { continue } - key := key2.New(k) + key := id.NewKey(k) if !key.IsValid() { return nil, nil, rerror.ErrInvalidParams } diff --git a/server/internal/adapter/integration/item_test.go b/server/internal/adapter/integration/item_test.go index 1a60c338e..f40070712 100644 --- a/server/internal/adapter/integration/item_test.go +++ b/server/internal/adapter/integration/item_test.go @@ -6,7 +6,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/integrationapi" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearthx/account/accountdomain" "github.com/samber/lo" @@ -22,8 +21,8 @@ func Test_convertMetaFields(t *testing.T) { tag2 := schema.NewTag("日本語", schema.TagColorOrange) tf, _ := schema.NewFieldTag(schema.TagList{tag1, tag2}) - sf1 := schema.NewField(tf.TypeProperty()).NewID().Key(key.New("sf-1")).MustBuild() - sf2 := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.New("sf-1")).MustBuild() + sf1 := schema.NewField(tf.TypeProperty()).NewID().Key(id.NewKey("sf-1")).MustBuild() + sf2 := schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.NewKey("sf-1")).MustBuild() var vi any = "日本語" var vi2 any = "xyz" s := schema.New().NewID().Fields(schema.FieldList{sf1, sf2}).Project(id.NewProjectID()).Workspace(accountdomain.NewWorkspaceID()).MustBuild() diff --git a/server/internal/adapter/publicapi/types_test.go b/server/internal/adapter/publicapi/types_test.go index f724591f4..289681fe1 100644 --- a/server/internal/adapter/publicapi/types_test.go +++ b/server/internal/adapter/publicapi/types_test.go @@ -2,13 +2,13 @@ package publicapi import ( "encoding/json" - "github.com/reearth/reearth-cms/server/pkg/group" "testing" + "github.com/reearth/reearth-cms/server/pkg/group" + "github.com/reearth/reearth-cms/server/pkg/asset" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" @@ -32,7 +32,7 @@ func TestNewItem(t *testing.T) { Project(id.NewProjectID()). Workspace(accountdomain.NewWorkspaceID()). Fields([]*schema.Field{ - schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.New("test1")).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.NewKey("test1")).MustBuild(), }). MustBuild() @@ -40,7 +40,7 @@ func TestNewItem(t *testing.T) { NewID(). Name("test group"). Project(id.NewProjectID()). - Key(key.New("group1")). + Key(id.NewKey("group1")). Schema(s2.ID()). MustBuild() @@ -49,9 +49,9 @@ func TestNewItem(t *testing.T) { Project(id.NewProjectID()). Workspace(accountdomain.NewWorkspaceID()). Fields([]*schema.Field{ - schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.New("aaaaa")).MustBuild(), - schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(key.New("bbbbb")).MustBuild(), - schema.NewField(schema.NewGroup(g.ID()).TypeProperty()).NewID().Key(key.New("ggggg")).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.NewKey("aaaaa")).MustBuild(), + schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(id.NewKey("bbbbb")).MustBuild(), + schema.NewField(schema.NewGroup(g.ID()).TypeProperty()).NewID().Key(id.NewKey("ggggg")).MustBuild(), }). MustBuild() ig := id.NewItemGroupID() @@ -112,8 +112,8 @@ func TestNewItem_Multiple(t *testing.T) { Project(id.NewProjectID()). Workspace(accountdomain.NewWorkspaceID()). Fields([]*schema.Field{ - schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(key.New("aaaaa")).Multiple(true).MustBuild(), - schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(key.New("bbbbb")).Multiple(true).MustBuild(), + schema.NewField(schema.NewText(nil).TypeProperty()).NewID().Key(id.NewKey("aaaaa")).Multiple(true).MustBuild(), + schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(id.NewKey("bbbbb")).Multiple(true).MustBuild(), }). MustBuild() it := item.New(). diff --git a/server/internal/infrastructure/memory/group_test.go b/server/internal/infrastructure/memory/group_test.go index 090f506e0..ad78dedf0 100644 --- a/server/internal/infrastructure/memory/group_test.go +++ b/server/internal/infrastructure/memory/group_test.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/group" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" "github.com/reearth/reearthx/util" "github.com/stretchr/testify/assert" @@ -34,7 +33,7 @@ func TestGroupRepo_FindByID(t *testing.T) { pid1 := id.NewProjectID() id1 := id.NewGroupID() sid1 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() tests := []struct { @@ -141,7 +140,7 @@ func TestGroupRepo_FindByIDs(t *testing.T) { id2 := id.NewGroupID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() m2 := group.New().ID(id2).Project(pid1).Schema(sid2).Key(k).MustBuild() @@ -258,7 +257,7 @@ func TestGroupRepo_FindByProject(t *testing.T) { id2 := id.NewGroupID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() m2 := group.New().ID(id2).Project(pid1).Schema(sid2).Key(k).MustBuild() diff --git a/server/internal/infrastructure/memory/model_test.go b/server/internal/infrastructure/memory/model_test.go index d235fa72e..7ce6a43ab 100644 --- a/server/internal/infrastructure/memory/model_test.go +++ b/server/internal/infrastructure/memory/model_test.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearthx/rerror" "github.com/reearth/reearthx/usecasex" @@ -37,7 +36,7 @@ func TestModelRepo_FindByID(t *testing.T) { pid1 := id.NewProjectID() id1 := id.NewModelID() sid1 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() tests := []struct { @@ -142,7 +141,7 @@ func TestModelRepo_FindByIDs(t *testing.T) { id2 := id.NewModelID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() m2 := model.New().ID(id2).Project(pid1).Schema(sid2).Key(k).UpdatedAt(mocknow).MustBuild() @@ -263,7 +262,7 @@ func TestModelRepo_FindByProject(t *testing.T) { id2 := id.NewModelID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() m2 := model.New().ID(id2).Project(pid1).Schema(sid2).Key(k).UpdatedAt(mocknow).MustBuild() diff --git a/server/internal/infrastructure/mongo/group_test.go b/server/internal/infrastructure/mongo/group_test.go index 0f2590d6d..ec2249b71 100644 --- a/server/internal/infrastructure/mongo/group_test.go +++ b/server/internal/infrastructure/mongo/group_test.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/group" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/mongox" "github.com/reearth/reearthx/mongox/mongotest" "github.com/reearth/reearthx/rerror" @@ -34,7 +33,7 @@ func TestGroupRepo_FindByID(t *testing.T) { pid1 := id.NewProjectID() id1 := id.NewGroupID() sid1 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() tests := []struct { @@ -144,7 +143,7 @@ func TestGroupRepo_FindByIDs(t *testing.T) { id2 := id.NewGroupID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() m2 := group.New().ID(id2).Project(pid1).Schema(sid2).Key(k).MustBuild() @@ -265,7 +264,7 @@ func TestGroupRepo_FindByProject(t *testing.T) { id2 := id.NewGroupID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := group.New().ID(id1).Project(pid1).Schema(sid1).Key(k).MustBuild() m2 := group.New().ID(id2).Project(pid1).Schema(sid2).Key(k).MustBuild() diff --git a/server/internal/infrastructure/mongo/model_test.go b/server/internal/infrastructure/mongo/model_test.go index 761a0abc9..009387012 100644 --- a/server/internal/infrastructure/mongo/model_test.go +++ b/server/internal/infrastructure/mongo/model_test.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearthx/mongox" "github.com/reearth/reearthx/mongox/mongotest" @@ -37,7 +36,7 @@ func TestModelRepo_FindByID(t *testing.T) { pid1 := id.NewProjectID() id1 := id.NewModelID() sid1 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() tests := []struct { @@ -146,7 +145,7 @@ func TestModelRepo_FindBySchema(t *testing.T) { pid1 := id.NewProjectID() id1 := id.NewModelID() sid1 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() tests := []struct { @@ -257,7 +256,7 @@ func TestModelRepo_FindByIDs(t *testing.T) { id2 := id.NewModelID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() m2 := model.New().ID(id2).Project(pid1).Schema(sid2).Key(k).UpdatedAt(mocknow).MustBuild() @@ -379,7 +378,7 @@ func TestModelRepo_FindByProject(t *testing.T) { id2 := id.NewModelID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).UpdatedAt(mocknow).MustBuild() m2 := model.New().ID(id2).Project(pid1).Schema(sid2).Key(k).UpdatedAt(mocknow).MustBuild() @@ -507,7 +506,7 @@ func TestModelRepo_FindByProjectAndKeyword(t *testing.T) { id2 := id.NewModelID() sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() - k := key.New("T123456") + k := id.NewKey("T123456") m1 := model.New().ID(id1).Project(pid1).Schema(sid1).Key(k).Name("m1").UpdatedAt(mocknow).MustBuild() m2 := model.New().ID(id2).Project(pid1).Schema(sid2).Key(k).Name("m2").UpdatedAt(mocknow).MustBuild() diff --git a/server/internal/infrastructure/mongo/mongodoc/group.go b/server/internal/infrastructure/mongo/mongodoc/group.go index 846c7cc08..8aa5fb004 100644 --- a/server/internal/infrastructure/mongo/mongodoc/group.go +++ b/server/internal/infrastructure/mongo/mongodoc/group.go @@ -3,7 +3,6 @@ package mongodoc import ( "github.com/reearth/reearth-cms/server/pkg/group" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/mongox" ) @@ -62,7 +61,7 @@ func (d *GroupDocument) Model() (*group.Group, error) { ID(mId). Name(d.Name). Description(d.Description). - Key(key.New(d.Key)). + Key(id.NewKey(d.Key)). Project(pId). Schema(sId). Order(d.Order). diff --git a/server/internal/infrastructure/mongo/mongodoc/group_test.go b/server/internal/infrastructure/mongo/mongodoc/group_test.go index 71c5e8570..1e2b802a4 100644 --- a/server/internal/infrastructure/mongo/mongodoc/group_test.go +++ b/server/internal/infrastructure/mongo/mongodoc/group_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/group" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/stretchr/testify/assert" @@ -32,7 +32,7 @@ func TestGroupDocument_Group(t *testing.T) { want: group.New().ID(mId). Name("abc"). Description("xyz"). - Key(key.New("mmm123")). + Key(id.NewKey("mmm123")). Project(pId). Schema(sId). Order(1). @@ -110,7 +110,7 @@ func TestNewGroup(t *testing.T) { args: group.New().ID(mId). Name("abc"). Description("xyz"). - Key(key.New("mmm123")). + Key(id.NewKey("mmm123")). Project(pId). Schema(sId). Order(1). diff --git a/server/internal/infrastructure/mongo/mongodoc/model.go b/server/internal/infrastructure/mongo/mongodoc/model.go index 0f2d9604c..baefb5eff 100644 --- a/server/internal/infrastructure/mongo/mongodoc/model.go +++ b/server/internal/infrastructure/mongo/mongodoc/model.go @@ -1,11 +1,11 @@ package mongodoc import ( - "github.com/reearth/reearth-cms/server/pkg/model" "time" + "github.com/reearth/reearth-cms/server/pkg/model" + "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/mongox" ) @@ -71,7 +71,7 @@ func (d *ModelDocument) Model() (*model.Model, error) { Name(d.Name). Description(d.Description). UpdatedAt(d.UpdatedAt). - Key(key.New(d.Key)). + Key(id.NewKey(d.Key)). Public(d.Public). Project(pId). Metadata(id.SchemaIDFromRef(d.Metadata)). diff --git a/server/internal/infrastructure/mongo/mongodoc/model_test.go b/server/internal/infrastructure/mongo/mongodoc/model_test.go index cb125fa86..28f91a2c2 100644 --- a/server/internal/infrastructure/mongo/mongodoc/model_test.go +++ b/server/internal/infrastructure/mongo/mongodoc/model_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" @@ -36,7 +36,7 @@ func TestModelDocument_Model(t *testing.T) { want: model.New().ID(mId). Name("abc"). Description("xyz"). - Key(key.New("mmm123")). + Key(id.NewKey("mmm123")). Public(true). Project(pId). Metadata(smId.Ref()). @@ -120,7 +120,7 @@ func TestNewModel(t *testing.T) { args: model.New().ID(mId). Name("abc"). Description("xyz"). - Key(key.New("mmm123")). + Key(id.NewKey("mmm123")). Public(true). Project(pId). Schema(sId). diff --git a/server/internal/infrastructure/mongo/mongodoc/schema.go b/server/internal/infrastructure/mongo/mongodoc/schema.go index bf1cca9ec..e3c040b54 100644 --- a/server/internal/infrastructure/mongo/mongodoc/schema.go +++ b/server/internal/infrastructure/mongo/mongodoc/schema.go @@ -4,7 +4,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" @@ -329,7 +328,7 @@ func (d *SchemaDocument) Model() (*schema.Schema, error) { Order(fd.Order). Required(fd.Required). Description(fd.Description). - Key(key.New(fd.Key)). + Key(id.NewKey(fd.Key)). UpdatedAt(fd.UpdatedAt). DefaultValue(fd.DefaultValue.MultipleValue()). Build() diff --git a/server/internal/usecase/interactor/group.go b/server/internal/usecase/interactor/group.go index 2058603c9..cf0554376 100644 --- a/server/internal/usecase/interactor/group.go +++ b/server/internal/usecase/interactor/group.go @@ -10,7 +10,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/group" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" @@ -81,7 +80,7 @@ func (i Group) Create(ctx context.Context, param interfaces.CreateGroupParam, op New(). NewID(). Schema(s.ID()). - Key(key.New(param.Key)). + Key(id.NewKey(param.Key)). Project(param.ProjectId). Name(param.Name) @@ -136,7 +135,7 @@ func (i Group) Update(ctx context.Context, param interfaces.UpdateGroupParam, op if gg != nil { return nil, id.ErrDuplicatedKey } - if err := g.SetKey(key.New(*param.Key)); err != nil { + if err := g.SetKey(id.NewKey(*param.Key)); err != nil { return nil, err } } @@ -151,7 +150,7 @@ func (i Group) Update(ctx context.Context, param interfaces.UpdateGroupParam, op func (i Group) CheckKey(ctx context.Context, pId id.ProjectID, s string) (bool, error) { return Run1(ctx, nil, i.repos, Usecase().Transaction(), func(ctx context.Context) (bool, error) { - if k := key.New(s); !k.IsValid() { + if k := id.NewKey(s); !k.IsValid() { return false, id.ErrInvalidKey } diff --git a/server/internal/usecase/interactor/item.go b/server/internal/usecase/interactor/item.go index 3ce744317..6268f2419 100644 --- a/server/internal/usecase/interactor/item.go +++ b/server/internal/usecase/interactor/item.go @@ -13,7 +13,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/event" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/request" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/thread" @@ -391,7 +390,7 @@ func (i Item) Import(ctx context.Context, param interfaces.ImportItemsParam, ope Required(fieldParam.Required). Name(fieldParam.Name). Description(lo.FromPtr(fieldParam.Description)). - Key(key.New(fieldParam.Key)). + Key(id.NewKey(fieldParam.Key)). DefaultValue(fieldParam.DefaultValue). Build() if err != nil { diff --git a/server/internal/usecase/interactor/item_test.go b/server/internal/usecase/interactor/item_test.go index 0b336b94d..6e5af5794 100644 --- a/server/internal/usecase/interactor/item_test.go +++ b/server/internal/usecase/interactor/item_test.go @@ -12,7 +12,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/request" @@ -175,7 +174,7 @@ func TestItem_FindBySchema(t *testing.T) { uid := accountdomain.NewUserID() wid := accountdomain.NewWorkspaceID() pid := id.NewProjectID() - sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s1 := schema.New().NewID().Workspace(wid).Project(pid).Fields(schema.FieldList{sf1}).MustBuild() s2 := schema.New().NewID().Workspace(wid).Project(pid).MustBuild() restore := util.MockNow(time.Now().Truncate(time.Millisecond).UTC()) @@ -479,9 +478,9 @@ func TestItem_IsItemReferenced(t *testing.T) { Description: "description", Required: true, } - sf1 := schema.NewField(schema.NewReference(id.NewModelID(), sid2, fid2.Ref(), cf1).TypeProperty()).ID(fid1).Name("f").Unique(true).Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewReference(id.NewModelID(), sid2, fid2.Ref(), cf1).TypeProperty()).ID(fid1).Name("f").Unique(true).Key(id.RandomKey()).MustBuild() s1 := schema.New().ID(sid1).Workspace(w).Project(prj.ID()).Fields(schema.FieldList{sf1}).MustBuild() - m1 := model.New().NewID().Schema(s1.ID()).Key(key.Random()).Project(s1.Project()).MustBuild() + m1 := model.New().NewID().Schema(s1.ID()).Key(id.RandomKey()).Project(s1.Project()).MustBuild() fs1 := []*item.Field{item.NewField(sf1.ID(), value.TypeReference.Value(id.NewItemID()).AsMultiple(), nil)} i1 := item.New().NewID().Schema(s1.ID()).Model(m1.ID()).Project(s1.Project()).Thread(id.NewThreadID()).Fields(fs1).MustBuild() @@ -491,16 +490,16 @@ func TestItem_IsItemReferenced(t *testing.T) { Description: "description", Required: true, } - sf2 := schema.NewField(schema.NewReference(id.NewModelID(), sid1, fid1.Ref(), cf2).TypeProperty()).ID(fid2).Name("f").Unique(true).Key(key.Random()).MustBuild() + sf2 := schema.NewField(schema.NewReference(id.NewModelID(), sid1, fid1.Ref(), cf2).TypeProperty()).ID(fid2).Name("f").Unique(true).Key(id.RandomKey()).MustBuild() s2 := schema.New().ID(sid2).Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{sf2}).MustBuild() - m2 := model.New().NewID().Schema(s2.ID()).Key(key.Random()).Project(s2.Project()).MustBuild() + m2 := model.New().NewID().Schema(s2.ID()).Key(id.RandomKey()).Project(s2.Project()).MustBuild() fs2 := []*item.Field{item.NewField(sf2.ID(), value.TypeReference.Value(id.NewItemID()).AsMultiple(), nil)} i2 := item.New().NewID().Schema(s2.ID()).Model(m2.ID()).Project(s2.Project()).Thread(id.NewThreadID()).Fields(fs2).MustBuild() fid3 := id.NewFieldID() - sf3 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).ID(fid3).Name("f").Unique(true).Key(key.Random()).MustBuild() + sf3 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).ID(fid3).Name("f").Unique(true).Key(id.RandomKey()).MustBuild() s3 := schema.New().ID(sid2).Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{sf3}).MustBuild() - m3 := model.New().NewID().Schema(s3.ID()).Key(key.Random()).Project(s3.Project()).MustBuild() + m3 := model.New().NewID().Schema(s3.ID()).Key(id.RandomKey()).Project(s3.Project()).MustBuild() fs3 := []*item.Field{item.NewField(sf3.ID(), value.TypeReference.Value(nil).AsMultiple(), nil)} i3 := item.New().NewID().Schema(s3.ID()).Model(m3.ID()).Project(s3.Project()).Thread(id.NewThreadID()).Fields(fs3).MustBuild() @@ -558,9 +557,9 @@ func TestItem_IsItemReferenced(t *testing.T) { func TestItem_Create(t *testing.T) { r := []workspace.Role{workspace.RoleReader, workspace.RoleWriter} prj := project.New().NewID().RequestRoles(r).MustBuild() - sf := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("f").Unique(true).Key(key.Random()).MustBuild() + sf := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("f").Unique(true).Key(id.RandomKey()).MustBuild() s := schema.New().NewID().Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{sf}).MustBuild() - m := model.New().NewID().Schema(s.ID()).Key(key.Random()).Project(s.Project()).MustBuild() + m := model.New().NewID().Schema(s.ID()).Key(id.RandomKey()).Project(s.Project()).MustBuild() ctx := context.Background() db := memory.New() @@ -720,9 +719,9 @@ func TestItem_Create(t *testing.T) { func TestItem_Update(t *testing.T) { uId := accountdomain.NewUserID().Ref() prj := project.New().NewID().MustBuild() - sf := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("f").Unique(true).Key(key.Random()).MustBuild() + sf := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("f").Unique(true).Key(id.RandomKey()).MustBuild() s := schema.New().NewID().Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{sf}).MustBuild() - m := model.New().NewID().Schema(s.ID()).Key(key.Random()).Project(s.Project()).MustBuild() + m := model.New().NewID().Schema(s.ID()).Key(id.RandomKey()).Project(s.Project()).MustBuild() i := item.New().NewID().User(*uId).Model(m.ID()).Project(s.Project()).Schema(s.ID()).Thread(id.NewThreadID()).MustBuild() i2 := item.New().NewID().User(*uId).Model(m.ID()).Project(s.Project()).Schema(s.ID()).Thread(id.NewThreadID()).MustBuild() i3 := item.New().NewID().User(accountdomain.NewUserID()).Model(m.ID()).Project(s.Project()).Schema(s.ID()).Thread(id.NewThreadID()).MustBuild() diff --git a/server/internal/usecase/interactor/model.go b/server/internal/usecase/interactor/model.go index 573390fbb..11ff9adbd 100644 --- a/server/internal/usecase/interactor/model.go +++ b/server/internal/usecase/interactor/model.go @@ -9,7 +9,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearthx/i18n" @@ -109,9 +108,9 @@ func (i Model) Create(ctx context.Context, param interfaces.CreateModelParam, op mb = mb.Public(*param.Public) } if param.Key != nil { - mb = mb.Key(key.New(*param.Key)) + mb = mb.Key(id.NewKey(*param.Key)) } else { - mb = mb.Key(key.Random()) + mb = mb.Key(id.RandomKey()) } models, _, err := i.repos.Model.FindByProject(ctx, param.ProjectId, usecasex.CursorPagination{First: lo.ToPtr(int64(1000))}.Wrap()) if err != nil { @@ -154,7 +153,7 @@ func (i Model) Update(ctx context.Context, param interfaces.UpdateModelParam, op m.SetDescription(*param.Description) } if param.Key != nil { - if err := m.SetKey(key.New(*param.Key)); err != nil { + if err := m.SetKey(id.NewKey(*param.Key)); err != nil { return nil, err } } @@ -172,7 +171,7 @@ func (i Model) Update(ctx context.Context, param interfaces.UpdateModelParam, op func (i Model) CheckKey(ctx context.Context, pId id.ProjectID, s string) (bool, error) { return Run1(ctx, nil, i.repos, Usecase().Transaction(), func(ctx context.Context) (bool, error) { - if k := key.New(s); !k.IsValid() { + if k := id.NewKey(s); !k.IsValid() { return false, model.ErrInvalidKey } diff --git a/server/internal/usecase/interactor/model_test.go b/server/internal/usecase/interactor/model_test.go index 697f263fb..9c412572f 100644 --- a/server/internal/usecase/interactor/model_test.go +++ b/server/internal/usecase/interactor/model_test.go @@ -10,7 +10,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearthx/account/accountdomain/user" @@ -23,9 +22,9 @@ import ( func TestModel_FindByID(t *testing.T) { sid := id.NewSchemaID() id1 := id.NewModelID() - m1 := model.New().ID(id1).Key(key.Random()).Schema(sid).Project(id.NewProjectID()).MustBuild() + m1 := model.New().ID(id1).Key(id.RandomKey()).Schema(sid).Project(id.NewProjectID()).MustBuild() id2 := id.NewModelID() - m2 := model.New().ID(id2).Key(key.Random()).Schema(sid).Project(id.NewProjectID()).MustBuild() + m2 := model.New().ID(id2).Key(id.RandomKey()).Schema(sid).Project(id.NewProjectID()).MustBuild() op := &usecase.Operator{ AcOperator: &accountusecase.Operator{ @@ -133,7 +132,7 @@ func TestModel_CheckKey(t *testing.T) { name: "with different key", seeds: seeds{ model: []*model.Model{ - model.New().NewID().Key(key.Random()).Project(pId).Schema(id.NewSchemaID()).MustBuild(), + model.New().NewID().Key(id.RandomKey()).Project(pId).Schema(id.NewSchemaID()).MustBuild(), }, }, args: args{ @@ -148,7 +147,7 @@ func TestModel_CheckKey(t *testing.T) { name: "with same key", seeds: seeds{ model: []*model.Model{ - model.New().NewID().Key(key.New("test123")).Project(pId).Schema(id.NewSchemaID()).MustBuild(), + model.New().NewID().Key(id.NewKey("test123")).Project(pId).Schema(id.NewSchemaID()).MustBuild(), }, }, args: args{ @@ -163,7 +162,7 @@ func TestModel_CheckKey(t *testing.T) { name: "with same key different project", seeds: seeds{ model: []*model.Model{ - model.New().NewID().Key(key.New("test123")).Project(pId).Schema(id.NewSchemaID()).MustBuild(), + model.New().NewID().Key(id.NewKey("test123")).Project(pId).Schema(id.NewSchemaID()).MustBuild(), }, }, args: args{ diff --git a/server/internal/usecase/interactor/schema.go b/server/internal/usecase/interactor/schema.go index 73f349770..b472a791f 100644 --- a/server/internal/usecase/interactor/schema.go +++ b/server/internal/usecase/interactor/schema.go @@ -9,7 +9,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase/repo" "github.com/reearth/reearth-cms/server/pkg/group" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/samber/lo" @@ -95,7 +94,7 @@ func (i Schema) CreateField(ctx context.Context, param interfaces.CreateFieldPar Required(param.Required). Name(param.Name). Description(lo.FromPtr(param.Description)). - Key(key.New(param.Key)). + Key(id.NewKey(param.Key)). DefaultValue(param.DefaultValue). Build() if err != nil { @@ -392,7 +391,7 @@ func updateField(param interfaces.UpdateFieldParam, f *schema.Field) error { } if param.Key != nil { - if err := f.SetKey(key.New(*param.Key)); err != nil { + if err := f.SetKey(id.NewKey(*param.Key)); err != nil { return err } } diff --git a/server/internal/usecase/interfaces/item.go b/server/internal/usecase/interfaces/item.go index 892025ce5..425706c1d 100644 --- a/server/internal/usecase/interfaces/item.go +++ b/server/internal/usecase/interfaces/item.go @@ -7,7 +7,6 @@ import ( "github.com/reearth/reearth-cms/server/internal/usecase" "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/model" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/version" @@ -29,7 +28,7 @@ var ( type ItemFieldParam struct { Field *item.FieldID - Key *key.Key + Key *id.Key // Type value.Type Value any Group *id.ItemGroupID diff --git a/server/pkg/exporters/csv_test.go b/server/pkg/exporters/csv_test.go index cfd686d7d..5319543f5 100644 --- a/server/pkg/exporters/csv_test.go +++ b/server/pkg/exporters/csv_test.go @@ -8,7 +8,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearth-cms/server/pkg/version" @@ -26,12 +25,12 @@ func TestCSVFromItems(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(key.Random()).MustBuild() - sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(id.RandomKey()).MustBuild() + sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf4 := schema.NewField(tp4).NewID().Name("age").Key(key.Random()).MustBuild() - sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(key.Random()).MustBuild() + sf4 := schema.NewField(tp4).NewID().Name("age").Key(id.RandomKey()).MustBuild() + sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(id.RandomKey()).MustBuild() s1 := schema.New().ID(sid).Fields([]*schema.Field{sf1, sf3, sf4, sf5}).Workspace(accountdomain.NewWorkspaceID()).Project(pid).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}").AsMultiple(), nil) fi2 := item.NewField(sf3.ID(), value.TypeGeometryEditor.Value("{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}").AsMultiple(), nil) @@ -59,7 +58,7 @@ func TestCSVFromItems(t *testing.T) { sid2 := id.NewSchemaID() mid2 := id.NewModelID() tid2 := id.NewThreadID() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s2 := schema.New().ID(sid).Fields([]*schema.Field{sf2}).Workspace(accountdomain.NewWorkspaceID()).Project(pid).MustBuild() i2 := item.New(). ID(iid2). @@ -83,7 +82,7 @@ func TestCSVFromItems(t *testing.T) { mid3 := id.NewModelID() tid3 := id.NewThreadID() gst2 := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypeLineString, schema.GeometryObjectSupportedTypePolygon} - sf6 := schema.NewField(schema.NewGeometryObject(gst2).TypeProperty()).NewID().Name("geo3").Key(key.Random()).MustBuild() + sf6 := schema.NewField(schema.NewGeometryObject(gst2).TypeProperty()).NewID().Name("geo3").Key(id.RandomKey()).MustBuild() s3 := schema.New().ID(sid).Fields([]*schema.Field{sf6}).Workspace(accountdomain.NewWorkspaceID()).Project(pid).MustBuild() i3 := item.New(). ID(iid3). @@ -107,12 +106,12 @@ func TestBuildCSVHeaders(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf3 := schema.NewField(tp4).NewID().Name("age").Key(key.Random()).MustBuild() - sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(key.Random()).MustBuild() + sf3 := schema.NewField(tp4).NewID().Name("age").Key(id.RandomKey()).MustBuild() + sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(id.RandomKey()).MustBuild() s1 := schema.New().ID(sid).Fields([]*schema.Field{sf1, sf3, sf4}).Workspace(accountdomain.NewWorkspaceID()).Project(pid).MustBuild() s2 := schema.New().ID(sid).Fields([]*schema.Field{sf1, sf2, sf3, sf4}).Workspace(accountdomain.NewWorkspaceID()).Project(pid).MustBuild() @@ -135,12 +134,12 @@ func TestRowFromItem(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf3 := schema.NewField(tp4).NewID().Name("age").Key(key.Random()).MustBuild() - sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(key.Random()).MustBuild() + sf3 := schema.NewField(tp4).NewID().Name("age").Key(id.RandomKey()).MustBuild() + sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(id.RandomKey()).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}").AsMultiple(), nil) fi2 := item.NewField(sf2.ID(), value.TypeGeometryEditor.Value("{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}").AsMultiple(), nil) fi3 := item.NewField(sf3.ID(), value.TypeInteger.Value(30).AsMultiple(), nil) @@ -194,12 +193,12 @@ func TestExtractFirstPointField(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("geo1").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("geo2").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf3 := schema.NewField(tp4).NewID().Name("age").Key(key.Random()).MustBuild() - sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(key.Random()).MustBuild() + sf3 := schema.NewField(tp4).NewID().Name("age").Key(id.RandomKey()).MustBuild() + sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("isMarried").Key(id.RandomKey()).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}").AsMultiple(), nil) fi2 := item.NewField(sf2.ID(), value.TypeGeometryEditor.Value("{\"coordinates\": [[[138.90306434425662,36.11737907906834],[138.90306434425662,36.33622175736386],[138.67187898370287,36.33622175736386],[138.67187898370287,36.11737907906834],[138.90306434425662,36.11737907906834]]],\"type\": \"Polygon\"}").AsMultiple(), nil) fi3 := item.NewField(sf3.ID(), value.TypeInteger.Value(30).AsMultiple(), nil) @@ -248,7 +247,7 @@ func TestExtractFirstPointField(t *testing.T) { } func TestToCSVProp(t *testing.T) { - sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if1 := item.NewField(sf1.ID(), value.TypeText.Value("test").AsMultiple(), nil) s1 := ToCSVProp(if1) assert.Equal(t, "test", s1) @@ -260,21 +259,21 @@ func TestToCSVProp(t *testing.T) { v3 := int64(30) in3, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp3 := in3.TypeProperty() - sf3 := schema.NewField(tp3).NewID().Name("age").Key(key.Random()).MustBuild() + sf3 := schema.NewField(tp3).NewID().Name("age").Key(id.RandomKey()).MustBuild() if3 := item.NewField(sf3.ID(), value.TypeInteger.Value(v3).AsMultiple(), nil) s3, ok3 := ToGeoJsonSingleValue(if3.Value().First()) assert.Equal(t, int64(30), s3) assert.True(t, ok3) v4 := true - sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf4 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if4 := item.NewField(sf4.ID(), value.TypeBool.Value(v4).AsMultiple(), nil) s4, ok4 := ToGeoJsonSingleValue(if4.Value().First()) assert.Equal(t, true, s4) assert.True(t, ok4) v5 := false - sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if5 := item.NewField(sf5.ID(), value.TypeBool.Value(v5).AsMultiple(), nil) s5, ok5 := ToGeoJsonSingleValue(if5.Value().First()) assert.Equal(t, false, s5) @@ -282,36 +281,36 @@ func TestToCSVProp(t *testing.T) { } func TestToCSVValue(t *testing.T) { - sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if1 := item.NewField(sf1.ID(), value.TypeText.Value("test").AsMultiple(), nil) s1 := ToCSVValue(if1.Value().First()) assert.Equal(t, "test", s1) - sf2 := schema.NewField(schema.NewTextArea(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf2 := schema.NewField(schema.NewTextArea(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if2 := item.NewField(sf2.ID(), value.TypeTextArea.Value("test").AsMultiple(), nil) s2 := ToCSVValue(if2.Value().First()) assert.Equal(t, "test", s2) - sf3 := schema.NewField(schema.NewURL().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf3 := schema.NewField(schema.NewURL().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() v3 := url.URL{Scheme: "https", Host: "reearth.io"} if3 := item.NewField(sf3.ID(), value.TypeURL.Value(v3).AsMultiple(), nil) s3 := ToCSVValue(if3.Value().First()) assert.Equal(t, "https://reearth.io", s3) - sf4 := schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf4 := schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if4 := item.NewField(sf4.ID(), value.TypeAsset.Value(id.NewAssetID()).AsMultiple(), nil) s4 := ToCSVValue(if4.Value().First()) assert.Empty(t, s4) gid := id.NewGroupID() igid := id.NewItemGroupID() - sf5 := schema.NewField(schema.NewGroup(gid).TypeProperty()).NewID().Key(key.Random()).Multiple(true).MustBuild() + sf5 := schema.NewField(schema.NewGroup(gid).TypeProperty()).NewID().Key(id.RandomKey()).Multiple(true).MustBuild() if5 := item.NewField(sf5.ID(), value.MultipleFrom(value.TypeGroup, []*value.Value{value.TypeGroup.Value(igid)}), nil) s5 := ToCSVValue(if5.Value().First()) assert.Empty(t, s5) v6 := id.NewItemID() - sf6 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf6 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if6 := item.NewField(sf6.ID(), value.TypeReference.Value(v6).AsMultiple(), nil) s6 := ToCSVValue(if6.Value().First()) assert.Empty(t, s6) @@ -319,7 +318,7 @@ func TestToCSVValue(t *testing.T) { v7 := int64(30) in7, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp7 := in7.TypeProperty() - sf7 := schema.NewField(tp7).NewID().Name("age").Key(key.Random()).MustBuild() + sf7 := schema.NewField(tp7).NewID().Name("age").Key(id.RandomKey()).MustBuild() if7 := item.NewField(sf7.ID(), value.TypeInteger.Value(v7).AsMultiple(), nil) s7 := ToCSVValue(if7.Value().First()) assert.Equal(t, "30", s7) @@ -327,19 +326,19 @@ func TestToCSVValue(t *testing.T) { v8 := float64(30.123) in8, _ := schema.NewNumber(lo.ToPtr(float64(1)), lo.ToPtr(float64(100))) tp8 := in8.TypeProperty() - sf8 := schema.NewField(tp8).NewID().Name("age").Key(key.Random()).MustBuild() + sf8 := schema.NewField(tp8).NewID().Name("age").Key(id.RandomKey()).MustBuild() if8 := item.NewField(sf8.ID(), value.TypeNumber.Value(v8).AsMultiple(), nil) s8 := ToCSVValue(if8.Value().First()) assert.Equal(t, "30.123", s8) v9 := true - sf9 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf9 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if9 := item.NewField(sf9.ID(), value.TypeBool.Value(v9).AsMultiple(), nil) s9 := ToCSVValue(if9.Value().First()) assert.Equal(t, "true", s9) v10 := time.Now() - sf10 := schema.NewField(schema.NewDateTime().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf10 := schema.NewField(schema.NewDateTime().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if10 := item.NewField(sf10.ID(), value.TypeDateTime.Value(v10).AsMultiple(), nil) s10 := ToCSVValue(if10.Value().First()) assert.Equal(t, v10.Format(time.RFC3339), s10) diff --git a/server/pkg/exporters/geojson_test.go b/server/pkg/exporters/geojson_test.go index 5308b5c59..e83fbce5f 100644 --- a/server/pkg/exporters/geojson_test.go +++ b/server/pkg/exporters/geojson_test.go @@ -8,7 +8,6 @@ import ( "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/item" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearth-cms/server/pkg/version" @@ -28,13 +27,13 @@ func TestFeatureCollectionFromItems(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString, schema.GeometryObjectSupportedTypePolygon} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString, schema.GeometryEditorSupportedTypePolygon} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(key.Random()).Multiple(true).MustBuild() - sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(id.RandomKey()).Multiple(true).MustBuild() + sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf4 := schema.NewField(tp4).NewID().Name("Age").Key(key.Random()).MustBuild() - sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(key.Random()).MustBuild() + sf4 := schema.NewField(tp4).NewID().Name("Age").Key(id.RandomKey()).MustBuild() + sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(id.RandomKey()).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[[139.65439725962517,36.34793305387103],[139.61688622815393,35.910803456352724]],\"type\":\"LineString\"}").AsMultiple(), nil) fi2 := item.NewField(sf2.ID(), value.MultipleFrom(value.TypeText, []*value.Value{value.TypeText.Value("a"), value.TypeText.Value("b"), value.TypeText.Value("c")}), nil) fi3 := item.NewField(sf3.ID(), value.TypeGeometryEditor.Value("{\"coordinates\": [[[138.90306434425662,36.11737907906834],[138.90306434425662,36.33622175736386],[138.67187898370287,36.33622175736386],[138.67187898370287,36.11737907906834],[138.90306434425662,36.11737907906834]]],\"type\": \"Polygon\"}").AsMultiple(), nil) @@ -114,8 +113,8 @@ func TestFeatureCollectionFromItems(t *testing.T) { func TestExtractGeometry(t *testing.T) { gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString, schema.GeometryObjectSupportedTypePolygon} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(key.Random()).Multiple(true).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(id.RandomKey()).Multiple(true).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[[139.65439725962517,36.34793305387103],[139.61688622815393,35.910803456352724]],\"type\":\"LineString\"}").AsMultiple(), nil) fi2 := item.NewField(sf2.ID(), value.MultipleFrom(value.TypeText, []*value.Value{value.TypeText.Value("a"), value.TypeText.Value("b"), value.TypeText.Value("c")}), nil) @@ -141,13 +140,13 @@ func TestExtractProperties(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString, schema.GeometryObjectSupportedTypePolygon} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString, schema.GeometryEditorSupportedTypePolygon} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(key.Random()).Multiple(true).MustBuild() - sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(id.RandomKey()).Multiple(true).MustBuild() + sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf4 := schema.NewField(tp4).NewID().Name("Age").Key(key.Random()).MustBuild() - sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(key.Random()).MustBuild() + sf4 := schema.NewField(tp4).NewID().Name("Age").Key(id.RandomKey()).MustBuild() + sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(id.RandomKey()).MustBuild() fi1 := item.NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[[139.65439725962517,36.34793305387103],[139.61688622815393,35.910803456352724]],\"type\":\"LineString\"}").AsMultiple(), nil) fi2 := item.NewField(sf2.ID(), value.MultipleFrom(value.TypeText, []*value.Value{value.TypeText.Value("a"), value.TypeText.Value("b"), value.TypeText.Value("c")}), nil) fi3 := item.NewField(sf3.ID(), value.TypeGeometryEditor.Value("{\"coordinates\": [[[138.90306434425662,36.11737907906834],[138.90306434425662,36.33622175736386],[138.67187898370287,36.33622175736386],[138.67187898370287,36.11737907906834],[138.90306434425662,36.11737907906834]]],\"type\": \"Polygon\"}").AsMultiple(), nil) @@ -223,7 +222,7 @@ func TestStringToGeometry(t *testing.T) { } func TestToGeoJSONProp(t *testing.T) { - sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if1 := item.NewField(sf1.ID(), value.TypeText.Value("test").AsMultiple(), nil) s1, ok1 := ToGeoJSONProp(if1) assert.Equal(t, "test", s1) @@ -234,7 +233,7 @@ func TestToGeoJSONProp(t *testing.T) { assert.Empty(t, s2) assert.False(t, ok2) - sf3 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf3 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if3 := item.NewField(sf3.ID(), value.MultipleFrom(value.TypeText, []*value.Value{value.TypeText.Value("a"), value.TypeText.Value("b"), value.TypeText.Value("c")}), nil) s3, ok3 := ToGeoJSONProp(if3) assert.Equal(t, []any{"a", "b", "c"}, s3) @@ -242,26 +241,26 @@ func TestToGeoJSONProp(t *testing.T) { } func TestToGeoJsonSingleValue(t *testing.T) { - sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if1 := item.NewField(sf1.ID(), value.TypeText.Value("test").AsMultiple(), nil) s1, ok1 := ToGeoJsonSingleValue(if1.Value().First()) assert.Equal(t, "test", s1) assert.True(t, ok1) - sf2 := schema.NewField(schema.NewTextArea(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf2 := schema.NewField(schema.NewTextArea(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if2 := item.NewField(sf2.ID(), value.TypeTextArea.Value("test").AsMultiple(), nil) s2, ok2 := ToGeoJsonSingleValue(if2.Value().First()) assert.Equal(t, "test", s2) assert.True(t, ok2) - sf3 := schema.NewField(schema.NewURL().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf3 := schema.NewField(schema.NewURL().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() v3 := url.URL{Scheme: "https", Host: "reearth.io"} if3 := item.NewField(sf3.ID(), value.TypeURL.Value(v3).AsMultiple(), nil) s3, ok3 := ToGeoJsonSingleValue(if3.Value().First()) assert.Equal(t, "https://reearth.io", s3) assert.True(t, ok3) - sf4 := schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf4 := schema.NewField(schema.NewAsset().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if4 := item.NewField(sf4.ID(), value.TypeAsset.Value(id.NewAssetID()).AsMultiple(), nil) s4, ok4 := ToGeoJsonSingleValue(if4.Value().First()) assert.Empty(t, s4) @@ -269,14 +268,14 @@ func TestToGeoJsonSingleValue(t *testing.T) { gid := id.NewGroupID() igid := id.NewItemGroupID() - sf5 := schema.NewField(schema.NewGroup(gid).TypeProperty()).NewID().Key(key.Random()).Multiple(true).MustBuild() + sf5 := schema.NewField(schema.NewGroup(gid).TypeProperty()).NewID().Key(id.RandomKey()).Multiple(true).MustBuild() if5 := item.NewField(sf5.ID(), value.MultipleFrom(value.TypeGroup, []*value.Value{value.TypeGroup.Value(igid)}), nil) s5, ok5 := ToGeoJsonSingleValue(if5.Value().First()) assert.Empty(t, s5) assert.False(t, ok5) v6 := id.NewItemID() - sf6 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf6 := schema.NewField(schema.NewReference(id.NewModelID(), id.NewSchemaID(), nil, nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() if6 := item.NewField(sf6.ID(), value.TypeReference.Value(v6).AsMultiple(), nil) s6, ok6 := ToGeoJsonSingleValue(if6.Value().First()) assert.Empty(t, s6) @@ -285,7 +284,7 @@ func TestToGeoJsonSingleValue(t *testing.T) { v7 := int64(30) in7, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp7 := in7.TypeProperty() - sf7 := schema.NewField(tp7).NewID().Name("age").Key(key.Random()).MustBuild() + sf7 := schema.NewField(tp7).NewID().Name("age").Key(id.RandomKey()).MustBuild() if7 := item.NewField(sf7.ID(), value.TypeInteger.Value(v7).AsMultiple(), nil) s7, ok7 := ToGeoJsonSingleValue(if7.Value().First()) assert.Equal(t, int64(30), s7) @@ -294,21 +293,21 @@ func TestToGeoJsonSingleValue(t *testing.T) { v8 := float64(30.123) in8, _ := schema.NewNumber(lo.ToPtr(float64(1)), lo.ToPtr(float64(100))) tp8 := in8.TypeProperty() - sf8 := schema.NewField(tp8).NewID().Name("age").Key(key.Random()).MustBuild() + sf8 := schema.NewField(tp8).NewID().Name("age").Key(id.RandomKey()).MustBuild() if8 := item.NewField(sf8.ID(), value.TypeNumber.Value(v8).AsMultiple(), nil) s8, ok8 := ToGeoJsonSingleValue(if8.Value().First()) assert.Equal(t, 30.123, s8) assert.True(t, ok8) v9 := true - sf9 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf9 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if9 := item.NewField(sf9.ID(), value.TypeBool.Value(v9).AsMultiple(), nil) s9, ok9 := ToGeoJsonSingleValue(if9.Value().First()) assert.Equal(t, true, s9) assert.True(t, ok9) v10 := time.Now() - sf10 := schema.NewField(schema.NewDateTime().TypeProperty()).NewID().Name("age").Key(key.Random()).MustBuild() + sf10 := schema.NewField(schema.NewDateTime().TypeProperty()).NewID().Name("age").Key(id.RandomKey()).MustBuild() if10 := item.NewField(sf10.ID(), value.TypeDateTime.Value(v10).AsMultiple(), nil) s10, ok10 := ToGeoJsonSingleValue(if10.Value().First()) assert.Equal(t, v10.Format(time.RFC3339), s10) diff --git a/server/pkg/group/builder.go b/server/pkg/group/builder.go index 52b4a0e62..7dbbff9a7 100644 --- a/server/pkg/group/builder.go +++ b/server/pkg/group/builder.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" ) @@ -70,7 +69,7 @@ func (b *Builder) Description(description string) *Builder { return b } -func (b *Builder) Key(key key.Key) *Builder { +func (b *Builder) Key(key id.Key) *Builder { b.group.key = key return b } diff --git a/server/pkg/group/builder_test.go b/server/pkg/group/builder_test.go index 3574dd4fa..1c5a5f976 100644 --- a/server/pkg/group/builder_test.go +++ b/server/pkg/group/builder_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/stretchr/testify/assert" ) @@ -36,7 +35,7 @@ func TestBuilder_Build(t *testing.T) { sId := id.NewSchemaID() type fields struct { m *Group - k key.Key + k id.Key } tests := []struct { name string @@ -53,10 +52,10 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Group{ id: mId, @@ -64,7 +63,7 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, wantErr: nil, @@ -78,10 +77,10 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Group{ id: mId, @@ -89,7 +88,7 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, wantErr: nil, @@ -102,10 +101,10 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -118,10 +117,10 @@ func TestBuilder_Build(t *testing.T) { project: pId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -151,7 +150,7 @@ func TestBuilder_MustBuild(t *testing.T) { sId := id.NewSchemaID() type fields struct { m *Group - k key.Key + k id.Key } tests := []struct { name string @@ -168,10 +167,10 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Group{ id: mId, @@ -179,7 +178,7 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, wantErr: nil, @@ -193,10 +192,10 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Group{ id: mId, @@ -204,7 +203,7 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, wantErr: nil, @@ -218,10 +217,10 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -234,10 +233,10 @@ func TestBuilder_MustBuild(t *testing.T) { project: pId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), order: 1, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -278,7 +277,7 @@ func TestBuilder_ID(t *testing.T) { func TestBuilder_Key(t *testing.T) { b := New() - k := key.New("xabczz") + k := id.NewKey("xabczz") b.Key(k) assert.Equal(t, k, b.group.Key()) } diff --git a/server/pkg/group/group.go b/server/pkg/group/group.go index 6ae62fe1c..63aad64ec 100644 --- a/server/pkg/group/group.go +++ b/server/pkg/group/group.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" ) @@ -14,7 +13,7 @@ type Group struct { project ProjectID name string description string - key key.Key + key id.Key order int } @@ -38,7 +37,7 @@ func (g *Group) Description() string { return g.description } -func (g *Group) Key() key.Key { +func (g *Group) Key() id.Key { return g.key } @@ -73,7 +72,7 @@ func (g *Group) SetDescription(des string) { g.description = des } -func (g *Group) SetKey(key key.Key) error { +func (g *Group) SetKey(key id.Key) error { if !validateGroupKey(key) { return &rerror.Error{ Label: id.ErrInvalidKey, @@ -84,6 +83,6 @@ func (g *Group) SetKey(key key.Key) error { return nil } -func validateGroupKey(key key.Key) bool { +func validateGroupKey(key id.Key) bool { return key.IsValid() && len(key.String()) > 2 } diff --git a/server/pkg/group/group_test.go b/server/pkg/group/group_test.go index de7859499..c872581ae 100644 --- a/server/pkg/group/group_test.go +++ b/server/pkg/group/group_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" "github.com/stretchr/testify/assert" ) @@ -26,7 +25,7 @@ func TestGroup_Clone(t *testing.T) { schema: sId, name: "n1", description: "d1", - key: key.New("123456"), + key: id.NewKey("123456"), order: 1, }, }, @@ -111,14 +110,14 @@ func TestGroup_Key(t *testing.T) { tests := []struct { name string group Group - want key.Key + want id.Key }{ { name: "test", group: Group{ - key: key.New("123456"), + key: id.NewKey("123456"), }, - want: key.New("123456"), + want: id.NewKey("123456"), }, } for _, tt := range tests { @@ -238,7 +237,7 @@ func TestGroup_SetDescription(t *testing.T) { func TestGroup_SetKey(t *testing.T) { type args struct { - key key.Key + key id.Key } tests := []struct { name string @@ -248,40 +247,40 @@ func TestGroup_SetKey(t *testing.T) { }{ { name: "pass", - args: args{key: key.New("123456")}, - want: Group{key: key.New("123456")}, + args: args{key: id.NewKey("123456")}, + want: Group{key: id.NewKey("123456")}, wantErr: nil, }, { name: "fail", - args: args{key: key.New("a")}, + args: args{key: id.NewKey("a")}, want: Group{}, wantErr: &rerror.Error{ Label: id.ErrInvalidKey, Err: fmt.Errorf("%s", "a"), }, }, - { - name: "fail 2", - args: args{key: key.New("_aaaaaaaa")}, - want: Group{}, - wantErr: &rerror.Error{ - Label: id.ErrInvalidKey, - Err: fmt.Errorf("%s", "_aaaaaaaa"), - }, - }, - { - name: "fail 3", - args: args{key: key.New("-aaaaaaaa")}, - want: Group{}, - wantErr: &rerror.Error{ - Label: id.ErrInvalidKey, - Err: fmt.Errorf("%s", "-aaaaaaaa"), - }, - }, + //{ + // name: "fail 2", + // args: args{key: id.NewKey("_aaaaaaaa")}, + // want: Group{}, + // wantErr: &rerror.Error{ + // Label: id.ErrInvalidKey, + // Err: fmt.Errorf("%s", "_aaaaaaaa"), + // }, + //}, + //{ + // name: "fail 3", + // args: args{key: id.NewKey("-aaaaaaaa")}, + // want: Group{}, + // wantErr: &rerror.Error{ + // Label: id.ErrInvalidKey, + // Err: fmt.Errorf("%s", "-aaaaaaaa"), + // }, + //}, { name: "empty", - args: args{key: key.New("")}, + args: args{key: id.NewKey("")}, want: Group{}, wantErr: &rerror.Error{ Label: id.ErrInvalidKey, diff --git a/server/pkg/group/list_test.go b/server/pkg/group/list_test.go index d1d7ab419..6b2c92985 100644 --- a/server/pkg/group/list_test.go +++ b/server/pkg/group/list_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/stretchr/testify/assert" ) @@ -45,9 +44,9 @@ func TestList_OrderByIDs(t *testing.T) { sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() sid3 := id.NewSchemaID() - group1 := New().NewID().Project(pid).Schema(sid1).Key(key.New("key1")).Order(0).MustBuild() - group2 := New().NewID().Project(pid).Schema(sid2).Key(key.New("key2")).Order(0).MustBuild() - group3 := New().NewID().Project(pid).Schema(sid3).Key(key.New("key3")).Order(0).MustBuild() + group1 := New().NewID().Project(pid).Schema(sid1).Key(id.NewKey("key1")).Order(0).MustBuild() + group2 := New().NewID().Project(pid).Schema(sid2).Key(id.NewKey("key2")).Order(0).MustBuild() + group3 := New().NewID().Project(pid).Schema(sid3).Key(id.NewKey("key3")).Order(0).MustBuild() groups := List{group1, group2, group3} assert.Equal(t, List{group2, group1, group3}, groups.OrderByIDs(id.GroupIDList{group2.ID(), group1.ID(), group3.ID()})) assert.Equal(t, id.ProjectIDList{pid, pid, pid}, groups.Projects()) @@ -55,9 +54,9 @@ func TestList_OrderByIDs(t *testing.T) { func TestList_Ordered(t *testing.T) { pid := id.NewProjectID() - g1 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key1")).Order(0).MustBuild() - g2 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key2")).Order(1).MustBuild() - g3 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key3")).Order(2).MustBuild() + g1 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key1")).Order(0).MustBuild() + g2 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key2")).Order(1).MustBuild() + g3 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key3")).Order(2).MustBuild() groups := List{g3, g1, g2} ordered := groups.Ordered() assert.NotEqual(t, groups, ordered) diff --git a/server/pkg/id/key.go b/server/pkg/id/key.go index ab101c272..5daf3a1a9 100644 --- a/server/pkg/id/key.go +++ b/server/pkg/id/key.go @@ -1,15 +1,14 @@ package id import ( - "github.com/reearth/reearthx/i18n" - "github.com/reearth/reearthx/rerror" "regexp" - "strings" + "slices" "github.com/goombaio/namegenerator" + "github.com/reearth/reearthx/i18n" + "github.com/reearth/reearthx/rerror" "github.com/reearth/reearthx/util" "github.com/samber/lo" - "golang.org/x/exp/slices" ) var ErrInvalidKey = rerror.NewE(i18n.T("invalid key")) @@ -25,9 +24,6 @@ type Key struct { } func NewKey(key string) Key { - if !keyRegexp.MatchString(key) { - return Key{} - } k := Key{key} return k } @@ -42,7 +38,11 @@ func RandomKey() Key { } func (k Key) IsValid() bool { - return k.key != "" && !strings.HasPrefix(k.key, "_") && !strings.HasPrefix(k.key, "-") && !slices.Contains(ngKeys, k.key) + return k.key != "" && !slices.Contains(ngKeys, k.key) // && !strings.HasPrefix(k.key, "_") && !strings.HasPrefix(k.key, "-") +} + +func (k Key) IsURLCompatible() bool { + return k.IsValid() && keyRegexp.MatchString(k.key) } func (k Key) Ref() *Key { diff --git a/server/pkg/id/key_test.go b/server/pkg/id/key_test.go index 667318708..fcddc667f 100644 --- a/server/pkg/id/key_test.go +++ b/server/pkg/id/key_test.go @@ -10,7 +10,8 @@ import ( func TestNewKey(t *testing.T) { assert.Equal(t, Key{key: "aaaaaaa"}, NewKey("aaaaaaa")) assert.Equal(t, Key{key: "aaaa"}, NewKey("aaaa")) - assert.Equal(t, Key{}, NewKey("aaa!@#")) + assert.Equal(t, Key{key: "aaa!@#"}, NewKey("aaa!@#")) + assert.Equal(t, Key{key: "テスト"}, NewKey("テスト")) } func TestRandomKey(t *testing.T) { @@ -25,6 +26,14 @@ func TestKey_IsValid(t *testing.T) { assert.False(t, Key{key: "id"}.IsValid()) } +func TestKey_IsURLCompatible(t *testing.T) { + assert.True(t, Key{key: "aaa"}.IsURLCompatible()) + assert.False(t, Key{}.IsURLCompatible()) + assert.False(t, Key{key: "id"}.IsURLCompatible()) + assert.False(t, Key{key: "#aaa"}.IsURLCompatible()) + assert.False(t, Key{key: "a b"}.IsURLCompatible()) +} + func TestKey_Ref(t *testing.T) { assert.Equal(t, lo.ToPtr(Key{key: "aaa"}), Key{key: "aaa"}.Ref()) } diff --git a/server/pkg/item/item_test.go b/server/pkg/item/item_test.go index 78b4de557..9b8dced53 100644 --- a/server/pkg/item/item_test.go +++ b/server/pkg/item/item_test.go @@ -5,7 +5,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" @@ -266,8 +265,8 @@ func TestItem_SetOriginalItem(t *testing.T) { func TestItem_GetTitle(t *testing.T) { wid := accountdomain.NewWorkspaceID() pid := id.NewProjectID() - sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s1 := schema.New().NewID().Workspace(wid).Project(pid).Fields(schema.FieldList{sf1, sf2}).MustBuild() if1 := NewField(sf1.ID(), value.TypeBool.Value(false).AsMultiple(), nil) if2 := NewField(sf2.ID(), value.TypeText.Value("test").AsMultiple(), nil) @@ -300,13 +299,13 @@ func TestGetFirstGeometryField(t *testing.T) { pid := id.NewProjectID() gst := schema.GeometryObjectSupportedTypeList{schema.GeometryObjectSupportedTypePoint, schema.GeometryObjectSupportedTypeLineString, schema.GeometryObjectSupportedTypePolygon} gest := schema.GeometryEditorSupportedTypeList{schema.GeometryEditorSupportedTypePoint, schema.GeometryEditorSupportedTypeLineString, schema.GeometryEditorSupportedTypePolygon} - sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(key.Random()).MustBuild() - sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(key.Random()).Multiple(true).MustBuild() - sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(key.Random()).MustBuild() + sf1 := schema.NewField(schema.NewGeometryObject(gst).TypeProperty()).NewID().Name("LineString").Key(id.RandomKey()).MustBuild() + sf2 := schema.NewField(schema.NewText(lo.ToPtr(10)).TypeProperty()).NewID().Name("Name").Key(id.RandomKey()).Multiple(true).MustBuild() + sf3 := schema.NewField(schema.NewGeometryEditor(gest).TypeProperty()).NewID().Name("Polygon").Key(id.RandomKey()).MustBuild() in4, _ := schema.NewInteger(lo.ToPtr(int64(1)), lo.ToPtr(int64(100))) tp4 := in4.TypeProperty() - sf4 := schema.NewField(tp4).NewID().Name("Age").Key(key.Random()).MustBuild() - sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(key.Random()).MustBuild() + sf4 := schema.NewField(tp4).NewID().Name("Age").Key(id.RandomKey()).MustBuild() + sf5 := schema.NewField(schema.NewBool().TypeProperty()).NewID().Name("IsMarried").Key(id.RandomKey()).MustBuild() fi1 := NewField(sf1.ID(), value.TypeGeometryObject.Value("{\"coordinates\":[[139.65439725962517,36.34793305387103],[139.61688622815393,35.910803456352724]],\"type\":\"LineString\"}").AsMultiple(), nil) fi2 := NewField(sf2.ID(), value.MultipleFrom(value.TypeText, []*value.Value{value.TypeText.Value("a"), value.TypeText.Value("b"), value.TypeText.Value("c")}), nil) fi3 := NewField(sf3.ID(), value.TypeGeometryEditor.Value("{\"coordinates\": [[[138.90306434425662,36.11737907906834],[138.90306434425662,36.33622175736386],[138.67187898370287,36.33622175736386],[138.67187898370287,36.11737907906834],[138.90306434425662,36.11737907906834]]],\"type\": \"Polygon\"}").AsMultiple(), nil) diff --git a/server/pkg/item/reference_test.go b/server/pkg/item/reference_test.go index 8a888f026..43cda453e 100644 --- a/server/pkg/item/reference_test.go +++ b/server/pkg/item/reference_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/project" "github.com/reearth/reearth-cms/server/pkg/schema" "github.com/reearth/reearth-cms/server/pkg/value" @@ -29,9 +28,9 @@ func Test_AreItemsReferenced(t *testing.T) { Description: "description", Required: true, } - f1 := schema.NewField(schema.NewReference(mid2, sid1, fid2.Ref(), cf1).TypeProperty()).ID(fid1).Key(key.Random()).MustBuild() - f2 := schema.NewField(schema.NewReference(mid1, sid2, fid1.Ref(), cf2).TypeProperty()).ID(fid2).Key(key.Random()).MustBuild() - f3 := schema.NewField(schema.NewReference(mid3, sid3, nil, nil).TypeProperty()).ID(fid3).Key(key.Random()).MustBuild() + f1 := schema.NewField(schema.NewReference(mid2, sid1, fid2.Ref(), cf1).TypeProperty()).ID(fid1).Key(id.RandomKey()).MustBuild() + f2 := schema.NewField(schema.NewReference(mid1, sid2, fid1.Ref(), cf2).TypeProperty()).ID(fid2).Key(id.RandomKey()).MustBuild() + f3 := schema.NewField(schema.NewReference(mid3, sid3, nil, nil).TypeProperty()).ID(fid3).Key(id.RandomKey()).MustBuild() s1 := schema.New().ID(sid1).Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{f1}).MustBuild() s2 := schema.New().ID(sid2).Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{f2}).MustBuild() s3 := schema.New().ID(sid3).Workspace(accountdomain.NewWorkspaceID()).Project(prj.ID()).Fields(schema.FieldList{f3}).MustBuild() diff --git a/server/pkg/key/key.go b/server/pkg/key/key.go deleted file mode 100644 index eaff31293..000000000 --- a/server/pkg/key/key.go +++ /dev/null @@ -1,11 +0,0 @@ -package key - -import ( - "github.com/reearth/reearth-cms/server/pkg/id" -) - -// TODO: completely delete this "key" package -type Key = id.Key - -var New = id.NewKey -var Random = id.RandomKey diff --git a/server/pkg/model/builder.go b/server/pkg/model/builder.go index 1efc169c0..7b52dc1c4 100644 --- a/server/pkg/model/builder.go +++ b/server/pkg/model/builder.go @@ -4,12 +4,11 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" ) type Builder struct { model *Model - k key.Key + k id.Key } func New() *Builder { @@ -75,13 +74,13 @@ func (b *Builder) Description(description string) *Builder { return b } -func (b *Builder) Key(key key.Key) *Builder { +func (b *Builder) Key(key id.Key) *Builder { b.k = key return b } func (b *Builder) RandomKey() *Builder { - b.k = key.Random() + b.k = id.RandomKey() return b } diff --git a/server/pkg/model/builder_test.go b/server/pkg/model/builder_test.go index 6258af644..edee5a1a2 100644 --- a/server/pkg/model/builder_test.go +++ b/server/pkg/model/builder_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" "github.com/stretchr/testify/assert" ) @@ -20,7 +19,7 @@ func TestNew(t *testing.T) { name: "test", want: &Builder{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -41,7 +40,7 @@ func TestBuilder_Build(t *testing.T) { now := time.Now() type fields struct { m *Model - k key.Key + k id.Key } tests := []struct { name string @@ -58,12 +57,12 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, order: 2, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Model{ id: mId, @@ -71,7 +70,7 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, order: 2, @@ -87,11 +86,11 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, // updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Model{ id: mId, @@ -99,7 +98,7 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: mId.Timestamp(), }, @@ -114,11 +113,11 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -132,11 +131,11 @@ func TestBuilder_Build(t *testing.T) { // schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -150,7 +149,7 @@ func TestBuilder_Build(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, @@ -189,7 +188,7 @@ func TestBuilder_MustBuild(t *testing.T) { now := time.Now() type fields struct { m *Model - k key.Key + k id.Key } tests := []struct { name string @@ -206,11 +205,11 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Model{ id: mId, @@ -218,7 +217,7 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, @@ -233,11 +232,11 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, // updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: &Model{ id: mId, @@ -245,7 +244,7 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: mId.Timestamp(), }, @@ -260,11 +259,11 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -278,11 +277,11 @@ func TestBuilder_MustBuild(t *testing.T) { // schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, - k: key.New("T123456"), + k: id.NewKey("T123456"), }, want: nil, wantErr: ErrInvalidID, @@ -296,7 +295,7 @@ func TestBuilder_MustBuild(t *testing.T) { schema: sId, name: "m1", description: "m1 desc", - key: key.New("T123456"), + key: id.NewKey("T123456"), public: false, updatedAt: now, }, @@ -333,7 +332,7 @@ func TestBuilder_MustBuild(t *testing.T) { func TestBuilder_Description(t *testing.T) { type fields struct { model *Model - k key.Key + k id.Key } type args struct { description string @@ -348,7 +347,7 @@ func TestBuilder_Description(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ description: "d1", @@ -357,7 +356,7 @@ func TestBuilder_Description(t *testing.T) { model: &Model{ description: "d1", }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -379,7 +378,7 @@ func TestBuilder_ID(t *testing.T) { mId := NewID() type fields struct { model *Model - k key.Key + k id.Key } type args struct { id ID @@ -394,7 +393,7 @@ func TestBuilder_ID(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ id: mId, @@ -403,7 +402,7 @@ func TestBuilder_ID(t *testing.T) { model: &Model{ id: mId, }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -424,7 +423,7 @@ func TestBuilder_ID(t *testing.T) { func TestBuilder_Public(t *testing.T) { type fields struct { model *Model - k key.Key + k id.Key } type args struct { public bool @@ -439,7 +438,7 @@ func TestBuilder_Public(t *testing.T) { name: "test 1", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ public: true, @@ -448,14 +447,14 @@ func TestBuilder_Public(t *testing.T) { model: &Model{ public: true, }, - k: key.Key{}, + k: id.Key{}, }, }, { name: "test 2", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ public: false, @@ -464,7 +463,7 @@ func TestBuilder_Public(t *testing.T) { model: &Model{ public: false, }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -485,10 +484,10 @@ func TestBuilder_Public(t *testing.T) { func TestBuilder_Key(t *testing.T) { type fields struct { model *Model - k key.Key + k id.Key } type args struct { - key key.Key + key id.Key } tests := []struct { name string @@ -500,14 +499,14 @@ func TestBuilder_Key(t *testing.T) { name: "test 1", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ - key: key.New("123321"), + key: id.NewKey("123321"), }, want: &Builder{ model: &Model{}, - k: key.New("123321"), + k: id.NewKey("123321"), }, }, } @@ -528,7 +527,7 @@ func TestBuilder_Key(t *testing.T) { func TestBuilder_Name(t *testing.T) { type fields struct { model *Model - k key.Key + k id.Key } type args struct { name string @@ -543,7 +542,7 @@ func TestBuilder_Name(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ name: "n1", @@ -552,7 +551,7 @@ func TestBuilder_Name(t *testing.T) { model: &Model{ name: "n1", }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -573,7 +572,7 @@ func TestBuilder_Name(t *testing.T) { func TestBuilder_NewID(t *testing.T) { type fields struct { p *Model - k key.Key + k id.Key } tests := []struct { name string @@ -583,7 +582,7 @@ func TestBuilder_NewID(t *testing.T) { name: "test", fields: fields{ p: &Model{}, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -606,7 +605,7 @@ func TestBuilder_Project(t *testing.T) { pId := id.NewProjectID() type fields struct { model *Model - k key.Key + k id.Key } type args struct { p id.ProjectID @@ -621,7 +620,7 @@ func TestBuilder_Project(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ p: pId, @@ -630,7 +629,7 @@ func TestBuilder_Project(t *testing.T) { model: &Model{ project: pId, }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -651,7 +650,7 @@ func TestBuilder_Project(t *testing.T) { func TestBuilder_RandomKey(t *testing.T) { type fields struct { p *Model - k key.Key + k id.Key } tests := []struct { name string @@ -661,7 +660,7 @@ func TestBuilder_RandomKey(t *testing.T) { name: "test", fields: fields{ p: &Model{}, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -684,7 +683,7 @@ func TestBuilder_Schema(t *testing.T) { sId := id.NewSchemaID() type fields struct { model *Model - k key.Key + k id.Key } type args struct { s id.SchemaID @@ -699,7 +698,7 @@ func TestBuilder_Schema(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ s: sId, @@ -708,7 +707,7 @@ func TestBuilder_Schema(t *testing.T) { model: &Model{ schema: sId, }, - k: key.Key{}, + k: id.Key{}, }, }, } @@ -730,7 +729,7 @@ func TestBuilder_UpdatedAt(t *testing.T) { now := time.Now() type fields struct { model *Model - k key.Key + k id.Key } type args struct { updatedAt time.Time @@ -745,7 +744,7 @@ func TestBuilder_UpdatedAt(t *testing.T) { name: "test", fields: fields{ model: &Model{}, - k: key.Key{}, + k: id.Key{}, }, args: args{ updatedAt: now, @@ -754,7 +753,7 @@ func TestBuilder_UpdatedAt(t *testing.T) { model: &Model{ updatedAt: now, }, - k: key.Key{}, + k: id.Key{}, }, }, } diff --git a/server/pkg/model/list_test.go b/server/pkg/model/list_test.go index d2c2cda34..6eda6eed1 100644 --- a/server/pkg/model/list_test.go +++ b/server/pkg/model/list_test.go @@ -4,8 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" - "github.com/stretchr/testify/assert" ) @@ -46,9 +44,9 @@ func TestList_OrderByIDs(t *testing.T) { sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() sid3 := id.NewSchemaID() - mod1 := New().NewID().Project(pid).Schema(sid1).Key(key.New("key1")).Order(0).MustBuild() - mod2 := New().NewID().Project(pid).Schema(sid2).Key(key.New("key2")).Order(0).MustBuild() - mod3 := New().NewID().Project(pid).Schema(sid3).Key(key.New("key3")).Order(0).MustBuild() + mod1 := New().NewID().Project(pid).Schema(sid1).Key(id.NewKey("key1")).Order(0).MustBuild() + mod2 := New().NewID().Project(pid).Schema(sid2).Key(id.NewKey("key2")).Order(0).MustBuild() + mod3 := New().NewID().Project(pid).Schema(sid3).Key(id.NewKey("key3")).Order(0).MustBuild() mods := List{mod1, mod2, mod3} assert.Equal(t, List{mod2, mod1, mod3}, mods.OrderByIDs(id.ModelIDList{mod2.ID(), mod1.ID(), mod3.ID()})) assert.Equal(t, id.ProjectIDList{pid}, mods.Projects()) @@ -59,9 +57,9 @@ func TestList_Remove(t *testing.T) { sid1 := id.NewSchemaID() sid2 := id.NewSchemaID() sid3 := id.NewSchemaID() - mod1 := New().NewID().Project(pid).Schema(sid1).Key(key.New("key1")).Order(0).MustBuild() - mod2 := New().NewID().Project(pid).Schema(sid2).Key(key.New("key2")).Order(1).MustBuild() - mod3 := New().NewID().Project(pid).Schema(sid3).Key(key.New("key3")).Order(2).MustBuild() + mod1 := New().NewID().Project(pid).Schema(sid1).Key(id.NewKey("key1")).Order(0).MustBuild() + mod2 := New().NewID().Project(pid).Schema(sid2).Key(id.NewKey("key2")).Order(1).MustBuild() + mod3 := New().NewID().Project(pid).Schema(sid3).Key(id.NewKey("key3")).Order(2).MustBuild() mods := List{mod1, mod2, mod3} assert.Equal(t, List{mod1, mod3}, mods.Remove(mod2.ID())) assert.Equal(t, List{mod1, mod2}, mods.Remove(mod3.ID())) @@ -70,12 +68,11 @@ func TestList_Remove(t *testing.T) { func TestList_Ordered(t *testing.T) { pid := id.NewProjectID() - m1 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key1")).Order(0).MustBuild() - m2 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key2")).Order(1).MustBuild() - m3 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(key.New("key3")).Order(2).MustBuild() + m1 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key1")).Order(0).MustBuild() + m2 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key2")).Order(1).MustBuild() + m3 := New().NewID().Project(pid).Schema(id.NewSchemaID()).Key(id.NewKey("key3")).Order(2).MustBuild() models := List{m3, m1, m2} ordered := models.Ordered() assert.NotEqual(t, models, ordered) assert.Equal(t, List{m1, m2, m3}, ordered) } - diff --git a/server/pkg/model/model.go b/server/pkg/model/model.go index 3a1ef10b9..ccd70aeb6 100644 --- a/server/pkg/model/model.go +++ b/server/pkg/model/model.go @@ -2,10 +2,10 @@ package model import ( "fmt" - "github.com/reearth/reearth-cms/server/pkg/id" "time" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" + "github.com/reearth/reearthx/i18n" "github.com/reearth/reearthx/rerror" "golang.org/x/exp/slices" @@ -23,7 +23,7 @@ type Model struct { metadata *SchemaID name string description string - key key.Key + key id.Key public bool updatedAt time.Time order int @@ -65,11 +65,11 @@ func (p *Model) SetDescription(description string) { p.description = description } -func (p *Model) Key() key.Key { +func (p *Model) Key() id.Key { return p.key } -func (p *Model) SetKey(key key.Key) error { +func (p *Model) SetKey(key id.Key) error { if !validateModelKey(key) { return &rerror.Error{ Label: ErrInvalidKey, @@ -129,7 +129,7 @@ func (p *Model) Clone() *Model { } } -func validateModelKey(k key.Key) bool { +func validateModelKey(k id.Key) bool { // assets is used as an API endpoint - return k.IsValid() && len(k.String()) > 2 && !slices.Contains(ngKeys, k.String()) + return k.IsURLCompatible() && len(k.String()) > 2 && !slices.Contains(ngKeys, k.String()) } diff --git a/server/pkg/model/model_test.go b/server/pkg/model/model_test.go index 7b17f97c5..fa24371f8 100644 --- a/server/pkg/model/model_test.go +++ b/server/pkg/model/model_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearthx/rerror" "github.com/stretchr/testify/assert" ) @@ -28,7 +27,7 @@ func TestModel_Clone(t *testing.T) { schema: sId, name: "n1", description: "d1", - key: key.New("123456"), + key: id.NewKey("123456"), public: false, updatedAt: now, order: 2, @@ -141,14 +140,14 @@ func TestModel_Key(t *testing.T) { tests := []struct { name string model Model - want key.Key + want id.Key }{ { name: "test", model: Model{ - key: key.New("123456"), + key: id.NewKey("123456"), }, - want: key.New("123456"), + want: id.NewKey("123456"), }, } for _, tt := range tests { @@ -299,7 +298,7 @@ func TestModel_SetDescription(t *testing.T) { func TestModel_SetKey(t *testing.T) { type args struct { - key key.Key + key id.Key } tests := []struct { name string @@ -309,40 +308,40 @@ func TestModel_SetKey(t *testing.T) { }{ { name: "pass", - args: args{key: key.New("123456")}, - want: Model{key: key.New("123456")}, + args: args{key: id.NewKey("123456")}, + want: Model{key: id.NewKey("123456")}, wantErr: nil, }, { name: "fail", - args: args{key: key.New("a")}, + args: args{key: id.NewKey("a")}, want: Model{}, wantErr: &rerror.Error{ Label: ErrInvalidKey, Err: fmt.Errorf("%s", "a"), }, }, - { - name: "fail 2", - args: args{key: key.New("_aaaaaaaa")}, - want: Model{}, - wantErr: &rerror.Error{ - Label: ErrInvalidKey, - Err: fmt.Errorf("%s", "_aaaaaaaa"), - }, - }, - { - name: "fail 3", - args: args{key: key.New("-aaaaaaaa")}, - want: Model{}, - wantErr: &rerror.Error{ - Label: ErrInvalidKey, - Err: fmt.Errorf("%s", "-aaaaaaaa"), - }, - }, + //{ + // name: "fail 2", + // args: args{key: id.NewKey("_aaaaaaaa")}, + // want: Model{}, + // wantErr: &rerror.Error{ + // Label: ErrInvalidKey, + // Err: fmt.Errorf("%s", "_aaaaaaaa"), + // }, + //}, + //{ + // name: "fail 3", + // args: args{key: id.NewKey("-aaaaaaaa")}, + // want: Model{}, + // wantErr: &rerror.Error{ + // Label: ErrInvalidKey, + // Err: fmt.Errorf("%s", "-aaaaaaaa"), + // }, + //}, { name: "fails assets", - args: args{key: key.New("assets")}, + args: args{key: id.NewKey("assets")}, want: Model{}, wantErr: &rerror.Error{ Label: ErrInvalidKey, @@ -351,7 +350,7 @@ func TestModel_SetKey(t *testing.T) { }, { name: "fails items", - args: args{key: key.New("items")}, + args: args{key: id.NewKey("items")}, want: Model{}, wantErr: &rerror.Error{ Label: ErrInvalidKey, @@ -360,7 +359,7 @@ func TestModel_SetKey(t *testing.T) { }, { name: "empty", - args: args{key: key.New("")}, + args: args{key: id.NewKey("")}, want: Model{}, wantErr: &rerror.Error{ Label: ErrInvalidKey, diff --git a/server/pkg/schema/corresponding_field.go b/server/pkg/schema/corresponding_field.go index e24d80f2d..db7617e0f 100644 --- a/server/pkg/schema/corresponding_field.go +++ b/server/pkg/schema/corresponding_field.go @@ -2,7 +2,6 @@ package schema import ( "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/value" ) @@ -20,7 +19,7 @@ func CreateCorrespondingField(sid id.SchemaID, mid id.ModelID, f *Field, inp Cor Required(inp.Required). Name(inp.Title). Description(inp.Description). - Key(key.New(inp.Key)). + Key(id.NewKey(inp.Key)). DefaultValue(nil). Build() if err != nil { diff --git a/server/pkg/schema/corresponding_field_test.go b/server/pkg/schema/corresponding_field_test.go index e9eb5a5c7..ec3c5b0c8 100644 --- a/server/pkg/schema/corresponding_field_test.go +++ b/server/pkg/schema/corresponding_field_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/stretchr/testify/assert" ) @@ -13,7 +12,7 @@ func TestFieldReferenceFromTypeProperty(t *testing.T) { mid1 := id.NewModelID() sid1 := id.NewSchemaID() fid1 := id.NewFieldID() - f1 := NewField(NewReference(mid1, sid1, nil, nil).TypeProperty()).ID(fid1).Key(key.Random()).MustBuild() + f1 := NewField(NewReference(mid1, sid1, nil, nil).TypeProperty()).ID(fid1).Key(id.RandomKey()).MustBuild() got1, ok := FieldReferenceFromTypeProperty(f1.TypeProperty()) want1 := &FieldReference{ modelID: mid1, @@ -26,7 +25,7 @@ func TestFieldReferenceFromTypeProperty(t *testing.T) { // check that it returns false and nil if type is not reference fid2 := id.NewFieldID() - f2 := NewField(NewText(nil).TypeProperty()).ID(fid2).Key(key.Random()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).ID(fid2).Key(id.RandomKey()).MustBuild() got2, ok := FieldReferenceFromTypeProperty(f2.TypeProperty()) assert.False(t, ok) assert.Nil(t, got2) diff --git a/server/pkg/schema/field.go b/server/pkg/schema/field.go index 83e573a56..05e47e0ef 100644 --- a/server/pkg/schema/field.go +++ b/server/pkg/schema/field.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/i18n" "github.com/reearth/reearthx/rerror" @@ -16,7 +16,7 @@ type Field struct { id FieldID name string description string - key key.Key + key id.Key unique bool multiple bool required bool @@ -74,11 +74,11 @@ func (f *Field) SetDefaultValue(v *value.Multiple) error { return nil } -func (f *Field) Key() key.Key { +func (f *Field) Key() id.Key { return f.key } -func (f *Field) SetKey(key key.Key) error { +func (f *Field) SetKey(key id.Key) error { if !key.IsValid() { return &rerror.Error{ Label: ErrInvalidKey, diff --git a/server/pkg/schema/field_builder.go b/server/pkg/schema/field_builder.go index f8dd7201c..06fbb0f12 100644 --- a/server/pkg/schema/field_builder.go +++ b/server/pkg/schema/field_builder.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/reearth/reearth-cms/server/pkg/key" + "github.com/reearth/reearth-cms/server/pkg/id" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/i18n" "github.com/reearth/reearthx/rerror" @@ -140,13 +140,13 @@ func (b *FieldBuilder) Description(description string) *FieldBuilder { return b } -func (b *FieldBuilder) Key(key key.Key) *FieldBuilder { +func (b *FieldBuilder) Key(key id.Key) *FieldBuilder { b.f.key = key return b } func (b *FieldBuilder) RandomKey() *FieldBuilder { - b.f.key = key.Random() + b.f.key = id.RandomKey() return b } diff --git a/server/pkg/schema/field_builder_test.go b/server/pkg/schema/field_builder_test.go index 05ced59b1..2fbf77d3c 100644 --- a/server/pkg/schema/field_builder_test.go +++ b/server/pkg/schema/field_builder_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/rerror" "github.com/stretchr/testify/assert" @@ -17,12 +16,12 @@ func TestNewField(t *testing.T) { now := time.Now() tp := NewText(nil).TypeProperty() dv := tp.Type().Value("aaa") - id := id.NewFieldID() - k := key.Random() + fId := id.NewFieldID() + k := id.RandomKey() assert.Equal( t, &Field{ - id: id, + id: fId, name: "name", description: "a", key: k, @@ -35,7 +34,7 @@ func TestNewField(t *testing.T) { defaultValue: dv.AsMultiple(), }, NewField(tp). - ID(id). + ID(fId). Name("name"). Description("a"). Key(k). @@ -50,7 +49,7 @@ func TestNewField(t *testing.T) { ) f := NewField(tp). - ID(id). + ID(fId). RandomKey(). Type(tp). MustBuild() diff --git a/server/pkg/schema/field_test.go b/server/pkg/schema/field_test.go index fbbd94feb..311240df1 100644 --- a/server/pkg/schema/field_test.go +++ b/server/pkg/schema/field_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/rerror" "github.com/samber/lo" @@ -70,7 +69,7 @@ func TestField_Clone(t *testing.T) { id: NewFieldID(), name: "a", description: "b", - key: key.Random(), + key: id.RandomKey(), unique: true, multiple: true, required: true, @@ -131,7 +130,7 @@ func TestField_SetOrder(t *testing.T) { func TestField_SetKey(t *testing.T) { f := &Field{} - k := key.Random() + k := id.RandomKey() assert.NoError(t, f.SetKey(k)) assert.Equal(t, &Field{key: k}, f) assert.Equal(t, k, f.Key()) @@ -139,7 +138,7 @@ func TestField_SetKey(t *testing.T) { assert.Equal(t, &rerror.Error{ Label: ErrInvalidKey, Err: fmt.Errorf("%s", ""), - }, f.SetKey(key.New(""))) + }, f.SetKey(id.NewKey(""))) } func TestField_SetTypeProperty(t *testing.T) { diff --git a/server/pkg/schema/list_test.go b/server/pkg/schema/list_test.go index e6dafaa3b..07b7cfbd9 100644 --- a/server/pkg/schema/list_test.go +++ b/server/pkg/schema/list_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/stretchr/testify/assert" ) @@ -44,8 +43,8 @@ func TestList_Schema(t *testing.T) { func TestList_Fields(t *testing.T) { id1 := NewID() id2 := NewID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() list := List{ &Schema{id: id2, fields: FieldList{f2}}, @@ -126,8 +125,8 @@ func TestFieldList_Ordered(t *testing.T) { } func TestFieldList_Find(t *testing.T) { - f := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() assert.Equal(t, f, FieldList{f, f2}.Find(f.ID())) assert.Equal(t, f2, FieldList{f, f2}.Find(f2.ID())) assert.Nil(t, FieldList{f, f2}.Find(NewFieldID())) diff --git a/server/pkg/schema/package_test.go b/server/pkg/schema/package_test.go index 87ac902ad..a4ddd74cc 100644 --- a/server/pkg/schema/package_test.go +++ b/server/pkg/schema/package_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/stretchr/testify/assert" ) @@ -13,9 +12,9 @@ func TestPackage_New(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) @@ -35,9 +34,9 @@ func TestPackage_Schema(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) @@ -53,9 +52,9 @@ func TestPackage_MetaSchema(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) @@ -71,9 +70,9 @@ func TestPackage_GroupSchemas(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) @@ -89,9 +88,9 @@ func TestPackage_GroupSchema(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) @@ -108,9 +107,9 @@ func TestPackage_Field(t *testing.T) { msID := id.NewSchemaID() gsID := id.NewSchemaID() gID := id.NewGroupID() - f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() - f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(key.Random()).MustBuild() + f1 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f2 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() + f3 := NewField(NewText(nil).TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() s := &Schema{id: sID, fields: FieldList{f1}} meta := &Schema{id: msID, fields: FieldList{f2}} groupSchemas := make(map[id.GroupID]*Schema) diff --git a/server/pkg/schema/schema.go b/server/pkg/schema/schema.go index 53acbd1ad..caf891534 100644 --- a/server/pkg/schema/schema.go +++ b/server/pkg/schema/schema.go @@ -4,7 +4,6 @@ import ( "errors" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" "github.com/samber/lo" @@ -87,7 +86,7 @@ func (s *Schema) Field(fId FieldID) *Field { return f } -func (s *Schema) FieldByIDOrKey(fId *FieldID, key *key.Key) *Field { +func (s *Schema) FieldByIDOrKey(fId *FieldID, key *id.Key) *Field { if s == nil || s.fields == nil { return nil } diff --git a/server/pkg/schema/schema_test.go b/server/pkg/schema/schema_test.go index 3b96dcc85..a3c627515 100644 --- a/server/pkg/schema/schema_test.go +++ b/server/pkg/schema/schema_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/reearth/reearth-cms/server/pkg/id" - "github.com/reearth/reearth-cms/server/pkg/key" "github.com/reearth/reearth-cms/server/pkg/value" "github.com/reearth/reearthx/account/accountdomain" "github.com/stretchr/testify/assert" @@ -203,8 +202,8 @@ func TestSchema_Field(t *testing.T) { func TestSchema_FieldByIDOrKey(t *testing.T) { f1 := &Field{id: NewFieldID(), name: "f1"} f2 := &Field{id: NewFieldID(), name: "f2"} - f3 := &Field{id: NewFieldID(), name: "f3", key: key.New("KEY")} - f4 := &Field{id: NewFieldID(), name: "f4", key: key.New("id")} + f3 := &Field{id: NewFieldID(), name: "f3", key: id.NewKey("KEY")} + f4 := &Field{id: NewFieldID(), name: "f4", key: id.NewKey("id")} s := &Schema{fields: []*Field{f1, f2, f3, f4}} assert.Equal(t, f1, s.FieldByIDOrKey(f1.ID().Ref(), nil)) @@ -214,9 +213,9 @@ func TestSchema_FieldByIDOrKey(t *testing.T) { assert.Equal(t, f3, s.FieldByIDOrKey(nil, f3.Key().Ref())) assert.Equal(t, f1, s.FieldByIDOrKey(f1.ID().Ref(), f3.Key().Ref())) assert.Nil(t, s.FieldByIDOrKey(id.NewFieldID().Ref(), nil)) - assert.Nil(t, s.FieldByIDOrKey(nil, key.New("").Ref())) - assert.Nil(t, s.FieldByIDOrKey(nil, key.New("x").Ref())) - assert.Nil(t, s.FieldByIDOrKey(nil, key.New("id").Ref())) + assert.Nil(t, s.FieldByIDOrKey(nil, id.NewKey("").Ref())) + assert.Nil(t, s.FieldByIDOrKey(nil, id.NewKey("x").Ref())) + assert.Nil(t, s.FieldByIDOrKey(nil, id.NewKey("id").Ref())) } func TestSchema_Fields(t *testing.T) { @@ -403,7 +402,7 @@ func TestSchema_TitleField(t *testing.T) { } func TestSchema_SetTitleField(t *testing.T) { - sf := NewField(NewBool().TypeProperty()).NewID().Key(key.Random()).MustBuild() + sf := NewField(NewBool().TypeProperty()).NewID().Key(id.RandomKey()).MustBuild() f := []*Field{sf} s := New().NewID().Project(id.NewProjectID()).Workspace(accountdomain.NewWorkspaceID()).Fields(f).MustBuild() @@ -453,13 +452,13 @@ func TestSchema_HasFieldByKey(t *testing.T) { }, { name: "add on not empty array", - s: &Schema{fields: []*Field{{id: fid1, name: "f1", key: key.New("K123123")}}}, + s: &Schema{fields: []*Field{{id: fid1, name: "f1", key: id.NewKey("K123123")}}}, fKey: "K123123", want: true, }, { name: "add duplicated field", - s: &Schema{fields: []*Field{{id: fid1, name: "f1", key: key.New("K123123")}, {id: fid2, name: "f2", key: key.New("K111222")}, {id: fid3, name: "f3", key: key.New("K123111")}}}, + s: &Schema{fields: []*Field{{id: fid1, name: "f1", key: id.NewKey("K123123")}, {id: fid2, name: "f2", key: id.NewKey("K111222")}, {id: fid3, name: "f3", key: id.NewKey("K123111")}}}, fKey: "K123123", want: true, }, From aec7b82b12dfa402013aa0063b175c1f02a342ad Mon Sep 17 00:00:00 2001 From: Nour Balaha Date: Wed, 16 Oct 2024 14:59:52 +0900 Subject: [PATCH 9/9] fix(web): download button is not showing (#1262) fix: download button is not showing --- web/src/components/molecules/Asset/Asset/AssetBody/Asset.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/molecules/Asset/Asset/AssetBody/Asset.tsx b/web/src/components/molecules/Asset/Asset/AssetBody/Asset.tsx index e998212d6..023bbcfcd 100644 --- a/web/src/components/molecules/Asset/Asset/AssetBody/Asset.tsx +++ b/web/src/components/molecules/Asset/Asset/AssetBody/Asset.tsx @@ -178,7 +178,7 @@ const AssetMolecule: React.FC = ({ /> )} - +