]> uap-core.de Git - note.git/commitdiff
add attachment type
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 28 Mar 2025 20:27:53 +0000 (21:27 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 28 Mar 2025 20:27:53 +0000 (21:27 +0100)
application/application.h
application/store_sqlite.c
application/types.c
application/types.h

index 43d4e1f75a8edef8804bcfe0b4e99f70df4773f8..62a7b76c1656bac0506c044b62d69728b42f79de 100644 (file)
@@ -159,9 +159,25 @@ struct NoteModel {
     bool modified;
 };
    
-typedef struct AttachmentObj {
-    int a;
-} AttachmentObj;
+typedef enum AttachmentType {
+    NOTE_ATTACHMENT_FILE = 0,
+    NOTE_ATTACHMENT_IMAGE
+} AttachmentType;
+
+typedef struct AttachmentModel {
+    UiContext *ctx;
+    const CxAllocator *note_allocator;
+    
+    Note *parent_note;
+    
+    int64_t resource_id;
+    AttachmentType type;
+    char *name;
+    char *temp_path;
+    char *temp_data;
+    
+    void *data;
+} AttachmentModel;
 
 void application_init();
 
index 0557bc47216cfc4bee73f5735660ff279536fcdd..881f2a13ba20283bc8a6da9b45f9038b41c2d60b 100644 (file)
     "foreign key (parent_id) references collections(collection_id), " \
     "unique (parent_id, name) " \
     ");"
+#define SQL_CREATE_TABLE_ATTACHMENTS "create table attachments( " \
+    "attachment_id           integer primary key, " \
+    "resource_id             integer, " \
+    "parent_id               integer, " \
+    "type                    integer , " \
+    "foreign key (resource_id) references notes(note_id), " \
+    "foreign key (parent_id) references notes(note_id) " \
+    ");"
 
 int store_sqlite_init_db(DBUConnection *connection) {
     char *sql[] = { 
@@ -88,7 +96,8 @@ int store_sqlite_init_db(DBUConnection *connection) {
         SQL_CREATE_TABLE_REPOSITORIES,
         SQL_CREATE_TABLE_COLLECTIONS,
         SQL_CREATE_TABLE_USER_SETTINGS,
-        SQL_CREATE_TABLE_NOTES
+        SQL_CREATE_TABLE_NOTES,
+        SQL_CREATE_TABLE_ATTACHMENTS
     };
     int nsql = sizeof(sql) / sizeof(char*);
     
index 7f5c563fb4cd90ed90e3add64c68c5e6b6b67b5f..6bc7737a5569d330ddc643ce0dcac0f95dda393d 100644 (file)
@@ -34,6 +34,7 @@ DBUClass *usersettings_class;
 DBUClass *repository_class;
 DBUClass *collection_class;
 DBUClass *notes_class;
+DBUClass *attachments_class;
 
 DBUContext* get_dbu_context() {
     return ctx;
@@ -77,4 +78,9 @@ void register_types() {
     dbuClassAdd(repository_class, Repository, default_key);
     dbuClassAdd(repository_class, Repository, authmethod);
     dbuClassAdd(repository_class, Repository, encryption);
+    
+    attachments_class = dbuRegisterClass(ctx, "attachments", Attachment, attachment_id);
+    dbuClassAdd(attachments_class, Attachment, resource_id);
+    dbuClassAdd(attachments_class, Attachment, parent_id);
+    dbuClassAdd(attachments_class, Attachment, type);
 }
index ad4ea21945958999449c4e7f213de8ff4b24b222..d95a26eae4820f33930ed1b37196df11d3a41478 100644 (file)
@@ -45,6 +45,7 @@ typedef struct UserSettings UserSettings;
 typedef struct Repository   Repository;
 typedef struct Collection   Collection;
 typedef struct Note         Note;
+typedef struct Attachment   Attachment;
     
 struct UserSettings {
     char    *host;
@@ -103,6 +104,19 @@ struct Note {
     NoteModel  *model;
 };
 
+struct Attachment {
+    // db fields
+    
+    int64_t    attachment_id;
+    int64_t    resource_id;
+    int64_t    parent_id;
+    int        type;
+    
+    // temp fields
+    char       *name;
+    cxmutstr   bin_content;
+};
+
 extern DBUClass *usersettings_class;
 extern DBUClass *repository_class;
 extern DBUClass *collection_class;