feat: frontend

This commit is contained in:
2025-11-17 21:07:51 -07:00
parent dd0ab39985
commit e1396e2d24
87 changed files with 13616 additions and 148 deletions

View File

@@ -35,7 +35,7 @@ func CreateOrder(pool *pgxpool.Pool) gin.HandlerFunc {
if user_query_err != nil {
log.Printf("CreateOrder(): ERROR Failed to query user... %s", user_query_err.Error())
ctx.String(http.StatusInternalServerError, "CreateOrder(): ERROR Failed to query user")
ctx.JSON(http.StatusInternalServerError, "CreateOrder(): ERROR Failed to query user")
return
}
@@ -44,7 +44,7 @@ func CreateOrder(pool *pgxpool.Pool) gin.HandlerFunc {
date_placed := ctx.Query("date_placed")
if orderer == "" || date_due == "" {
ctx.String(http.StatusBadRequest, "CreateOrder(): ERROR orderer or date_due not supplied")
ctx.JSON(http.StatusBadRequest, "CreateOrder(): ERROR orderer or date_due not supplied")
return
}
@@ -55,20 +55,20 @@ func CreateOrder(pool *pgxpool.Pool) gin.HandlerFunc {
_, placed_date_err := time.Parse(time.RFC3339, date_placed)
if placed_date_err != nil {
ctx.String(http.StatusBadRequest, "CreateOrder(): Bad time format")
ctx.JSON(http.StatusBadRequest, "CreateOrder(): Bad time format")
return
}
_, due_date_err := time.Parse(time.RFC3339, date_due)
if due_date_err != nil {
ctx.String(http.StatusBadRequest, "CreateOrder(): Bad Time format")
ctx.JSON(http.StatusBadRequest, "CreateOrder(): Bad Time format")
return
}
_, exec_err := conn.Exec(context.Background(), queries.CREATE_ORDER, current_user.Id, orderer, date_due, date_placed)
if exec_err != nil {
ctx.String(http.StatusInternalServerError, "CreateOrder(): Failed to create order")
ctx.JSON(http.StatusInternalServerError, "CreateOrder(): Failed to create order")
log.Printf("CreateOrder(): ERROR... Failed to create order... %s", exec_err.Error())
return
}
@@ -76,7 +76,7 @@ func CreateOrder(pool *pgxpool.Pool) gin.HandlerFunc {
var order dto.OrderResponse
order_query_err := conn.QueryRow(context.Background(), queries.GET_TOTAL_ORDER_FROM_ORDER_INFORMATION, current_user.Id, orderer, date_placed).Scan(&order.Id, &order.UserId, &order.Orderer, &order.DateDue, &order.DatePlaced, &order.AmountPaid, &order.OrderTotal, &order.AmountDue, &order.Filled, &order.Delivered)
if order_query_err != nil {
ctx.String(http.StatusInternalServerError, "CreateOrder(): Failed to create order")
ctx.JSON(http.StatusInternalServerError, "CreateOrder(): Failed to create order")
log.Printf("CreateOrder(): ERROR... failed to query order after creation ... %s", order_query_err.Error())
return
}
@@ -98,7 +98,7 @@ func GetOrderByOrderId(pool *pgxpool.Pool) gin.HandlerFunc {
order_id := ctx.Query("order_id")
_, order_id_parse_err := strconv.ParseInt(order_id, 10, 64)
if order_id == "" || order_id_parse_err != nil {
ctx.String(http.StatusBadRequest, "GetOrderByOrderId(): ERROR... order_id not valid")
ctx.JSON(http.StatusBadRequest, "GetOrderByOrderId(): ERROR... order_id not valid")
return
}
@@ -110,10 +110,10 @@ func GetOrderByOrderId(pool *pgxpool.Pool) gin.HandlerFunc {
if scan_err != nil {
if scan_err == pgx.ErrNoRows {
ctx.String(http.StatusBadRequest, "GetOrderByOrderId(): ERROR... no order matches the query")
ctx.JSON(http.StatusBadRequest, "GetOrderByOrderId(): ERROR... no order matches the query")
return
}
ctx.String(http.StatusInternalServerError, "GetOrderByOrderId(): ERROR... internal server error")
ctx.JSON(http.StatusInternalServerError, "GetOrderByOrderId(): ERROR... internal server error")
log.Printf("GetOrderByOrderId(): ERROR... Failed to scan row... %s", scan_err.Error())
return
}
@@ -135,7 +135,7 @@ func GetOrderTable(pool *pgxpool.Pool) gin.HandlerFunc {
page := ctx.Query("page")
page_int, page_parse_err := strconv.ParseInt(page, 10, 64)
if page == "" || page_parse_err != nil {
ctx.String(http.StatusBadRequest, "GetOrderTable(): Invalid page number")
ctx.JSON(http.StatusBadRequest, "GetOrderTable(): Invalid page number")
return
}
@@ -143,21 +143,21 @@ func GetOrderTable(pool *pgxpool.Pool) gin.HandlerFunc {
bind_err := ctx.ShouldBindJSON(&table_query)
if bind_err != nil {
ctx.String(http.StatusBadRequest, "GetOrderTable(): ERROR... invalid query")
ctx.JSON(http.StatusBadRequest, "GetOrderTable(): ERROR... invalid query")
return
}
filter := ctx.Query("filter")
filter_int, filter_parse_err := strconv.ParseInt(filter, 10, 64)
if filter == "" || filter_parse_err != nil {
ctx.String(http.StatusBadRequest, "GetOrderTable(): Invalid Filter Options")
ctx.JSON(http.StatusBadRequest, "GetOrderTable(): Invalid Filter Options")
return
}
query_string := utils.GetOrderTableQueryString(filter_int)
rows, query_err := conn.Query(context.Background(), query_string, utils.PAGE_SIZE*page_int, utils.PAGE_SIZE, table_query.Orderer, table_query.DateDue, table_query.DatePlaced)
if query_err != nil {
ctx.String(http.StatusInternalServerError, "GetOrdertable(): ERROR... internal server error")
ctx.JSON(http.StatusInternalServerError, "GetOrdertable(): ERROR... internal server error")
log.Printf("GetOrderTable(): ERROR... Failed to query table...\nQUERY: %s\n %s", query_string, query_err.Error())
return
}
@@ -168,7 +168,7 @@ func GetOrderTable(pool *pgxpool.Pool) gin.HandlerFunc {
var order_response dto.OrderResponse
scan_err := rows.Scan(&order_response.Id, &order_response.UserId, &order_response.Orderer, &order_response.DateDue, &order_response.DatePlaced, &order_response.AmountPaid, &order_response.OrderTotal, &order_response.AmountDue, &order_response.Filled, &order_response.Delivered)
if scan_err != nil {
ctx.String(http.StatusInternalServerError, "GetOrdertable(): ERROR... internal server error")
ctx.JSON(http.StatusInternalServerError, "GetOrdertable(): ERROR... internal server error")
log.Printf("GetOrderTable(): ERROR... Failed to scan query... %s", scan_err.Error())
return
}
@@ -193,13 +193,13 @@ func DeleteOrder(pool *pgxpool.Pool) gin.HandlerFunc {
order_id := ctx.Query("order_id")
order_id_int, parse_err := strconv.ParseInt(order_id, 10, 64)
if parse_err != nil {
ctx.String(http.StatusBadRequest, "DeleteOrder(): Invalid input")
ctx.JSON(http.StatusBadRequest, "DeleteOrder(): Invalid input")
return
}
_, exec_err := conn.Exec(context.Background(), "DELETE FROM order_record WHERE id = $1", order_id_int)
if exec_err != nil {
ctx.String(http.StatusInternalServerError, "DeleteOrder(): ERROR... failed to delete order")
ctx.JSON(http.StatusInternalServerError, "DeleteOrder(): ERROR... failed to delete order")
log.Printf("DeleteOrder(): ERROR... Failed to delete order %s", exec_err.Error())
return
}