Skip to content

Commit

Permalink
feat: add image entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed May 11, 2024
1 parent 8189036 commit ec392a6
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2023 Sven Loesekann
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ch.xxx.aidoclibchat.adapter.repository;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

import org.springframework.stereotype.Repository;

import ch.xxx.aidoclibchat.domain.model.entity.Image;
import ch.xxx.aidoclibchat.domain.model.entity.ImageRepository;

@Repository
public class ImageRepositoryBean implements ImageRepository {
private final JpaImageRepository jpaImageRepository;

public ImageRepositoryBean(JpaImageRepository jpaImageRepository) {
this.jpaImageRepository = jpaImageRepository;
}

@Override
public Optional<Image> findById(UUID id) {
return this.findById(id);
}

@Override
public Image save(Image document) {
return this.jpaImageRepository.save(document);
}

@Override
public List<Image> findAll() {
return this.jpaImageRepository.findAll();
}

@Override
public List<Image> findAllById(Iterable<UUID> ids) {
return this.jpaImageRepository.findAllById(ids);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2023 Sven Loesekann
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ch.xxx.aidoclibchat.adapter.repository;

import java.util.UUID;

import org.springframework.data.jpa.repository.JpaRepository;

import ch.xxx.aidoclibchat.domain.model.entity.Image;

public interface JpaImageRepository extends JpaRepository<Image, UUID> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class MetaData {
public enum DataType {
DOCUMENT, TABLE, COLUMN, ROW
DOCUMENT, TABLE, COLUMN, ROW, IMAGE
};

public enum DocumentType {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright 2023 Sven Loesekann
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ch.xxx.aidoclibchat.domain.model.entity;

import java.util.UUID;

import ch.xxx.aidoclibchat.domain.common.MetaData.ImageType;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;

@Entity
public class Image {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
private String imageName;
@Enumerated(EnumType.STRING)
private ImageType imageType;
@Lob
private byte[] imageContent;

public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getImageName() {
return imageName;
}
public void setImageName(String imageName) {
this.imageName = imageName;
}
public ImageType getImageType() {
return imageType;
}
public void setImageType(ImageType imageType) {
this.imageType = imageType;
}
public byte[] getImageContent() {
return imageContent;
}
public void setImageContent(byte[] imageContent) {
this.imageContent = imageContent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2023 Sven Loesekann
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ch.xxx.aidoclibchat.domain.model.entity;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

public interface ImageRepository {
Optional<Image> findById(UUID id);
Image save(Image document);
List<Image> findAll();
List<Image> findAllById(Iterable<UUID> ids);
}
24 changes: 24 additions & 0 deletions backend/src/main/resources/dbchangelog/changes/db.changelog-3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2019 Sven Loesekann Licensed under the Apache License, Version
2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the License. -->
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet author="angular2guy" id="19">
<createTable tableName="image">
<column name="id" type="uuid">
<constraints primaryKey="true" />
</column>
<column name="image_name" type="varchar(120)" />
<column name="image_type" type="varchar(10)" />
<column name="image_content" type="blob" />
</createTable>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<include file="changes/db.changelog-1.xml" relativeToChangelogFile="true"/>
<include file="changes/db.changelog-1-ollama.xml" relativeToChangelogFile="true"/>
<include file="changes/db.changelog-2.xml" relativeToChangelogFile="true"/>
<include file="changes/db.changelog-3.xml" relativeToChangelogFile="true"/>

<include file="db.changelog-loaddata.xml" relativeToChangelogFile="true"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<include file="changes/db.changelog-1.xml" relativeToChangelogFile="true"/>
<include file="changes/db.changelog-2.xml" relativeToChangelogFile="true"/>
<include file="changes/db.changelog-3.xml" relativeToChangelogFile="true"/>

<include file="db.changelog-loaddata.xml" relativeToChangelogFile="true"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { MatToolbarModule } from '@angular/material/toolbar';
styleUrl: './image-query.component.scss'
})
export class ImageQueryComponent {
//'What do you see in the image? Describe the background. Describe the colors.'
protected imageForm = new FormGroup({
file: new FormControl<File | null>(null, Validators.required),
query: new FormControl<string>('', Validators.minLength(3))
Expand Down

0 comments on commit ec392a6

Please sign in to comment.