Skip to content

Commit

Permalink
Merge pull request #168 from Team-HMH/develop
Browse files Browse the repository at this point in the history
deploy: main <- develop
  • Loading branch information
kseysh authored Jun 15, 2024
2 parents 21b79dd + f219314 commit 8d8a750
Show file tree
Hide file tree
Showing 41 changed files with 307 additions and 306 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hmh-cd-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
aws-region: ${{ secrets.AWS_REGION }}

- name: 🚀 s3 upload
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://${{matrix.s3-bucket}}/prod/deploy/$GITHUB_SHA.zip # 수정 고려
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://${{matrix.s3-bucket}}/prod/deploy/$GITHUB_SHA.zip

- name: ☀️ CodeDeploy~!
run: aws deploy create-deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: 🏭 APPLICATION-BUILD!
on:
pull_request:
branches: [ "develop" ]
push:
branches: [ "develop" ]

permissions:
contents: read
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/hmh-ci-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 🏭 APPLICATION-BUILD!

on:
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v3

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

- name: Copy application.yml
run: |
mkdir ./src/main/resources
touch ./src/main/resources/application.yml
echo "${{ secrets.APPLICATION_PROD_YML }}" >> ./src/main/resources/application.yml
cat ./src/main/resources/application.yml
shell: bash

- name: Grant execute permission for gradlew
run: |
chmod +x gradlew
- name: Build with Gradle
run: |
./gradlew clean build
32 changes: 1 addition & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

