diff --git a/src/main/java/com/easysoftware/adapter/query/OEPackageQueryAdapter.java b/src/main/java/com/easysoftware/adapter/query/OEPackageQueryAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..efb4e53ad2a164e76560b34270659a112685021e --- /dev/null +++ b/src/main/java/com/easysoftware/adapter/query/OEPackageQueryAdapter.java @@ -0,0 +1,45 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ +package com.easysoftware.adapter.query; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.easysoftware.application.oepackage.dto.OEPackageSearchCondition; +import com.easysoftware.application.oepackage.OEPackageService; +import com.easysoftware.common.aop.RequestLimitRedis; + +import jakarta.validation.Valid; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; + +@RestController +@RequestMapping("/oepkg") +public class OEPackageQueryAdapter { + /** + * Autowired service for handling OEpackage-related operations. + */ + @Autowired + private OEPackageService oEPackageService; + + /** + * Endpoint to search for OEpackages based on the provided search condition. + * + * @param condition The search condition for querying OEpackages. + * @return ResponseEntity. + */ + @GetMapping() + @RequestLimitRedis() + public ResponseEntity searchOEpkg(@Valid final OEPackageSearchCondition condition) { + return oEPackageService.searchOEPkg(condition); + } +} diff --git a/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java b/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java index f031537e1963acce57889f7f69f6f2b028a601b4..5d84989f6d6af925613c635b2c9aa16ba622ab9f 100644 --- a/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java +++ b/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java @@ -26,6 +26,7 @@ import com.easysoftware.application.filedapplication.dto.FiledApplicationSerachC import com.easysoftware.application.filedapplication.vo.EulerLifeCycleVo; import com.easysoftware.application.filedapplication.vo.FiledApplicationVo; import com.easysoftware.application.oepackage.dto.OEPackageSearchCondition; +import com.easysoftware.application.oepackage.vo.OEPackageMenuVo; import com.easysoftware.application.rpmpackage.RPMPackageService; import com.easysoftware.application.rpmpackage.dto.RPMPackageSearchCondition; import com.easysoftware.application.rpmpackage.vo.RPMPackageDetailVo; @@ -303,7 +304,7 @@ public class FieldApplicationServiceImpl implements FieldApplicationService { Map map = oePkgGateway.queryMenuByName(oep); Long total = (Long) map.get("total"); - List list = (List) map.get("list"); + List list = (List) map.get("list"); if (total == 0 || list.size() == 0) { throw new NoneResException("the rpm package does not exist"); diff --git a/src/main/java/com/easysoftware/application/oepackage/OEPackageServiceImpl.java b/src/main/java/com/easysoftware/application/oepackage/OEPackageServiceImpl.java index 498cf8335f992739752a506f9a97cd8c6696eb33..48ebb1eaa0234dd5f5c6de1312378ee868321298 100644 --- a/src/main/java/com/easysoftware/application/oepackage/OEPackageServiceImpl.java +++ b/src/main/java/com/easysoftware/application/oepackage/OEPackageServiceImpl.java @@ -23,9 +23,11 @@ import com.easysoftware.common.exception.NoneResException; import com.easysoftware.common.exception.ParamErrorException; import com.easysoftware.common.utils.ResultUtil; import com.easysoftware.domain.oepackage.gateway.OEPackageGateway; +import org.springframework.stereotype.Service; import jakarta.annotation.Resource; +@Service public class OEPackageServiceImpl implements OEPackageService { /** @@ -46,13 +48,13 @@ public class OEPackageServiceImpl implements OEPackageService { throw new ParamErrorException("the pkgid can not be null"); } - List rpmList = oEPkgGateway.queryDetailByPkgId(condition.getPkgId()); - if (rpmList.isEmpty()) { + List oepList = oEPkgGateway.queryDetailByPkgId(condition.getPkgId()); + if (oepList.isEmpty()) { throw new NoneResException("the oe package does not exist"); } Map res = Map.ofEntries( - Map.entry("total", rpmList.size()), - Map.entry("list", rpmList)); + Map.entry("total", oepList.size()), + Map.entry("list", oepList)); return ResultUtil.success(HttpStatus.OK, res); } diff --git a/src/test/java/com/easysoftware/adapter/query/OEPackageQueryAdapterTest.java b/src/test/java/com/easysoftware/adapter/query/OEPackageQueryAdapterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c6afcc53a61741ebf48f1a302b72a950a0554d6a --- /dev/null +++ b/src/test/java/com/easysoftware/adapter/query/OEPackageQueryAdapterTest.java @@ -0,0 +1,39 @@ +package com.easysoftware.adapter.query; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.context.WebApplicationContext; + +import com.easysoftware.common.entity.ResultVo; +import com.easysoftware.common.utils.CommonUtil; +import com.easysoftware.domain.oepackage.gateway.OEPackageGateway; + +public class OEPackageQueryAdapterTest { + @Autowired + private WebApplicationContext webApplicationContext; + private MockMvc mockMvc; + + @MockBean + private OEPackageGateway gateway; + + @BeforeEach + public void setUp() throws Exception { + mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + } + + // test /oepkg + @Test + void test_rpm() throws Exception { + MultiValueMap paramMap = new LinkedMultiValueMap<>(); + paramMap.add("name", "grafana"); + paramMap.add("os", "openEuler-20.03-LTS-SP1"); + ResultVo res = CommonUtil.executeGet(mockMvc, "/oepkg", paramMap); + CommonUtil.assertList(res); + } +}