From a7cc51d3580f0f1b0812baf3a63e55318af2018c Mon Sep 17 00:00:00 2001
From: zachmann <gabriel.zachmann@kit.edu>
Date: Mon, 22 Aug 2022 16:33:24 +0200
Subject: [PATCH] improve code

---
 internal/db/dbrepo/mytokenrepo/tree/tree.go  | 12 ++++++------
 internal/endpoints/consent/pkg/capability.go |  3 +++
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/internal/db/dbrepo/mytokenrepo/tree/tree.go b/internal/db/dbrepo/mytokenrepo/tree/tree.go
index ea7d0db4..2384f787 100644
--- a/internal/db/dbrepo/mytokenrepo/tree/tree.go
+++ b/internal/db/dbrepo/mytokenrepo/tree/tree.go
@@ -25,7 +25,7 @@ type MytokenEntry struct {
 
 // MytokenEntryTree is a tree of MytokenEntry
 type MytokenEntryTree struct {
-	Token    MytokenEntry       `json:"token"`
+	Token    *MytokenEntry      `json:"token"`
 	Children []MytokenEntryTree `json:"children,omitempty"`
 }
 
@@ -64,7 +64,7 @@ func TokenSubTree(rlog log.Ext1FieldLogger, tx *sqlx.Tx, tokenID mtid.MTID) (Myt
 			break
 		}
 	}
-	tree, _ := tokensToTree(root, tokens)
+	tree, _ := tokensToTree(&root, tokens)
 	return tree, nil
 }
 
@@ -81,26 +81,26 @@ func tokensToTrees(tokens []MytokenEntry) (trees []MytokenEntryTree) {
 	}
 	var tmp MytokenEntryTree
 	for _, r := range roots {
-		tmp, tokens = tokensToTree(r, tokens)
+		tmp, tokens = tokensToTree(&r, tokens)
 		trees = append(trees, tmp)
 	}
 	return
 }
 
-func tokensToTree(root MytokenEntry, tokens []MytokenEntry) (MytokenEntryTree, []MytokenEntry) {
+func tokensToTree(root *MytokenEntry, tokens []MytokenEntry) (MytokenEntryTree, []MytokenEntry) {
 	tree := MytokenEntryTree{
 		Token: root,
 	}
 	children := popChildren(root, &tokens)
 	var cTree MytokenEntryTree
 	for _, c := range children {
-		cTree, tokens = tokensToTree(c, tokens)
+		cTree, tokens = tokensToTree(&c, tokens)
 		tree.Children = append(tree.Children, cTree)
 	}
 	return tree, tokens
 }
 
-func popChildren(root MytokenEntry, tokens *[]MytokenEntry) (children []MytokenEntry) {
+func popChildren(root *MytokenEntry, tokens *[]MytokenEntry) (children []MytokenEntry) {
 	i := 0
 	for i < len(*tokens) {
 		t := (*tokens)[i]
diff --git a/internal/endpoints/consent/pkg/capability.go b/internal/endpoints/consent/pkg/capability.go
index 9cb3a13c..8cbcf263 100644
--- a/internal/endpoints/consent/pkg/capability.go
+++ b/internal/endpoints/consent/pkg/capability.go
@@ -168,11 +168,13 @@ func (c webCapability) getDangerLevel() int {
 }
 
 // ColorClass returns the html class for coloring this Capability
+// skipcq: CRT-P0003
 func (c webCapability) ColorClass() string {
 	return textColorByDanger(c.getDangerLevel())
 }
 
 // CapabilityLevel returns a string describing the power of this capability
+// skipcq: CRT-P0003
 func (c webCapability) CapabilityLevel() string {
 	intClass := c.getIntClass()
 	switch intClass {
@@ -187,6 +189,7 @@ func (c webCapability) CapabilityLevel() string {
 }
 
 // IsCreateMT checks if this WebCapability is api.CapabilityCreateMT
+// skipcq: CRT-P0003
 func (c WebCapability) IsCreateMT() bool {
 	return c.ReadWriteCapability.Name == api.CapabilityCreateMT.Name
 }
-- 
GitLab