- **Language** : Java (jdk-17)
- **Web application Framework** : Spring boot (3.2.1), Spring Data JPA
- **DataBase** : MySql (8.1.0), Redis
- **DataBase** : MySql (8.1.0)
- **Cloud/Infra** : Aws EC2, RDS, code deploy
- **web server** : Tomcat, Nginx
- **Collaborative Tool** : Github, Slack, Notion
Expand All @@ -28,34 +28,4 @@
| <img width="300" alt="image" src="https://github.com/Team-HMH/HMH-Server/assets/76610340/ea57f67f-adcb-4abc-a198-7b962e61a6bc"> | <img width="300" alt="image" src="https://github.com/SOPT-33-iOS-Team-1/SOPKATHON_33-Server/assets/86935274/b1308faa-06cb-4818-878e-aeb8e17ac14c"> |
| [jumining](https://github.com/jumining) | [kseysh](https://github.com/kseysh) |

<br/>

## ✅ Convention



### 🚀Convention

- [💻 협업 컨벤션](https://hmhteam.notion.site/6fa22000670d4cf783559f7808c01d1a?pvs=4) <br>

### 🚀 Branch Strategy

- [💻 브랜치 전략](https://hmhteam.notion.site/9d8065b238c543b890ceeb9912966dd0?pvs=4)

<br/>

## 💾 ERD

![image](https://github.com/Team-HMH/HMH-Server/assets/69035864/f4b95b3d-6507-4d33-be41-8a4847bc076f)

<br>

<br>

## ⚙️ Architecture

![architecture](https://github.com/Team-HMH/HMH-Server/assets/69035864/e0eefac1-d8be-4a08-a3de-6e9786557042)


<br>

18 changes: 11 additions & 7 deletions script/start.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# 인스턴스에 클론 받은 디렉토리 이름을 `app`으로 바꿔야합니다.
APPLICATION_PATH=/home/ubuntu/app
# shellcheck disable=SC2164
cd $APPLICATION_PATH

# shellcheck disable=SC2010
JAR_NAME=$(ls $APPLICATION_PATH/build/libs/ | grep '.jar' | tail -n 1)

# shellcheck disable=SC2034
JAR_PATH=build/libs/$JAR_NAME
JAR_PID=$(pgrep -f $JAR_NAME)

Expand All @@ -20,7 +16,15 @@ JAR_PID=$(pgrep -f $JAR_NAME)
fi

echo "> $JAR_PATH 배포" #3
# shellcheck disable=SC2153
# shellcheck disable=SC2024

source ~/.bashrc
sudo nohup java -jar -Dspring.profiles.active=prod "$JAR_PATH" >nohup.out 2>&1 </dev/null &

if [ "$DEPLOYMENT_GROUP_NAME" == "hmh-dev-deploy-group" ]
then
sudo nohup java -jar -Dspring.profiles.active=dev "$JAR_PATH" >nohup.out 2>&1 </dev/null &
fi

if [ "$DEPLOYMENT_GROUP_NAME" == "hmh-prod-deploy-group" ]
then
sudo nohup java -jar -Dspring.profiles.active=prod "$JAR_PATH" >nohup.out 2>&1 </dev/null &
fi
Empty file removed src/HMH-Server.iml
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public abstract class AppConstants {
public static final Long MINIMUM_APP_TIME = 0L;
public static final Long MAXIMUM_APP_TIME = 3659000L;
public static final Long MAXIMUM_APP_TIME = 21_600_000L; // 6시간
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class Challenge extends BaseTimeEntity {
private Integer period;
private Long goalTime;

private boolean isChallengeFailedToday;

@OneToMany(mappedBy = "challenge", cascade = CascadeType.REMOVE, orphanRemoval = true)
private List<ChallengeApp> apps = new ArrayList<>();

Expand All @@ -39,7 +37,6 @@ private Challenge(Integer period, Long userId, Long goalTime, List<ChallengeApp>
this.period = period;
this.userId = userId;
this.goalTime = goalTime;
this.isChallengeFailedToday = false;
this.apps = apps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public abstract class ChallengeConstants {
public static final Long MINIMUM_GOAL_TIME = 7200000L;
public static final Long MAXIMUM_GOAL_TIME = 21600000L;
public static final Long MINIMUM_GOAL_TIME = 3_600_000L; // 1시간
public static final Long MAXIMUM_GOAL_TIME = 21_600_000L; // 6시간
public static final Integer USAGE_POINT = 100;
public static final Integer EARNED_POINT = 20;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import sopt.org.hmh.domain.challenge.dto.response.DailyChallengeResponse;
import sopt.org.hmh.domain.challenge.repository.ChallengeRepository;
import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge;
import sopt.org.hmh.domain.dailychallenge.domain.Status;
import sopt.org.hmh.domain.dailychallenge.repository.DailyChallengeRepository;
import sopt.org.hmh.domain.user.domain.User;
import sopt.org.hmh.domain.user.service.UserService;
Expand Down Expand Up @@ -100,9 +99,6 @@ public DailyChallengeResponse getDailyChallenge(Long userId) {
Challenge challenge = findCurrentChallengeByUserId(userId);

return DailyChallengeResponse.builder()
.status(Boolean.TRUE.equals(challenge.isChallengeFailedToday())
? Status.FAILURE
: Status.NONE)
.goalTime(challenge.getGoalTime())
.apps(challenge.getApps().stream()
.map(app -> new ChallengeAppResponse(app.getAppCode(), app.getGoalTime())).toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequest;
import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequest;
import sopt.org.hmh.global.auth.jwt.JwtConstants;
import sopt.org.hmh.global.common.response.BaseResponse;
import sopt.org.hmh.global.common.response.EmptyJsonResponse;
Expand All @@ -33,6 +34,13 @@ public interface DailyChallengeApi {
ResponseEntity<BaseResponse<EmptyJsonResponse>> orderAddHistoryDailyChallenge(
@Parameter(hidden = true) final Long userId,
final String os,
final FinishedDailyChallengeListRequest request);
final FinishedDailyChallengeListRequest request
);

ResponseEntity<BaseResponse<EmptyJsonResponse>> orderChangeStatusDailyChallenge(
@Parameter(hidden = true) final Long userId,
final String os,
final FinishedDailyChallengeStatusListRequest request
);
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import org.springframework.web.bind.annotation.*;
import sopt.org.hmh.domain.dailychallenge.domain.exception.DailyChallengeSuccess;
import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeListRequest;
import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequest;
import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeFacade;
import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeService;
import sopt.org.hmh.global.auth.UserId;
import sopt.org.hmh.global.common.response.BaseResponse;
import sopt.org.hmh.global.common.response.EmptyJsonResponse;
Expand All @@ -16,6 +18,7 @@
public class DailyChallengeController implements DailyChallengeApi {

private final DailyChallengeFacade dailyChallengeFacade;
private final DailyChallengeService dailyChallengeService;

@Override
@PostMapping("/finish")
Expand All @@ -29,4 +32,17 @@ public ResponseEntity<BaseResponse<EmptyJsonResponse>> orderAddHistoryDailyChall
.status(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS.getHttpStatus())
.body(BaseResponse.success(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS, new EmptyJsonResponse()));
}

@Override
@PostMapping("/success")
public ResponseEntity<BaseResponse<EmptyJsonResponse>> orderChangeStatusDailyChallenge(
@UserId final Long userId,
@RequestHeader("OS") final String os,
@RequestBody final FinishedDailyChallengeStatusListRequest request
) {
dailyChallengeService.changeDailyChallengeStatusByIsSuccess(userId, request);
return ResponseEntity
.status(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS.getHttpStatus())
.body(BaseResponse.success(DailyChallengeSuccess.SEND_FINISHED_DAILY_CHALLENGE_SUCCESS, new EmptyJsonResponse()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package sopt.org.hmh.domain.dailychallenge.dto.request;

import java.util.List;

public record FinishedDailyChallengeStatusListRequest(
List<FinishedDailyChallengeStatusRequest> finishedDailyChallenges
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package sopt.org.hmh.domain.dailychallenge.dto.request;

import java.time.LocalDate;

public record FinishedDailyChallengeStatusRequest(
LocalDate challengeDate,
boolean isSuccess
) {

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package sopt.org.hmh.domain.dailychallenge.service;

import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge;
import sopt.org.hmh.domain.dailychallenge.domain.Status;
import sopt.org.hmh.domain.dailychallenge.domain.exception.DailyChallengeError;
import sopt.org.hmh.domain.dailychallenge.domain.exception.DailyChallengeException;
import sopt.org.hmh.domain.dailychallenge.dto.request.FinishedDailyChallengeStatusListRequest;
import sopt.org.hmh.domain.dailychallenge.repository.DailyChallengeRepository;

@Service
Expand All @@ -22,8 +24,16 @@ public DailyChallenge findByChallengeDateAndUserIdOrThrowException(LocalDate cha
.orElseThrow(() -> new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_NOT_FOUND));
}

public void validateDailyChallengeStatus(DailyChallenge dailyChallenge, Status expected) {
if (dailyChallenge.getStatus() != expected) {
public void validateDailyChallengeStatus(Status dailyChallengeStatus, List<Status> expectedStatuses) {
boolean isAlreadyProcessed = true;
for (Status expected : expectedStatuses) {
if (dailyChallengeStatus == expected) {
isAlreadyProcessed = false;
break;
}
}

if (isAlreadyProcessed) {
throw new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_ALREADY_PROCESSED);
}
}
Expand All @@ -42,4 +52,17 @@ private void handleAlreadyProcessedDailyChallenge(DailyChallenge dailyChallenge)
}
throw new DailyChallengeException(DailyChallengeError.DAILY_CHALLENGE_ALREADY_PROCESSED);
}

public void changeDailyChallengeStatusByIsSuccess(Long userId, FinishedDailyChallengeStatusListRequest requests) {
requests.finishedDailyChallenges().forEach(request -> {
DailyChallenge dailyChallenge = this.findByChallengeDateAndUserIdOrThrowException(request.challengeDate(), userId);
if (request.isSuccess()) {
this.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE));
dailyChallenge.changeStatus(Status.UNEARNED);
} else {
this.validateDailyChallengeStatus(dailyChallenge.getStatus(), List.of(Status.NONE, Status.FAILURE));
dailyChallenge.changeStatus(Status.FAILURE);
}
});
}
}
14 changes: 0 additions & 14 deletions src/main/java/sopt/org/hmh/domain/dummy/DummyApp.java

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/java/sopt/org/hmh/domain/dummy/DummyAppController.java

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/java/sopt/org/hmh/domain/dummy/DummyAppListResponse.java

This file was deleted.

Loading

0 comments on commit 8d8a750

Please sign in to comment.