Skip to content

Commit fc5e59d

Browse files
committed
configuration(dependency) mongodb
MongoDB 의존성 제거 VotePaper, VoteChoice, Vote Entity JPA 영속성 모델로 변경
1 parent 0484401 commit fc5e59d

34 files changed

+260
-349
lines changed

build.gradle

+1-16
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,9 @@ dependencies {
7575

7676
// Persistence Layer
7777
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
78-
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
7978
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
79+
implementation 'io.hypersistence:hypersistence-utils-hibernate-63:3.7.4'
8080
implementation "io.github.openfeign.querydsl:querydsl-jpa-spring:${queryDslVersion}"
81-
implementation("io.github.openfeign.querydsl:querydsl-mongodb:${queryDslVersion}") {
82-
exclude group: 'org.mongodb', module: 'mongo-java-driver'
83-
}
8481
implementation "io.github.openfeign.querydsl:querydsl-collections:${queryDslVersion}"
8582
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.1'
8683
implementation 'org.flywaydb:flyway-core'
@@ -137,8 +134,6 @@ dependencies {
137134
annotationProcessor(
138135
'org.springframework.boot:spring-boot-configuration-processor',
139136
"io.github.openfeign.querydsl:querydsl-jpa-spring:${queryDslVersion}",
140-
"io.github.openfeign.querydsl:querydsl-mongodb:${queryDslVersion}",
141-
'org.springframework.boot:spring-boot-starter-data-mongodb',
142137
'org.projectlombok:lombok',
143138
"org.mapstruct:mapstruct-processor:${mapstructVersion}",
144139
'org.projectlombok:lombok-mapstruct-binding:0.2.0'
@@ -171,16 +166,13 @@ dependencies {
171166
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
172167
testImplementation 'org.testcontainers:junit-jupiter'
173168
testImplementation 'org.testcontainers:postgresql'
174-
testImplementation 'org.testcontainers:mongodb'
175169
testImplementation 'org.testcontainers:kafka'
176170
testImplementation 'org.testcontainers:localstack'
177171
testImplementation 'org.elasticmq:elasticmq-server_3:1.6.1'
178172

179173
testAnnotationProcessor(
180174
'org.springframework.boot:spring-boot-configuration-processor',
181175
"io.github.openfeign.querydsl:querydsl-jpa-spring:${queryDslVersion}",
182-
"io.github.openfeign.querydsl:querydsl-mongodb:${queryDslVersion}",
183-
'org.springframework.boot:spring-boot-starter-data-mongodb',
184176
'org.projectlombok:lombok',
185177
"org.mapstruct:mapstruct-processor:${mapstructVersion}",
186178
'org.projectlombok:lombok-mapstruct-binding:0.2.0'
@@ -193,13 +185,6 @@ sourceSets {
193185
}
194186

195187
tasks.withType(JavaCompile).configureEach {
196-
options.compilerArgs += [
197-
"-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor,' +
198-
'org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor,' +
199-
'com.querydsl.apt.jpa.JPAAnnotationProcessor,' +
200-
'org.mapstruct.ap.MappingProcessor,' +
201-
'org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor'
202-
]
203188
options.annotationProcessorGeneratedSourcesDirectory(file(generated))
204189
}
205190

compose.yaml

+1-12
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,4 @@ services:
1414
container_name: 'tune_fun_redis'
1515
restart: always
1616
ports:
17-
- '6378:6379'
18-
19-
mongodb:
20-
image: 'mongo:7.0.4'
21-
container_name: 'tune_fun_mongodb'
22-
restart: always
23-
environment:
24-
MONGO_INITDB_DATABASE: mydatabase
25-
MONGO_INITDB_ROOT_PASSWORD: secret
26-
MONGO_INITDB_ROOT_USERNAME: root
27-
ports:
28-
- '27016:27017'
17+
- '6378:6379'

src/docs/asciidoc/index.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ include::common/message.adoc[]
1313
include::account-api.adoc[]
1414
include::oauth2-api.adoc[]
1515
include::otp-api.adoc[]
16+
include::vote-api.adoc[]

src/docs/asciidoc/vote-api.adoc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[[Vote-API]]
2+
== Vote API
3+
4+
=== 투표 게시물 등록 API
5+
6+
==== 성공
7+
8+
operation::register-vote-paper-success[snippets='http-request,http-response,request-fields']

src/main/java/com/tune_fun/v1/account/adapter/input/rest/RegisterController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class RegisterController {
2929
*/
3030
@PostMapping(value = Uris.REGISTER)
3131
public ResponseEntity<Response<RegisterResult>> register(@RequestParam(name = "type") RegisterType type, @Valid @RequestBody final AccountCommands.Register command) {
32-
RegisterResult registerResult = registerUseCase.register(type, command);
32+
RegisterResult registerResult = registerUseCase.register(type.name(), command);
3333
return responseMapper.ok(registerResult);
3434
}
3535

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.tune_fun.v1.account.application.port.input.usecase;
22

3-
import com.tune_fun.v1.account.adapter.input.rest.RegisterType;
43
import com.tune_fun.v1.account.application.port.input.command.AccountCommands;
54
import com.tune_fun.v1.account.domain.value.RegisterResult;
65

76
@FunctionalInterface
87
public interface RegisterUseCase {
9-
RegisterResult register(RegisterType type, final AccountCommands.Register command);
8+
RegisterResult register(String registerType, final AccountCommands.Register command);
109
}

src/main/java/com/tune_fun/v1/account/application/service/RegisterService.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.tune_fun.v1.account.application.service;
22

3-
import com.tune_fun.v1.account.adapter.input.rest.RegisterType;
43
import com.tune_fun.v1.account.application.port.input.command.AccountCommands;
54
import com.tune_fun.v1.account.application.port.input.usecase.RegisterUseCase;
65
import com.tune_fun.v1.account.application.port.output.LoadAccountPort;
@@ -36,8 +35,8 @@ public class RegisterService implements RegisterUseCase {
3635
private final PasswordEncoder passwordEncoder;
3736

3837
@NotNull
39-
private static SaveAccount getSaveAccount(final RegisterType type, final AccountCommands.Register command, final String encodedPassword) {
40-
return new SaveAccount(type.name(),
38+
private static SaveAccount getSaveAccount(final String registerType, final AccountCommands.Register command, final String encodedPassword) {
39+
return new SaveAccount(registerType,
4140
StringUtil.uuid(), command.username(), encodedPassword,
4241
command.email(), command.nickname(), command.notification().voteDeliveryNotification(),
4342
command.notification().voteEndNotification(), command.notification().voteDeliveryNotification()
@@ -51,11 +50,11 @@ private static RegisterResult getRegisterResult(CurrentAccount savedAccount, Str
5150

5251
@Override
5352
@Transactional
54-
public RegisterResult register(final RegisterType type, final AccountCommands.Register command) {
53+
public RegisterResult register(final String registerType, final AccountCommands.Register command) {
5554
checkRegisterdAccount(command);
5655

5756
String encodedPassword = passwordEncoder.encode(command.password());
58-
SaveAccount saveAccount = getSaveAccount(type, command, encodedPassword);
57+
SaveAccount saveAccount = getSaveAccount(registerType, command, encodedPassword);
5958
CurrentAccount savedAccount = saveAccountPort.saveAccount(saveAccount);
6059

6160
String authorities = String.join(",", savedAccount.roles());

src/main/java/com/tune_fun/v1/common/config/SpringDataConfig.java

-43
This file was deleted.

src/main/java/com/tune_fun/v1/external/aws/sqs/SqsProvider.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ public class SqsProvider {
1818
private final SqsTemplate sqsTemplate;
1919
private final EventProperty eventProperty;
2020

21-
public SendResult<?> sendMessageRangedQueue(@NotBlank final String queueName, @NotBlank final String messageGroupId,
22-
@NotNull final Object message) {
21+
public SendResult<?> sendMessageRangedQueue(@NotBlank final String queueName, @NotNull final Object message) {
2322
EventProperty.SqsProducer sqsProducer = eventProperty.getSqsProducer(queueName);
2423

2524
return sqsTemplate.send(to -> to
2625
.queue(sqsProducer.queueName())
2726
.header(CONTENT_TYPE, APPLICATION_JSON_VALUE)
2827
.payload(message)
29-
.messageGroupId(messageGroupId)
3028
);
3129
}
3230

src/main/java/com/tune_fun/v1/vote/adapter/output/message/VoteMessageBrokerAdapter.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class VoteMessageBrokerAdapter implements ProduceVotePaperUploadEventPort
1616

1717
@Override
1818
public void produceVotePaperUploadEvent(final ProduceVotePaperUploadEvent produceVotePaperUploadEvent) {
19-
sqsProvider.sendMessageRangedQueue(VOTE_PAPER_UPLOAD_QUEUE, produceVotePaperUploadEvent.id() + "_fcm",
20-
produceVotePaperUploadEvent);
19+
sqsProvider.sendMessageRangedQueue(VOTE_PAPER_UPLOAD_QUEUE, produceVotePaperUploadEvent);
2120
}
2221
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
package com.tune_fun.v1.vote.adapter.output.persistence;
22

3-
import lombok.AllArgsConstructor;
4-
import lombok.Builder;
5-
import lombok.Getter;
6-
import lombok.NoArgsConstructor;
7-
83
import java.util.Set;
94

10-
@Builder
11-
@Getter
12-
@AllArgsConstructor
13-
@NoArgsConstructor
14-
public final class Offer {
15-
private String name;
16-
private String artistName;
17-
private Set<String> genres;
18-
private String releaseDate;
19-
private Integer durationMs;
5+
public record Offer(String music, String artistName, Set<String> genres, String releaseDate, Integer durationMs) {
206
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.tune_fun.v1.vote.adapter.output.persistence;
2+
3+
import com.tune_fun.v1.common.entity.BaseEntity;
4+
import jakarta.persistence.*;
5+
import jakarta.validation.constraints.NotNull;
6+
import jakarta.validation.constraints.Size;
7+
import lombok.AllArgsConstructor;
8+
import lombok.Getter;
9+
import lombok.NoArgsConstructor;
10+
import lombok.experimental.SuperBuilder;
11+
import org.hibernate.annotations.Comment;
12+
import org.hibernate.annotations.JdbcTypeCode;
13+
import org.hibernate.type.SqlTypes;
14+
15+
@SuperBuilder(toBuilder = true)
16+
@NoArgsConstructor
17+
@AllArgsConstructor
18+
@Getter
19+
@Entity
20+
@Table(name = "vote_choice")
21+
public class VoteChoiceJpaEntity extends BaseEntity {
22+
23+
@Id
24+
@GeneratedValue(strategy = GenerationType.IDENTITY)
25+
@Column(name = "id", nullable = false, updatable = false)
26+
@Comment("Sequence")
27+
private Long id;
28+
29+
@Size(max = 255)
30+
@NotNull
31+
@Column(name = "uuid", nullable = false)
32+
@Comment("고유번호")
33+
private String uuid;
34+
35+
@ManyToOne(fetch = FetchType.LAZY)
36+
@JoinColumn(name = "vote_paper_id", nullable = false, updatable = false, referencedColumnName = "id")
37+
@Comment("투표 게시물 ID")
38+
private VotePaperJpaEntity votePaper;
39+
40+
@JdbcTypeCode(SqlTypes.JSON)
41+
@Comment("선택지 제안사항")
42+
private Offer offer;
43+
44+
}

src/main/java/com/tune_fun/v1/vote/adapter/output/persistence/VoteChoiceMongoEntity.java

-38
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.tune_fun.v1.vote.adapter.output.persistence;
22

3-
import org.springframework.data.mongodb.repository.MongoRepository;
3+
import org.springframework.data.jpa.repository.JpaRepository;
44

5-
public interface VoteChoiceRepository extends MongoRepository<VoteChoiceMongoEntity, String> {
5+
public interface VoteChoiceRepository extends JpaRepository<VoteChoiceJpaEntity, String> {
66
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.tune_fun.v1.vote.adapter.output.persistence;
2+
3+
import com.tune_fun.v1.account.adapter.output.persistence.AccountJpaEntity;
4+
import com.tune_fun.v1.common.entity.BaseEntity;
5+
import jakarta.persistence.*;
6+
import jakarta.validation.constraints.NotNull;
7+
import jakarta.validation.constraints.Size;
8+
import lombok.AllArgsConstructor;
9+
import lombok.Getter;
10+
import lombok.NoArgsConstructor;
11+
import lombok.experimental.SuperBuilder;
12+
import org.hibernate.annotations.Comment;
13+
14+
@SuperBuilder(toBuilder = true)
15+
@NoArgsConstructor
16+
@AllArgsConstructor
17+
@Getter
18+
@Entity
19+
@Table(name = "vote")
20+
public class VoteJpaEntity extends BaseEntity {
21+
22+
@Id
23+
@GeneratedValue(strategy = GenerationType.IDENTITY)
24+
@Column(name = "id", nullable = false, updatable = false)
25+
@Comment("Sequence")
26+
private Long id;
27+
28+
@Size(max = 255)
29+
@NotNull
30+
@Column(name = "uuid", nullable = false)
31+
@Comment("고유번호")
32+
private String uuid;
33+
34+
@ManyToOne(fetch = FetchType.LAZY)
35+
@JoinColumn(name = "vote_choice_id", nullable = false, updatable = false, referencedColumnName = "id")
36+
@Comment("투표 선택지 ID")
37+
private VoteChoiceJpaEntity voteChoice;
38+
39+
@ManyToOne(fetch = FetchType.LAZY)
40+
@JoinColumn(name = "voter_id", nullable = false, updatable = false, referencedColumnName = "id")
41+
@Comment("투표자 ID")
42+
private AccountJpaEntity voter;
43+
44+
}

0 commit comments

Comments
 (0)