@@ -34,8 +34,9 @@ type Task struct {
3434}
3535
3636type Category struct {
37- ID int `json:"id"`
38- Name string `json:"name"`
37+ ID int `json:"id"`
38+ Name string `json:"name"`
39+ IsDefault bool `json:"is_default"`
3940}
4041
4142type CreateTaskRequest struct {
@@ -115,7 +116,8 @@ func initDB() {
115116 schema := `
116117 CREATE TABLE IF NOT EXISTS categories (
117118 id INTEGER PRIMARY KEY AUTOINCREMENT,
118- name TEXT NOT NULL UNIQUE
119+ name TEXT NOT NULL UNIQUE,
120+ is_default BOOLEAN NOT NULL DEFAULT 0
119121 );
120122
121123 CREATE TABLE IF NOT EXISTS tasks (
@@ -146,8 +148,14 @@ func initDB() {
146148 // Column already exists, ignore error
147149 }
148150
151+ // Add is_default column if it doesn't exist (migration for existing databases)
152+ _ , err = db .Exec ("ALTER TABLE categories ADD COLUMN is_default BOOLEAN NOT NULL DEFAULT 0" )
153+ if err != nil {
154+ // Column already exists, ignore error
155+ }
156+
149157 // Insert default category if not exists
150- _ , err = db .Exec ("INSERT OR IGNORE INTO categories (id, name) VALUES (1, 'General')" )
158+ _ , err = db .Exec ("INSERT OR IGNORE INTO categories (id, name, is_default ) VALUES (1, 'General', 1 )" )
151159 if err != nil {
152160 log .Fatal (err )
153161 }
@@ -159,7 +167,7 @@ func getVersion(w http.ResponseWriter, r *http.Request) {
159167}
160168
161169func getCategories (w http.ResponseWriter , r * http.Request ) {
162- rows , err := db .Query ("SELECT id, name FROM categories ORDER BY name" )
170+ rows , err := db .Query ("SELECT id, name, is_default FROM categories ORDER BY name" )
163171 if err != nil {
164172 http .Error (w , err .Error (), http .StatusInternalServerError )
165173 return
@@ -169,7 +177,7 @@ func getCategories(w http.ResponseWriter, r *http.Request) {
169177 categories := []Category {}
170178 for rows .Next () {
171179 var c Category
172- if err := rows .Scan (& c .ID , & c .Name ); err != nil {
180+ if err := rows .Scan (& c .ID , & c .Name , & c . IsDefault ); err != nil {
173181 http .Error (w , err .Error (), http .StatusInternalServerError )
174182 return
175183 }
0 commit comments