Skip to content

Commit

Permalink
[merge] 유저 등록 데이트 코스 조회 API(내가 등록한 코스) 구현 - #80
Browse files Browse the repository at this point in the history
[FEAT] 유저 등록 데이트 코스 조회 API(내가 등록한 코스) 구현 - #80
  • Loading branch information
gardening-y authored Jul 12, 2024
2 parents 5656279 + 69271db commit fa40648
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CourseController {
private final AsyncService asyncService;

@GetMapping
public ResponseEntity<CourseGetAllRes> getAllCourse(
public ResponseEntity<CourseGetAllRes> getAllCourses(
final @ModelAttribute CourseGetAllReq courseGetAllReq
) {
CourseGetAllRes courseAll = courseService.getAllCourses(courseGetAllReq);
Expand All @@ -44,7 +44,7 @@ public ResponseEntity<CourseGetAllRes> getSortedCourses(final @RequestParam Stri
}

@GetMapping("/date-access")
public ResponseEntity<DateAccessGetAllRes> getAllDataAccesCourse(
public ResponseEntity<DateAccessGetAllRes> getAllDataAccessCourse(
final @UserId Long userId
) {
DateAccessGetAllRes dateAccessGetAllRes = courseService.getAllDataAccessCourse(userId);
Expand All @@ -67,6 +67,12 @@ public ResponseEntity<CourseCreateRes> createCourse(
).body(CourseCreateRes.of(course.getId()));
}

@GetMapping("/users")
public ResponseEntity<DateAccessGetAllRes> getMyCourses(final @UserId Long userId) {
DateAccessGetAllRes dateAccessGetAllRes = courseService.getMyCourses(userId);
return ResponseEntity.ok(dateAccessGetAllRes);
}

@PostMapping("/{courseId}/date-access")
public ResponseEntity<Void> openCourse(
@UserId final Long userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ private CourseDtoGetRes convertToDto(final Course course) {
);
}

public DateAccessGetAllRes getMyCourses(Long userId) {
User findUser = getUser(userId);
List<Course> courses = courseRepository.findByUser(findUser);
List<CourseDtoGetRes> courseDtoGetResList = convertToDtoList(courses, Function.identity());
return DateAccessGetAllRes.of(courseDtoGetResList);
}

public DateAccessGetAllRes getAllDataAccessCourse(final Long userId) {
List<Course> accesses = dateAccessRepository.findCoursesByUserId(userId);
List<CourseDtoGetRes> courseDtoGetResList = convertToDtoList(accesses, Function.identity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import org.dateroad.date.domain.Course;
import org.dateroad.user.domain.User;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
Expand All @@ -12,9 +13,9 @@
@Repository
public interface CourseRepository extends JpaRepository<Course, Long> , JpaSpecificationExecutor<Course> {
boolean existsByUserId(Long userId);
List<Course> findByUser(User user);
@Query("SELECT c FROM Course c LEFT JOIN Like l ON c.id = l.course.id GROUP BY c.id ORDER BY COUNT(l) DESC")
List<Course> findTopCoursesByLikes(Pageable pageable);
@Query("SELECT c FROM Course c ORDER BY c.createdAt DESC")
List<Course> findTopCoursesByCreatedAt(Pageable pageable);
}

0 comments on commit fa40648

Please sign in to comment.