Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 일정찾기 - 키워드로 검색기능 #34

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
src/main/generated/**

### STS ###
.apt_generated
Expand Down
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ dependencies {
//s3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

//QueryDsl
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

//jwt
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5")
Expand All @@ -68,8 +74,4 @@ dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

tasks.named('test') {
useJUnitPlatform()
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/catcher/core/db/ScheduleRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.catcher.core.db;

import com.catcher.core.domain.entity.Schedule;

import java.util.List;

public interface ScheduleRepository {

/**
* 키워드로 스케줄 검색
*
* @param keyword
* @return
*/
List<Schedule> findScheduleByKeywordAndFilter(
final String keyword
// final Long budget,
// final ZonedDateTime startAt,
// final ZonedDateTime endAt
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ public class Schedule extends BaseTimeEntity {

@Column(name = "participate_end_at", nullable = false)
private ZonedDateTime participateEndAt; // 모집 종료
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ public class ScheduleDetail extends BaseTimeEntity {
private ZonedDateTime endAt;

private ZonedDateTime deletedAt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public class UploadFile {

@Column(name = "deleted_at")
private ZonedDateTime deletedAt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

public enum ContentType {
COMMENT, COMMENTREPLY, SCHEDULEDETAIL, SCHEDULE
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/catcher/core/dto/ScheduleCondition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.catcher.core.dto;

import com.catcher.core.domain.entity.Location;
import lombok.Data;

import java.time.ZonedDateTime;

@Data
public class ScheduleCondition {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘는 사용 안하는것 같은데 사용하시다가 지운건가요?


private String keyword;

// private String them;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

없어도 되는 부분이면 지워도 좋을거같아용!


private Long budget;

private ZonedDateTime startAt;

private ZonedDateTime endAt;

private Location location;

}
30 changes: 30 additions & 0 deletions src/main/java/com/catcher/core/service/ScheduleService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.catcher.core.service;

import com.catcher.core.db.ScheduleRepository;
import com.catcher.core.domain.entity.Schedule;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ScheduleService {
private final ScheduleRepository scheduleRepository;
Copy link
Contributor

@dev-khg dev-khg Nov 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scheduleRepository 는 jpa repository를 직접 참조하고 있는데 수정이 필요할거같아용
(Part-Backend 채팅방 아이디어 탭 참조해보면 될거같아용)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이해 안되시면 배치 서비스에 구현된 방법을 참고하셔도 될 것 같아요


public List<Schedule> getScheduleByKeywordAndFilter(
final String keyword
// final Long budget,
// final ZonedDateTime startAt,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 주석이 혹시 필요한 부분일까요?

// final ZonedDateTime endAt

){
final List<Schedule> schedules = scheduleRepository.findScheduleByKeywordAndFilter(
keyword
// budget,
// startAt,
// endAt
);
return schedules;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/catcher/datasource/config/QuerydslConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.catcher.datasource.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuerydslConfig {

@PersistenceContext
private EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.catcher.datasource.schedule;

import com.catcher.core.domain.entity.Schedule;
import com.catcher.core.db.ScheduleRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

public interface ScheduleJpaRepository extends JpaRepository<Schedule, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.catcher.datasource.schedule;

import com.catcher.core.db.ScheduleRepository;
import com.catcher.core.domain.entity.QSchedule;
import com.catcher.core.domain.entity.Schedule;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ScheduleRepositoryImpl extends QuerydslRepositorySupport implements ScheduleRepository {

private final JPAQueryFactory jpaQueryFactory;
private static final QSchedule SCHEDULE = QSchedule.schedule;

public ScheduleRepositoryImpl(JPAQueryFactory queryFactory) {
super(Schedule.class);
this.jpaQueryFactory = queryFactory;
}

@Override
public List<Schedule> findScheduleByKeywordAndFilter(
final String keyword
// final Long budget,
// final ZonedDateTime startAt,
// final ZonedDateTime endAt
) {
return jpaQueryFactory
.select(SCHEDULE)
.from(SCHEDULE)
.where(
containsKeywordInTitle(keyword)
)
.fetch();
}

private BooleanExpression containsKeywordInTitle(final String keyword) {
return SCHEDULE.title.contains(keyword);
}

}
26 changes: 26 additions & 0 deletions src/main/java/com/catcher/resource/ScheduleController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.catcher.resource;

import com.catcher.common.response.CommonResponse;
import com.catcher.core.domain.entity.Schedule;
import com.catcher.core.service.ScheduleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/schedule")
@RequiredArgsConstructor
public class ScheduleController {

private final ScheduleService scheduleService;


@GetMapping("/list")
public CommonResponse<List<Schedule>> getScheduleByKeywordAndFilter(
@RequestParam(defaultValue = "") String keyword
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

디폴트가 빈 스트링이면 아무것도 안썼을때 정상동작하나요??

){
List<Schedule> scheduleByKeywordAndFilter = scheduleService.getScheduleByKeywordAndFilter(keyword);

return CommonResponse.success(200, scheduleByKeywordAndFilter);
}
}