Explorar el Código

added new directory creation

turos.robert hace 4 semanas
padre
commit
8f2137ac76

+ 5 - 0
cmds/webservice/bin/Scoala/notita-2026-03-05-183434.697315.json

@@ -0,0 +1,5 @@
+{
+  "titlu": "Teste",
+  "continut": "Multe teste",
+  "director": "Scoala"
+}

+ 4 - 0
cmds/webservice/bin/notes/notita-2026-03-05-182957.416486.json

@@ -0,0 +1,4 @@
+{
+  "titlu": "Teste",
+  "continut": "Multe teste"
+}

+ 5 - 0
cmds/webservice/bin/notes/notita-2026-03-05-183515.544056.json

@@ -0,0 +1,5 @@
+{
+  "titlu": "Bam",
+  "continut": "Bum",
+  "director": "notes"
+}

+ 4 - 0
cmds/webservice/bin/notite/notita-2026-03-05-181711.177972.json

@@ -0,0 +1,4 @@
+{
+  "titlu": "Test",
+  "continut": "Test"
+}

+ 8 - 0
cmds/webservice/bin/templates/index.html

@@ -19,6 +19,14 @@
       </div>
 
       <form class="space-y-6" method="POST" action="api/save_note">
+
+        
+        <div>
+          <label class="block text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2">Folder</label>
+          <input type="text" name="director" placeholder="ex: scoala/istorie"
+            class="w-full bg-[#202020] border border-[#3e3e3e] text-gray-200 text-sm rounded-lg focus:ring-2 focus:ring-[#7b58ad] focus:border-transparent outline-none p-3 transition-all placeholder:text-gray-600">
+        </div>
+
         <div>
           <label class="block text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2">Titlu Fișier</label>
           <input type="text" name="titlu" placeholder="ex: Plan de idei 2026"

+ 7 - 0
cmds/webservice/go.mod

@@ -1,3 +1,10 @@
 module git.linuxit.ro/turos.robert/mynotes/cmds/webservice
 
 go 1.25.0
+
+require git.linuxit.ro/turos.robert/mynotes/lib/server v0.0.0-20260305131437-15e42abd9873
+
+require (
+	git.linuxit.ro/turos.robert/mynotes/lib/inout v0.0.0-20260305131437-15e42abd9873 // indirect
+	github.com/yuin/goldmark v1.7.16 // indirect
+)

+ 6 - 0
cmds/webservice/go.sum

@@ -0,0 +1,6 @@
+git.linuxit.ro/turos.robert/mynotes/lib/inout v0.0.0-20260305131437-15e42abd9873 h1:We4h/lfTShqwl9uMQMRWRpoieSVF6+JlFLbJpzuUBbo=
+git.linuxit.ro/turos.robert/mynotes/lib/inout v0.0.0-20260305131437-15e42abd9873/go.mod h1:aNjUqIGY56BbY8nzTVZq4I2hV6cVhsTpvFUSrNKfX9k=
+git.linuxit.ro/turos.robert/mynotes/lib/server v0.0.0-20260305131437-15e42abd9873 h1:t0JrgAoU04/thFZps9hVnXRKXRuwPQX/FwPRQ+G/YrU=
+git.linuxit.ro/turos.robert/mynotes/lib/server v0.0.0-20260305131437-15e42abd9873/go.mod h1:hEsMbRVhhkTY8orZ2svT15Ci+T/61Xivf/iY1JlO29Q=
+github.com/yuin/goldmark v1.7.16 h1:n+CJdUxaFMiDUNnWC3dMWCIQJSkxH4uz3ZwQBkAlVNE=
+github.com/yuin/goldmark v1.7.16/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=

+ 1 - 0
cmds/webservice/types/types.go

@@ -3,5 +3,6 @@ package types
 type Notita struct {
 	Titlu    string `json:"titlu"`
 	Continut string `json:"continut"`
+	Folder   string `json:"director"`
 	HTML     string `json:"-"`
 }

+ 17 - 15
lib/server/handlers.go

@@ -20,18 +20,12 @@ func Wildcard(w http.ResponseWriter, r *http.Request) {
 	if r.Method == "GET" {
 		base_dir := "./templates/"
 		endpoint := strings.TrimPrefix(r.URL.Path, "/")
-		fmt.Println(endpoint)
-		/*if endpoint == "" {
+		//fmt.Println(endpoint)
+		//fmt.Println(r.URL.Path)
+		if endpoint == "" {
 			//in cazul in care apelam root
-			endpoint = "index"
+			endpoint = "index.html"
 		}
-		path := filepath.Join("templates", endpoint+".tmpl")
-		_, err := os.Stat(path)
-		if err != nil {
-			w.WriteHeader(http.StatusNotFound)
-			w.Write(inout.FileToBytes("templates/error.tmpl"))
-			return
-		}*/
 		path := filepath.Join(base_dir, endpoint)
 		_, err := os.Stat(path)
 		if err != nil {
@@ -44,7 +38,7 @@ func Wildcard(w http.ResponseWriter, r *http.Request) {
 
 }
 
-func API(w http.ResponseWriter, r *http.Request, notesFolder string) {
+func API(w http.ResponseWriter, r *http.Request) {
 	action := strings.TrimPrefix(r.URL.Path, "/api/")
 	if r.Method == "POST" {
 		//w.WriteHeader(http.StatusNotImplemented)
@@ -52,19 +46,27 @@ func API(w http.ResponseWriter, r *http.Request, notesFolder string) {
 		switch action {
 		case "save_note":
 			r.ParseForm()
-			fisier := fmt.Sprintf("notita-%s.json", time.Now().Format("2006-01-02-150405.999999"))
-			//fmt.Println(fisier, r.Form)
-			//return
 			n := types.Notita{}
 			n.Titlu = r.Form.Get("titlu")
 			n.Continut = r.Form.Get("notita")
-			err := inout.ObjToFile(filepath.Join(notesFolder, fisier), n, true)
+			n.Folder = r.Form.Get("director")
+			err := os.MkdirAll(n.Folder, 0755)
+			if err != nil {
+				w.WriteHeader(http.StatusBadRequest)
+				fmt.Fprintf(w, "ParseForm error: %+v", err)
+			}
+			fisier := fmt.Sprintf("notita-%s.json", time.Now().Format("2006-01-02-150405.999999"))
+			//fmt.Println(fisier, r.Form)
+			//return
+
+			err = inout.ObjToFile(filepath.Join(n.Folder, fisier), n, true)
 			if err != nil {
 				w.WriteHeader(http.StatusInternalServerError)
 				fmt.Fprintf(w, "%+v", err)
 				return
 			}
 			referinta := r.Referer()
+			fmt.Println(referinta)
 			if referinta != "" {
 				http.Redirect(w, r, referinta, http.StatusSeeOther)
 			} else {

+ 1 - 1
lib/server/srv.go

@@ -23,7 +23,7 @@ func (s *Server) Run() {
 	// adding endpoints to the server
 	http.HandleFunc("/", Wildcard)
 	http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
-		API(w, r, "notes")
+		API(w, r)
 	})
 	http.HandleFunc("/notes/", func(w http.ResponseWriter, r *http.Request) {
 		note := r.URL.Query().Get("note")