Refactor: Use create service for REST API

What does this MR do and why?

Refactor Environments REST API to use Environments::CreateService. This will improve consistency because GraphQL API uses the service already, and in this way we can have the same logic in one place.

Why we refactor this now is because we want to set a default value for auto_stop_setting. By refactoring this, we can add a new logic only to the create service, and it will take effect to both REST API and GraphQL.

For more details, see: !181746 (comment 2354846816).

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Set up GDK.
  2. Create environment.

Validation error:

$ curl curl \
-X POST \
--header "PRIVATE-TOKEN: $TOKEN" \
--data "name=deploy5" \
"https://gdk.test:3443/api/v4/projects/35/environments" | jq

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    85  100    73  100    12    748    123 --:--:-- --:--:-- --:--:--   876
{
  "message": [
    "Name has already been taken",
    "Slug has already been taken"
  ]
}

Successful case:

$ curl \
-X POST \
--header "PRIVATE-TOKEN: $TOKEN" \
--data "name=deploy8" \
"https://gdk.test:3443/api/v4/projects/35/environments" | jq

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1236  100  1224  100    12   1252     12  0:00:01 --:--:--  0:00:01  1263
{
  "id": 58,
  "name": "deploy8",
  "slug": "deploy8",
  "external_url": null,
  "created_at": "2025-02-25T03:57:12.858Z",
  "updated_at": "2025-02-25T03:57:12.858Z",
  "tier": "other",
...
Edited by Taka Nishida

Merge request reports

Loading