Skip to content

Commit

Permalink
Attachment-Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
commel committed Nov 17, 2023
1 parent 68d4829 commit 859d959
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 15 deletions.
26 changes: 20 additions & 6 deletions doc/db2/01_schema/09_attachments.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
create type attachment_data_type as enum ('url', 'storage');

create table if not exists attachment_groups(
id integer primary key default nextval('hibernate_sequence'),
code varchar(255) not null unique,
label varchar(255) not null
);

create table if not exists attachment_types(
id integer primary key default nextval('hibernate_sequence'),
code varchar(255) not null,
label varchar(255) not null,
attachment_group_id integer references attachment_groups(id),
datatype attachment_data_type,
unique(code, attachment_group_id)
);

create table if not exists attachments(
id integer primary key default nextval('hibernate_sequence'),

nodeid integer not null,

ordering integer default 0,
weight integer default 0,
description varchar(255),

attachment_group varchar(255),
attachment_type varchar(255),
attachment_datatype varchar(255),
attachment_type_id integer references attachment_types(id),

attachment_data varchar(4096),

created timestamptz not null default CURRENT_TIMESTAMP,
updated timestamptz not null default CURRENT_TIMESTAMP,
update_userid integer references users(id)
updated timestamptz not null default CURRENT_TIMESTAMP
);
13 changes: 7 additions & 6 deletions doc/db2/01_schema/10_search.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ SELECT
LEFT JOIN node_tags ON node_tags.nodeid = ar.nodeid
LEFT JOIN tags ON tags.id = node_tags.tagid
LEFT JOIN attachments att ON att.id = (
SElECT id
FROM attachments
WHERE nodeid = ar.id AND attachment_type = 'SCREENSHOT' AND attachment_group = 'IMAGE' ORDER BY id LIMIT 1
select a2.id from attachments a2
inner join attachment_types at2 on at2.id = a2.attachment_type_id
where at2.code = 'screenshot' order by a2.weight, a2.id limit 1
)
left join node_slugs nsl on nsl.id = (
select id
Expand Down Expand Up @@ -59,9 +59,9 @@ SELECT
LEFT JOIN node_tags ON node_tags.nodeid = nr.nodeid
LEFT JOIN tags ON tags.id = node_tags.tagid
LEFT JOIN attachments att ON att.id = (
SElECT id
FROM attachments
WHERE nodeid = nr.id AND attachment_type = 'SCREENSHOT' AND attachment_group = 'IMAGE' ORDER BY id LIMIT 1
select a2.id from attachments a2
inner join attachment_types at2 on at2.id = a2.attachment_type_id
where at2.code = 'screenshot' order by a2.weight, a2.id limit 1
)
left join node_slugs nsl on nsl.id = (
select id
Expand Down Expand Up @@ -103,6 +103,7 @@ ALTER MATERIALIZED VIEW mv_searchindex OWNER TO holarse;
CREATE INDEX IF NOT EXISTS idx_fts_search ON mv_searchindex USING gin(document);
CREATE INDEX IF NOT EXISTS idx_fts_tags ON mv_searchindex (tags, doctype);


---
--- Suggestions
---
Expand Down
37 changes: 37 additions & 0 deletions doc/db2/02_data/01_roles_taggroups_forums.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,40 @@ INSERT INTO apiusers (id, login, rolename, token, active)
VALUES
(nextval('hibernate_sequence'), 'dbl', 'API_DRÜCKBLICK', 'ADDB0F5E7826C857D7376D1BD9BC33C0C544790A2EAC96144A8AF22B1298C940', true); -- u: dbl, p: geheim

-- 6. attachments
insert into attachment_groups (code, label)
values
('website', 'Webseiten'),
('wine', 'wine'),
('shop', 'Shops'),
('video', 'Videos'),
('image', 'Bilder/Screenshots'),
('file', 'Dateien/Anhänge'),
('repo', 'Repos');

insert into attachment_types (code, label, attachment_group_id, datatype) values
('link', 'Link', (select id from attachment_groups where code = 'website'), 'url'),

('winehq', 'WineHQ', (select id from attachment_groups where code = 'wine'), 'url'),
('protondb', 'ProtonDB', (select id from attachment_groups where code = 'wine'), 'url'),
('protonofficial', 'Proton Official', (select id from attachment_groups where code = 'wine'), 'url'),
('crossoverdb', 'CrossOver', (select id from attachment_groups where code = 'wine'), 'url'),

('steam', 'Steam', (select id from attachment_groups where code = 'shop'), 'url'),
('humble', 'HumbleStore', (select id from attachment_groups where code = 'shop'), 'url'),
('gog', 'GOG', (select id from attachment_groups where code = 'shop'), 'url'),
('ownshop', 'Hersteller', (select id from attachment_groups where code = 'shop'), 'url'),
('itch', 'Itch', (select id from attachment_groups where code = 'shop'), 'url'),

('youtube', 'YouTube', (select id from attachment_groups where code = 'video'), 'url'),
('youtube-channel', 'YouTube-Kanal', (select id from attachment_groups where code = 'video'), 'url'),
('twitch', 'Twitch', (select id from attachment_groups where code = 'video'), 'url'),

('screenshot', 'Screenshot', (select id from attachment_groups where code = 'image'), 'storage'),

('file', 'Dateianhang', (select id from attachment_groups where code = 'file'), 'storage'),

('appimage', 'AppImage', (select id from attachment_groups where code = 'repo'), 'url'),
('flatpak', 'Flatpak', (select id from attachment_groups where code = 'repo'), 'url'),
('Snap', 'Snap', (select id from attachment_groups where code = 'repo'), 'url');

3 changes: 0 additions & 3 deletions src/main/java/de/holarse/backend/db/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.OrderBy;
import jakarta.persistence.Table;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Table(name = "articles")
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/de/holarse/backend/db/Attachment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package de.holarse.backend.db;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

@Table(name = "attachments")
@Entity
public class Attachment extends TimestampedBase {

private static final long serialVersionUID = 1L;

@Column(name = "nodeid")
private Integer nodeId;

@Column
private int weight;

@Column(length = 255)
private String description;

@ManyToOne
@JoinColumn(name="attachment_type_id", nullable=false, referencedColumnName = "id")
private AttachmentGroup group;

@Column(name = "attachment_data", length = 4096)
private String data;

public Integer getNodeId() {
return nodeId;
}

public void setNodeId(Integer nodeId) {
this.nodeId = nodeId;
}

public int getWeight() {
return weight;
}

public void setWeight(int weight) {
this.weight = weight;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public AttachmentGroup getGroup() {
return group;
}

public void setGroup(AttachmentGroup group) {
this.group = group;
}

public String getData() {
return data;
}

public void setData(String data) {
this.data = data;
}

}
34 changes: 34 additions & 0 deletions src/main/java/de/holarse/backend/db/AttachmentGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package de.holarse.backend.db;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;

@Table(name = "attachment_groups")
@Entity
public class AttachmentGroup extends Base {

private static final long serialVersionUID = 1L;

@Column(length = 255)
private String code;
@Column(length = 255)
private String label;

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

}
67 changes: 67 additions & 0 deletions src/main/java/de/holarse/backend/db/AttachmentType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package de.holarse.backend.db;

import de.holarse.backend.types.AttachmentDataType;
import io.hypersistence.utils.hibernate.type.basic.PostgreSQLEnumType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import org.hibernate.annotations.Type;

@Entity
@Table(name = "attachment_types")
public class AttachmentType extends Base {

private static final long serialVersionUID = 1L;

@Column(length = 255)
private String code;

@Column(length = 255)
private String label;

@ManyToOne
@JoinColumn(name="attachment_group_id", nullable=false, referencedColumnName = "id")
private AttachmentGroup attachmentGroup;

@Enumerated(EnumType.STRING)
@Type(PostgreSQLEnumType.class)
@Column(columnDefinition = "attachment_data_type", name = "datatype")
private AttachmentDataType dataType;

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public AttachmentGroup getAttachmentGroup() {
return attachmentGroup;
}

public void setAttachmentGroup(AttachmentGroup attachmentGroup) {
this.attachmentGroup = attachmentGroup;
}

public AttachmentDataType getDataType() {
return dataType;
}

public void setDataType(AttachmentDataType dataType) {
this.dataType = dataType;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.holarse.backend.types;

public enum AttachmentDataType {

url,
storage

}

0 comments on commit 859d959

Please sign in to comment.