Skip to content

Commit

Permalink
fix courseLearning requests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdo1511 committed Nov 25, 2024
1 parent 0602841 commit 04b55ed
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ResponseEntity<?> createCourse(Principal principal, @Valid @RequestBody C
}

@DeleteMapping("/{id}")
@PreAuthorize("hasPermission(#id, 'course.amdin.{id}')")
@PreAuthorize("hasPermission(#id, 'course.amdin.{long}')")
public ResponseEntity<?> deleteCourse(Principal principal, @PathVariable Long id) {
courseService.deleteCourse(principal, id);
return ResponseEntity.ok().build();
Expand Down Expand Up @@ -103,14 +103,14 @@ public ResponseEntity<Long> createCourseLearningResourceCategory(@Valid @Request
return ResponseEntity.status(HttpStatus.CREATED).body(id);
}

@GetMapping("/resource/categories")
@PreAuthorize("hasPermission(#id, 'course.amdin.{id}')")
@GetMapping("/resource/categories/{id}")
@PreAuthorize("hasPermission(#id, 'course.amdin.{long}')")
public ResponseEntity<List<CourseLearningResourceCategoryEntityDto>> getCourseLearningResourceCategory(@PathVariable Long id) {
return ResponseEntity.ok(courseService.getCourseLearningResourceCategories(id));
}

@DeleteMapping("/resource/category/{id}")
@PreAuthorize("hasPermission(#id, 'course.amdin.{id}')")
@PreAuthorize("hasPermission(#id, 'course.amdin.{long}')")
public ResponseEntity<Long> deleteCourseLearningResourceCategory(@PathVariable Long id) {
courseService.deleteCourseLearningResourceCategory(id);
return ResponseEntity.status(HttpStatus.OK).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public List<CourseLearningResourceEntityDto> getCourseLearningResource(Long cate
public Long createResource(CreateCourseLearningResourceModel createCourseLearningResourceModel) {
CourseLearningResourceFolderEntity courseLearningResourceFolderEntity = null;
if (!(createCourseLearningResourceModel.getFolderId() == null)) {
courseLearningResourceFolderEntity = courseLearningResourceFolderRepository.findById(createCourseLearningResourceModel.getFolderId()).orElse(null);
courseLearningResourceFolderEntity = courseLearningResourceFolderRepository.findCourseLearningResourceFolderEntityById(createCourseLearningResourceModel.getFolderId()).orElse(null);
}

CourseLearningResourceEntity courseLearningResourceEntity = CourseLearningResourceEntity.builder()
Expand All @@ -69,6 +69,7 @@ public void deleteResource(Long id) {
public Long createFolder(CreateCourseLEarningFolderModel createCourseLEarningFolderModel) {
CourseLearningResourceFolderEntity courseLearningResourceFolderEntity = CourseLearningResourceFolderEntity.builder()
.name(createCourseLEarningFolderModel.getName())
.category(CourseLearningResourceCategoryEntity.builder().id(createCourseLEarningFolderModel.getCategoryId()).build())
.build();
courseLearningResourceFolderRepository.save(courseLearningResourceFolderEntity);
return courseLearningResourceFolderEntity.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface CourseLearningResourceFolderRepository extends JpaRepository<CourseLearningResourceFolderEntity, Long> {
Optional<CourseLearningResourceFolderEntity> findCourseLearningResourceFolderEntityById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
public class CreateCourseLEarningFolderModel {

private String name;
private Long categoryId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public PermissionElevator(UserPermissionService userPermissionService) {

@Override
public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
if (targetDomainObject.getClass().equals(Long.class)) {
return userPermissionService.hasPermission(authentication.getName(), permission.toString().replace("{" + "long" + "}", targetDomainObject.toString()));
}
String permissionName = permission.toString();
if (targetDomainObject != null) {
for (Field field : targetDomainObject.getClass().getDeclaredFields()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.espada.ep.iptip.user.optional_user_event;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
@Table(name = "optional_user_event")
public class OptionalUserEventEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "user_id")
private Long userId;
@Column(name = "event_id")
private Long eventId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ResponseEntity<?> createGroup(Principal principal, @Valid @RequestBody Cr
}

@GetMapping("/{id}")
@PreAuthorize("hasPermission(#id, 'group.{group}')")
@PreAuthorize("hasPermission(#id, 'group.{long}')")
public ResponseEntity<GroupEntityDto> getGroup(@PathVariable Long id) {
return ResponseEntity.ok(groupService.getGroup(id));
}
Expand Down

0 comments on commit 04b55ed

Please sign in to comment.