Skip to content

Commit

Permalink
#117 device set tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Michiii11 committed Oct 3, 2024
1 parent 206935b commit 6ec4137
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

import at.camconnect.dtos.deviceSet.DeviceSetCreateDTO;
import at.camconnect.model.Device;
import at.camconnect.model.DeviceType;
import at.camconnect.repository.DeviceSetRepository;
import at.camconnect.responseSystem.CCException;
import at.camconnect.responseSystem.CCResponse;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import java.util.List;

@Path("deviceset")
public class DeviceSetResource {
//TODO this and the repo

@Inject
DeviceSetRepository deviceSetRepository;

Expand Down Expand Up @@ -61,4 +62,19 @@ public Response delete(@QueryParam("id") Long id){
return CCResponse.error(ex);
}
}

@POST
@Path("getbyid/{id: [0-9]+}/tag/{tagId: [0-9]+}/toggle")
@Consumes(MediaType.APPLICATION_JSON)
@Transactional
public Response addTag(@PathParam("id") Long id, @PathParam("tagId") Long tagId){
DeviceType result;
try{
deviceSetRepository.toggleTag(id, tagId);
}catch (CCException ex){
return CCResponse.error(ex);
}

return CCResponse.ok();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

import java.util.List;

public record DeviceSetCreateDTO (Long id, String name, String description, List<Long> deviceTypeIds, DeviceStatus status) {
public record DeviceSetCreateDTO (Long id, String name, String description, List<Long> deviceTypeIds, DeviceStatus status, List<Long> tagIds) {
}
14 changes: 14 additions & 0 deletions backend/src/main/java/at/camconnect/model/DeviceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class DeviceSet {
@Enumerated(EnumType.STRING)
private DeviceStatus status;

@ManyToMany(fetch = FetchType.EAGER)
private List<Tag> tags;

private String image_blob;

private LocalDateTime creation_date;
Expand All @@ -39,6 +42,17 @@ public DeviceSet() {
}

//region Getter and Setter
public List<Tag> getTags() {
return tags;
}

public void toggleTag(Tag tag) {
if (tags.contains(tag)) {
tags.remove(tag);
} else {
tags.add(tag);
}
}

public String getDescription() {
return description;
Expand Down
15 changes: 15 additions & 0 deletions backend/src/main/java/at/camconnect/model/DeviceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public abstract class DeviceType{

private String image_blob;

@ManyToMany(fetch = FetchType.EAGER)
private List<Tag> tags;

private final LocalDateTime creation_date;
private LocalDateTime change_date;

Expand Down Expand Up @@ -91,6 +94,18 @@ public void setChange_date(LocalDateTime change_date) {
public abstract List<DeviceTypeAttribute> getAttributes();

//getter setter
public List<Tag> getTags() {
return tags;
}

public void toggleTag(Tag tag) {
if (tags.contains(tag)) {
tags.remove(tag);
} else {
tags.add(tag);
}
}


public DeviceTypeStatusEnum getStatus() {
return status;
Expand Down
17 changes: 1 addition & 16 deletions backend/src/main/java/at/camconnect/model/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public class Tag {
@Column(length = 4)
private Long tag_id;

@ManyToMany(fetch = FetchType.EAGER)
private List<DeviceType> types;

@Column(length = 20, unique = true)
private String name;

Expand All @@ -27,19 +24,7 @@ public Tag(String name, String description) {

public Tag() {
}

public List<DeviceType> getTypes() {
return types;
}

public void toggleType(DeviceType type) {
if (types.contains(type)) {
types.remove(type);
} else {
types.add(type);
}
}


public Long getTag_id() {
return tag_id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import at.camconnect.dtos.deviceSet.DeviceSetCreateDTO;
import at.camconnect.model.DeviceSet;
import at.camconnect.model.DeviceType;
import at.camconnect.model.Tag;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
Expand All @@ -25,13 +26,20 @@ public void create(DeviceSetCreateDTO dto){
em.persist(deviceSet);
em.flush();

if(dto.deviceTypeIds() == null) {
return;
if(dto.deviceTypeIds() != null) {
for (Long deviceTypeId : dto.deviceTypeIds()) {
DeviceType deviceType = em.find(DeviceType.class, deviceTypeId);
deviceSet.getDevice_types().add(deviceType);
}
}
for (Long deviceTypeId : dto.deviceTypeIds()) {
DeviceType deviceType = em.find(DeviceType.class, deviceTypeId);
deviceSet.getDevice_types().add(deviceType);

if(dto.tagIds() != null) {
for (Long tagId : dto.tagIds()) {
Tag tag = em.find(Tag.class, tagId);
deviceSet.getTags().add(tag);
}
}

em.merge(deviceSet);
}

Expand Down Expand Up @@ -59,4 +67,13 @@ public void delete(Long id) {
DeviceSet deviceSet = em.find(DeviceSet.class, id);
em.remove(deviceSet);
}

public void toggleTag(Long id, Long tagId) {
DeviceSet deviceSet = em.find(DeviceSet.class, id);
Tag tag = em.find(Tag.class, tagId);

deviceSet.toggleTag(tag);

em.merge(deviceSet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ public List<DeviceTypeFullDTO> getAllFull(DeviceTypeFilters filters) {
.getResultStream().findFirst().orElse(0L);

List<Tag> tagList = em.createQuery(
"SELECT t FROM Tag t " +
"JOIN FETCH t.types dt " +
"WHERE dt = :deviceType", Tag.class)
.setParameter("deviceType", deviceType)
"SELECT t FROM DeviceType dt " +
"JOIN dt.tags t " +
"WHERE dt.type_id = :type_id", Tag.class)
.setParameter("type_id", deviceType.getType_id())
.getResultList();

boolean includeInList = true;
Expand Down Expand Up @@ -432,8 +432,8 @@ public void toggleTag(Long id, Long tagId) {
DeviceType deviceType = getById(id);
Tag tag = em.find(Tag.class, tagId);

tag.toggleType(deviceType);
deviceType.toggleTag(tag);

em.merge(tag);
em.merge(deviceType);
}
}
4 changes: 2 additions & 2 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ quarkus.http.cors.origins=*
quarkus.http.cors.methods=GET, POST, PUT, DELETE
quarkus.http.cors.headers=Content-Type, Authorization

quarkus.hibernate-orm.database.generation=update
quarkus.hibernate-orm.log.sql=false
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.log.sql=true
#added dont-import.qsl because quarkus will crash wehen fed a completly commented out sql script.. or maybe just our sql script
quarkus.hibernate-orm.sql-load-script=import.sql

Expand Down
73 changes: 42 additions & 31 deletions backend/src/main/resources/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -142,40 +142,51 @@ VALUES
(3, 3); -- Audio Set with Sony Alpha a7 III

-- assigning tags to devicetypes
INSERT INTO tag_devicetype (tag_tag_id, types_type_id)
INSERT INTO devicetype_tag (devicetype_type_id, tags_tag_id)
VALUES
(1, 1), -- Foto tag for Canon EOS 5D Mark IV
(2, 2), -- Video tag for Nikon D850
(1, 3), -- Foto tag for Sony Alpha a7 III
(1, 4), -- Foto tag for Fujifilm X-T3
(1, 5), -- Foto tag for Olympus OM-D E-M10 Mark III
(2, 3), -- Video tag for Sony Alpha a7 III
(2, 4), -- Video tag for Fujifilm X-T3
(2, 5), -- Video tag for Olympus OM-D E-M10 Mark III
(1, 6), -- Foto tag for Sennheiser HD 600
(2, 7), -- Video tag for Bose QuietComfort 35
(1, 8), -- Foto tag for Sony WH-1000XM4
(2, 9), -- Video tag for Audio-Technica ATH-M50X
(1, 10), -- Foto tag for AKG K702
(1, 11), -- Foto tag for Canon EF 50mm f/1.8 STM
(1, 12), -- Foto tag for Nikon Z 35mm f/1.8 S
(1, 13), -- Foto tag for Sony FE 85mm f/1.4 GM
(1, 14), -- Foto tag for Fujifilm XF 24mm f/2.0 R
(1, 15), -- Foto tag for Sigma 70-200mm f/2.8 DG OS HSM
(2, 16), -- Video tag for Aputure LS C300d II
(2, 17), -- Video tag for Godox SL-200W II
(2, 18), -- Video tag for Nanlite Forza 300B
(2, 19), -- Video tag for Neewer 400W LED
(2, 20), -- Video tag for Yongnuo YN360 III Pro
(2, 21), -- Video tag for Shure SM7B
(2, 22), -- Video tag for Rode NT1-A
(2, 23), -- Video tag for Audio-Technica AT2020
(2, 24), -- Video tag for Blue Yeti X
(2, 25), -- Video tag for AKG C414 XLII
(1, 26), -- Foto tag for Samsung Galaxy Buds
(2, 27), -- Video tag for Apple AirPods Pro
(1, 28), -- Foto tag for Beats Powerbeats Pro
(2, 29); -- Video tag for Jabra Elite 75t
(3, 1), -- Foto tag for Sony Alpha a7 III
(4, 1), -- Foto tag for Fujifilm X-T3
(5, 1), -- Foto tag for Olympus OM-D E-M10 Mark III
(3, 2), -- Video tag for Sony Alpha a7 III
(4, 2), -- Video tag for Fujifilm X-T3
(5, 2), -- Video tag for Olympus OM-D E-M10 Mark III
(6, 1), -- Foto tag for Sennheiser HD 600
(7, 2), -- Video tag for Bose QuietComfort 35
(8, 1), -- Foto tag for Sony WH-1000XM4
(9, 2), -- Video tag for Audio-Technica ATH-M50X
(10, 1), -- Foto tag for AKG K702
(11, 2), -- Foto tag for Canon EF 50mm f/1.8 STM
(12, 1), -- Foto tag for Nikon Z 35mm f/1.8 S
(13, 1), -- Foto tag for Sony FE 85mm f/1.4 GM
(14, 1), -- Foto tag for Fujifilm XF 24mm f/2.0 R
(15, 2), -- Foto tag for Sigma 70-200mm f/2.8 DG OS HSM
(16, 2), -- Video tag for Aputure LS C300d II
(17, 2), -- Video tag for Godox SL-200W II
(18, 1), -- Video tag for Nanlite Forza 300B
(19, 2), -- Video tag for Neewer 400W LED
(20, 1), -- Video tag for Yongnuo YN360 III Pro
(21, 2), -- Video tag for Shure SM7B
(22, 1), -- Video tag for Rode NT1-A
(23, 1), -- Video tag for Audio-Technica AT2020
(24, 1), -- Video tag for Blue Yeti X
(25, 1), -- Video tag for AKG C414 XLII
(26, 1), -- Foto tag for Samsung Galaxy Buds
(27, 1), -- Video tag for Apple AirPods Pro
(28, 2), -- Foto tag for Beats Powerbeats Pro
(29, 2); -- Video tag for Jabra Elite 75t

INSERT INTO deviceset_tag (deviceset_id, tags_tag_id)
values
(1, 1),
(2, 2),
(3, 3),
(4, 4),
(5, 1),
(6, 2),
(7, 3),
(8, 4);

-- Devices
insert into device (type_id, note, number, serial, status, creation_date) values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ export class DeviceSetEditComponent extends LitElement {
name: deviceSet.name,
description: deviceSet.description,
deviceTypeIds: deviceSet.device_types.map(deviceType => deviceType.type_id) || [],
status: deviceSet.status
status: deviceSet.status,
tags: deviceSet.tags
} as DeviceSetCreateDTO
model.appState.value.openOverlay(html`<cc-edit-device-set-modal .element="${convertedDeviceSet}" .isEditMode="${true}"></cc-edit-device-set-modal>`, () => {})}}">
model.appState.value.openOverlay(html`<cc-edit-device-set-modal .element="${convertedDeviceSet}" .isEditMode="${true}" .elementId="${deviceSet.id}"></cc-edit-device-set-modal>`, () => {})}}">
}}"></cc-device-set-edit-entry>`
})}
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {AppState} from "../../../AppState"
import {model} from "../../../index"
import PopupEngine from "../../../util/PopupEngine"
import DeviceSetService, {DeviceSet, DeviceSetCreateDTO} from "../../../service/deviceSet.service"
import {ChipType} from "../../basic/chip.component"

@customElement('cc-device-set-edit-entry')
export class DeviceSetEditEntryComponent extends LitElement {
Expand All @@ -31,7 +32,11 @@ export class DeviceSetEditEntryComponent extends LitElement {
<!-- todo für yanik <cc-line type="${Orientation.VERTICAL}"></cc-line>-->
<div class="tags">
${
this.deviceSet.tags?.map(tag => {
return html`<cc-chip type="${ChipType.DEFAULT}" color="${ColorEnum.GRAY}" size="${SizeEnum.SMALL}" text="${tag.name}"></cc-chip>`
})
}
</div>
<div class="deviceSetInfo">
Expand All @@ -49,12 +54,13 @@ export class DeviceSetEditEntryComponent extends LitElement {
name: this.deviceSet.name,
description: this.deviceSet.description,
deviceTypeIds: this.deviceSet.device_types.map(deviceType => deviceType.type_id) || [],
status: this.deviceSet.status
status: this.deviceSet.status,
tags: this.deviceSet.tags
} as DeviceSetCreateDTO
//UrlHandler.updateUrl('/app/edit/device?did=' + this.device.device_id)
model.appState.value.openOverlay(html`<cc-edit-device-set-modal .element="${convertedDeviceSet}" .isEditMode="${true}"></cc-edit-device-set-modal>`, () => {})
model.appState.value.openOverlay(html`<cc-edit-device-set-modal .element="${convertedDeviceSet}" .isEditMode="${true}" .elementId="${this.deviceSet.id}"></cc-edit-device-set-modal>`, () => {})
event.stopPropagation()
}}">
<div slot="left" class="icon accent">
Expand Down
Loading

0 comments on commit 6ec4137

Please sign in to comment.