Kaynağa Gözat

Create container

wfansh 6 ay önce
ebeveyn
işleme
e9cf475e18

+ 30 - 0
src/main/java/com/wechi/adweb/bridge/google/gtm/controller/GTMController.java

@@ -6,6 +6,7 @@ import com.wechi.adweb.bridge.common.OpenAPIRequest;
 import com.wechi.adweb.bridge.common.OpenAPIResponse;
 import com.wechi.adweb.bridge.exception.BadRequestException;
 import com.wechi.adweb.bridge.exception.DataException;
+import com.wechi.adweb.bridge.google.gtm.dto.CreateContainerRequestDTO;
 import com.wechi.adweb.bridge.google.gtm.dto.GTMAccountDTO;
 import com.wechi.adweb.bridge.google.gtm.dto.GTMContainerDTO;
 import com.wechi.adweb.bridge.google.gtm.service.GTMService;
@@ -70,6 +71,35 @@ public class GTMController extends BaseController {
                 .build();
     }
 
+    @PostMapping("/containers/create")
+    @ResponseBody
+    public OpenAPIResponse<GTMContainerDTO> createContainer(
+            @RequestBody OpenAPIRequest<CreateContainerRequestDTO> apiRequest)
+            throws BadRequestException, DataException {
+        long start = System.currentTimeMillis();
+        log.info("****** createContainer() ****** apiRequest = {}", JsonUtils.toJson(apiRequest));
+        CreateContainerRequestDTO createContainerRequest = apiRequest.getData();
+
+        // 1. Validates the request parameters.
+        if (StringUtils.isEmpty(createContainerRequest.getAccountResourceName())
+                || StringUtils.isEmpty(createContainerRequest.getDisplayName())
+                || StringUtils.isEmpty(createContainerRequest.getGoogleTagId())) {
+            throw new BadRequestException(apiRequest);
+        }
+
+        // 2. Executes the API request.
+        GTMContainerDTO gtmContainer =
+                gtmService.createContainer(
+                        createContainerRequest.getAccountResourceName(),
+                        createContainerRequest.getDisplayName(),
+                        createContainerRequest.getGoogleTagId());
+        log.info("****** createContainer() ****** duration = {} seconds", getElapsedSeconds(start));
+        return OpenAPIResponse.<GTMContainerDTO>builder()
+                .status(APIStatus.SUCCESS)
+                .data(gtmContainer)
+                .build();
+    }
+
     @PostMapping("/containers/delete")
     @ResponseBody
     public OpenAPIResponse<String> deleteContainer(@RequestBody OpenAPIRequest<String> apiRequest)

+ 16 - 0
src/main/java/com/wechi/adweb/bridge/google/gtm/dto/CreateContainerRequestDTO.java

@@ -0,0 +1,16 @@
+package com.wechi.adweb.bridge.google.gtm.dto;
+
+import lombok.Data;
+
+/**
+ * @author wfansh
+ */
+@Data
+public class CreateContainerRequestDTO {
+
+    private String accountResourceName;
+
+    private String displayName;
+
+    private String googleTagId;
+}