using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; using System; using System.Data; using System.Net; using REPORT_API_ver6.Services; using REPORT_API_ver6.Models; using Microsoft.AspNetCore.Cors; namespace REPORT_API_ver6.Controllers { [Route("api/v1/project")] [ApiController] public class ProjectAPI : ControllerBase { HttpContextAccessor hcAccessor = new HttpContextAccessor(); [Route("list")] [HttpGet] public IActionResult GetProjectList([FromHeader] string token) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); DataTable resultTable = project.getProjectList(userInfo.Team, userInfo.ID, userInfo.IsAdmin); string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("list/{intranetCd}/{gkey}/{isKiwi}")] [HttpGet] public IActionResult GetProjectList ( [FromHeader(Name = "token")] string? token, [FromHeader(Name = "X-API-Key")] string? xApiKey, [FromRoute] string intranetCd, [FromRoute] string gkey, [FromRoute] int isKiwi, [FromQuery(Name = "keyword")] string keyword = "" ) { var configuration = Common.GetConfiguration(); var apikey = configuration.GetSection("X-API-Key")[xApiKey ?? ""]; UserInfo? userInfo = String.IsNullOrEmpty(token)? null : Security.ValidateToken(token); if (userInfo != null || !String.IsNullOrEmpty(apikey)) { intranetCd = intranetCd.Split("_")[0]; Project project = new Project(); DataTable resultTable = project.getProjectList(intranetCd, gkey, isKiwi, keyword); string returnString = Common.GetJsonFromObject(resultTable); hcAccessor.HttpContext.Response.ContentType = "application/json"; Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("assign")] [HttpGet] public IActionResult GetAssignList([FromHeader] string token) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "text/plain"; Project project = new Project(); string returnString = project.getAssignCount(userInfo.ID).ToString(); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("last")] [HttpGet] public IActionResult GetStateCount([FromHeader] string token) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); DataTable resultTable = project.lastProjectCount(userInfo.Team, userInfo.ID, userInfo.IsAdmin, 6); string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("custom/progress")] [HttpGet] public IActionResult GetCustomProgress([FromHeader] string token, [FromHeader] string skey) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); var konReportTable = project.getKonReportURL(pkeyInfo.Pkey, pkeyInfo.isKiwi); var includeFileTable = project.projectIncludeFiles(pkeyInfo.Pkey, pkeyInfo.isKiwi); DataTable resultTable = includeFileTable.Clone(); if (konReportTable.Rows.Count > 0) { string progressURL = konReportTable.Rows[0]["file_name"].ToString(); if (progressURL.IndexOf("http") < 0) { progressURL = "https://kon.kric.com" + progressURL; } resultTable.Rows.Add(new object[] { 0, 1, progressURL }); } for (int i = 0; i < includeFileTable.Rows.Count; i++) { string realFileName = string.Empty; string appendType = includeFileTable.Rows[i]["append_type"].ToString(); if (appendType == "0") { realFileName = Common.MapPath(includeFileTable.Rows[i]["file_name"].ToString()); } else { realFileName = includeFileTable.Rows[i]["file_name"].ToString(); } if (System.IO.File.Exists(realFileName) || appendType != "0") { var addRowArray = includeFileTable.Rows[i].ItemArray; resultTable.Rows.Add(addRowArray); } } string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("progress/type")] [HttpGet] public IActionResult GetTypeByState([FromHeader] string token, [FromHeader] string skey, [FromHeader] string selectDate) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); DataTable resultTable = project.getTypeByState(pkeyInfo.Pkey, pkeyInfo.isKiwi, selectDate); string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("progress/loi")] [HttpGet] public IActionResult GetLOI([FromHeader] string token, [FromHeader] string skey, [FromHeader] string selectDate) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); DataTable resultTable = project.getLOI(pkeyInfo.Pkey, pkeyInfo.isKiwi, selectDate); string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("progress/day")] [HttpGet] public IActionResult GetDayByState([FromHeader] string token, [FromHeader] string skey) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); DataTable resultTable = project.getDayByState(pkeyInfo.Pkey, pkeyInfo.isKiwi); string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("progress/screen")] [HttpGet] public IActionResult GetQidByScreen([FromHeader] string token, [FromHeader] string skey, [FromHeader] string selectDate) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); DataTable resultTable = project.getQidByScreen(pkeyInfo.Pkey, pkeyInfo.isKiwi, selectDate); string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("question/{qid}")] [HttpGet] public IActionResult GetQuestionListWithQID([FromHeader] string token, [FromHeader] string skey, string qid) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); DataTable resultTable = project.getQuestionList(pkeyInfo.Pkey, qid, pkeyInfo.isKiwi, userInfo.IsAdmin); string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("question")] [HttpGet] public IActionResult GetQuestionList([FromHeader] string token, [FromHeader] string skey) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); DataTable resultTable = project.getQuestionList(pkeyInfo.Pkey, "", pkeyInfo.isKiwi, userInfo.IsAdmin); string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("quota")] [HttpGet] public IActionResult GetQuotaList([FromHeader] string token, [FromHeader] string skey) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); DataTable resultTable = project.getQuotaList(pkeyInfo.Pkey, pkeyInfo.isKiwi); string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("bookmark/{page}")] [HttpGet] public IActionResult GetBookmarkList([FromHeader] string token, [FromHeader] string skey, string page) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); DataTable resultTable = project.getBookmark(pkeyInfo.Pkey, page, userInfo.Team, userInfo.ID); string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("bookmark/create")] [HttpPost] public IActionResult CreateBookmark([FromHeader] string token, [FromBody] BookmarkParam bookmarkParam, [FromHeader] string skey) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "text/plain"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); string returnString = project.insertBookmark(pkeyInfo.Pkey, bookmarkParam, userInfo.Team, userInfo.ID); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("bookmark/update")] [HttpPost] public IActionResult UpdateBookmark([FromHeader] string token, [FromBody] BookmarkParam bookmarkParam, [FromHeader] string skey) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "text/plain"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); string returnString = project.updateBookmark(pkeyInfo.Pkey, bookmarkParam, userInfo.Team, userInfo.ID); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("bookmark/delete/{bookmarkID}")] [HttpPost] public IActionResult DeleteBookmark([FromHeader] string token, [FromHeader] string skey, string bookmarkID) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "text/plain"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); string returnString = project.deleteBookmark(pkeyInfo.Pkey, bookmarkID, userInfo.ID); if (returnString.IndexOf("오류") > -1) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; } else { Response.StatusCode = (int)HttpStatusCode.OK; } return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("derived")] [HttpGet] public IActionResult GetDerivedList([FromHeader] string token, [FromHeader] string skey) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "application/json"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); DataTable resultTable = project.getOnlyDerivedList(pkeyInfo.Pkey, pkeyInfo.isKiwi, userInfo.Team, userInfo.IsAdmin); string returnString = Common.GetJsonFromObject(resultTable); Response.StatusCode = (int)HttpStatusCode.OK; return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("derived/all")] [HttpPost] public IActionResult UpdateAllDerivedVariable([FromHeader] string token, [FromHeader] string skey) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "text/plain"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); string returnString = project.updateAllDerived(pkeyInfo.Pkey, pkeyInfo.isKiwi, userInfo.ID); if(returnString.IndexOf("오류") > -1) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; } else { Response.StatusCode = (int)HttpStatusCode.OK; } return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("derived/create")] [HttpPost] public IActionResult CreateDerivedVariable([FromHeader] string token, [FromBody] DerivedParam derivedParam, [FromHeader] string skey) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "text/plain"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); string returnString = project.insertDerivedVariable(pkeyInfo.Pkey, pkeyInfo.isKiwi, derivedParam, userInfo.Team, userInfo.ID); if (returnString.IndexOf("오류") > -1) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; } else { Response.StatusCode = (int)HttpStatusCode.OK; } return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("derived/update")] [HttpPost] public IActionResult UpdateDerivedVariable([FromHeader] string token, [FromBody] DerivedParam derivedParam, [FromHeader] string skey) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "text/plain"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); string returnString = project.updateDerivedVariable(pkeyInfo.Pkey, pkeyInfo.isKiwi, derivedParam, userInfo.Team, userInfo.ID); if (returnString.IndexOf("오류") > -1) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; } else { Response.StatusCode = (int)HttpStatusCode.OK; } return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("derived/delete/{variableID}")] [HttpPost] public IActionResult DeleteDerived([FromHeader] string token, [FromHeader] string skey, string variableID) { UserInfo userInfo = Security.ValidateToken(token); if (userInfo != null) { hcAccessor.HttpContext.Response.ContentType = "text/plain"; Project project = new Project(); PkeyInfo pkeyInfo = new PkeyInfo(skey); variableID = variableID.Split('_')[0].ToUpper(); string returnString = project.deleteDerivedVariable(pkeyInfo.Pkey, pkeyInfo.isKiwi, variableID, userInfo.ID); if (returnString.IndexOf("오류") > -1) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; } else { Response.StatusCode = (int)HttpStatusCode.OK; } return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } [Route("derived/{iskiwi}/{pkey}/{idkey}")] [HttpPost] public IActionResult CreateDerivedData(string iskiwi,string pkey, string idkey) { hcAccessor.HttpContext.Response.ContentType = "text/plain"; if (Common.IsNumeric(iskiwi)) { Project project = new Project(); string returnString = project.setDerivedDataWithID(pkey, Convert.ToInt32(iskiwi), idkey); if (returnString.IndexOf("오류") > -1) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; } else { Response.StatusCode = (int)HttpStatusCode.OK; } return Content(returnString); } Response.StatusCode = (int)HttpStatusCode.Unauthorized; return Content(null); } } }