From: Olaf Wintermann Date: Fri, 28 Mar 2025 20:27:53 +0000 (+0100) Subject: add attachment type X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=481f18bd5b1804f13eb6ee4b8602e430377e3490;p=note.git add attachment type --- diff --git a/application/application.h b/application/application.h index 43d4e1f..62a7b76 100644 --- a/application/application.h +++ b/application/application.h @@ -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(); diff --git a/application/store_sqlite.c b/application/store_sqlite.c index 0557bc4..881f2a1 100644 --- a/application/store_sqlite.c +++ b/application/store_sqlite.c @@ -81,6 +81,14 @@ "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*); diff --git a/application/types.c b/application/types.c index 7f5c563..6bc7737 100644 --- a/application/types.c +++ b/application/types.c @@ -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); } diff --git a/application/types.h b/application/types.h index ad4ea21..d95a26e 100644 --- a/application/types.h +++ b/application/types.h @@ -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;