Skip to content
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
36 changes: 18 additions & 18 deletions .github/workflows/dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
token: ${{ secrets.PACKAGE_DELETE_TOKEN }}
image-names: solid-connection-dev
delete-untagged: true
keep-n-tags: 5
keep-n-tags: 2
account-type: org
org-name: ${{ github.repository_owner }}
cut-off: '7 days ago UTC'
Expand Down Expand Up @@ -123,28 +123,28 @@ jobs:
export OWNER_LOWERCASE=$(echo "${{ github.repository_owner }}" | tr "[:upper:]" "[:lower:]")
export IMAGE_TAG_ONLY="${{ needs.build-and-push.outputs.image_tag }}"
export FULL_IMAGE_NAME="ghcr.io/${OWNER_LOWERCASE}/solid-connection-dev:${IMAGE_TAG_ONLY}"

# 2. GHCR 로그인 & Pull
export IMAGE_NAME_BASE="ghcr.io/${OWNER_LOWERCASE}/solid-connection-dev"

# 2. Pull 전 정리 (디스크 공간 확보)
echo "Cleaning up old tagged images (keeping last 2)..."
docker images "${IMAGE_NAME_BASE}" --format "{{.Tag}}" | \
sort -r | \
tail -n +3 | \
xargs -I {} docker rmi "${IMAGE_NAME_BASE}:{}" || true

echo "Pruning dangling images..."
docker image prune -f

# 3. GHCR 로그인 & Pull
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
echo "Pulling new image: $FULL_IMAGE_NAME"
docker pull $FULL_IMAGE_NAME
# 3. Spring Boot 앱 재시작

# 4. Spring Boot 앱 재시작
echo "Restarting Docker Compose with tag: $IMAGE_TAG_ONLY"
cd /home/${{ secrets.DEV_USERNAME }}/solid-connection-dev
docker compose -f docker-compose.dev.yml down || true
OWNER_LOWERCASE=$OWNER_LOWERCASE IMAGE_TAG=$IMAGE_TAG_ONLY docker compose -f docker-compose.dev.yml up -d

# 4. 정리 작업
echo "Pruning dangling images..."
docker image prune -f

echo "Cleaning up old tagged images (keeping last 5)..."
IMAGE_NAME_BASE="ghcr.io/${OWNER_LOWERCASE}/solid-connection-dev"
docker images "${IMAGE_NAME_BASE}" --format "{{.Tag}}" | \
sort -r | \
tail -n +6 | \
xargs -I {} docker rmi "${IMAGE_NAME_BASE}:{}" || true


