feat: finish back-end work (untested)
This commit is contained in:
@@ -31,7 +31,7 @@ func CreateOrder(pool *pgxpool.Pool) gin.HandlerFunc {
|
||||
|
||||
var current_user dto.UserResponse
|
||||
|
||||
user_query_err := conn.QueryRow(context.Background(), queries.GET_CURRENT_USER_OBJECT, sub_id).Scan(¤t_user.Id, ¤t_user.Name, ¤t_user.Job_Position, ¤t_user.Active, ¤t_user.Admin)
|
||||
user_query_err := conn.QueryRow(context.Background(), queries.GET_CURRENT_USER_OBJECT, sub_id).Scan(¤t_user.Id, ¤t_user.Name, ¤t_user.JobPosition, ¤t_user.Active, ¤t_user.Admin)
|
||||
|
||||
if user_query_err != nil {
|
||||
log.Printf("CreateOrder(): ERROR Failed to query user... %s", user_query_err.Error())
|
||||
@@ -139,6 +139,14 @@ func GetOrderTable(pool *pgxpool.Pool) gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
var table_query dto.OrderTableQuery
|
||||
|
||||
bind_err := ctx.ShouldBindJSON(&table_query)
|
||||
if bind_err != nil {
|
||||
ctx.String(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 {
|
||||
@@ -147,7 +155,7 @@ func GetOrderTable(pool *pgxpool.Pool) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
query_string := utils.GetOrderTableQueryString(filter_int)
|
||||
rows, query_err := conn.Query(context.Background(), query_string, utils.PAGE_SIZE*page_int, utils.PAGE_SIZE)
|
||||
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")
|
||||
log.Printf("GetOrderTable(): ERROR... Failed to query table...\nQUERY: %s\n %s", query_string, query_err.Error())
|
||||
@@ -172,8 +180,28 @@ func GetOrderTable(pool *pgxpool.Pool) gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func SetOrderFilled(pool *pgxpool.Pool) gin.HandlerFunc {
|
||||
func DeleteOrder(pool *pgxpool.Pool) gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
conn, conn_err := pool.Acquire(ctx)
|
||||
if conn_err != nil {
|
||||
log.Printf("DeleteOrder(): ERROR: Failed to connect... %s", conn_err.Error())
|
||||
ctx.AbortWithStatus(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer conn.Release()
|
||||
|
||||
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")
|
||||
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")
|
||||
log.Printf("DeleteOrder(): ERROR... Failed to delete order %s", exec_err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user