메뉴 목록 가져오는 로직 추가, demo api url 삭제
This commit is contained in:
@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
@Tag(name = "변화탐지", description = "변화탐지 API")
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping({"/api/change-detection", "/demo/api/change-detection"})
|
||||
@RequestMapping({"/api/change-detection"})
|
||||
@Transactional
|
||||
public class ChangeDetectionApiController {
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.kamco.cd.kamcoback.menu;
|
||||
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.menu.dto.MenuDto;
|
||||
import com.kamco.cd.kamcoback.menu.service.MenuService;
|
||||
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 lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "메뉴 관리", description = "메뉴 관리 API")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/menu")
|
||||
public class MenuApiController {
|
||||
|
||||
private final MenuService menuService;
|
||||
|
||||
@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<MenuDto.Basic>> getFindAll() {
|
||||
return ApiResponseDto.ok(menuService.getFindAll());
|
||||
}
|
||||
}
|
||||
67
src/main/java/com/kamco/cd/kamcoback/menu/dto/MenuDto.java
Normal file
67
src/main/java/com/kamco/cd/kamcoback/menu/dto/MenuDto.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.kamco.cd.kamcoback.menu.dto;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public class MenuDto {
|
||||
|
||||
@Schema(name = "Menu Basic", description = "메뉴 기본 정보")
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
public static class Basic {
|
||||
|
||||
private String menuUid;
|
||||
private String menuNm;
|
||||
private String menuUrl;
|
||||
private String description;
|
||||
private Long menuOrder;
|
||||
private Boolean isUse;
|
||||
private Boolean deleted;
|
||||
private Long createdUid;
|
||||
private Long updatedUid;
|
||||
|
||||
private List<MenuDto.Basic> children;
|
||||
|
||||
@JsonFormatDttm
|
||||
private ZonedDateTime createdDttm;
|
||||
|
||||
@JsonFormatDttm
|
||||
private ZonedDateTime updatedDttm;
|
||||
|
||||
private String menuApiUrl;
|
||||
|
||||
public Basic(
|
||||
String menuUid,
|
||||
String menuNm,
|
||||
String menuUrl,
|
||||
String description,
|
||||
Long menuOrder,
|
||||
Boolean isUse,
|
||||
Boolean deleted,
|
||||
Long createdUid,
|
||||
Long updatedUid,
|
||||
List<MenuDto.Basic> children,
|
||||
ZonedDateTime createdDttm,
|
||||
ZonedDateTime updatedDttm,
|
||||
String menuApiUrl) {
|
||||
this.menuUid = menuUid;
|
||||
this.menuNm = menuNm;
|
||||
this.menuUrl = menuUrl;
|
||||
this.description = description;
|
||||
this.menuOrder = menuOrder;
|
||||
this.isUse = isUse;
|
||||
this.deleted = deleted;
|
||||
this.createdUid = createdUid;
|
||||
this.updatedUid = updatedUid;
|
||||
this.children = children;
|
||||
this.createdDttm = createdDttm;
|
||||
this.updatedDttm = updatedDttm;
|
||||
this.menuApiUrl = menuApiUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.kamco.cd.kamcoback.menu.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.menu.dto.MenuDto;
|
||||
import com.kamco.cd.kamcoback.postgres.core.MenuCoreService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MenuService {
|
||||
private final MenuCoreService menuCoreService;
|
||||
|
||||
@Cacheable(value = "menuFindAll")
|
||||
public List<MenuDto.Basic> getFindAll(){
|
||||
return menuCoreService.getFindAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.menu.dto.MenuDto;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MenuEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.menu.MenuRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MenuCoreService {
|
||||
|
||||
private final MenuRepository menuRepository;
|
||||
|
||||
public List<MenuDto.Basic> getFindAll() {
|
||||
return menuRepository.getFindAll().stream().map(MenuEntity::toDto).toList();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import com.kamco.cd.kamcoback.menu.dto.MenuDto;
|
||||
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -47,4 +48,25 @@ public class MenuEntity extends CommonDateEntity {
|
||||
|
||||
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||
private List<MenuEntity> children = new ArrayList<>();
|
||||
|
||||
@Column(name = "menu_api_uri")
|
||||
private String menuApiUri;
|
||||
|
||||
public MenuDto.Basic toDto(){
|
||||
return new MenuDto.Basic(
|
||||
this.menuUid,
|
||||
this.menuNm,
|
||||
this.menuUrl,
|
||||
this.description,
|
||||
this.menuOrder,
|
||||
this.isUse,
|
||||
this.deleted,
|
||||
this.createdUid,
|
||||
this.updatedUid,
|
||||
this.children.stream().map(MenuEntity::toDto).toList(),
|
||||
this.getCreatedDate(),
|
||||
this.getModifiedDate(),
|
||||
this.menuApiUri
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.menu;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MenuEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface MenuRepository extends JpaRepository<MenuEntity, String>, MenuRepositoryCustom {}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.menu;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MenuEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MenuRepositoryCustom {
|
||||
|
||||
List<MenuEntity> getFindAll();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.menu;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MenuEntity;
|
||||
import com.querydsl.core.types.dsl.Expressions;
|
||||
import com.querydsl.core.types.dsl.StringExpression;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QMenuEntity.menuEntity;
|
||||
|
||||
public class MenuRepositoryImpl extends QuerydslRepositorySupport implements MenuRepositoryCustom {
|
||||
|
||||
private final JPAQueryFactory queryFactory;
|
||||
private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");
|
||||
|
||||
public MenuRepositoryImpl(JPAQueryFactory queryFactory) {
|
||||
super(MenuEntity.class);
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuEntity> getFindAll() {
|
||||
return queryFactory
|
||||
.selectFrom(menuEntity)
|
||||
.where(menuEntity.deleted.isFalse())
|
||||
.fetch();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user