Skip to content

Commit

Permalink
chore: 병합 충돌
Browse files Browse the repository at this point in the history
  • Loading branch information
thguss committed Oct 13, 2024
2 parents 14af097 + cb40557 commit ac02818
Show file tree
Hide file tree
Showing 69 changed files with 701 additions and 429 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ jobs:
if ! grep -q "IMAGE_NAME=" .env; then
echo "IMAGE_NAME=${{ secrets.IMAGE_NAME_DEV }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_TOKEN=" .env; then
echo "SECRET_MANAGER_TOKEN=${{ secrets.SECRET_MANAGER_TOKEN }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_WORKSPACE_ID=" .env; then
echo "SECRET_MANAGER_WORKSPACE_ID=${{ secrets.SECRET_MANAGER_WORKSPACE_ID }}" >> .env
fi
# 배포 스크립트 실행
sudo ./deploy.sh
6 changes: 6 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ jobs:
if ! grep -q "IMAGE_NAME=" .env; then
echo "IMAGE_NAME=${{ secrets.IMAGE_NAME_PROD }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_TOKEN=" .env; then
echo "SECRET_MANAGER_TOKEN=${{ secrets.SECRET_MANAGER_TOKEN }}" >> .env
fi
if ! grep -q "SECRET_MANAGER_WORKSPACE_ID=" .env; then
echo "SECRET_MANAGER_WORKSPACE_ID=${{ secrets.SECRET_MANAGER_WORKSPACE_ID }}" >> .env
fi
# 배포 스크립트 실행
sudo ./deploy.sh
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
<br/><br/>

## Tech Stack
- Java, Spring Boot
- PostgreSQL, Spring Data JPA, QueryDSL
- AWS : EC2, RDS, Code Deploy, Nginx
- JUnit5
- Java 17, Spring Boot 3.2.1, Spring Data JPA
- PostgreSQL, AWS(EC2, RDS), Docker
- Swagger
- Kakao/Apple Oauth, Discord WebHook, Firebase Messaging Service

Expand Down
7 changes: 6 additions & 1 deletion script/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ source .env

REGISTRY_URL=${REGISTRY_URL}
IMAGE_NAME=${IMAGE_NAME}
SECRET_MANAGER_TOKEN=${SECRET_MANAGER_TOKEN}
SECRET_MANAGER_WORKSPACE_ID=${SECRET_MANAGER_WORKSPACE_ID}
TAG="latest"
CONTAINER_NAME="smeem"
HEALTH_CHECK_URI="/actuator/health"
Expand All @@ -17,7 +19,10 @@ if [ "$(sudo docker ps -a -q -f name=${CONTAINER_NAME})" ]; then
fi

echo "> Run docker"
sudo docker run -d --name ${CONTAINER_NAME} -p 80:8080 "${REGISTRY_URL}"/"${IMAGE_NAME}":${TAG}
sudo docker run -d --name ${CONTAINER_NAME} -p 80:8080 \
-e SECRET_MANAGER_TOKEN="${SECRET_MANAGER_TOKEN}" \
-e SECRET_MANAGER_WORKSPACE_ID="${SECRET_MANAGER_WORKSPACE_ID}" \
"${REGISTRY_URL}"/"${IMAGE_NAME}":${TAG}

echo "----------------------------------------------------------------------"

Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ include 'smeem-output-notification:firebase'
include 'smeem-output-oauth'
include 'smeem-output-oauth:apple'
include 'smeem-output-oauth:kakao'
include 'smeem-output-cache'
include 'smeem-output-cache:redis'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.smeem.application.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(SmeemProperties.class)
public class SmeemConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.smeem.application.config;

import jakarta.annotation.PostConstruct;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

