ocket8888 commented on a change in pull request #5071:
URL: https://github.com/apache/trafficcontrol/pull/5071#discussion_r501960916



##########
File path: traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
##########
@@ -20,451 +22,843 @@ package request
  */
 
 import (
+       "database/sql"
+       "encoding/json"
        "errors"
        "fmt"
-       
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/util/ims"
        "net/http"
-       "strconv"
+       "strings"
        "time"
 
+       
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/util/ims"
+
        "github.com/apache/trafficcontrol/lib/go-log"
+       "github.com/apache/trafficcontrol/lib/go-rfc"
        "github.com/apache/trafficcontrol/lib/go-tc"
        "github.com/apache/trafficcontrol/lib/go-util"
        "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
-       "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/auth"
        
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+       
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/deliveryservice"
+       
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/routing/middleware"
        "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/tenant"
 
        "github.com/jmoiron/sqlx"
+       "github.com/lib/pq"
 )
 
-// TODeliveryServiceRequest is the type alias to define functions on
-type TODeliveryServiceRequest struct {
-       api.APIInfoImpl `json:"-"`
-       tc.DeliveryServiceRequestNullable
-}
+const selectQuery = `
+SELECT
+       a.username AS author,
+       e.username AS lastEditedBy,
+       s.username AS assignee,
+       r.assignee_id,
+       r.author_id,
+       r.change_type,
+       r.created_at,
+       r.id,
+       r.last_edited_by_id,
+       r.last_updated,
+       r.deliveryservice,
+       r.original,
+       r.status
+FROM deliveryservice_request r
+JOIN tm_user a ON r.author_id = a.id
+LEFT OUTER JOIN tm_user s ON r.assignee_id = s.id
+LEFT OUTER JOIN tm_user e ON r.last_edited_by_id = e.id
+`
 
-func (v *TODeliveryServiceRequest) SetLastUpdated(t tc.TimeNoMod) { 
v.LastUpdated = &t }
-func (v *TODeliveryServiceRequest) InsertQuery() string           { return 
insertRequestQuery() }
-func (v *TODeliveryServiceRequest) UpdateQuery() string           { return 
updateRequestQuery() }
-func (v *TODeliveryServiceRequest) DeleteQuery() string {
-       return `DELETE FROM deliveryservice_request WHERE id = :id`
-}
+const originalsQuery = deliveryservice.SelectDeliveryServicesQuery + `
+WHERE ds.id = ANY(:ids)
+`
 
-func (req TODeliveryServiceRequest) GetKeyFieldsInfo() []api.KeyFieldInfo {
-       return []api.KeyFieldInfo{{"id", api.GetIntKey}}
-}
+const insertQuery = `
+INSERT INTO deliveryservice_request (
+       assignee_id,
+       author_id,
+       change_type,
+       last_edited_by_id,
+       deliveryservice,
+       original,
+       status
+) VALUES (
+       $1,
+       $2,
+       $3,
+       $2,
+       $4,
+       $5,
+       $6
+)
+RETURNING
+       id,
+       last_updated,
+       created_at
+`
 
-func (req TODeliveryServiceRequest) GetKeys() (map[string]interface{}, bool) {
-       if req.ID == nil {
-               return map[string]interface{}{"id": 0}, false
-       }
-       return map[string]interface{}{"id": *req.ID}, true
-}
+const updateQuery = `
+UPDATE deliveryservice_request
+SET
+       assignee_id = $1,
+       change_type = $2,
+       last_edited_by_id = $3,
+       deliveryservice = $4,
+       original = $5,
+       status = $6
+WHERE id = $7
+RETURNING
+       last_updated,
+       created_at
+`
 
-func (req *TODeliveryServiceRequest) SetKeys(keys map[string]interface{}) {
-       i, _ := keys["id"].(int) //this utilizes the non panicking type 
assertion, if the thrown away ok variable is false i will be the zero of the 
type, 0 here.
-       req.ID = &i
-}
+const deleteQuery = `
+DELETE
+FROM deliveryservice_request
+WHERE id=$1
+`
 
-// GetAuditName is part of the tc.Identifier interface
-func (req TODeliveryServiceRequest) GetAuditName() string {
-       return req.getXMLID()
+//TODO: figure out how to modify 'AddTenancyCheck' so this isn't necessary
+const customTenancyCheck = `(
+       CASE r.change_type
+       WHEN 'delete' THEN CAST(r.original->>'tenantId' AS bigint) = 
ANY(CAST(:accessibleTenants AS bigint[]))
+       ELSE CAST(r.deliveryservice->>'tenantId' AS bigint) = 
ANY(CAST(:accessibleTenants AS bigint[]))

Review comment:
       Eh. I've seen types go both ways, but I don't really care which way we 
go, so I'll change it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to