/*
   Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   SPDX-License-Identifier: Apache-2.0
*/
package com.aws.rest;

import org.springframework.stereotype.Component;
import software.amazon.awssdk.services.redshiftdata.model.ExecuteStatementResponse;
import software.amazon.awssdk.services.redshiftdata.model.RedshiftDataException;
import software.amazon.awssdk.services.redshiftdata.model.SqlParameter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Component
public class InjectWorkService {


    public String injectNewSubmission(WorkItem item) {
        try {
            String name = item.getName();
            String guide = item.getGuide();
            String description = item.getDescription();
            String status = item.getStatus();
            String archived = "0";

            UUID uuid = UUID.randomUUID();
            String workId = uuid.toString();

            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
            LocalDateTime now = LocalDateTime.now();
            String sDate1 = dtf.format(now);
            Date date1 = new SimpleDateFormat("yyyy/MM/dd").parse(sDate1);
            java.sql.Date sqlDate = new java.sql.Date(date1.getTime());

            String sql = "INSERT INTO work (idwork, username, date, description, guide, status, archive) VALUES" +
                "(:idwork, :username, :date, :description, :guide, :status, :archive);";
            List<SqlParameter> paremeters = List.of(
                param("idwork", workId),
                param("username", name),
                param("date", sqlDate.toString()),
                param("description", description),
                param("guide", guide),
                param("status", status),
                param("archive", archived)
            );

            ExecuteStatementResponse result = App.execute(sql, paremeters);
            System.out.println(result.toString());
            return workId;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    SqlParameter param(String name, String value) {
        return SqlParameter.builder().name(name).value(value).build();
    }

    public String modifySubmission(String id, String desc, String status) {
        try {
            App.execute(
                "UPDATE Work SET description = :description, status = :status WHERE idwork = :idwork;",
                List.of(
                   param("idwork", id),
                   param("description", desc),
                   param("status", status)
                )
            );
            return id;

        } catch (RedshiftDataException e) {
            e.printStackTrace();
        }
        return "";
    }
}
@@ -2428,567 +2428,7 @@
  %7D%0D%0A
+%7D
 %0D%0A
-    public String modifySubmission(String id, String desc, String status) %7B%0D%0A        try %7B%0D%0A            App.execute(%0D%0A                %22UPDATE Work SET description = :description, status = :status WHERE idwork = :idwork;%22,%0D%0A                List.of(%0D%0A                   param(%22idwork%22, id),%0D%0A                   param(%22description%22, desc),%0D%0A                   param(%22status%22, status)%0D%0A                )%0D%0A            );%0D%0A            return id;%0D%0A%0D%0A        %7D catch (RedshiftDataException e) %7B%0D%0A            e.printStackTrace();%0D%0A        %7D%0D%0A        return %22%22;%0D%0A    %7D%0D%0A%7D

Update InjectWorkService.java