Skip to content

Commit

Permalink
Merge pull request #128 from Dear-project/feat/#120
Browse files Browse the repository at this point in the history
feat: bookMark
  • Loading branch information
GayeongKimm authored Oct 22, 2024
2 parents 46fa4fd + bc045d0 commit 7069322
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.dear.domain.professor.dto.response;

import com.dear.domain.bookMark.domain.BookMarkEntity;
import com.dear.domain.major.dto.Major;
import com.dear.domain.school.dto.School;
import com.dear.domain.user.dto.User;
import com.dear.domain.major.domain.MajorEntity;
import com.dear.domain.school.domain.SchoolEntity;
import com.dear.domain.user.domain.UserEntity;
import com.dear.global.common.image.entity.ImageEntity;

import java.util.Optional;
Expand All @@ -14,18 +13,20 @@ public record ProfessorLoadResponse(
String school,
String major,
String email,
String profileImage
String profileImage,
Boolean isBookMarked
) {


public static ProfessorLoadResponse of(User user, School school, Major major, ImageEntity profileImage) {
public static ProfessorLoadResponse of(UserEntity user, SchoolEntity school, Optional<MajorEntity> major, ImageEntity profileImage, Boolean isBookMarked) {
return new ProfessorLoadResponse(
user.getId(),
user.getName(),
school != null ? school.getSchoolName() : null,
major != null ? major.getMClass() : null,
major.map(MajorEntity::getMClass).orElse(null),
user.getEmail(),
profileImage != null ? profileImage.getImagePath() : null
profileImage != null ? profileImage.getImagePath() : null,
isBookMarked
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.dear.domain.professor.dto.response.ProfessorLoadResponse;
import com.dear.domain.professor.service.LoadProfessorService;
import com.dear.domain.professor.service.ProfessorServiceImpl;
import com.dear.global.common.dto.request.PageRequest;
import com.dear.global.response.ResponseData;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -23,13 +24,15 @@
public class ProfessorController {

private final LoadProfessorService loadProfessorService;
private final ProfessorServiceImpl professorService;

@Operation(description = "load Professor")
@GetMapping("")
public ResponseData<List<ProfessorLoadResponse>> loadProfessor(
@Valid @ModelAttribute PageRequest pageRequest
){
return ResponseData.of(HttpStatus.OK, "조회 성공", loadProfessorService.loadProfessor(pageRequest));
}
){
// return ResponseData.of(HttpStatus.OK, "조회 성공", loadProfessorService.loadProfessor(pageRequest));
return ResponseData.of(HttpStatus.OK, "조회 성공", professorService.load());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.dear.domain.professor.service;

import com.dear.domain.bookMark.repository.BookMarkRepository;
import com.dear.domain.major.domain.MajorEntity;
import com.dear.domain.major.repository.MajorRepository;
import com.dear.domain.professor.dto.response.ProfessorLoadResponse;
import com.dear.domain.professor.repository.query.QueryDslRepository;
import com.dear.domain.user.domain.UserEntity;
import com.dear.domain.user.enums.UserRole;
import com.dear.domain.user.mapper.UserMapper;
import com.dear.domain.user.repository.UserRepository;
import com.dear.global.common.repository.UserSecurity;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
@AllArgsConstructor
public class ProfessorServiceImpl{
private final UserSecurity userSecurity;
private final UserRepository userRepository;
private final BookMarkRepository bookMarkRepository;
private final QueryDslRepository queryDslRepository;
private final UserMapper userMapper;
private final MajorRepository majorRepository;

public List<ProfessorLoadResponse> load(){
UserEntity userEntity = userMapper.toEntity(userSecurity.getUser());
Optional<MajorEntity> majorEntity = majorRepository.findById(userEntity.getId());
List<UserEntity> professor = userRepository.findByRole(UserRole.PROFESSOR);

return professor.stream()
.map(professor1->ProfessorLoadResponse.of(
professor1,
professor1.getSchools(),
majorEntity,
queryDslRepository.findProfile(professor1.getId()),
bookMarkRepository.existsByProfessorEntityAndUser(professor1, userEntity)
))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import com.dear.domain.school.domain.SchoolEntity;
import com.dear.domain.user.domain.UserEntity;
import com.dear.domain.user.enums.UserRole;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface UserRepository extends JpaRepository<UserEntity,Long> {

Optional<UserEntity> findByEmail(String email);
boolean existsByEmail(String email);

UserEntity getByEmail(String email);
List<UserEntity> findByRole(UserRole userRole);

}

0 comments on commit 7069322

Please sign in to comment.