Skip to content

Commit

Permalink
Merge pull request #120 from UdL-EPS-SoftArch/112-backend-support-for…
Browse files Browse the repository at this point in the history
…-uploading-and-storing-images-associated-with-apartments

112 backend support for uploading and storing images associated with apartments
  • Loading branch information
rogargon authored Dec 15, 2024
2 parents 3cf3eba + df3953b commit def55d1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exce
.requestMatchers(HttpMethod.PATCH, "/advertisementStatuses/*").hasAnyRole("ADMIN")
.requestMatchers(HttpMethod.POST, "/users").anonymous()
.requestMatchers(HttpMethod.POST, "/users/*").denyAll()
.requestMatchers(HttpMethod.POST, "/images").hasAuthority("ROLE_OWNER")
.requestMatchers(HttpMethod.POST, "/images/").hasAnyRole("OWNER")
.requestMatchers(HttpMethod.POST, "/rooms").authenticated()
.requestMatchers(HttpMethod.POST, "/rooms/*").hasAnyRole("OWNER")
.requestMatchers(HttpMethod.PATCH, "/rooms").authenticated()
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Image.java
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;
}
}
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);
}

0 comments on commit def55d1

Please sign in to comment.