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
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
"/webjars/**")

.permitAll()
.requestMatchers("/api/v1/admin/**").hasAnyAuthority(Role.ADMIN.name())
.requestMatchers("/api/v1/student/**").hasAnyAuthority(Role.STUDENT.name())
.requestMatchers("/api/v1/teacher/**").hasAnyAuthority(Role.TEACHER.name())
.requestMatchers("/api/v1/auth-service-protected/admin/**").hasAnyAuthority(Role.ADMIN.name())
.requestMatchers("/api/v1/auth-service-protected/student/**").hasAnyAuthority(Role.STUDENT.name(), Role.ADMIN.name())
.requestMatchers("/api/v1/auth-service-protected/teacher/**").hasAnyAuthority(Role.TEACHER.name(), Role.ADMIN.name())
.anyRequest().authenticated())

.sessionManagement(manager->manager.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
package com.itgura.authservice.controller;

import com.itgura.authservice.dto.request.changeRoleRequest;
import com.itgura.authservice.services.AuthenticationService;
import com.itgura.dto.AppResponse;
import com.itgura.exception.ApplicationException;
import com.itgura.exception.ValueNotExistException;
import com.itgura.exception.ValueNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@CrossOrigin(origins = "*", allowedHeaders = "*")
@RestController
@RequestMapping("api/v1/admin")

@RequestMapping("api/v1/auth-service-protected/admin")
@RequiredArgsConstructor
public class AdminController {

@Autowired
private final AuthenticationService authenticationService;

@PostMapping("/testAdmin")
public ResponseEntity<String> seyHello() {
return ResponseEntity.ok("Hello from Admin Controller!");
}

@PostMapping("/changeRole")
public AppResponse<String> changeUserRole(@RequestBody changeRoleRequest request) {
try {
return AppResponse.ok(authenticationService.changeUserRole(request));

} catch (ValueNotExistException e) {
return AppResponse.error(null, "Value not found", "404", "", e.getMessage());

}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public AppResponse<Boolean> validateToken(@RequestParam("token") String token){

//ToDo: Remove this endpoint after testing

@PostMapping("/changeUserRole")
public AppResponse<String> changeUserRole(@RequestBody changeRoleRequest role) {
@PostMapping("/changeUserRoleTemp/{role}")
public AppResponse<String> changeUserRoleTemp(@PathVariable String role) {
{
try {
return AppResponse.ok(authenticationService.changeUserRole(role));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package com.itgura.authservice.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin(origins = "*", allowedHeaders = "*")
@RequestMapping("api/v1/student")
@RequestMapping("api/v1/auth-service-protected/student")
@RequiredArgsConstructor


public class StudentController {

@PostMapping("/testStudent")
public String seyHello() {
return "Hello from Student Controller!";
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin(origins = "*", allowedHeaders = "*")
@RequestMapping("api/v1/teacher")
@RequestMapping("api/v1/auth-service-protected/admin/teacher")
@RequiredArgsConstructor
public class TeacherController {

@PostMapping("/testTeacher")
public String seyHello() {
return "Hello from Teacher Controller!";
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.itgura.authservice.dto.request;


import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -11,5 +12,8 @@
@AllArgsConstructor
@NoArgsConstructor
public class changeRoleRequest {
@JsonProperty("username(email)")
private String username;
@JsonProperty("changeRole")
private String changeRole;
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Boolean validateToken(String token) {
return jwtService.validateToken(token);
}

public String changeUserRole( changeRoleRequest role) throws ApplicationException {
public String changeUserRole( String role) throws ApplicationException {


String authorizationHeader = UserUtil.extractToken();
Expand All @@ -99,7 +99,7 @@ public String changeUserRole( changeRoleRequest role) throws ApplicationExceptio
Optional<User> user = userRepository.findByEmail(email);

if (user.isPresent()) {
user.get().setRole(Role.valueOf(role.getChangeRole()));
user.get().setRole(Role.valueOf(role));
userRepository.save(user.get());
return "Role changed successfully";
}else {
Expand All @@ -111,4 +111,17 @@ public String changeUserRole( changeRoleRequest role) throws ApplicationExceptio
}

}

public String changeUserRole(changeRoleRequest request) throws ValueNotExistException {
String email = request.getUsername();
Optional<User> user = userRepository.findByEmail(email);

if (user.isPresent()) {
user.get().setRole(Role.valueOf(request.getChangeRole()));
userRepository.save(user.get());
return "Role changed successfully";
}else {
throw new ValueNotExistException("User: "+email+ " not found");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class URIPathVariable {
public static final String PAYMENT_SERVICE = "/payment-service";
public static final String QUIZ_SERVICE = "/quiz-service";
public static final String CONTENT_ID = "/{contentId}";
public static final String REF = "/{ref}";
}
1 change: 1 addition & 0 deletions lib-global/src/main/java/com/itgura/util/URIPrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public class URIPrefix {
public static final String GET_ACCESS_TIME_DURATION = "/get-access-time-duration";
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";
}
13 changes: 13 additions & 0 deletions lms-gateway/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ spring.cloud.gateway.routes[2].filters[0].name=RewritePath
spring.cloud.gateway.routes[2].filters[0].args.regexp=/auth-service/(?<remaining>.*)
spring.cloud.gateway.routes[2].filters[0].args.replacement=/api/v1/auth-service/${remaining}

#auth-service-protected
spring.cloud.gateway.routes[5].id=auth-service-protected
spring.cloud.gateway.routes[5].uri=lb://auth-service
spring.cloud.gateway.routes[5].predicates[0].name=Path
spring.cloud.gateway.routes[5].predicates[0].args.pattern=/auth-service-protected/**


spring.cloud.gateway.routes[5].filters[0].name=RewritePath
spring.cloud.gateway.routes[5].filters[0].args.regexp=/auth-service-protected/(?<remaining>.*)
spring.cloud.gateway.routes[5].filters[0].args.replacement=/api/v1/auth-service-protected/${remaining}



#payment-service
spring.cloud.gateway.routes[3].id=payment-service
spring.cloud.gateway.routes[3].uri=lb://payment-service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.UUID;
Expand All @@ -34,18 +35,20 @@ public AppResponse<List<ClassResponseDto>> getAllClasses() {
}
}
@PreAuthorize("hasAuthority('ROLE_ADMIN')")
@PostMapping(ResourceManagementURI.CLASS + ResourceManagementURI.CREATE)
public AppResponse<String> createClass(@RequestBody AppRequest<ClassRequest> request) {
@PostMapping(value = ResourceManagementURI.CLASS + ResourceManagementURI.CREATE,consumes = "multipart/form-data")
public AppResponse<String> createClass(@RequestPart("request") AppRequest<ClassRequest> request,@RequestPart(value = "image", required = false) MultipartFile file) {

try {

String response = this.classService.create(request.getData());
String response = this.classService.create(request.getData(), file);
return AppResponse.ok(response);
} catch (Exception e) {
return AppResponse.error(null, e.getMessage(), "Server Error", "500", "");
}
}



//getClassFee

@GetMapping(ResourceManagementURI.CLASS + ResourceManagementURI.GET_CLASS_FEE+URIPrefix.BY_ID)
Expand All @@ -68,10 +71,10 @@ public AppResponse<ClassResponseDto> getClass(@PathVariable UUID id) {
}
}

@PatchMapping(ResourceManagementURI.CLASS + URIPrefix.UPDATE + URIPrefix.ID)
public AppResponse<String> updateClass(@PathVariable("id") UUID id, @RequestBody AppRequest<ClassRequest> request) {
@PatchMapping(value=ResourceManagementURI.CLASS + URIPrefix.UPDATE + URIPrefix.ID,consumes = "multipart/form-data")
public AppResponse<String> updateClass(@PathVariable("id") UUID id, @RequestPart("request") AppRequest<ClassRequest> request,@RequestPart(value = "image", required = false) MultipartFile file) {
try {
String update = this.classService.update(id, request.getData());
String update = this.classService.update(id, request.getData(), file);
return AppResponse.ok(update);
} catch (Exception e) {
return AppResponse.error(null, e.getMessage(), "Server Error", "500", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.itgura.util.URIPrefix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.UUID;
Expand All @@ -21,22 +22,22 @@
public class LessonController {
@Autowired
private LessonService lessonService;
@PostMapping(ResourceManagementURI.LESSON + URIPrefix.CREATE)
public AppResponse<String> createLesson(@RequestBody AppRequest<LessonRequest> request) {
@PostMapping(value = ResourceManagementURI.LESSON + URIPrefix.CREATE, consumes = "multipart/form-data")
public AppResponse<String> createLesson(@RequestPart("request")AppRequest<LessonRequest> request,@RequestPart (value = "image", required = false) MultipartFile file) {

try {
String s = lessonService.saveLesson( request.getData());
String s = lessonService.saveLesson( request.getData(), file);
return AppResponse.ok(s);
} catch (ValueNotExistException e) {
return AppResponse.error(null, e.getMessage(), "Value Not Found", "404", "");
} catch (Exception e) {
return AppResponse.error(null, e.getMessage(), "Server Error", "500", "");
}
}
@PatchMapping(ResourceManagementURI.LESSON + URIPrefix.UPDATE+ URIPrefix.ID)
public AppResponse<String> updateLesson(@RequestBody AppRequest<LessonRequest> request, @PathVariable UUID id){
@PatchMapping(value=ResourceManagementURI.LESSON + URIPrefix.UPDATE+ URIPrefix.ID, consumes = "multipart/form-data")
public AppResponse<String> updateLesson(@RequestPart("request") AppRequest<LessonRequest> request, @PathVariable UUID id,@RequestPart (value = "image", required = false) MultipartFile file){
try {
String s = lessonService.updateLesson(request.getData(), id);
String s = lessonService.updateLesson(request.getData(), id, file);
return AppResponse.ok(s);
} catch (ValueNotExistException e) {
return AppResponse.error(null, e.getMessage(), "Value Not Found", "404", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.itgura.dto.AppRequest;
import com.itgura.dto.AppResponse;
import com.itgura.request.MaterialRequest;
import com.itgura.request.SignedUrlRequest;
import com.itgura.service.MaterialService;
import com.itgura.util.ResourceManagementURI;
import com.itgura.util.URIPathVariable;
Expand Down Expand Up @@ -49,5 +50,17 @@ public AppResponse<String> deleteMaterial(@PathVariable UUID materialId) {
}
}

@GetMapping(ResourceManagementURI.MATERIAL + URIPrefix.GET_VIDEO_Signed_Url)
public AppResponse<String> getVideoMaterialSignedUrl(@RequestBody AppRequest<SignedUrlRequest> request) {
try {
String s = materialService.getVideoMaterialSignedUrl(request.getData());
return AppResponse.ok(s);
} 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 @@ -3,4 +3,17 @@ spring.application.name=resource-management
logging.level.org.springframework.core.env=DEBUG
spring.profiles.active=dev
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration
logging.level.org.springframework.security=DEBUG
logging.level.org.springframework.security=DEBUG

spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB

#CloudFront
#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

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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class Content {
private List<ContentTag> contentTagList;
@Enumerated(EnumType.STRING)
private ContentAccessType contentAccessType;
@Lob
@Column(name = "image")
private Byte[] image;


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
@Getter
@PrimaryKeyJoinColumn(name = "quiz_image_id")
public class QuizImage extends Content{
@Column(name = "image")
private byte[] image;
@Column(name = "quiz_image")
private byte[] quizImage;
@OneToOne
@JoinColumn(name = "quiz_question_id")
private QuizQuestion quizQuestion;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.itgura.request;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SignedUrlRequest {
@JsonProperty("filePath")
String filePath;
@JsonProperty("userIpAddress")
String userIpAddress;
@JsonProperty("expiresInHours")
int expiresInHours;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public class ClassResponseDto {
private String className;
@JsonProperty("content_access_type")
private ContentAccessType contentAccesstype;
@JsonProperty("image")
private String image;

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ public class LessonResponseDto {
private String updatedByName;
@JsonProperty("content_access_type")
private ContentAccessType contentAccesstype;
@JsonProperty("image")
private String image;

}
Loading
Loading