package com.pms.controller; import java.util.HashMap; import java.util.List; import java.util.Map; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.pms.service.TableManagementService; /** * 테이블 관리 API 컨트롤러 */ @RestController @RequestMapping("/table-management") public class TableManagementController { @Autowired private TableManagementService tableManagementService; /** * 테이블 목록 조회 */ @GetMapping("/tables") public ResponseEntity> getTableList(HttpServletRequest request) { try { List> tableList = tableManagementService.getTableList(); Map response = new HashMap<>(); response.put("success", true); response.put("data", tableList); response.put("message", "테이블 목록을 성공적으로 조회했습니다."); return ResponseEntity.ok(response); } catch (Exception e) { Map response = new HashMap<>(); response.put("success", false); response.put("message", "테이블 목록 조회 중 오류가 발생했습니다: " + e.getMessage()); return ResponseEntity.badRequest().body(response); } } /** * 테이블 컬럼 정보 조회 */ @GetMapping("/tables/{tableName}/columns") public ResponseEntity> getColumnList( HttpServletRequest request, @PathVariable String tableName) { try { List> columns = tableManagementService.getColumnList(tableName); Map response = new HashMap<>(); response.put("success", true); response.put("data", columns); response.put("message", "컬럼 목록을 성공적으로 조회했습니다."); return ResponseEntity.ok(response); } catch (Exception e) { Map response = new HashMap<>(); response.put("success", false); response.put("message", "컬럼 목록 조회 중 오류가 발생했습니다: " + e.getMessage()); return ResponseEntity.badRequest().body(response); } } @PostMapping("/tables/{tableName}/columns/{columnName}/settings") public ResponseEntity> updateColumnSettings( HttpServletRequest request, @PathVariable String tableName, @PathVariable String columnName, @RequestBody Map settings) { try { tableManagementService.updateColumnSettings(tableName, columnName, settings); Map response = new HashMap<>(); response.put("success", true); response.put("message", "컬럼 설정을 성공적으로 저장했습니다."); return ResponseEntity.ok(response); } catch (Exception e) { Map response = new HashMap<>(); response.put("success", false); response.put("message", "컬럼 설정 저장 중 오류가 발생했습니다: " + e.getMessage()); return ResponseEntity.badRequest().body(response); } } @PostMapping("/tables/{tableName}/columns/settings") public ResponseEntity> updateAllColumnSettings( HttpServletRequest request, @PathVariable String tableName, @RequestBody List> columnSettings) { try { tableManagementService.updateAllColumnSettings(tableName, columnSettings); Map response = new HashMap<>(); response.put("success", true); response.put("message", "모든 컬럼 설정을 성공적으로 저장했습니다."); return ResponseEntity.ok(response); } catch (Exception e) { Map response = new HashMap<>(); response.put("success", false); response.put("message", "컬럼 설정 저장 중 오류가 발생했습니다: " + e.getMessage()); return ResponseEntity.badRequest().body(response); } } }