Skip to content

Commit

Permalink
Merge pull request #177 from Funssion-SWM/develope
Browse files Browse the repository at this point in the history
Develope
  • Loading branch information
comolove authored Nov 9, 2023
2 parents 5a04d08 + 65ce3af commit 6216b8e
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class Employee {
private final Long userId;
private final String username;
private final String email;
private final String imagePath;
private final String rank;
private final String introduce;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public class EmployeeWithStatus {
private final Long userId;
private final String username;
private final String email;
private final String imagePath;
private final String rank;
private final String introduce;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public List<Long> getEmployersLikedUser(Long likedUserId) {
public List<Employee> getInterviewEmployees(Boolean isDone){
Long employerId = SecurityContextUtils.getAuthorizedUserId();
String sql =
"SELECT U.id, U.name, U.image_path, U.rank, EMP.introduce, EMP.development_area, EMP.description, EMP.tech_stack, EMP.is_visible " +
"SELECT U.id, U.name, U.email, U.image_path, U.rank, EMP.introduce, EMP.development_area, EMP.description, EMP.tech_stack, EMP.is_visible " +
"FROM member.info U, member.professional_profile EMP " +
"WHERE U.id = EMP.user_id " +
"AND (SELECT status " +
Expand All @@ -50,7 +50,7 @@ public List<Employee> getInterviewEmployees(Boolean isDone){
public List<EmployeeWithStatus> getLikeEmployees() {
Long employerId = SecurityContextUtils.getAuthorizedUserId();
String sql =
"SELECT U.id, U.name, U.image_path, U.rank, EMP.introduce, EMP.development_area, EMP.description, EMP.tech_stack, EMP.is_visible, INTER.status " +
"SELECT U.id, U.name, U.email, U.image_path, U.rank, EMP.introduce, EMP.development_area, EMP.description, EMP.tech_stack, EMP.is_visible, INTER.status " +
"FROM member.info U " +
"INNER JOIN member.professional_profile EMP " +
"ON U.id = EMP.user_id " +
Expand Down Expand Up @@ -133,6 +133,7 @@ private RowMapper<Employee> employeeListRowMapper(){
Employee.builder()
.userId(rs.getLong("id"))
.username(rs.getString("name"))
.email(rs.getString("email"))
.imagePath(rs.getString("image_path"))
.rank(rs.getString("rank"))
.developmentArea(rs.getString("development_area"))
Expand All @@ -148,6 +149,7 @@ private RowMapper<EmployeeWithStatus> employeeWithStatusListRowMapper(){
EmployeeWithStatus.builder()
.userId(rs.getLong("id"))
.username(rs.getString("name"))
.email(rs.getString("email"))
.imagePath(rs.getString("image_path"))
.rank(rs.getString("rank"))
.developmentArea(rs.getString("development_area"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public void removeMemo(@PathVariable @Min(1) Long id) {
memoService.deleteMemo(id);
}

@GetMapping("/{id}/recommendations")
public List<MemoListDto> getMemoRecommendationsByTags(
@PathVariable @Min(1) Long id
) {
return memoService.getMemoRecommendations(id);
}

@PostMapping("/{id}/image")
public ImageDto uploadImageInMemo(
@PathVariable @Min(1) Long id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface MemoRepository {
List<Memo> findAllOrderById(Long pageNum, Long resultCntPerPage);
List<Memo> findAllByUserIdOrderById(Long userId, Long pageNum, Long resultCntPerPage);
List<Memo> findAllLikedMemosByUserId(Long userId, Long pageNum, Long resultCntPerPage);
List<Memo> findAllByTagsOrderByMatchesAndLikes(Long memoId);
List<Memo> findAllDraftMemosByUserId(Long userId);
List<Memo> findAllBySearchQuery(List<String> searchStringList, OrderType orderType, Long userId, Long pageNum, Long resultCntPerPage);
List<Memo> findAllByTag(String tagText, OrderType orderType, Long pageNum, Long resultCntPerPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ public List<Memo> findAllLikedMemosByUserId(Long userId, Long pageNum, Long resu
return template.query(sql, memoRowMapper(), userId, resultCntPerPage, resultCntPerPage*pageNum);
}

@Override
public List<Memo> findAllByTagsOrderByMatchesAndLikes(Long memoId) {
String sql = "SELECT m.* " +
"FROM post.memo m , UNNEST(m.tags) tag_element " +
"WHERE tag_element ILIKE ANY(ARRAY(SELECT tags FROM post.memo WHERE id = ? AND array_length(tags, 1) >= 1)) " +
"AND NOT id = ? " +
"AND is_temporary = false " +
"GROUP BY id " +
"ORDER BY COUNT(tag_element) desc, likes desc, id desc";

return template.query(sql, memoRowMapper(), memoId, memoId);
}

@Override
public List<Memo> findAllDraftMemosByUserId(Long userId) {
String sql = "select * from post.memo where author_id = ? and is_temporary = true order by id desc";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ public MemoDto getMemoBy(Long memoId) {
return responseDto;
}

public List<MemoListDto> getMemoRecommendations(Long id) {

return memoRepository.findAllByTagsOrderByMatchesAndLikes(id).stream()
.map(MemoListDto::new)
.toList();
}

@Transactional
public MemoDto updateMemo(Long memoId, MemoSaveDto form) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class UserProfileForEmployer {

private final Long id;
private final String name;
private final String email;
private final String imagePath;
private final String rank;
private final String introduce;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public List<UserProfileForEmployer> findUserProfilesForEmployer(TechStackDto tec
paramList.add(techStackDto.getDevelopmentArea());
String sql = "SELECT *, CASE WHEN EMPLOYER_LIKE.employee_id IS NOT NULL THEN 'true' ELSE 'false' END AS i_like " +
"FROM (" +
" SELECT m.id, m.name, m.image_path, m.rank, p.introduce, p.development_area, p.tech_stack, p.description, (" +
" SELECT m.id, m.name, m.email, m.image_path, m.rank, p.introduce, p.development_area, p.tech_stack, p.description, (" +
" SELECT 2*count(stack_element)" +
" FROM jsonb_array_elements(p.tech_stack) AS stack_element" +
" WHERE p.development_area = ? AND stack_element->>'stack' in " + techStackElements(techStackDto.getTechStacks(), paramList) +
Expand Down Expand Up @@ -148,6 +148,7 @@ private RowMapper<UserProfileForEmployer> userProfileRowMapperForEmployer() {
return (rs, rowNum) -> UserProfileForEmployer.builder()
.id(rs.getLong("id"))
.name(rs.getString("name"))
.email(rs.getString("email"))
.isLike(rs.getBoolean("i_like"))
.imagePath(rs.getString("image_path"))
.rank(rs.getString("rank"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Funssion.Inforum.common.exception.etc.ArrayToListException;
import Funssion.Inforum.common.exception.etc.UnAuthorizedException;
import Funssion.Inforum.common.utils.SecurityContextUtils;
import Funssion.Inforum.domain.employer.repository.EmployerRepository;
import Funssion.Inforum.domain.follow.repository.FollowRepository;
import Funssion.Inforum.domain.member.entity.MemberProfileEntity;
import Funssion.Inforum.domain.mypage.exception.HistoryNotFoundException;
Expand Down Expand Up @@ -47,6 +48,8 @@ public class MemoServiceTest {
@Mock MemoRepository memoRepository;
@Mock TagRepository tagRepository;
@Mock MyRepository myRepository;
@Mock
EmployerRepository employerRepository;
@Mock S3Repository s3Repository;
@Mock
ScoreRepository scoreRepository;
Expand Down Expand Up @@ -373,6 +376,8 @@ void createMemoWithLogin() {
willThrow(HistoryNotFoundException.class)
.given(myRepository)
.updateHistory(any(), any(), any(), any());
given(employerRepository.getEmployersLikedUser(any()))
.willReturn(Collections.emptyList());

MemoDto memo = memoService.createMemo(memoSaveDto);

Expand Down Expand Up @@ -456,6 +461,8 @@ void updateTempMemoToRealMemoFirstTime() {
.willReturn(memo2);
given(followRepository.findFollowedUserIdByUserId(any()))
.willReturn(Collections.emptyList());
given(employerRepository.getEmployersLikedUser(any()))
.willReturn(Collections.emptyList());

MemoDto updated = memoService.updateMemo(memoID4, memoSaveDto);

Expand All @@ -473,6 +480,8 @@ void updateTempMemoToRealMemo() {
.willReturn(memo2);
given(followRepository.findFollowedUserIdByUserId(any()))
.willReturn(Collections.emptyList());
given(employerRepository.getEmployersLikedUser(any()))
.willReturn(Collections.emptyList());

MemoDto updated = memoService.updateMemo(memoID5, memoSaveDto);

Expand Down Expand Up @@ -525,6 +534,8 @@ void updateMemoToTempMemoWithLoginEx() throws SQLException {
.willThrow(SQLException.class);
given(followRepository.findFollowedUserIdByUserId(any()))
.willReturn(Collections.emptyList());
given(employerRepository.getEmployersLikedUser(any()))
.willReturn(Collections.emptyList());

assertThatThrownBy(() -> memoService.updateMemo(memoID4, memoSaveDto))
.isInstanceOf(ArrayToListException.class);
Expand Down

0 comments on commit 6216b8e

Please sign in to comment.