22
33import com .itgura .dto .AppRequest ;
44import com .itgura .dto .AppResponse ;
5+ import com .itgura .exception .ValueNotExistException ;
56import com .itgura .request .MaterialRequest ;
67import com .itgura .request .SignedUrlRequest ;
7- import com .itgura .response .dto .MaterialResponseDto ;
8+ import com .itgura .request .VideoUploadRequest ;
9+ import com .itgura .response .dto .PreSignedUrlToUploadVideoResponseDto ;
810import com .itgura .service .MaterialService ;
911import com .itgura .util .ResourceManagementURI ;
1012import com .itgura .util .URIPathVariable ;
1113import com .itgura .util .URIPrefix ;
14+ import io .swagger .annotations .ApiOperation ;
1215import org .springframework .beans .factory .annotation .Autowired ;
16+ import org .springframework .security .access .prepost .PreAuthorize ;
1317import org .springframework .web .bind .annotation .*;
1418
1519import java .util .UUID ;
2024public class MaterialController {
2125 @ Autowired
2226 private MaterialService materialService ;
27+ @ PreAuthorize ("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_TEACHER')" )
2328 @ PostMapping ( ResourceManagementURI .MATERIAL +URIPrefix .CREATE +ResourceManagementURI .SESSION_ID )
2429 public AppResponse <String > createMaterial (@ PathVariable UUID sessionId , @ RequestBody AppRequest <MaterialRequest > request ) {
2530 try {
@@ -30,6 +35,7 @@ public AppResponse<String> createMaterial(@PathVariable UUID sessionId, @Request
3035 return AppResponse .error (null , e .getMessage (), "Server Error" , "500" , "" );
3136 }
3237 }
38+ @ PreAuthorize ("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_TEACHER')" )
3339 @ PatchMapping ( ResourceManagementURI .MATERIAL +URIPrefix .UPDATE +ResourceManagementURI .MATERIAL_ID )
3440 public AppResponse <String > updateMaterial (@ PathVariable UUID materialId , @ RequestBody AppRequest <MaterialRequest > request ) {
3541 try {
@@ -40,6 +46,7 @@ public AppResponse<String> updateMaterial(@PathVariable UUID materialId, @Reques
4046 return AppResponse .error (null , e .getMessage (), "Server Error" , "500" , "" );
4147 }
4248 }
49+ @ PreAuthorize ("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_TEACHER')" )
4350 @ DeleteMapping ( ResourceManagementURI .MATERIAL +URIPrefix .DELETE +ResourceManagementURI .MATERIAL_ID )
4451 public AppResponse <String > deleteMaterial (@ PathVariable UUID materialId ) {
4552 try {
@@ -51,7 +58,7 @@ public AppResponse<String> deleteMaterial(@PathVariable UUID materialId) {
5158 }
5259 }
5360
54- @ PostMapping (ResourceManagementURI .MATERIAL + URIPrefix .GET_VIDEO_Signed_Url )
61+ @ PostMapping (ResourceManagementURI .MATERIAL + URIPrefix .GET_VIDEO_Signed_Url )
5562 public AppResponse <String > getVideoMaterialSignedUrl (@ RequestBody AppRequest <SignedUrlRequest > request ) {
5663 try {
5764 String s = materialService .getVideoMaterialSignedUrl (request .getData ());
@@ -61,26 +68,42 @@ public AppResponse<String> getVideoMaterialSignedUrl(@RequestBody AppRequest<Sig
6168 return AppResponse .error (null , e .getMessage (), "Server Error" , "500" , "" );
6269 }
6370 }
64- @ GetMapping (ResourceManagementURI .MATERIAL + ResourceManagementURI .MATERIAL_ID )
65- public AppResponse <MaterialResponseDto > getMaterialById (@ PathVariable UUID materialId ) {
71+
72+ @ PreAuthorize ("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_TEACHER')" )
73+ @ PostMapping (ResourceManagementURI .MATERIAL +URIPrefix .GET_Pre_Signed_Url_To_Upload_Video )
74+ public AppResponse <PreSignedUrlToUploadVideoResponseDto > getPreSignedUrlToUploadVideo (@ RequestBody AppRequest <VideoUploadRequest > request ) {
6675 try {
67- MaterialResponseDto dto = materialService .getMaterialById (materialId );
68- return AppResponse .ok (dto );
69- } catch (Exception e ) {
76+ PreSignedUrlToUploadVideoResponseDto responseDto = materialService .getPreSignedUrlToUploadVideo (request .getData ());
77+ return AppResponse .ok (responseDto );
78+ } catch (ValueNotExistException e ) {
79+ e .printStackTrace ();
80+ return AppResponse .error (null , e .getMessage (), "Value Not Found" , "404" , "" );
81+ }catch (Exception e ) {
7082 e .printStackTrace ();
7183 return AppResponse .error (null , e .getMessage (), "Server Error" , "500" , "" );
7284 }
7385 }
74- @ GetMapping (ResourceManagementURI .MATERIAL +URIPrefix .GET_ALL + ResourceManagementURI .SESSION_ID )
75- public AppResponse <List <MaterialResponseDto >> getAllMaterialBySessionId (@ PathVariable UUID sessionId ) {
86+
87+ @ PreAuthorize ("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_TEACHER')" )
88+ @ PostMapping (ResourceManagementURI .MATERIAL +URIPrefix .MARKED_VIDEO_AS_UPLOADED +ResourceManagementURI .MATERIAL_ID )
89+ public AppResponse <String > markedVideoAsUploaded ( @ PathVariable UUID materialId ) {
7690 try {
77- List <MaterialResponseDto > dto = materialService .getAllMaterialBySessionId (sessionId );
78- return AppResponse .ok (dto );
91+ String s = materialService .markedVideoAsUploaded (materialId );
92+ return AppResponse .ok (s );
93+
94+ } catch (ValueNotExistException ex ) {
95+ ex .printStackTrace ();
96+ return AppResponse .error (null , ex .getMessage (), "Value Not Found" , "404" , "" );
97+
7998 } catch (Exception e ) {
8099 e .printStackTrace ();
81100 return AppResponse .error (null , e .getMessage (), "Server Error" , "500" , "" );
82101 }
83102 }
84103
85104
105+
106+
107+
108+
86109}
0 commit comments