feat: admin settings (accounts, system, notification, audit)
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package com.srsystem.controller;
|
||||
|
||||
import com.srsystem.entity.SystemConfig;
|
||||
import com.srsystem.repository.SystemConfigRepository;
|
||||
import com.srsystem.dto.ApiResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/admin/config")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
@RequiredArgsConstructor
|
||||
public class SystemConfigController {
|
||||
|
||||
private final SystemConfigRepository repository;
|
||||
|
||||
@GetMapping
|
||||
public ApiResponse<List<SystemConfig>> getAll() {
|
||||
return ApiResponse.ok(repository.findAll());
|
||||
}
|
||||
|
||||
@GetMapping("/{key}")
|
||||
public ApiResponse<SystemConfig> getByKey(@PathVariable String key) {
|
||||
return repository.findByConfigKey(key)
|
||||
.map(ApiResponse::ok)
|
||||
.orElse(ApiResponse.error("설정을 찾을 수 없습니다: " + key));
|
||||
}
|
||||
|
||||
@PutMapping("/{key}")
|
||||
public ApiResponse<SystemConfig> update(@PathVariable String key, @RequestBody Map<String, String> body) {
|
||||
String value = body.get("configValue");
|
||||
if (value == null) {
|
||||
return ApiResponse.error("configValue가 필요합니다.");
|
||||
}
|
||||
SystemConfig config = repository.findByConfigKey(key).orElse(null);
|
||||
if (config == null) {
|
||||
config = SystemConfig.builder().configKey(key).createdAt(LocalDateTime.now()).build();
|
||||
}
|
||||
config.setConfigValue(value);
|
||||
config.setUpdatedAt(LocalDateTime.now());
|
||||
return ApiResponse.ok(repository.save(config));
|
||||
}
|
||||
|
||||
@PutMapping("/batch")
|
||||
public ApiResponse<List<SystemConfig>> batchUpdate(@RequestBody Map<String, String> entries) {
|
||||
entries.forEach((k, v) -> {
|
||||
SystemConfig config = repository.findByConfigKey(k).orElse(null);
|
||||
if (config == null) {
|
||||
config = SystemConfig.builder().configKey(k).createdAt(LocalDateTime.now()).build();
|
||||
}
|
||||
config.setConfigValue(v);
|
||||
config.setUpdatedAt(LocalDateTime.now());
|
||||
repository.save(config);
|
||||
});
|
||||
return ApiResponse.ok(repository.findAll());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.srsystem.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "tb_system_config")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class SystemConfig {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_system_config")
|
||||
@SequenceGenerator(name = "seq_system_config", allocationSize = 50)
|
||||
@Column(name = "config_id")
|
||||
private Long configId;
|
||||
|
||||
@Column(name = "config_key", nullable = false, unique = true, length = 100)
|
||||
private String configKey;
|
||||
|
||||
@Column(name = "config_value", columnDefinition = "TEXT")
|
||||
private String configValue;
|
||||
|
||||
@Column(name = "description", length = 255)
|
||||
private String description;
|
||||
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.srsystem.repository;
|
||||
|
||||
import com.srsystem.entity.SystemConfig;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface SystemConfigRepository extends JpaRepository<SystemConfig, Long> {
|
||||
Optional<SystemConfig> findByConfigKey(String configKey);
|
||||
}
|
||||
Reference in New Issue
Block a user