MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / updateProjectTableRules

Function updateProjectTableRules

cmd/cql-proxy/api/project.go:1162–1224  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

1160}
1161
1162func updateProjectTableRules(c *gin.Context) {
1163 r := struct {
1164 DB proto.DatabaseID `json:"db" json:"project" form:"db" form:"project" uri:"db" uri:"project" binding:"required,len=64"`
1165 Table string `json:"table" form:"table" uri:"table" binding:"required,max=128"`
1166 Rules json.RawMessage `json:"rules"`
1167 }{}
1168
1169 _ = c.ShouldBindUri(&r)
1170
1171 if err := c.ShouldBind(&r); err != nil {
1172 abortWithError(c, http.StatusBadRequest, err)
1173 return
1174 }
1175
1176 _, projectDB, err := getProjectDB(c, r.DB)
1177 if err != nil {
1178 _ = c.Error(err)
1179 abortWithError(c, http.StatusForbidden, ErrLoadProjectDatabaseFailed)
1180 return
1181 }
1182
1183 rulesCtx, err := getRulesContext(r.DB, projectDB)
1184 if err != nil {
1185 _ = c.Error(err)
1186 abortWithError(c, http.StatusInternalServerError, ErrGetProjectRulesFailed)
1187 return
1188 }
1189
1190 var (
1191 pc *model.ProjectConfig
1192 ptc *model.ProjectTableConfig
1193 ok bool
1194 )
1195
1196 if pc, ok = rulesCtx.tables[r.Table]; ok {
1197 ptc = pc.Value.(*model.ProjectTableConfig)
1198 ptc.Rules = r.Rules
1199 rulesCtx.toUpdate = pc
1200 } else {
1201 _ = c.Error(err)
1202 abortWithError(c, http.StatusInternalServerError, ErrTableNotExists)
1203 return
1204 }
1205
1206 if _, err = populateRulesContext(c, rulesCtx); err != nil {
1207 _ = c.Error(err)
1208 abortWithError(c, http.StatusBadRequest, ErrPopulateProjectRulesFailed)
1209 return
1210 }
1211
1212 responseWithData(c, http.StatusOK, gin.H{
1213 "project": r.DB,
1214 "db": r.DB,
1215 "table": r.Table,
1216 "created": formatUnixTime(pc.Created),
1217 "last_updated": formatUnixTime(pc.LastUpdated),
1218 "columns": ptc.Columns,
1219 "types": ptc.Types,

Callers

nothing calls this directly

Calls 7

abortWithErrorFunction · 0.85
getProjectDBFunction · 0.85
getRulesContextFunction · 0.85
populateRulesContextFunction · 0.85
responseWithDataFunction · 0.85
formatUnixTimeFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected