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

#240 [feat] jpql 로직 querydsl로 이전 #241

Merged
merged 7 commits into from
Dec 13, 2023
Merged
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
24 changes: 12 additions & 12 deletions .github/workflows/dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ jobs:
- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./asap_dev_server.zip s3://$S3_BUCKET_NAME/

# Deploy
- name: Deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
run:
aws deploy create-deployment
--application-name asap-dev-codedeploy
--deployment-group-name asap-dev-codedeploy-group
--file-exists-behavior OVERWRITE
--s3-location bucket=asap-develop-bucket,bundleType=zip,key=asap_dev_server.zip
--region ap-northeast-2
# # Deploy
# - name: Deploy
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
# run:
# aws deploy create-deployment
# --application-name asap-dev-codedeploy
# --deployment-group-name asap-dev-codedeploy-group
# --file-exists-behavior OVERWRITE
# --s3-location bucket=asap-develop-bucket,bundleType=zip,key=asap_dev_server.zip
# --region ap-northeast-2
83 changes: 45 additions & 38 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,58 +1,65 @@
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.13'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
id 'org.springframework.boot' version '2.7.13'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'com.asap'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '11'
sourceCompatibility = '11'
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.security:spring-security-crypto:5.7.9'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// VALIDATION
implementation 'org.springframework.boot:spring-boot-starter-validation'

// JPA & Database
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java:8.0.32'

// SWAGGER
implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'

// Jwt Token
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2'
implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2'
implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2'

// Slack Webhook
implementation 'com.slack.api:slack-api-client:1.28.0'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
implementation 'com.slack.api:slack-app-backend:1.28.0'
implementation 'com.slack.api:slack-api-model:1.28.0'
// == 스프링 부트 3.0 미만 ==
implementation 'com.querydsl:querydsl-jpa'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jpa"

annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.security:spring-security-crypto:5.7.9'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// VALIDATION
implementation 'org.springframework.boot:spring-boot-starter-validation'

// JPA & Database
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java:8.0.32'

// SWAGGER
implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'

// Jwt Token
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2'
implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2'
implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2'

// Slack Webhook
implementation 'com.slack.api:slack-api-client:1.28.0'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
implementation 'com.slack.api:slack-app-backend:1.28.0'
implementation 'com.slack.api:slack-api-model:1.28.0'
}

tasks.named('test') {
useJUnitPlatform()
useJUnitPlatform()
}
19 changes: 19 additions & 0 deletions src/main/java/com/asap/server/config/querydsl/QueryDslConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.asap.server.config.querydsl;

import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Configuration
public class QueryDslConfig {
@PersistenceContext
private EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
21 changes: 0 additions & 21 deletions src/main/java/com/asap/server/repository/MeetingRepository.java

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/java/com/asap/server/repository/UserRepository.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.asap.server.repository.meeting;

import com.asap.server.domain.Meeting;
import org.springframework.data.repository.Repository;

import java.util.Optional;

public interface MeetingRepository extends Repository<Meeting, Long>, MeetingRepositoryCustom {
Optional<Meeting> findById(final Long id);

Meeting save(final Meeting meeting);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.asap.server.repository.meeting;

import com.asap.server.domain.Meeting;

import java.util.Optional;

public interface MeetingRepositoryCustom {
Optional<Meeting> findByIdWithHost(final Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.asap.server.repository.meeting;

import com.asap.server.domain.Meeting;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;

import java.util.Optional;

import static com.asap.server.domain.QMeeting.meeting;
import static com.asap.server.domain.QUser.user;

@RequiredArgsConstructor
public class MeetingRepositoryImpl implements MeetingRepositoryCustom {
private final JPAQueryFactory queryFactory;

@Override
public Optional<Meeting> findByIdWithHost(Long id) {
return Optional.ofNullable(
queryFactory.selectFrom(meeting)
.where(meeting.id.eq(id))
.join(meeting.host, user)
.fetchJoin()
.fetchOne()
);
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/asap/server/repository/user/UserRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.asap.server.repository.user;

import com.asap.server.domain.Meeting;
import com.asap.server.domain.User;
import org.springframework.data.repository.Repository;

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

public interface UserRepository extends Repository<User, Long>, UserRepositoryCustom {
User save(final User user);

List<User> findByMeetingAndIsFixed(final Meeting meeting, final boolean isFixed);

Optional<User> findById(final Long id);

List<User> findByMeeting(final Meeting meeting);

int countByMeeting(final Meeting meeting);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.asap.server.repository.user;

import com.asap.server.domain.Meeting;
import com.asap.server.domain.User;

import java.util.List;

public interface UserRepositoryCustom {
void updateUserIsFixedByMeeting(final Meeting meeting, final List<Long> users);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.asap.server.repository.user;

import com.asap.server.domain.Meeting;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;

import java.util.List;

import static com.asap.server.domain.QUser.user;

@RequiredArgsConstructor
public class UserRepositoryImpl implements UserRepositoryCustom {
private final JPAQueryFactory queryFactory;

@Override
public void updateUserIsFixedByMeeting(Meeting meeting, List<Long> users) {
queryFactory.update(user)
.set(user.isFixed, true)
.where(
user.meeting.eq(meeting)
.and(user.id.in(users))
)
.execute();
}
}
4 changes: 1 addition & 3 deletions src/main/java/com/asap/server/service/MeetingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.asap.server.exception.model.ForbiddenException;
import com.asap.server.exception.model.NotFoundException;
import com.asap.server.exception.model.UnauthorizedException;
import com.asap.server.repository.MeetingRepository;
import com.asap.server.repository.meeting.MeetingRepository;
import com.asap.server.service.vo.BestMeetingTimeVo;
import com.asap.server.service.vo.TimeBlocksByDateVo;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -104,8 +104,6 @@ public void confirmMeeting(
LocalDateTime fixedEndDateTime = LocalDateTime.of(fixedDate, endTime);
meeting.setConfirmedDateTime(fixedStartDateTime, fixedEndDateTime);

meetingRepository.saveAndFlush(meeting);

userService.setFixedUsers(meeting, meetingConfirmRequestDto.getUsers());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/asap/server/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.asap.server.exception.model.HostTimeForbiddenException;
import com.asap.server.exception.model.NotFoundException;
import com.asap.server.exception.model.UnauthorizedException;
import com.asap.server.repository.MeetingRepository;
import com.asap.server.repository.UserRepository;
import com.asap.server.repository.meeting.MeetingRepository;
import com.asap.server.repository.user.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
Expand Down
Loading