88 lines
3.0 KiB
Java
88 lines
3.0 KiB
Java
package com.goldenchart.controller;
|
|
|
|
import com.goldenchart.dto.StrategyDto;
|
|
import com.goldenchart.service.StrategyConditionTimeframeService;
|
|
import com.goldenchart.service.StrategyService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 투자전략 CRUD REST API.
|
|
*
|
|
* <p>헤더:
|
|
* <ul>
|
|
* <li>X-Device-Id — 비회원 기기 식별자 (필수)</li>
|
|
* <li>X-User-Id — 회원 ID (선택)</li>
|
|
* </ul>
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/strategies")
|
|
@RequiredArgsConstructor
|
|
public class StrategyController {
|
|
|
|
private final StrategyService service;
|
|
private final StrategyConditionTimeframeService conditionTimeframes;
|
|
|
|
/** 전략 목록 조회 */
|
|
@GetMapping
|
|
public ResponseEntity<List<StrategyDto>> list(
|
|
@RequestHeader Map<String, String> headers) {
|
|
long uid = TradingControllerSupport.requireRegisteredUser(headers);
|
|
return ResponseEntity.ok(service.list(uid, null));
|
|
}
|
|
|
|
/** 단일 전략 조회 */
|
|
@GetMapping("/{id}")
|
|
public ResponseEntity<StrategyDto> get(
|
|
@PathVariable Long id,
|
|
@RequestHeader Map<String, String> headers) {
|
|
TradingControllerSupport.requireRegisteredUser(headers);
|
|
return service.findById(id)
|
|
.map(ResponseEntity::ok)
|
|
.orElse(ResponseEntity.notFound().build());
|
|
}
|
|
|
|
/** 전략 저장 (id 없으면 생성, 있으면 수정) */
|
|
@PostMapping
|
|
public ResponseEntity<StrategyDto> save(
|
|
@RequestBody StrategyDto dto,
|
|
@RequestHeader Map<String, String> headers) {
|
|
long uid = TradingControllerSupport.requireRegisteredUser(headers);
|
|
return ResponseEntity.ok(service.save(dto, uid, null));
|
|
}
|
|
|
|
/** 전략 DSL에 포함된 평가 시간봉 목록 */
|
|
@GetMapping("/{id}/timeframes")
|
|
public ResponseEntity<List<String>> timeframes(
|
|
@PathVariable Long id,
|
|
@RequestHeader Map<String, String> headers) {
|
|
TradingControllerSupport.requireRegisteredUser(headers);
|
|
return ResponseEntity.ok(conditionTimeframes.collectForStrategyList(id));
|
|
}
|
|
|
|
/** TIMEFRAME 래핑 누락 DSL 보정 (3분봉 전략이 1분봉으로 평가되는 경우) */
|
|
@PostMapping("/{id}/repair-timeframes")
|
|
public ResponseEntity<StrategyDto> repairTimeframes(
|
|
@PathVariable Long id,
|
|
@RequestHeader Map<String, String> headers) {
|
|
TradingControllerSupport.requireRegisteredUser(headers);
|
|
return service.repairTimeframeWrappers(id)
|
|
.map(ResponseEntity::ok)
|
|
.orElse(ResponseEntity.notFound().build());
|
|
}
|
|
|
|
/** 전략 삭제 */
|
|
@DeleteMapping("/{id}")
|
|
public ResponseEntity<Void> delete(
|
|
@PathVariable Long id,
|
|
@RequestHeader Map<String, String> headers) {
|
|
TradingControllerSupport.requireRegisteredUser(headers);
|
|
service.delete(id);
|
|
return ResponseEntity.noContent().build();
|
|
}
|
|
}
|