Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

로컬 개발환경 세팅 #418

Merged
merged 6 commits into from
Jun 4, 2024
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: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ out/

### VS Code ###
.vscode/
/src/main/resources/application-local.yml
/.env
/src/main/resources/firebase/firebase-service-key-local.json
/src/main/generated/
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ configurations {

repositories {
mavenCentral()
jcenter()
google()
}

Expand Down Expand Up @@ -94,8 +93,6 @@ dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis', version: '3.1.4'
// redisson
implementation 'org.redisson:redisson-spring-data-26:3.23.5'
// embedded-redis
implementation(group: 'it.ozimov', name: 'embedded-redis', version: '0.7.2')
// FCM push
implementation 'com.google.firebase:firebase-admin:6.8.1'
// OpenFeign
Expand All @@ -118,9 +115,9 @@ dependencies {
// easy random
testImplementation 'org.jeasy:easy-random-core:5.0.0'

testImplementation 'org.testcontainers:testcontainers:1.17.2'
implementation 'org.testcontainers:testcontainers:1.19.8'

testImplementation 'org.testcontainers:junit-jupiter:1.17.2'
implementation 'org.testcontainers:junit-jupiter:1.19.8'

testImplementation 'org.mockito:mockito-inline:3.6.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

import javax.persistence.*;

@ToString
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@ToString
public class BreadDiary extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -35,4 +35,12 @@ public class BreadDiary extends BaseEntity {

@Column(nullable = false)
private int rating;

public BreadDiary(User user, Bakery bakery, String productName, int productPrice, int rating) {
this.user = user;
this.bakery = bakery;
this.productName = productName;
this.productPrice = productPrice;
this.rating = rating;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface BreadDiaryRepository extends JpaRepository<BreadDiary, Long> {

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
package com.depromeet.breadmapbackend.domain.breaddiary;

import com.depromeet.breadmapbackend.domain.bakery.Bakery;
import com.depromeet.breadmapbackend.domain.bakery.BakeryRepository;
import com.depromeet.breadmapbackend.domain.breaddiary.dto.AddBreadDiaryDto;
import com.depromeet.breadmapbackend.domain.image.ImageService;
import com.depromeet.breadmapbackend.domain.user.User;
import com.depromeet.breadmapbackend.domain.user.UserRepository;
import com.depromeet.breadmapbackend.global.exception.DaedongException;
import com.depromeet.breadmapbackend.global.exception.DaedongStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;

@RequiredArgsConstructor
@Service
@RequiredArgsConstructor
@Transactional
public class BreadDiaryServiceImpl implements BreadDiaryService {

private final ImageService imageService;

private final UserRepository userRepository;

private final BakeryRepository bakeryRepository;

private final BreadDiaryRepository breadDiaryRepository;

@Override
public void addBreadDiary(AddBreadDiaryDto dto) {

User user = userRepository.findByOAuthId(dto.oAuthId())
.orElseThrow(() -> new DaedongException(DaedongStatus.USER_NOT_FOUND));
Bakery bakery = bakeryRepository.findById(dto.bakeryId())
.orElseThrow(() -> new DaedongException(DaedongStatus.BAKERY_NOT_FOUND));
try {
imageService.uploadImage(dto.image());
} catch (IOException e) {
throw new DaedongException(DaedongStatus.IMAGE_INVALID_EXCEPTION);
}
breadDiaryRepository.save(new BreadDiary(user, bakery, dto.productName(), dto.productPrice(), dto.rating()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.depromeet.breadmapbackend.domain.review.tag;

public class TagBakeryMapping {
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
package com.depromeet.breadmapbackend.global.infra;

import javax.annotation.PostConstruct;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.PostConstruct;

@Slf4j
@Profile({"default", "local"})
@Configuration
@RequiredArgsConstructor
public class EmbeddedRedisConfig {

private static final String REDIS_DOCKER_IMAGE = "redis:6";
private final StringRedisTemplate redisTemplate;

static {
GenericContainer<?> REDIS_CONTAINER =
new GenericContainer<>(DockerImageName.parse(REDIS_DOCKER_IMAGE))
.waitingFor(Wait.forLogMessage(".*Ready to accept connections.*\\n", 1))
.withExposedPorts(6379)
.withReuse(true);

REDIS_CONTAINER.start();

System.setProperty("spring.redis.host", REDIS_CONTAINER.getHost());
System.setProperty("spring.redis.port", REDIS_CONTAINER.getMappedPort(6379).toString());
}

@PostConstruct
public void setUp() {
try {
redisTemplate.opsForStream()
.createGroup("bakery-view-event", "bakery-view-event:group");
} catch (Exception e) {
log.info("bakery-view-event:group already exists : {} ", e.getMessage());
}
}
private static final String REDIS_DOCKER_IMAGE = "redis:6";
private final StringRedisTemplate redisTemplate;

static {
GenericContainer<?> REDIS_CONTAINER =
new GenericContainer<>(DockerImageName.parse(REDIS_DOCKER_IMAGE))
.waitingFor(Wait.forLogMessage(".*Ready to accept connections.*\\n", 1))
.withExposedPorts(6379);

REDIS_CONTAINER.start();
System.setProperty("spring.redis.host", REDIS_CONTAINER.getHost());
System.setProperty("spring.redis.port", REDIS_CONTAINER.getMappedPort(6379).toString());
}

@PostConstruct
public void setUp() {
try {
redisTemplate.opsForStream()
.createGroup("bakery-view-event", "bakery-view-event:group");
} catch (Exception e) {
log.info("bakery-view-event:group already exists : {} ", e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.depromeet.breadmapbackend.global.infra;

import lombok.extern.slf4j.Slf4j;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;

import java.util.Map;

@Slf4j
class LocalMysqlConfig {
static {
if (System.getProperty("spring.profiles.active").contains("local")) {
DockerImageName MYSQL_IMAGE = DockerImageName.parse("mysql:8.0.36");
GenericContainer<?> MYSQL_CONTAINER = new GenericContainer<>(MYSQL_IMAGE)
.withExposedPorts(3306)
.withEnv(Map.of(
"MYSQL_DATABASE", "local_bread_map",
"MYSQL_USER", "admin",
"MYSQL_ROOT_PASSWORD", "1234",
"MYSQL_PASSWORD", "1234"
));
MYSQL_CONTAINER.start();
String jdbcUrl = String.format("jdbc:mysql://localhost:%s/local_bread_map", MYSQL_CONTAINER.getMappedPort(3306));
System.setProperty("spring.datasource.url", jdbcUrl);
log.info("Generated JDBC URL: {}", jdbcUrl);
}
}
}
89 changes: 89 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
spring:
lifecycle:
timeout-per-shutdown-phase: 40s
jwt:
secret: thisisjwtsecretthisisjwtsecretthisisjwtsecretthisisjwtsecretthisisjwtsecretthisisjwtsecretthisisjwtsecret
admin: thisisjwtadminkeythisisjwtadminkeythisisjwtadminkeythisisjwtadminkeythisisjwtadminkeythisisjwtadminkey
datasource:
url:
username: root
password: 1234
hikari:
maximum-pool-size: 20
# idle-timeout: 300
# max-lifeitme: 300
jpa:
hibernate:
ddl-auto: validate
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
properties:
default_batch_fetch_size: 100
generate-ddl: false
redis:
key:
delete: delete
recent: recent
access: access
refresh: refresh
admin-refresh: admin-refresh
bakery-review: bakery-review
product-review: product-review
user-review: user-review

oauth:
google: google-id
kakao: kakao-id
apple: apple-id

cloud:
aws:
region:
static: us-east-1
s3:
bucket: bucket
cloud-front: cloud-front
default-bucket:
image: image
default-image:
bakery: bakery
comment: comment
like: like
report: report
flag: flag
user: user
curation: curation
event: event
breadAdd: breadAdd
open-search:
id: id
password: password
host: host

firebase:
credentials: credentials
scope: scope
projectId: projectId
message:
path:
user: user
review: review

sgis:
src: 1
dst1: 2
dst2: 3
key: key
secret: secret

admin:
event:
post:
user-id: 1

redis:
poll-timeout:
bakery-view: 5
bakery-ranking-calculator: 20

server:
shutdown: graceful
2 changes: 0 additions & 2 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ spring:
bakery-review: ${REDIS_KEY_BAKERY_REVIEW}
product-review: ${REDIS_KEY_PRODUCT_REVIEW}
user-review: ${REDIS_KEY_USER_REVIEW}
flyway:
enabled: false

oauth:
google: ${GOOGLE_ID}
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/application-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ spring:
bakery-review: ${REDIS_KEY_BAKERY_REVIEW}
product-review: ${REDIS_KEY_PRODUCT_REVIEW}
user-review: ${REDIS_KEY_USER_REVIEW}
flyway:
enabled: true
baseline-on-migrate: true
baseline-version: 0

oauth:
google: ${GOOGLE_ID}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ spring:
redis:
repositories:
enabled: false # Spring Data Redis 저장소 기능
flyway:
enabled: true
baseline-on-migrate: true
baseline-version: 1

#logging:
# level:
Expand Down

This file was deleted.

Loading
Loading