-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from UdL-EPS-SoftArch/112-backend-support-for…
…-uploading-and-storing-images-associated-with-apartments 112 backend support for uploading and storing images associated with apartments
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cat.udl.eps.softarch.demo.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIdentityReference; | ||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@EqualsAndHashCode(callSuper = true) | ||
@Entity | ||
@Data | ||
public class Image extends UriEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@NotBlank | ||
private String filename; | ||
|
||
@Column(length = 5 * 1024 * 1024) // 5MB | ||
@Size(max = 5 * 1024 * 1024) // 5MB | ||
private String content; | ||
|
||
@JsonIdentityReference(alwaysAsId = true) | ||
@ManyToOne | ||
private Apartment apartment; | ||
|
||
@Override | ||
public Object getId() { | ||
return id; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/cat/udl/eps/softarch/demo/repository/ImageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cat.udl.eps.softarch.demo.repository; | ||
|
||
|
||
import cat.udl.eps.softarch.demo.domain.Apartment; | ||
import cat.udl.eps.softarch.demo.domain.Image; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.repository.PagingAndSortingRepository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface ImageRepository extends CrudRepository<Image, Long>, PagingAndSortingRepository<Image, Long> { | ||
@NotNull | ||
Optional<Image> findById(@NotNull @Param("id") Long id); | ||
List<Image> findByApartment(@Param("country") Apartment Apartment); | ||
List<Image> findByFilename(@Param("filename") String filename); | ||
List<Image> findByContent(@Param("content") String content); | ||
} |