Skip to content

Commit

Permalink
Feature: 기술 스택 기반 원티드 JD 및 인프런 강의 조회 API
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonseon12 committed Jan 24, 2024
1 parent 05ec2da commit 3c6547d
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package kernel.jdon.skill.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -12,8 +9,6 @@
import kernel.jdon.auth.dto.SessionUserInfo;
import kernel.jdon.dto.response.CommonResponse;
import kernel.jdon.global.annotation.LoginUser;
import kernel.jdon.skill.dto.response.FindJdResponse;
import kernel.jdon.skill.dto.response.FindLectureResponse;
import kernel.jdon.skill.dto.response.FindListDataBySkillResponse;
import kernel.jdon.skill.dto.response.FindListHotSkillResponse;
import kernel.jdon.skill.dto.response.FindListJobCategorySkillResponse;
Expand All @@ -25,6 +20,7 @@
@RequiredArgsConstructor
public class SkillController {
private final SkillService skillService;

@GetMapping("/api/v1/skills/hot")
public ResponseEntity<CommonResponse> getHotSkillList() {
FindListHotSkillResponse hotSkillList = skillService.findHotSkillList();
Expand All @@ -51,41 +47,7 @@ public ResponseEntity<CommonResponse> getJobCategorySkillList(@PathVariable Long
@GetMapping("/api/v1/skills/search")
public ResponseEntity<CommonResponse> getDataListBySkill(
@RequestParam(name = "keyword", defaultValue = "") String keyword) {

List<FindLectureResponse> findLectureResponseList = new ArrayList<>();
List<FindJdResponse> findJdResponseList = new ArrayList<>();
for (long i = 1; i <= 3; i++) {
FindLectureResponse findLectureResponse = FindLectureResponse.builder()
.lectureId(i)
.title("스프링부트 고급편_" + i)
.lectureUrl("www.inflearn.com/we234")
.imageUrl(
"https://cdn.inflearn.com/public/courses/327260/cover/a51a5154-c375-4210-9fb1-0b716fd4ac73/327260-eng.png")
.instructor("김영한")
.studentCount(5332)
.price(180000)
.isFavorite(false)
.build();

findLectureResponseList.add(findLectureResponse);
}

for (long i = 1; i <= 6; i++) {
FindJdResponse findJdResponse = FindJdResponse.builder()
.company("트렌비_" + i)
.title("백엔드개발자_" + i)
.imageUrl("https://www.amazon.s3.sdkjfhwk.dkjfhwkjdh")
.jdUrl("https://www.wanted.co.kr/wd/196444")
.build();

findJdResponseList.add(findJdResponse);
}

FindListDataBySkillResponse findListDataBySkillResponse =
FindListDataBySkillResponse.builder()
.lectureList(findLectureResponseList)
.jdList(findJdResponseList)
.build();
FindListDataBySkillResponse findListDataBySkillResponse = skillService.findDataBySkillList(keyword);

return ResponseEntity.ok(CommonResponse.of(findListDataBySkillResponse));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package kernel.jdon.skill.dto.object;

import com.querydsl.core.annotations.QueryProjection;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class FindLectureDto {
private Long lectureId;
private String title;
private String lectureUrl;
private String imageUrl;
private String instructor;
private Long studentCount;
private Integer price;
private Boolean isFavorite;

@Builder
@QueryProjection
public FindLectureDto(Long lectureId, String title, String lectureUrl, String imageUrl, String instructor,
Long studentCount, Integer price) {
this.lectureId = lectureId;
this.title = title;
this.lectureUrl = lectureUrl;
this.imageUrl = imageUrl;
this.instructor = instructor;
this.studentCount = studentCount;
this.price = price;
this.isFavorite = false; // todo 이슈번호 #189에서 수정
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package kernel.jdon.skill.dto.object;

import com.querydsl.core.annotations.QueryProjection;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class FindWantedJdDto {
private String company;
private String title;
private String imageUrl;
private String jdUrl;

@QueryProjection
public FindWantedJdDto(String company, String title, String imageUrl, String jdUrl) {
this.company = company;
this.title = title;
this.imageUrl = imageUrl;
this.jdUrl = jdUrl;
}
}

This file was deleted.

This file was deleted.

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

import java.util.List;

import kernel.jdon.skill.dto.object.FindLectureDto;
import kernel.jdon.skill.dto.object.FindWantedJdDto;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -13,6 +15,15 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor
public class FindListDataBySkillResponse {
private List<FindLectureResponse> lectureList;
private List<FindJdResponse> jdList;
private String keyword;
private List<FindLectureDto> lectureList;
private List<FindWantedJdDto> jdList;

public static FindListDataBySkillResponse of (String keyword, List<FindLectureDto> lectureList, List<FindWantedJdDto> jdList) {
return FindListDataBySkillResponse.builder()
.keyword(keyword)
.lectureList(lectureList)
.jdList(jdList)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

import kernel.jdon.skill.dto.object.FindHotSkillDto;
import kernel.jdon.skill.dto.object.FindMemberSkillDto;
import kernel.jdon.skill.dto.object.FindWantedJdDto;
import kernel.jdon.skill.dto.object.FindLectureDto;

public interface SkillRepositoryCustom {
List<FindHotSkillDto> findHotSkillList();

List<FindMemberSkillDto> findMemberSkillList(Long memberId);
List<FindWantedJdDto> findWantedJdListBySkill(String keyword);
List<FindLectureDto> findInflearnLectureListBySkill(String keyword);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package kernel.jdon.skill.repository;

import static kernel.jdon.inflearncourse.domain.QInflearnCourse.*;
import static kernel.jdon.inflearnjdskill.domain.QInflearnJdSkill.*;
import static kernel.jdon.memberskill.domain.QMemberSkill.*;
import static kernel.jdon.skill.domain.QSkill.*;
import static kernel.jdon.skillhistory.domain.QSkillHistory.*;
import static kernel.jdon.wantedjd.domain.QWantedJd.*;
import static kernel.jdon.wantedjdskill.domain.QWantedJdSkill.*;

import java.util.List;

import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;

import kernel.jdon.skill.dto.object.FindHotSkillDto;
import kernel.jdon.skill.dto.object.FindLectureDto;
import kernel.jdon.skill.dto.object.FindMemberSkillDto;
import kernel.jdon.skill.dto.object.FindWantedJdDto;
import kernel.jdon.skill.dto.object.QFindHotSkillDto;
import kernel.jdon.skill.dto.object.QFindLectureDto;
import kernel.jdon.skill.dto.object.QFindMemberSkillDto;
import kernel.jdon.skill.dto.object.QFindWantedJdDto;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
Expand All @@ -24,25 +34,66 @@ public List<FindHotSkillDto> findHotSkillList() {
final int hotSkillKeywordCount = 10;

return jpaQueryFactory
.select(new QFindHotSkillDto(skill.id, skill.keyword))
.from(skillHistory)
.innerJoin(skill)
.on(skillHistory.jobCategory.id.eq(skill.jobCategory.id)
.and(skillHistory.keyword.eq(skill.keyword)))
.groupBy(skill.id, skill.keyword)
.orderBy(skill.keyword.count().desc())
.limit(hotSkillKeywordCount)
.fetch();
.select(new QFindHotSkillDto(skill.id, skill.keyword))
.from(skillHistory)
.innerJoin(skill)
.on(skillHistory.jobCategory.id.eq(skill.jobCategory.id)
.and(skillHistory.keyword.eq(skill.keyword)))
.groupBy(skill.id, skill.keyword)
.orderBy(skill.keyword.count().desc())
.limit(hotSkillKeywordCount)
.fetch();
}

@Override
public List<FindMemberSkillDto> findMemberSkillList(Long memberId) {
public List<FindMemberSkillDto> findMemberSkillList(final Long memberId) {
return jpaQueryFactory
.select(new QFindMemberSkillDto(skill.id, skill.keyword))
.from(memberSkill)
.leftJoin(skill)
.on(memberSkill.skill.id.eq(skill.id))
.where(memberSkill.member.id.eq(memberId))
.fetch();
.select(new QFindMemberSkillDto(skill.id, skill.keyword))
.from(memberSkill)
.leftJoin(skill)
.on(memberSkill.skill.id.eq(skill.id))
.where(memberSkill.member.id.eq(memberId))
.fetch();
}

@Override
public List<FindWantedJdDto> findWantedJdListBySkill(final String keyword) {
final int wantedJdCount = 6;

return jpaQueryFactory
.select(new QFindWantedJdDto(wantedJd.companyName, wantedJd.title, wantedJd.imageUrl, wantedJd.detailUrl))
.from(wantedJdSkill)
.innerJoin(wantedJd)
.on(wantedJdSkill.wantedJd.id.eq(wantedJd.id))
.where(
wantedJdSkill.skill.id.in(
JPAExpressions
.select(skill.id)
.from(skill)
.where(skill.keyword.eq(keyword))))
.orderBy(Expressions.numberTemplate(Double.class, "function('rand')").asc())
.limit(wantedJdCount)
.fetch();
}

@Override
public List<FindLectureDto> findInflearnLectureListBySkill(final String keyword) {
final int inflearnLectureCount = 3;

return jpaQueryFactory
.select(new QFindLectureDto(inflearnCourse.id, inflearnCourse.title, inflearnCourse.lectureUrl,
inflearnCourse.imageUrl, inflearnCourse.instructor, inflearnCourse.studentCount, inflearnCourse.price
))
.from(inflearnJdSkill)
.innerJoin(inflearnCourse)
.on(inflearnJdSkill.inflearnCourse.id.eq(inflearnCourse.id))
.where(
inflearnJdSkill.skill.id.in(
JPAExpressions
.select(skill.id)
.from(skill)
.where(skill.keyword.eq(keyword))))
.limit(inflearnLectureCount)
.fetch();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package kernel.jdon.skill.service;

import static org.springframework.util.StringUtils.*;

import java.util.List;

import org.springframework.stereotype.Service;

import kernel.jdon.skill.dto.object.FindHotSkillDto;
import kernel.jdon.skill.dto.object.FindMemberSkillDto;
import kernel.jdon.skill.dto.object.FindWantedJdDto;
import kernel.jdon.skill.dto.response.FindJobCategorySkillResponse;
import kernel.jdon.skill.dto.object.FindLectureDto;
import kernel.jdon.skill.dto.response.FindListDataBySkillResponse;
import kernel.jdon.skill.dto.response.FindListHotSkillResponse;
import kernel.jdon.skill.dto.response.FindListJobCategorySkillResponse;
import kernel.jdon.skill.dto.response.FindListMemberSkillResponse;
Expand Down Expand Up @@ -36,7 +41,15 @@ public FindListJobCategorySkillResponse findJobCategorySkillList(Long jobCategor
.map(FindJobCategorySkillResponse::of)
.toList();


return new FindListJobCategorySkillResponse(findJobCategorySkillList);
}

public FindListDataBySkillResponse findDataBySkillList(String keyword) {
keyword = hasText(keyword) ? keyword
: skillRepository.findHotSkillList().get(0).getKeyword();
List<FindWantedJdDto> findWantedJdList = skillRepository.findWantedJdListBySkill(keyword);
List<FindLectureDto> findLectureList = skillRepository.findInflearnLectureListBySkill(keyword);

return FindListDataBySkillResponse.of(keyword, findLectureList, findWantedJdList);
}
}

0 comments on commit 3c6547d

Please sign in to comment.