Skip to content

Commit

Permalink
Merge pull request #29 from YAPP-Github/feature/PC-268-matching-algor…
Browse files Browse the repository at this point in the history
…ithm

[PC-268] Greedy 매칭 알고리즘 구현
  • Loading branch information
devchlee12 authored Jan 25, 2025
2 parents 13f8b20 + b2017f9 commit fb13ec4
Show file tree
Hide file tree
Showing 37 changed files with 999 additions and 103 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CI/CD using github actions & docker

on:
push:
branches: [ "main", "develope" ]

permissions:
contents: read

jobs:
CI-CD:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# secret yml 파일 생성
- name: make application-secret.yml
if: |
contains(github.ref, 'main') ||
contains(github.ref, 'develope')
run: |
cd ./api/src/main/resources
touch ./application-secret.yml
echo "${{ secrets.YML }}" > ./application-secret.yml
shell: bash

# gradle build
- name: Build with Gradle
run: ./gradlew build -x test

# docker build & push to develop
- name: Docker build & push to dev
if: contains(github.ref, 'develope')
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile-dev -t ${{ secrets.DOCKER_USERNAME }}/docker-test-dev .
docker push ${{ secrets.DOCKER_USERNAME }}/docker-test-dev
## deploy to develop
- name: Deploy to dev
uses: appleboy/ssh-action@master
id: deploy-dev
if: contains(github.ref, 'develope')
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: 22
key: ${{ secrets.PRIVATE_KEY }}
script: |
sudo docker ps
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/docker-test-dev
sudo docker run -d -p 8080:8080 --add-host=localhost:host-gateway ${{ secrets.DOCKER_USERNAME }}/docker-test-dev
sudo docker image prune -f
45 changes: 45 additions & 0 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: PR Test

on:
pull_request:
branches: [ "develope" ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Test with Gradle
run: ./gradlew --info test

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: ${{ always() }}
with:
files: build/reports/test-results/**/*.xml

- name: Cleanup Gradle Cache
# Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
# Restoring these files from a GitHub Actions cache might cause problems for future builds.
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
7 changes: 7 additions & 0 deletions Dockerfile-admin
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM eclipse-temurin:17-jdk

ARG JAR_FILE=admin/build/libs/*.jar

COPY ${JAR_FILE} app.jar

ENTRYPOINT ["java", "-jar", "/app.jar"]
7 changes: 7 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM eclipse-temurin:17-jdk

ARG JAR_FILE=api/build/libs/*.jar

COPY ${JAR_FILE} app.jar

ENTRYPOINT ["java", "-jar", "/app.jar"]
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.yapp.domain.block.application;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yapp.domain.block.Block;
Expand All @@ -13,37 +12,37 @@
import java.util.Set;
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class BlockService {
private final BlockRepository blockRepository;

@Transactional()
public void blockPhoneNumbers(BlockCreateDto blockCreateDto) {
Long userId = blockCreateDto.userId();
List<String> phoneNumbers = blockCreateDto.phoneNumbers();
List<Block> newBlocks = new ArrayList<>();

Set<String> blockedPhoneNumbers = blockRepository.findBlocksByUserId(userId)
.stream()
.map(Block::getPhoneNumber)
.collect(Collectors.toSet());

phoneNumbers.stream()
.filter(phoneNumber -> !blockedPhoneNumbers.contains(phoneNumber))
.forEach(phoneNumber -> {
Block block = Block.builder()
.user(User.builder().id(userId).build())
.phoneNumber(phoneNumber)
.build();
newBlocks.add(block);
});

blockRepository.saveAll(newBlocks);
}

@Transactional(readOnly = false)
public List<Block> findBlocksByUserId(Long userId) {
return blockRepository.findBlocksByUserId(userId);
}
private final BlockRepository blockRepository;

@Transactional()
public void blockPhoneNumbers(BlockCreateDto blockCreateDto) {
Long userId = blockCreateDto.userId();
List<String> phoneNumbers = blockCreateDto.phoneNumbers();
List<Block> newBlocks = new ArrayList<>();

Set<String> blockedPhoneNumbers =
blockRepository.findBlocksByUserId(userId).stream().map(Block::getPhoneNumber).collect(Collectors.toSet());

phoneNumbers.stream().filter(phoneNumber -> !blockedPhoneNumbers.contains(phoneNumber)).forEach(phoneNumber -> {
Block block = Block.builder().user(User.builder().id(userId).build()).phoneNumber(phoneNumber).build();
newBlocks.add(block);
});

blockRepository.saveAll(newBlocks);
}

@Transactional(readOnly = true)
public Boolean checkIfUserBlockedPhoneNumber(Long userId, String phoneNumber) {
return blockRepository.existsByUserIdAndPhoneNumber(userId, phoneNumber);
}

@Transactional(readOnly = false)
public List<Block> findBlocksByUserId(Long userId) {
return blockRepository.findBlocksByUserId(userId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.yapp.domain.block.application;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.yapp.application.AuthenticationService;
import org.yapp.domain.block.DirectBlock;
import org.yapp.domain.block.dao.DirectBlockRepository;

@Service
@RequiredArgsConstructor
public class DirectBlockService {

private final DirectBlockRepository directBlockRepository;
private final AuthenticationService authenticationService;

public DirectBlock blockUser(Long blockId) {
Long userId = authenticationService.getUserId();
return directBlockRepository.save(new DirectBlock(userId, blockId));
}

public boolean checkBlock(Long userId, Long partnerId) {
return directBlockRepository.existsDirectBlockByBlockingUserIdAndBlockedUserId(userId,
partnerId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@

@Repository
public interface BlockRepository extends JpaRepository<Block, Long> {
List<Block> findBlocksByUserId(Long userId);
boolean existsByUserIdAndPhoneNumber(Long userId, String phoneNumber);

List<Block> findBlocksByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.yapp.domain.block.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.yapp.domain.block.DirectBlock;

public interface DirectBlockRepository extends JpaRepository<DirectBlock, Long> {

boolean existsDirectBlockByBlockingUserIdAndBlockedUserId(Long blockingUserId,
Long blockedUserId);
}
Loading

0 comments on commit fb13ec4

Please sign in to comment.