@Getter
@ConfigurationProperties(prefix = "smeem")
public class SmeemProperties {
private final Secret secret;
private final Duration duration;
private final Client client;

public SmeemProperties(Secret secret, Duration duration, Client client) {
this.secret = secret;
this.duration = duration;
this.client = client;
}

@Getter
public static class Secret {
private String key;

public Secret(String key) {
this.key = key;
}

@PostConstruct
private void init() {
this.key = Base64.getEncoder().encodeToString(key.getBytes(StandardCharsets.UTF_8));
}
}

public record Duration(
int remind,
int expired
) {
}

public record Client(
Version version
) {

public record Version(
String title,
String content,
APP ios,
APP android
) {

public record APP(
String app,
String force
) {
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package com.smeem.application.domain.auth;

import com.smeem.common.util.SmeemProperty;
import com.smeem.application.config.SmeemProperties;
import io.jsonwebtoken.security.Keys;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Component;

import javax.crypto.SecretKey;

import static java.util.Base64.getEncoder;
import java.util.Base64;

@Component
@RequiredArgsConstructor
public class SecretKeyFactory {
private final SmeemProperty smeemProperty;
private final SmeemProperties smeemProperties;

public SecretKey create() {
val encodedKey = getEncoder().encodeToString(smeemProperty.getSMEEM_SECRET_KEY().getBytes());
val encodedKey = Base64.getEncoder().encodeToString(smeemProperties.getSecret().getKey().getBytes());
return Keys.hmacShaKeyFor(encodedKey.getBytes());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.smeem.application.domain.diary;

import com.smeem.application.config.SmeemProperties;
import com.smeem.application.domain.badge.Badge;
import com.smeem.application.domain.badge.BadgeType;
import com.smeem.application.domain.member.Member;
Expand Down Expand Up @@ -27,6 +28,7 @@ public class DiaryService implements DiaryUseCase {
private final BadgePort badgePort;
private final MemberBadgePort memberBadgePort;
private final TopicPort topicPort;
private final SmeemProperties smeemProperties;

@Transactional
public WriteDiaryResponse writeDiary(long memberId, WriteDiaryRequest request) {
Expand Down Expand Up @@ -73,9 +75,10 @@ public void deleteDiary(long diary) {
}

public RetrieveDiariesResponse retrieveDiariesByTerm(long memberId, LocalDate startDate, LocalDate endDate) {
val remindDuration = smeemProperties.getDuration().remind();
return RetrieveDiariesResponse.of(
diaryPort.findByMemberAndTerm(memberId, startDate, endDate),
diaryPort.isExistByMemberAndPastAgo(memberId, 30));
diaryPort.isExistByMemberAndPastAgo(memberId, remindDuration));
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.smeem.application.domain.badge.Badge;
import com.smeem.application.domain.trainingtime.DayType;
import com.smeem.application.domain.trainingtime.TrainingTime;
import com.smeem.application.domain.visit.Visit;
import com.smeem.application.port.input.MemberUseCase;
import com.smeem.application.port.input.dto.request.member.UpdateMemberHasPushAlarmRequest;
import com.smeem.application.port.input.dto.request.member.UpdateMemberRequest;
Expand All @@ -13,6 +12,7 @@
import com.smeem.application.port.input.dto.response.member.UpdateMemberResponse;
import com.smeem.application.port.input.dto.response.member.UsernameDuplicatedResponse;
import com.smeem.application.port.input.dto.response.plan.RetrieveMemberPlanResponse;
import com.smeem.application.port.output.cache.CachePort;
import com.smeem.application.port.output.persistence.*;
import com.smeem.common.logger.HookLogger;
import com.smeem.common.logger.LoggingMessage;
Expand All @@ -21,6 +21,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;

@Service
Expand All @@ -31,10 +33,10 @@ public class MemberService implements MemberUseCase {
private final TrainingTimePort trainingTimePort;
private final BadgePort badgePort;
private final DiaryPort diaryPort;
private final VisitPort visitPort;
private final GoalPort goalPort;
private final PlanPort planPort;
private final HookLogger hookLogger;
private final CachePort cachePort;

@Transactional
public UpdateMemberResponse updateMember(long memberId, UpdateMemberRequest request) {
Expand Down Expand Up @@ -89,12 +91,15 @@ public RetrievePerformanceResponse retrieveMemberPerformance(long memberId) {
}

@Transactional
public void checkAttendance(long memberId) {
val foundMember = memberPort.findById(memberId);
if (!visitPort.isExistByMemberAndToday(foundMember.getId())) {
public void visit(long memberId) {
Member foundMember = memberPort.findById(memberId);
String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
String key = "visit:" + today;

if (!cachePort.getBit(key, foundMember.getId())) {
foundMember.visit();
memberPort.update(foundMember);
visitPort.visit(new Visit(foundMember.getId()));
cachePort.setBit(key, foundMember.getId(), true);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.smeem.application.domain.version;

import com.smeem.application.config.SmeemProperties;
import com.smeem.application.port.input.VersionUseCase;
import com.smeem.application.port.input.dto.response.version.RetrieveAppVersionResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -10,16 +11,16 @@
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class VersionService implements VersionUseCase {
private final Property property;
private final SmeemProperties smeemProperties;

@Override
public RetrieveAppVersionResponse retrieveAppVersion() {
return RetrieveAppVersionResponse.of(
property.getCLIENT_VERSION_UPDATE_TITLE(),
property.getCLIENT_VERSION_UPDATE_CONTENT(),
property.getCLIENT_VERSION_ANDROID_VERSION(),
property.getCLIENT_VERSION_ANDROID_FORCE_VERSION(),
property.getCLIENT_VERSION_IOS_VERSION(),
property.getCLIENT_VERSION_IOS_FORCE_VERSION());
smeemProperties.getClient().version().title(),
smeemProperties.getClient().version().content(),
smeemProperties.getClient().version().android().app(),
smeemProperties.getClient().version().android().force(),
smeemProperties.getClient().version().ios().app(),
smeemProperties.getClient().version().ios().force());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface MemberUseCase {
UsernameDuplicatedResponse checkUsernameDuplicated(String username);
void updateMemberHasPush(long memberId, UpdateMemberHasPushAlarmRequest request);
RetrievePerformanceResponse retrieveMemberPerformance(long memberId);
void checkAttendance(long memberId);
void visit(long memberId);
void updatePlan(long memberId, UpdateMemberPlanRequest request);
RetrieveMemberPlanResponse retrieveMemberPlan(long memberId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.smeem.application.port.output.cache;

public interface CachePort {
void setBit(String key, long offset, boolean value);
boolean getBit(String key, long offset);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
smeem:
secret:
key: ${SMEEM_SECRET_KEY}
duration:
remind: ${SMEEM_DURATION_REMIND}
client:
version:
title: ${CLIENT_VERSION_TITLE}
content: ${CLIENT_VERSION_CONTENT}
ios:
app: ${CLIENT_VERSION_IOS_APP}
force: ${CLIENT_VERSION_IOS_FORCE}
android:
app: ${CLIENT_VERSION_ANDROID_APP}
force: ${CLIENT_VERSION_ANDROID_FORCE}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
smeem:
secret:
key: ${SMEEM_SECRET_KEY}
duration:
remind: ${SMEEM_DURATION_REMIND}
client:
version:
title: ${CLIENT_VERSION_TITLE}
content: ${CLIENT_VERSION_CONTENT}
ios:
app: ${CLIENT_VERSION_IOS_APP}
force: ${CLIENT_VERSION_IOS_FORCE}
android:
app: ${CLIENT_VERSION_ANDROID_APP}
force: ${CLIENT_VERSION_ANDROID_FORCE}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
smeem:
secret:
key: ${SMEEM_SECRET_KEY}
duration:
remind: ${SMEEM_DURATION_REMIND}
client:
version:
title: ${CLIENT_VERSION_TITLE}
content: ${CLIENT_VERSION_CONTENT}
ios:
app: ${CLIENT_VERSION_IOS_APP}
force: ${CLIENT_VERSION_IOS_FORCE}
android:
app: ${CLIENT_VERSION_ANDROID_APP}
force: ${CLIENT_VERSION_ANDROID_FORCE}
Loading

0 comments on commit ac02818

Please sign in to comment.