Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

112 backend support for uploading and storing images associated with apartments #120

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading