Skip to content

Commit 187efef

Browse files
authored
Merge branch 'develop' into feat/login/1
2 parents c5d09be + fddea9a commit 187efef

File tree

7 files changed

+108
-11
lines changed

7 files changed

+108
-11
lines changed

.github/workflows/gradle.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Java CI with Gradle
2+
3+
on:
4+
push:
5+
branches: [ "develop" ]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Set up JDK 17
15+
uses: actions/setup-java@v3
16+
with:
17+
java-version: '17'
18+
distribution: 'temurin'
19+
20+
## 원격 서버에서 docker-compose 실행
21+
- name: Build and Run Docker on Server
22+
uses: appleboy/ssh-action@master
23+
with:
24+
host: ${{ secrets.HOST }}
25+
username: ${{ secrets.USERNAME }}
26+
key: ${{ secrets.PRIVATE_KEY }}
27+
port: ${{ secrets.PORT }}
28+
script: |
29+
# 최신 코드 가져오기
30+
cd /home/ubuntu/server
31+
git pull origin develop
32+
33+
# application.properties 새로 생성
34+
touch ./src/main/resources/application.properties
35+
echo "${{ secrets.APPLICATION }}" | sudo tee ./src/main/resources/application.properties > /dev/null
36+
37+
# 🔹 JAR 빌드 (서버에서 실행)
38+
./gradlew bootJar
39+
40+
# 파일명 변경
41+
mv /home/ubuntu/server/build/libs/SoundLink_Java-0.0.1-SNAPSHOT.jar /home/ubuntu/docker/soundlink.jar
42+
43+
cd /home/ubuntu/docker
44+
45+
# 기존 Spring 컨테이너 중지 및 제거
46+
sudo docker-compose stop spring
47+
sudo docker-compose rm -f spring
48+
49+
# Spring 컨테이너만 다시 빌드 & 실행
50+
docker-compose up --build -d spring
51+
sudo docker-compose up -d spring
52+
53+
# 불필요한 이미지 정리
54+
sudo docker image prune -f

src/main/java/org/dfbf/soundlink/domain/blocklist/entity/Blocklist.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public class Blocklist {
2020
@GeneratedValue(strategy = GenerationType.IDENTITY)
2121
private Long blocklistId;
2222

23-
@ManyToOne (cascade = CascadeType.REMOVE)
23+
@ManyToOne
2424
@JoinColumn(name = "user_id")
2525
private User user;
2626

27-
@ManyToOne (cascade = CascadeType.REMOVE)
27+
@ManyToOne
2828
@JoinColumn(name = "blocked_user_id")
2929
private User blockedUser;
3030

src/main/java/org/dfbf/soundlink/domain/emotionRecord/entity/EmotionRecord.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class EmotionRecord {
1818
@GeneratedValue(strategy = GenerationType.IDENTITY)
1919
private Long recordId;
2020

21-
@ManyToOne(cascade = CascadeType.REMOVE)
21+
@ManyToOne
2222
@JoinColumn(name = "user_id")
2323
private User user;
2424

@@ -44,10 +44,3 @@ public EmotionRecord(User user, Emotions emotion, String comment) {
4444
this.comment = comment;
4545
}
4646
}
47-
48-
/**
49-
* PERSIST - 부모와 자식엔티티를 한 번에 영속화
50-
* REMOVE - 함께 저장했던 부모와 자식의 엔티티를 모두 제거할 경우 (고아로 만듭니다)
51-
* ALL - CascadeType.PERSIST 와 CascadeType.REMOVE 동시 적용
52-
* orphanRemoval=true -> 해당 고아 객체를 자동으로 삭제해 주는 옵션
53-
*/

src/main/java/org/dfbf/soundlink/domain/user/dto/response/EmotionRecordDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public record EmotionRecordDto(Long spotifyId, String title, String artist, String album, Emotions emotion, String comment ,String createdAt) {
99
// 커스텀 생성자 -> createdAt을 timestamp에서 String으로
10-
public EmotionRecordDto(Long spotifyId, String title, String artist, String album, Emotions emotion, String comment ,Timestamp createdAt) {
10+
public EmotionRecordDto(Long spotifyId, String title, String artist, String album, Emotions emotion, String comment, Timestamp createdAt) {
1111
this(spotifyId, title, artist, album, emotion, comment, formatTimestamp(createdAt));
1212
}
1313

src/main/java/org/dfbf/soundlink/domain/user/entity/ProfileMusic.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import jakarta.persistence.Id;
55
import lombok.Builder;
66
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
78
import org.dfbf.soundlink.domain.emotionRecord.entity.SpotifyMusic;
89
import org.hibernate.annotations.CreationTimestamp;
910
import org.hibernate.annotations.UpdateTimestamp;
@@ -12,6 +13,7 @@
1213

1314
@Entity
1415
@Getter
16+
@NoArgsConstructor
1517
public class ProfileMusic {
1618
@Id
1719
@GeneratedValue(strategy = GenerationType.IDENTITY)

src/main/java/org/dfbf/soundlink/domain/user/entity/User.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import jakarta.persistence.*;
44
import lombok.*;
5+
import org.dfbf.soundlink.domain.blocklist.entity.Blocklist;
6+
import org.dfbf.soundlink.domain.emotionRecord.entity.EmotionRecord;
57
import org.dfbf.soundlink.domain.user.dto.request.UserUpdateDto;
68
import org.dfbf.soundlink.global.comm.enums.SocialType;
79
import org.hibernate.annotations.CreationTimestamp;
810
import org.hibernate.annotations.UpdateTimestamp;
911
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
1012

1113
import java.sql.Timestamp;
14+
import java.util.List;
1215

1316
@Entity
1417
@Getter
@@ -33,6 +36,15 @@ public class User {
3336
private String password;
3437
private String email;
3538

39+
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
40+
private List<Blocklist> blocklist;
41+
42+
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE)
43+
private List<EmotionRecord> emotionRecord;
44+
45+
@OneToOne(mappedBy = "user", cascade = CascadeType.REMOVE)
46+
private ProfileMusic profileMusic;
47+
3648
@CreationTimestamp
3749
private Timestamp createdAt;
3850
@UpdateTimestamp
@@ -55,3 +67,20 @@ public void update(UserUpdateDto userUpdateDto, BCryptPasswordEncoder passwordEn
5567
this.email = userUpdateDto.email();
5668
}
5769
}
70+
71+
/**
72+
* PERSIST - 부모 엔티티가 영속화(저장)될 때, 자식 엔티티도 자동으로 저장
73+
* MERGE - 부모 엔티티가 병합될 때, 자식 엔티티도 자동으로 병합
74+
* REMOVE - 부모 엔티티가 삭제될 때, 자식 엔티티도 자동으로 삭제
75+
* REFRESH - 부모 엔티티가 새로고침(refresh)될 때, 자식 엔티티도 자동으로 새로고침
76+
* DETACH - 부모 엔티티가 분리(detach)될 때, 자식 엔티티도 자동으로 분리
77+
* ALL - 모든 작업을 자식 엔티티에 전파
78+
*/
79+
80+
/**
81+
* CascadeType.REMOVE -> 부모 엔티티가 삭제될 때 자식 엔티티는 삭제
82+
* orphanRemoval = true -> 자식 엔티티가 부모와의 관계에서 제거될 때 삭제
83+
* 가끔 사용하지 않는 데이터가 DB에 남아있는 경우가 있는데, 이를 방지하기 위해 사용
84+
* 혹은 User쪽에 있는 리스트에서 제거할 경우, 양방향 매핑이기 떄문에 자식이 고아가 댐 -> 이를 위헤서 orphanRemoval를 사용
85+
* 근데 우린 사용 안하니까 사실 빼도 무방할 듯....
86+
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.dfbf.soundlink.global;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import org.dfbf.soundlink.global.exception.ErrorCode;
5+
import org.dfbf.soundlink.global.exception.ResponseResult;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
@RestController
11+
@RequiredArgsConstructor
12+
public class Controller {
13+
14+
// health check
15+
@GetMapping("/health")
16+
public ResponseResult health() {
17+
return new ResponseResult(ErrorCode.SUCCESS,"ok");
18+
}
19+
}

0 commit comments

Comments
 (0)