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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ out/
.vscode/

.env
*.pem
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ repositories {
}

dependencies {
// spring starter
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

// database
runtimeOnly 'com.mysql:mysql-connector-j'

// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/ita/growin/domain/event/entity/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ita.growin.domain.event.entity;

import ita.growin.domain.task.entity.Task;
import ita.growin.domain.user.entity.User;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Event {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "event_id")
private Long id;

@OneToMany(mappedBy = "event", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Task> tasks;

@JoinColumn(name = "user_id")
@ManyToOne(fetch = FetchType.LAZY)
private User user;
Comment on lines +27 to +29

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โš ๏ธ Potential issue | ๐Ÿ”ด Critical

Many-to-One ๊ด€๊ณ„์—์„œ CascadeType.ALL์€ ์œ„ํ—˜ํ•ฉ๋‹ˆ๋‹ค.

Event์—์„œ User๋กœ์˜ @ManyToOne ๊ด€๊ณ„์— CascadeType.ALL์„ ์‚ฌ์šฉํ•˜๋ฉด Event๋ฅผ ์‚ญ์ œํ•  ๋•Œ ์—ฐ๊ด€๋œ User๊นŒ์ง€ ์‚ญ์ œ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ์˜๋„ํ•˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ ์†์‹ค์„ ์ดˆ๋ž˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ผ๋ฐ˜์ ์œผ๋กœ Many-to-One ๊ด€๊ณ„์—์„œ๋Š” CascadeType.PERSIST์™€ CascadeType.MERGE๋งŒ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, cascade๋ฅผ ์™„์ „ํžˆ ์ œ๊ฑฐํ•˜๋Š” ๊ฒƒ์ด ์•ˆ์ „ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ diff๋ฅผ ์ ์šฉํ•˜์—ฌ cascade๋ฅผ ์ œ๊ฑฐํ•˜์„ธ์š”:

     @JoinColumn(name = "user_id")
-    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+    @ManyToOne(fetch = FetchType.LAZY)
     private User user;
๐Ÿค– Prompt for AI Agents
src/main/java/ita/growin/domain/event/entity/Event.java lines 27-29: the
@ManyToOne relationship to User currently uses cascade = CascadeType.ALL which
risks deleting Users when Events are removed; remove the cascade attribute (or
replace with only CascadeType.PERSIST and CascadeType.MERGE if you need
lifecycle propagation) by changing the annotation to @ManyToOne(fetch =
FetchType.LAZY) (or @ManyToOne(fetch = FetchType.LAZY, cascade =
{CascadeType.PERSIST, CascadeType.MERGE})), then recompile/run tests to ensure
no side effects.

}
24 changes: 24 additions & 0 deletions src/main/java/ita/growin/domain/task/entity/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ita.growin.domain.task.entity;

import ita.growin.domain.event.entity.Event;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Task {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "task_id", nullable = false)
private Long id;

@JoinColumn(name = "event_id")
@ManyToOne(fetch = FetchType.LAZY)
private Event event;
Comment on lines +21 to +23

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โš ๏ธ Potential issue | ๐Ÿ”ด Critical

Many-to-One ๊ด€๊ณ„์—์„œ CascadeType.ALL์€ ์œ„ํ—˜ํ•ฉ๋‹ˆ๋‹ค.

Task์—์„œ Event๋กœ์˜ @ManyToOne ๊ด€๊ณ„์— CascadeType.ALL์„ ์‚ฌ์šฉํ•˜๋ฉด Task๋ฅผ ์‚ญ์ œํ•  ๋•Œ ์—ฐ๊ด€๋œ Event๊นŒ์ง€ ์‚ญ์ œ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ์˜๋„ํ•˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ ์†์‹ค์„ ์ดˆ๋ž˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ผ๋ฐ˜์ ์œผ๋กœ Many-to-One ๊ด€๊ณ„(์ž์‹ -> ๋ถ€๋ชจ)์—์„œ๋Š” cascade๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ฑฐ๋‚˜, CascadeType.PERSIST์™€ CascadeType.MERGE๋งŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์•ˆ์ „ํ•ฉ๋‹ˆ๋‹ค. ๋ถ€๋ชจ ์—”ํ‹ฐํ‹ฐ์˜ ์ƒ๋ช…์ฃผ๊ธฐ๋Š” ์ž์‹์ด ์•„๋‹Œ ๋ถ€๋ชจ ์ธก์—์„œ ๊ด€๋ฆฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ diff๋ฅผ ์ ์šฉํ•˜์—ฌ cascade๋ฅผ ์ œ๊ฑฐํ•˜์„ธ์š”:

     @JoinColumn(name = "event_id")
-    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+    @ManyToOne(fetch = FetchType.LAZY)
     private Event event;
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@JoinColumn(name = "event_id")
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Event event;
@JoinColumn(name = "event_id")
@ManyToOne(fetch = FetchType.LAZY)
private Event event;
๐Ÿค– Prompt for AI Agents
In src/main/java/ita/growin/domain/task/entity/Task.java around lines 21 to 23,
the @ManyToOne relationship to Event currently uses cascade = CascadeType.ALL
which can delete the parent Event when a Task is removed; remove the cascade
attribute (or replace it with only CascadeType.PERSIST and CascadeType.MERGE if
persistence cascading is required) so the parent Event lifecycle is not driven
by the child Task.

}
27 changes: 27 additions & 0 deletions src/main/java/ita/growin/domain/user/entity/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ita.growin.domain.user.entity;


