package com.example.test.rest_controllers;

import java.io.IOException;

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;
import org.springframework.web.multipart.MultipartFile;

import com.example.test.services.ModelHandleService;

@RestController
@RequestMapping("/api")
public class OpenModelController {
	
	private final ModelHandleService modelService;
	
	OpenModelController(ModelHandleService oms){
		this.modelService = oms;
	}

	@PostMapping("/open_model")
	public void openModel(@RequestParam("file") MultipartFile file, @RequestParam("session_id") String sessionId) {
		try {
			modelService.openModel(file.getInputStream(), sessionId);
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}
	
	@PostMapping("/open_model_text")
	public void openModel(@RequestParam("model_text") String modelText, @RequestParam("session_id") String sessionId) {
		System.out.println(modelText);
		modelService.openModel(modelText, sessionId);
	}
	
	
	
	
}




