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 @@ -23,7 +23,9 @@
@Getter
@Setter
@Builder
@Table(name = "course")
@Table(name = "course", indexes = {
@Index(name = "idx_course_title", columnList = "title")
})
public class Course extends AbstractAuditEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -25,6 +26,18 @@ public CourseController(CourseService courseService) {
this.courseService = courseService;
}

@GetMapping("/courses/spec")
public ResponseEntity<PageableData<CourseVM>> testSpecification (
Pageable pageable,
@RequestParam(value = "course", required = false) String[] course,
@RequestParam(value = "category", required = false) String [] category

) {
PageableData<CourseVM> pageableCourses = courseService.advanceSearchWithSpecifications(pageable, course, category);
return ResponseEntity.ok().body(pageableCourses);
}



@GetMapping("/admin/courses/paging")
public ResponseEntity<PageableData<CourseVM>> getPageableCourse (
Expand Down Expand Up @@ -52,7 +65,7 @@ public ResponseEntity<List<CourseListGetVM>> getPageableCourse (
@GetMapping("/courses/search")
public ResponseEntity<PageableData<CourseListGetVM>> getCoursesByMultiQueryWithPageable (
@RequestParam(value = "pageNum", defaultValue = Constants.PageableConstant.DEFAULT_PAGE_NUMBER, required = false) int pageNum,
@RequestParam(value = "pageSize", defaultValue = Constants.PageableConstant.DEFAULT_PAGE_SIZE, required = false) int pageSize,
@RequestParam(value = "pageSize", defaultValue = Constants.PageableConstant.DEFAULT_COURSE_PAGE_SIZE, required = false) int pageSize,
@RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "ratingStar", required = false) Float rating,
@RequestParam(value = "level", required = false) List<String> level,
Expand Down Expand Up @@ -125,12 +138,16 @@ public ResponseEntity<Void> delete (
return ResponseEntity.noContent().build();
}


@GetMapping("/admin/courses/promotions/{promotionId}")
public ResponseEntity<List<CourseAssignPromotion>> getByPromotionId(@PathVariable("promotionId") Long promotionId){
List<CourseAssignPromotion> courses = courseService.getByPromotionId(promotionId);
return ResponseEntity.ok().body(courses);
}

@GetMapping("/courses/suggestions")
public ResponseEntity<List<String>> getSuggestions(@RequestParam("keyword") String keyword){
return ResponseEntity.ok().body(courseService.getSuggestion(keyword));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.backend.elearning.domain.section.Section;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

Expand All @@ -15,7 +13,11 @@
import java.util.Optional;

@Repository
public interface CourseRepository extends JpaRepository<Course, Long> {
public interface CourseRepository extends JpaRepository<Course, Long> , JpaSpecificationExecutor<Course> {


@Override
Page<Course> findAll(Specification<Course> spec, Pageable pageable);

@Query("""
select count(1)
Expand Down Expand Up @@ -310,6 +312,12 @@ Page<Course> findByMultiQueryWithKeyword(
);


@Query("SELECT p FROM Course p " +
"WHERE LOWER(p.title) LIKE LOWER(CONCAT('%', :keyword, '%'))")
List<Course> getSuggestionCourse(@Param("keyword") String keyword, Pageable pageable);




@Query(value = """
select c
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.backend.elearning.domain.course;

import com.backend.elearning.domain.common.PageableData;
import org.springframework.data.domain.Pageable;

import java.util.List;

Expand Down Expand Up @@ -35,4 +36,8 @@ PageableData<CourseListGetVM> getCoursesByMultiQuery(int pageNum,
List<CourseAssignPromotion> getByPromotionId(Long promotionId);

List<CourseListGetVM> getCoursesByCategory(String categoryName, int pageNum, int pageSize);

List<String> getSuggestion(String keyword);

PageableData<CourseVM> advanceSearchWithSpecifications(Pageable pageable, String[] course, String[] category);
}
Loading
Loading