import ita.growin.domain.event.entity.Event;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class User {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id")
private Long id;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Event> events = new ArrayList<>();
}
9 changes: 9 additions & 0 deletions src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring:
config:
activate:
on-profile: "dev"
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${DEV_DB_URL}
username: ${DEV_DB_USERNAME}
password: ${DEV_DB_PASSWORD}
15 changes: 15 additions & 0 deletions src/main/resources/application-local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
spring:
config:
activate:
on-profile: "local"
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${LOCAL_DB_URL}
username: ${LOCAL_DB_USERNAME}
password: ${LOCAL_DB_PASSWORD}

jpa:
show-sql: true
open-in-view: false
hibernate:
ddl-auto: create-drop
Comment on lines +14 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โš ๏ธ Potential issue | ๐ŸŸ  Major

ddl-auto: create-drop๋Š” ๋„ˆ๋ฌด ํŒŒ๊ดด์ ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

create-drop ์„ค์ •์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์žฌ์‹œ์ž‘๋  ๋•Œ๋งˆ๋‹ค ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…Œ์ด๋ธ”์„ ์‚ญ์ œํ•˜๊ณ  ์žฌ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์ด๋ผ๋„ ์ž‘์—… ์ค‘์ธ ๋ฐ์ดํ„ฐ๊ฐ€ ์†์‹ค๋  ์ˆ˜ ์žˆ์–ด ๋ถˆํŽธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋” ์•ˆ์ „ํ•œ ์˜ต์…˜์„ ๊ณ ๋ คํ•ด๋ณด์„ธ์š”:

  • update: ์Šคํ‚ค๋งˆ๋ฅผ ์ž๋™์œผ๋กœ ์—…๋ฐ์ดํŠธ (ํ”„๋กœ๋•์…˜์—๋Š” ๊ถŒ์žฅํ•˜์ง€ ์•Š์Œ)
  • validate: ์Šคํ‚ค๋งˆ ๊ฒ€์ฆ๋งŒ ์ˆ˜ํ–‰
  • none: ์ž๋™ ์Šคํ‚ค๋งˆ ๊ด€๋ฆฌ ๋น„ํ™œ์„ฑํ™” (Flyway/Liquibase ์‚ฌ์šฉ ์‹œ)

๋‹ค์Œ diff๋ฅผ ์ ์šฉํ•˜์—ฌ ๋” ์•ˆ์ „ํ•œ ์„ค์ •์œผ๋กœ ๋ณ€๊ฒฝํ•˜์„ธ์š”:

     hibernate:
-      ddl-auto: create-drop
+      ddl-auto: update
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
hibernate:
ddl-auto: create-drop
hibernate:
ddl-auto: update
๐Ÿค– Prompt for AI Agents
In src/main/resources/application-local.yaml around lines 14 to 15 the hibernate
ddl-auto is set to the destructive value "create-drop"; change it to a safer
option such as "update" (to auto-apply non-destructive schema changes) or "none"
(to disable automatic schema management when you use Flyway/Liquibase), by
replacing "create-drop" with your chosen safer value and, if choosing "none",
ensure migration tooling (Flyway/Liquibase) is configured for local development.

8 changes: 7 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
spring:
application:
name: growin
name: growin

profiles:
group:
local: "local"
dev: "dev"
test: "test"
11 changes: 11 additions & 0 deletions src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
spring:
config:
activate:
on-profile: "test"

# h2 ์‚ฌ์šฉํ•˜๊ธฐ?
# datasource:
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: ${TEST_DB_URL}
# username: ${TEST_DB_USERNAME}
# password: ${TEST_DB_PASSWORD}
Loading