echo "Deployment finished successfully."
'
'
2 changes: 1 addition & 1 deletion .github/workflows/prod-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ jobs:
# 6. 정리
docker image prune -f
echo "Deployment finished successfully."
'
'
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ dependencies {

// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:mysql'
testImplementation 'org.testcontainers:testcontainers:2.0.2'
testImplementation 'org.testcontainers:testcontainers-junit-jupiter:2.0.2'
testImplementation 'org.testcontainers:testcontainers-mysql:2.0.2'
testImplementation 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.awaitility:awaitility:4.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public class NewsController {

// todo: 추후 Slice 적용
@GetMapping
public ResponseEntity<NewsListResponse> findNewsBySiteUserId(
public ResponseEntity<NewsListResponse> findNews(
@AuthorizedUser(required = false) Long siteUserId,
@RequestParam(value = "author-id") Long authorId
@RequestParam(value = "author-id", required = false) Long authorId
) {
NewsListResponse newsListResponse = newsQueryService.findNewsByAuthorId(siteUserId, authorId);
NewsListResponse newsListResponse = newsQueryService.findNews(siteUserId, authorId);
return ResponseEntity.ok(newsListResponse);
}

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

public interface NewsRepository extends JpaRepository<News, Long>, NewsCustomRepository {

List<News> findAllByOrderByUpdatedAtDesc();

List<News> findAllBySiteUserIdOrderByUpdatedAtDesc(long siteUserId);

void deleteAllBySiteUserId(long siteUserId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
public interface NewsCustomRepository {

List<NewsResponse> findNewsByAuthorIdWithLikeStatus(long authorId, Long siteUserId);

List<NewsResponse> findAllNewsWithLikeStatus(Long siteUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ public class NewsCustomRepositoryImpl implements NewsCustomRepository {

private final EntityManager entityManager;

@Override
public List<NewsResponse> findAllNewsWithLikeStatus(Long siteUserId) {
String jpql = """
SELECT new com.example.solidconnection.news.dto.NewsResponse(
n.id,
n.title,
n.description,
n.thumbnailUrl,
n.url,
CASE WHEN ln.id IS NOT NULL THEN true ELSE false END,
n.updatedAt
)
FROM News n
LEFT JOIN LikedNews ln ON n.id = ln.newsId AND ln.siteUserId = :siteUserId
ORDER BY n.updatedAt DESC
""";

return entityManager.createQuery(jpql, NewsResponse.class)
.setParameter("siteUserId", siteUserId)
.getResultList();
}

@Override
public List<NewsResponse> findNewsByAuthorIdWithLikeStatus(long authorId, Long siteUserId) {
String jpql = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.solidconnection.news.service;

import com.example.solidconnection.news.domain.News;
import com.example.solidconnection.news.dto.NewsListResponse;
import com.example.solidconnection.news.dto.NewsResponse;
import com.example.solidconnection.news.repository.NewsRepository;
Expand All @@ -15,19 +16,24 @@ public class NewsQueryService {
private final NewsRepository newsRepository;

@Transactional(readOnly = true)
public NewsListResponse findNewsByAuthorId(Long siteUserId, long authorId) {
// 로그인하지 않은 경우
public NewsListResponse findNews(Long siteUserId, Long authorId) {
if (siteUserId == null) {
List<NewsResponse> newsResponseList = newsRepository.findAllBySiteUserIdOrderByUpdatedAtDesc(authorId)
.stream()
List<NewsResponse> newsResponseList = findNewsEntities(authorId).stream()
.map(news -> NewsResponse.of(news, null))
.toList();
return NewsListResponse.from(newsResponseList);
}

// 로그인한 경우
List<NewsResponse> newsResponseList = newsRepository.findNewsByAuthorIdWithLikeStatus(authorId, siteUserId);

List<NewsResponse> newsResponseList = (authorId == null)
? newsRepository.findAllNewsWithLikeStatus(siteUserId)
: newsRepository.findNewsByAuthorIdWithLikeStatus(authorId, siteUserId);
return NewsListResponse.from(newsResponseList);
}

private List<News> findNewsEntities(Long authorId) {
if (authorId == null) {
return newsRepository.findAllByOrderByUpdatedAtDesc();
}
return newsRepository.findAllBySiteUserIdOrderByUpdatedAtDesc(authorId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ALTER TABLE language_requirement
MODIFY COLUMN language_test_type ENUM(
'CEFR',
'DALF',
'DELF',
'DELE',
'DUOLINGO',
'IELTS',
'JLPT',
'NEW_HSK',
'TCF',
'TEF',
'TOEFL_IBT',
'TOEFL_ITP',
'TOEIC',
'ETC'
) NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.mysql.MySQLContainer;

@SpringBootTest
@ContextConfiguration(initializers = {RedisTestContainer.class, FlywayMigrationTest.FlywayMySQLInitializer.class})
Expand All @@ -19,7 +19,7 @@
})
class FlywayMigrationTest {

private static final MySQLContainer<?> CONTAINER = new MySQLContainer<>("mysql:8.0")
private static final MySQLContainer CONTAINER = new MySQLContainer("mysql:8.0")
.withDatabaseName("flyway_test")
.withUsername("flyway_user")
.withPassword("flyway_password");
Expand Down
Loading