Skip to content
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
3 changes: 3 additions & 0 deletions lib-global/src/main/java/com/itgura/util/URIPrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ public class URIPrefix {
public static final String GET_PRICE = "/get-price";
public static final String UPDATE_TAGS = "/update-tags";
public static final String GET_VIDEO_Signed_Url = "/get-video-signed-url";
public static final String Upload_Video_Material = "/upload-video";
public static final String GET_Pre_Signed_Url_To_Upload_Video = "/get-pre-signed-url-to-upload-video";
public static final String MARKED_VIDEO_AS_UPLOADED = "/marked-video-as-uploaded";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.itgura.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;

@Configuration
public class S3Config {

@Value("${aws.s3.accessKey}")
private String S3_ACCESS_KEY;

@Value("${aws.s3.secretKey}")
private String S3_SECRET_KEY;


@Bean
public S3Presigner s3Presigner() {
return S3Presigner.builder()
.region(Region.AP_SOUTH_1) // Replace with your AWS region
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create(
S3_ACCESS_KEY,
S3_SECRET_KEY
)
))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import com.itgura.dto.AppRequest;
import com.itgura.dto.AppResponse;
import com.itgura.exception.ValueNotExistException;
import com.itgura.request.MaterialRequest;
import com.itgura.request.SignedUrlRequest;
import com.itgura.response.dto.MaterialResponseDto;
import com.itgura.request.VideoUploadRequest;
import com.itgura.response.dto.PreSignedUrlToUploadVideoResponseDto;
import com.itgura.service.MaterialService;
import com.itgura.util.ResourceManagementURI;
import com.itgura.util.URIPathVariable;
import com.itgura.util.URIPrefix;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;
Expand All @@ -20,6 +24,7 @@
public class MaterialController {
@Autowired
private MaterialService materialService;
@PreAuthorize("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_TEACHER')")
@PostMapping( ResourceManagementURI.MATERIAL+URIPrefix.CREATE+ResourceManagementURI.SESSION_ID)
public AppResponse<String> createMaterial(@PathVariable UUID sessionId, @RequestBody AppRequest<MaterialRequest> request) {
try {
Expand All @@ -30,6 +35,7 @@ public AppResponse<String> createMaterial(@PathVariable UUID sessionId, @Request
return AppResponse.error(null, e.getMessage(), "Server Error", "500", "");
}
}
@PreAuthorize("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_TEACHER')")
@PatchMapping( ResourceManagementURI.MATERIAL+URIPrefix.UPDATE+ResourceManagementURI.MATERIAL_ID)
public AppResponse<String> updateMaterial(@PathVariable UUID materialId, @RequestBody AppRequest<MaterialRequest> request) {
try {
Expand All @@ -40,6 +46,7 @@ public AppResponse<String> updateMaterial(@PathVariable UUID materialId, @Reques
return AppResponse.error(null, e.getMessage(), "Server Error", "500", "");
}
}
@PreAuthorize("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_TEACHER')")
@DeleteMapping( ResourceManagementURI.MATERIAL+URIPrefix.DELETE+ResourceManagementURI.MATERIAL_ID)
public AppResponse<String> deleteMaterial(@PathVariable UUID materialId) {
try {
Expand All @@ -51,7 +58,7 @@ public AppResponse<String> deleteMaterial(@PathVariable UUID materialId) {
}
}

@PostMapping (ResourceManagementURI.MATERIAL + URIPrefix.GET_VIDEO_Signed_Url)
@PostMapping (ResourceManagementURI.MATERIAL+URIPrefix.GET_VIDEO_Signed_Url)
public AppResponse<String> getVideoMaterialSignedUrl(@RequestBody AppRequest<SignedUrlRequest> request) {
try {
String s = materialService.getVideoMaterialSignedUrl(request.getData());
Expand All @@ -61,26 +68,42 @@ public AppResponse<String> getVideoMaterialSignedUrl(@RequestBody AppRequest<Sig
return AppResponse.error(null, e.getMessage(), "Server Error", "500", "");
}
}
@GetMapping (ResourceManagementURI.MATERIAL + ResourceManagementURI.MATERIAL_ID)
public AppResponse<MaterialResponseDto> getMaterialById(@PathVariable UUID materialId) {

@PreAuthorize("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_TEACHER')")
@PostMapping (ResourceManagementURI.MATERIAL+URIPrefix.GET_Pre_Signed_Url_To_Upload_Video)
public AppResponse<PreSignedUrlToUploadVideoResponseDto> getPreSignedUrlToUploadVideo(@RequestBody AppRequest<VideoUploadRequest> request) {
try {
MaterialResponseDto dto = materialService.getMaterialById(materialId);
return AppResponse.ok(dto);
} catch (Exception e) {
PreSignedUrlToUploadVideoResponseDto responseDto = materialService.getPreSignedUrlToUploadVideo(request.getData());
return AppResponse.ok(responseDto);
} catch (ValueNotExistException e) {
e.printStackTrace();
return AppResponse.error(null, e.getMessage(), "Value Not Found", "404", "");
}catch (Exception e) {
e.printStackTrace();
return AppResponse.error(null, e.getMessage(), "Server Error", "500", "");
}
}
@GetMapping (ResourceManagementURI.MATERIAL +URIPrefix.GET_ALL+ ResourceManagementURI.SESSION_ID)
public AppResponse<List<MaterialResponseDto>> getAllMaterialBySessionId(@PathVariable UUID sessionId) {

@PreAuthorize("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_TEACHER')")
@PostMapping (ResourceManagementURI.MATERIAL+URIPrefix.MARKED_VIDEO_AS_UPLOADED+ResourceManagementURI.MATERIAL_ID)
public AppResponse<String> markedVideoAsUploaded( @PathVariable UUID materialId) {
try {
List<MaterialResponseDto> dto = materialService.getAllMaterialBySessionId(sessionId);
return AppResponse.ok(dto);
String s = materialService.markedVideoAsUploaded(materialId);
return AppResponse.ok(s);

} catch (ValueNotExistException ex) {
ex.printStackTrace();
return AppResponse.error(null, ex.getMessage(), "Value Not Found", "404", "");

} catch (Exception e) {
e.printStackTrace();
return AppResponse.error(null, e.getMessage(), "Server Error", "500", "");
}
}






}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spring.servlet.multipart.max-request-size=10MB
#cloudfront.keyPairId=YOUR_KEY_PAIR_ID
#cloudfront.privateKeyPath=classpath:private-key.pem # Ensure the private key file is in the classpath

cloudfront.domain=https://yourdistribution.cloudfront.net
cloudfront.keyPairId=YOUR_KEY_PAIR_ID
cloudfront.privateKeyPath=classpath:private-key.pem # Ensure the private key file is in the classpath
#AWS s3
aws.s3.bucketName= YourBucketName
aws.s3.accessKey=YOUR_ACCESS_KEY
aws.s3.secretKey=YOUR_SECRET_KEY
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.Instant;
import java.util.UUID;

@Entity
Expand All @@ -14,13 +15,19 @@
@NoArgsConstructor
@Getter
@Setter
@PrimaryKeyJoinColumn(name = "material_id")
@PrimaryKeyJoinColumn(name = "material_id") // For video this was video_id
public class Material extends Content {

@Column(name = "material_name")
@Column(name = "material_name") // For video this was original video name
private String materialName;
@Column(name = "reference")
@Column(name = "reference") // For video this was S3 Key
private String reference;
@Column(name="signedUrlExpireTime")
private int signedUrlExpireTime;
@Column(name="status")
private String status; // For video this was video status (pending,uploaded)
@Column(name="created_at")
private Instant createdAt; // For video this was video created at
@Column(name = "description",columnDefinition = "TEXT")
private String description;
@ManyToOne
Expand All @@ -32,4 +39,11 @@ public class Material extends Content {
@Column(name = "is_available_for_students")
private Boolean isAvailableForStudents;

@PrePersist
public void prePersist() {
if (this.createdAt == null) {
this.createdAt = Instant.now();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MaterialType {
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "material_type_id")
private UUID materialTypeId;
@Column(name = "material_type")
@Column(name = "material_type") // e.g. VIDEO, PDF, DOCX, PPT
private String materialType;
@OneToMany(mappedBy = "materialType",cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private List<Material> materialList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import com.itgura.entity.Material;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.stereotype.Repository;

import java.time.Instant;
import java.util.List;
import java.util.UUID;

@Repository
@EnableJpaRepositories
public interface MaterialRepository extends JpaRepository<Material, UUID> {
List<Material> findAllBySession_ContentId(UUID sessionId);
@Query("SELECT m FROM Material m WHERE m.status = ?1 AND m.createdAt < ?2")
List<Material> findAllByStatusAndCreatedAtBefore(String pending, Instant cutoffTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.itgura.entity.MaterialType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.stereotype.Repository;

Expand All @@ -10,4 +11,6 @@
@Repository
@EnableJpaRepositories
public interface MaterialTypeRepository extends JpaRepository<MaterialType, UUID> {
@Query("SELECT mt FROM MaterialType mt WHERE mt.materialType = :name")
MaterialType findByName(String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.itgura.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.UUID;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class VideoUploadRequest {

@NotNull(message = "Original file name is required")
@JsonProperty("original_file_name")
private String OriginalFileName;

@NotNull(message = "Signed URL expire time required")
@JsonProperty("signed_url_expire_time")
private Integer signedUrlExpireTime;

@JsonProperty("Description")
private String description;

@JsonProperty("session_id")
private UUID sessionId;

@JsonProperty("is_available_for_students")
private Boolean isAvailableForStudents;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.itgura.response.dto;


import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.UUID;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class PreSignedUrlToUploadVideoResponseDto {

@JsonProperty("video_uuid")
private UUID id;
@JsonProperty("pre_signed_url")
private String preSignedUrl;
}
14 changes: 14 additions & 0 deletions resource-management/resource-management-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@
<artifactId>cloudfront</artifactId>
<version>2.29.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/s3 -->
<!-- <dependency>-->
<!-- <groupId>software.amazon.awssdk</groupId>-->
<!-- <artifactId>s3</artifactId>-->
<!-- <version>2.29.39</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.29.39</version>
<scope>compile</scope>
</dependency>

</dependencies>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.itgura.service;


import com.itgura.dto.AppRequest;
import com.itgura.exception.ApplicationException;
import com.itgura.exception.BadRequestRuntimeException;
import com.itgura.exception.ValueNotExistException;
import com.itgura.request.MaterialRequest;
import com.itgura.request.SignedUrlRequest;
import com.itgura.response.dto.MaterialResponseDto;
import com.itgura.request.VideoUploadRequest;
import com.itgura.response.dto.PreSignedUrlToUploadVideoResponseDto;

import javax.security.auth.login.CredentialNotFoundException;
import java.util.List;
import java.util.UUID;

public interface MaterialService {
Expand All @@ -20,9 +19,11 @@ public interface MaterialService {

String getVideoMaterialSignedUrl(SignedUrlRequest signedUrlRequest) throws Exception;

MaterialResponseDto getMaterialById(UUID materialId);
PreSignedUrlToUploadVideoResponseDto getPreSignedUrlToUploadVideo(VideoUploadRequest videoUploadRequest) throws ValueNotExistException,RuntimeException, ApplicationException;

String markedVideoAsUploaded(UUID uuid) throws ValueNotExistException;


List<MaterialResponseDto> getAllMaterialBySessionId(UUID sessionId);
// MaterialResponseDto findMaterialById(UUID materialId) throws ApplicationException, CredentialNotFoundException, BadRequestRuntimeException;
// List<MaterialResponseDto> findAllMaterial(UUID sessionId) throws ApplicationException, CredentialNotFoundException, BadRequestRuntimeException;
}
Loading
Loading