Compare commits
1
Commits
NCP-2
..
149bd961e2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
149bd961e2 |
@@ -16,7 +16,6 @@ services:
|
|||||||
|
|
||||||
app:
|
app:
|
||||||
image: popovtsev/ncp
|
image: popovtsev/ncp
|
||||||
# build: .
|
|
||||||
container_name: no_copy_app
|
container_name: no_copy_app
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_DB: no_copy_
|
POSTGRES_DB: no_copy_
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ package ru.soune.no_copy.controller;
|
|||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ru.soune.no_copy.dto.AuthResponse;
|
import ru.soune.no_copy.dto.AuthResponse;
|
||||||
import ru.soune.no_copy.dto.LoginRequest;
|
import ru.soune.no_copy.dto.LoginRequest;
|
||||||
import ru.soune.no_copy.dto.LoginResponse;
|
import ru.soune.no_copy.dto.LoginResponse;
|
||||||
@@ -11,8 +14,6 @@ import ru.soune.no_copy.dto.RegisterRequest;
|
|||||||
import ru.soune.no_copy.entity.AuthToken;
|
import ru.soune.no_copy.entity.AuthToken;
|
||||||
import ru.soune.no_copy.service.AuthService;
|
import ru.soune.no_copy.service.AuthService;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/auth")
|
@RequestMapping("/api/auth")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -35,13 +36,4 @@ public class AuthController {
|
|||||||
return ResponseEntity.ok(new LoginResponse(true, login.getUser().getEmail(),
|
return ResponseEntity.ok(new LoginResponse(true, login.getUser().getEmail(),
|
||||||
login.getToken(),login.getExpiresAt().toString()));
|
login.getToken(),login.getExpiresAt().toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/logout")
|
|
||||||
public ResponseEntity<?> logout(@RequestHeader("Authorization") String tokenHeader) {
|
|
||||||
String token = tokenHeader.replace("Bearer ", "");
|
|
||||||
|
|
||||||
authService.logout(token);
|
|
||||||
|
|
||||||
return ResponseEntity.ok(Map.of("success", true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package ru.soune.no_copy.controller;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import ru.soune.no_copy.dto.UserDTO;
|
|
||||||
import ru.soune.no_copy.repository.UserRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/user")
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class UserController {
|
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
|
||||||
|
|
||||||
@GetMapping("/all")
|
|
||||||
public ResponseEntity<List<UserDTO>> getAllUsers() {
|
|
||||||
List<UserDTO> allUsers = userRepository.findAll().stream()
|
|
||||||
.map(u -> new UserDTO(u.getFirstName(), u.getEmail(), u.getIsActive()))
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
return ResponseEntity.ok(allUsers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package ru.soune.no_copy.dto;
|
||||||
|
|
||||||
|
import ru.soune.no_copy.entity.ContentStatus;
|
||||||
|
import ru.soune.no_copy.entity.FileType;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public record UserContentResponse(
|
||||||
|
Long id,
|
||||||
|
String filename,
|
||||||
|
String originalFilename,
|
||||||
|
FileType fileType,
|
||||||
|
long fileSize,
|
||||||
|
String filePath,
|
||||||
|
ContentStatus status,
|
||||||
|
LocalDateTime uploadDate
|
||||||
|
) {}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package ru.soune.no_copy.dto;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class UserDTO {
|
|
||||||
private String fullName;
|
|
||||||
private String email;
|
|
||||||
private boolean isActive;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package ru.soune.no_copy.entity;
|
||||||
|
|
||||||
|
public enum ContentStatus {
|
||||||
|
PROCESSING, COMPLETED, ERROR
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package ru.soune.no_copy.entity;
|
||||||
|
|
||||||
|
public enum FileType {
|
||||||
|
PHOTO, DOCUMENT, AUDIO, VIDEO
|
||||||
|
}
|
||||||
@@ -53,6 +53,6 @@ public class User {
|
|||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
@Column(name = "is_active")
|
@Column(name = "is_active")
|
||||||
private Boolean isActive = true;
|
private Boolean isActive;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package ru.soune.no_copy.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Getter @Setter
|
||||||
|
@Table(name = "user_content",
|
||||||
|
indexes = {
|
||||||
|
@Index(name = "idx_user_id", columnList = "user_id"),
|
||||||
|
@Index(name = "idx_file_type", columnList = "file_type"),
|
||||||
|
@Index(name = "idx_upload_date", columnList = "upload_date")
|
||||||
|
})
|
||||||
|
public class UserContent {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "user_id", nullable = false,
|
||||||
|
foreignKey = @ForeignKey(name = "fk_usercontent_user"))
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String filename;
|
||||||
|
|
||||||
|
@Column(name = "original_filename", nullable = false)
|
||||||
|
private String originalFilename;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(name = "file_type", nullable = false, length = 16)
|
||||||
|
private FileType fileType;
|
||||||
|
|
||||||
|
@Column(name = "file_extension", length = 16)
|
||||||
|
private String fileExtension;
|
||||||
|
|
||||||
|
@Column(name = "file_size", nullable = false)
|
||||||
|
private Long fileSize;
|
||||||
|
|
||||||
|
@Column(name = "file_path", columnDefinition = "TEXT", nullable = false)
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
@Column(name = "protection_level")
|
||||||
|
private Integer protectionLevel;
|
||||||
|
|
||||||
|
@Column(name = "geometric_resistant")
|
||||||
|
private Boolean geometricResistant = false;
|
||||||
|
|
||||||
|
@Column(name = "watermark_applied")
|
||||||
|
private Boolean watermarkApplied = false;
|
||||||
|
|
||||||
|
@Column(name = "protection_hash", length = 64)
|
||||||
|
private String protectionHash;
|
||||||
|
|
||||||
|
@Column(name = "watermark_id", length = 50)
|
||||||
|
private String watermarkId;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(length = 16)
|
||||||
|
private ContentStatus status = ContentStatus.PROCESSING;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
@Column(name = "upload_date", nullable = false, updatable = false)
|
||||||
|
private LocalDateTime uploadDate;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -10,5 +10,4 @@ import java.util.Optional;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface AuthTokenRepository extends JpaRepository<AuthToken, Long> {
|
public interface AuthTokenRepository extends JpaRepository<AuthToken, Long> {
|
||||||
Optional<AuthToken> findByTokenAndExpiresAtAfter(String token, LocalDate expiresAtAfter);
|
Optional<AuthToken> findByTokenAndExpiresAtAfter(String token, LocalDate expiresAtAfter);
|
||||||
Optional<AuthToken> findByToken(String token);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package ru.soune.no_copy.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.soune.no_copy.entity.FileType;
|
||||||
|
import ru.soune.no_copy.entity.UserContent;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface UserContentRepository extends JpaRepository<UserContent, Long> {
|
||||||
|
List<UserContent> findByUserIdOrderByUploadDateDesc(Long userId);
|
||||||
|
|
||||||
|
List<UserContent> findByUserIdAndFileTypeOrderByUploadDateDesc(
|
||||||
|
Long userId, FileType type, Pageable pageable
|
||||||
|
);
|
||||||
|
|
||||||
|
long countByUserIdAndFileType(Long userId, FileType type);
|
||||||
|
|
||||||
|
long countByUserId(Long userId);
|
||||||
|
}
|
||||||
@@ -78,10 +78,6 @@ public class AuthService {
|
|||||||
return authTokenRepository.save(authToken);
|
return authTokenRepository.save(authToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logout(String token) {
|
|
||||||
authTokenRepository.findByToken(token)
|
|
||||||
.ifPresent(authTokenRepository::delete);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateAuthToken() {
|
private String generateAuthToken() {
|
||||||
byte[] bytes = new byte[32];
|
byte[] bytes = new byte[32];
|
||||||
|
|||||||
Reference in New Issue
Block a user