메뉴 추가 및 spotless 적용
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.kamco.cd.kamcoback.menu;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kamco.cd.kamcoback.common.utils.UserUtil;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiLogFunction;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.menu.dto.MenuDto;
|
||||
@@ -11,17 +10,14 @@ import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Tag(name = "메뉴 관리", description = "메뉴 관리 API")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/menu")
|
||||
@@ -68,43 +64,4 @@ public class MenuApiController {
|
||||
|
||||
return ApiResponseDto.ok(ApiLogFunction.getUriMenuInfo(result, apiUri));
|
||||
}
|
||||
|
||||
@Operation(summary = "권한별 메뉴 레디스 저장", description = "권한별 메뉴 레디스 저장")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "201",
|
||||
description = "등록 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = MenuDto.Basic.class))),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@PostMapping("/auth")
|
||||
public ApiResponseDto<String> getFindByRoleRedis() {
|
||||
menuService.getFindByRoleRedis();
|
||||
return ApiResponseDto.createOK("ok");
|
||||
}
|
||||
|
||||
@Operation(summary = "권한별 메뉴 조회", description = "로그인 권한별 메뉴 목록")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "조회 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = MenuDto.Basic.class))),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@GetMapping("/auth")
|
||||
public ApiResponseDto<List<MenuDto.Basic>> getFindAllByRole() {
|
||||
UserUtil userUtil = new UserUtil();
|
||||
String role = userUtil.getRole();
|
||||
return ApiResponseDto.ok(menuService.getFindByRole(role));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.kamco.cd.kamcoback.menu;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.utils.UserUtil;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.menu.dto.MenuDto;
|
||||
import com.kamco.cd.kamcoback.menu.dto.MyMenuDto;
|
||||
import com.kamco.cd.kamcoback.menu.service.MyMenuService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Tag(name = "메뉴 조회", description = "메뉴 조회 API")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/my/menus")
|
||||
public class MyMenuApiController {
|
||||
|
||||
private final MyMenuService myMenuService;
|
||||
|
||||
@Operation(summary = "사용자별 메뉴 조회", description = "로그인 사용자별 권한 메뉴 목록")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "조회 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = MenuDto.Basic.class))),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@GetMapping
|
||||
public ApiResponseDto<List<MyMenuDto.Basic>> getFindAllByRole() {
|
||||
UserUtil userUtil = new UserUtil();
|
||||
String role = userUtil.getRole();
|
||||
return ApiResponseDto.ok(myMenuService.getFindByRole(role));
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.kamco.cd.kamcoback.menu;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/my/menus")
|
||||
public class MyMenusApiController {}
|
||||
29
src/main/java/com/kamco/cd/kamcoback/menu/dto/MyMenuDto.java
Normal file
29
src/main/java/com/kamco/cd/kamcoback/menu/dto/MyMenuDto.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.kamco.cd.kamcoback.menu.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
public class MyMenuDto {
|
||||
|
||||
@Schema(name = "My Menu Basic", description = "사용자별 권한 메뉴 목록")
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
public static class Basic {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String menuUrl;
|
||||
private Long order;
|
||||
private List<Basic> children = new ArrayList<>();
|
||||
|
||||
public Basic(String menuUid, String menuNm, String menuUrl, Long menuOrder) {
|
||||
this.id = menuUid;
|
||||
this.name = menuNm;
|
||||
this.menuUrl = menuUrl;
|
||||
this.order = menuOrder;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
package com.kamco.cd.kamcoback.menu.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kamco.cd.kamcoback.common.enums.RoleType;
|
||||
import com.kamco.cd.kamcoback.common.utils.UserUtil;
|
||||
import com.kamco.cd.kamcoback.menu.dto.MenuDto;
|
||||
import com.kamco.cd.kamcoback.postgres.core.MenuCoreService;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
@@ -27,60 +23,4 @@ public class MenuService {
|
||||
public List<MenuDto.Basic> getFindAll() {
|
||||
return menuCoreService.getFindAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 권한별 메뉴 목록 redis 등록
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public void getFindByRoleRedis() {
|
||||
|
||||
for (RoleType role : RoleType.values()) {
|
||||
List<MenuDto.Basic> menus = menuCoreService.getFindByRole(role.name());
|
||||
|
||||
try {
|
||||
String key = "menu:role:" + role.name();
|
||||
String value = objectMapper.writeValueAsString(menus);
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
List<MenuDto.MenuWithRolesDto> menusWithRoles = menuCoreService.getMenuWithRoles();
|
||||
|
||||
try {
|
||||
String key = "auth:api:role";
|
||||
String value = objectMapper.writeValueAsString(menusWithRoles);
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 권한별 메뉴 목록 조회
|
||||
*
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
public List<MenuDto.Basic> getFindByRole(String role) {
|
||||
String key = "menu:role:" + role;
|
||||
String json = redisTemplate.opsForValue().get(key);
|
||||
if (json == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
JavaType type =
|
||||
objectMapper.getTypeFactory().constructCollectionType(List.class, MenuDto.Basic.class);
|
||||
|
||||
List<MenuDto.Basic> cached;
|
||||
|
||||
try {
|
||||
cached = objectMapper.readValue(json, type);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.kamco.cd.kamcoback.menu.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.menu.dto.MyMenuDto;
|
||||
import com.kamco.cd.kamcoback.postgres.core.MenuCoreService;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
public class MyMenuService {
|
||||
|
||||
private final MenuCoreService menuCoreService;
|
||||
|
||||
/**
|
||||
* 권한별 메뉴 목록 조회
|
||||
*
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
public List<MyMenuDto.Basic> getFindByRole(String role) {
|
||||
return menuCoreService.getFindByRole(role);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user