Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions backend/Controllers/Task.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"

"github.com/CSUOS/KOS/backend/Models"

"github.com/gin-gonic/gin"
)

Expand Down Expand Up @@ -441,39 +440,45 @@ func Attribute(c *gin.Context) {

err = Models.GetAttr(&task, req.Type)

type Attrtemplate struct {
Type string `json:"type"`
Attribute []struct {
Key string `json:"key"`
Value [][]interface{} `json:"value"`
} `json:"attribute"`
}

// 어트리뷰트가 없는 상태, 추가한다.
if err != nil {
data := "{" + "\"type\"" + ":\"" + req.Type + "\"," + "\"attribute\"" + ":" + "[{" + "\"key\"" + ":\"" + req.Key + "\"," + "\"value\"" + ":" + "[[" + strconv.FormatBool(req.Modifiable) + "," + "\"modifiable\"" + "]," + "[" + strconv.FormatBool(req.Selectable) + "," + "\"selectable\"" + "]," + "[" + strconv.FormatBool(req.Creatable) + "," + "\"creatable\"" + "]]" + "}]}"

var newAttr Attrtemplate
input := "{" + "\"" + req.Type + "\"" + ":" + "[{" + "\"key\"" + ":\"" + req.Key + "\"," + "\"value\"" + ":" + "[[" + strconv.FormatBool(req.Modifiable) + "," + "\"modifiable\"" + "]," + "[" + strconv.FormatBool(req.Selectable) + "," + "\"selectable\"" + "]," + "[" + strconv.FormatBool(req.Creatable) + "," + "\"creatable\"" + "]]" + "}]}"

fmt.Println(data)
data := make(map[string]interface{})

err = json.Unmarshal([]byte(data), &newAttr)
err := json.Unmarshal([]byte(input), &data)

if err != nil {
fmt.Println("Attribute JSON Unmarshal fail")
fmt.Println("Byte to JSON Unmarshal fail.")
}

b, err := json.Marshal(newAttr)
if len(task.Attribute) > 0 {
// 어트리뷰트를 덧 붙인다.
} else {
b, err := json.Marshal(data)

if err != nil {
fmt.Println("Map to JSON Marshal fail.")
} else {
task.Attribute = b
Models.UpdateTask(&task, req.TaskID)
c.JSON(http.StatusOK, task)
}
}

} else {
// 이미 해당 타입의 어트리뷰트가 존재하므로 수정한다.
var f interface{}

err = json.Unmarshal(task.Attribute, &f)

if err != nil {
fmt.Println("Attribute Marshal fail")
fmt.Println("JSON Unmarshal fail.")
} else {
task.Attribute = b
Models.UpdateTask(&task, req.TaskID)
c.JSON(http.StatusOK, task)
m := f.(map[string]interface{})

fmt.Println(m)
}
} else {
// 같은 어트리뷰트가 존재
}

}
2 changes: 1 addition & 1 deletion backend/Models/TaskModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Task struct {
[false, "check2"]
]
}]
}
}
*/
Attribute datatypes.JSON // 태스크 속성

Expand Down
1 change: 0 additions & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.4.3 // indirect
github.com/jinzhu/gorm v1.9.16
github.com/joho/godotenv v1.3.0
github.com/json-iterator/go v1.1.10 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand Down
2 changes: 2 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/mattn/go-sqlite3 v1.14.3/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
Expand Down