Skip to content

Commit

Permalink
merge: conflict 해결 #321
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgksqkr committed Oct 16, 2024
2 parents e43cfbe + 4e13fea commit 94de7a0
Show file tree
Hide file tree
Showing 23 changed files with 160 additions and 782 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/be-cd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Setting application-dev.yml
- name: Setting dev-secret.yml
run: |
echo "${{ secrets.APPLICATION_DEV_YML }}" > ./src/main/resources/application-dev.yml
echo "${{ secrets.DEV_SECRET_YML }}" > ./src/main/resources/dev-secret.yml
- name: Set up JDK 17
uses: actions/setup-java@v4
Expand Down
11 changes: 11 additions & 0 deletions backend/src/main/java/ddangkong/domain/room/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ddangkong.domain.room.Room;
import ddangkong.exception.room.member.AlreadyMasterException;
import ddangkong.exception.room.member.InvalidNicknameException;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand All @@ -20,6 +21,9 @@
@Getter
public class Member {

private static final int NICKNAME_MIN_LENGTH = 2;
private static final int NICKNAME_MAX_LENGTH = 12;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand All @@ -35,11 +39,18 @@ public class Member {
private boolean isMaster;

private Member(String nickname, Room room, boolean isMaster) {
validateNickname(nickname);
this.nickname = nickname;
this.room = room;
this.isMaster = isMaster;
}

private void validateNickname(String nickname) {
if (nickname.length() < NICKNAME_MIN_LENGTH || nickname.length() > NICKNAME_MAX_LENGTH) {
throw new InvalidNicknameException(NICKNAME_MIN_LENGTH, NICKNAME_MAX_LENGTH);
}
}

public static Member createMaster(String nickname, Room room) {
return new Member(nickname, room, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum ClientErrorCode {
NOT_EXIST_COMMON("일반 멤버가 존재하지 않습니다."),
EXCEED_MAX_MEMBER_COUNT("방의 최대 인원을 초과했습니다. 현재 멤버 수: %d"),
NOT_ROOM_MEMBER("방에 존재하지 않는 멤버입니다."),
INVALID_NICKNAME("닉네임은 최소 %d글자, 최대 %d글자여야 합니다."),

// RoomContent
NOT_FOUND_ROOM_CONTENT("방에 존재하지 않는 컨텐츠입니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ddangkong.exception.room.member;

import static ddangkong.exception.ClientErrorCode.INVALID_NICKNAME;

import ddangkong.exception.BadRequestException;

public class InvalidNicknameException extends BadRequestException {

public InvalidNicknameException(int minLength, int maxLength) {
super(INVALID_NICKNAME.getMessage().formatted(minLength, maxLength));
}

@Override
public String getErrorCode() {
return INVALID_NICKNAME.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
public record RoomJoinRequest(
@NotBlank
String nickname
) { // todo validation 닉네임 정책
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RequiredArgsConstructor
@Profile("prod")
public class RoomScheduler {

private static final int DELAYED_HOURS = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -23,11 +24,18 @@ public class RoomBalanceVoteService {

@Transactional
public RoomBalanceVote createVote(Member member, BalanceOptions balanceOptions, Long votedOptionId) {
for (BalanceOption option : balanceOptions.getOptions()) {
validDuplicatedVote(member, option);
}
validDuplicatedVotes(member, balanceOptions);
BalanceOption votedOption = balanceOptions.getOptionById(votedOptionId);
return roomVoteRepository.save(new RoomBalanceVote(member, votedOption));
try {
return roomVoteRepository.save(new RoomBalanceVote(member, votedOption));
} catch (DataIntegrityViolationException e) {
throw new AlreadyVotedException(member.getNickname(), votedOption.getName());
}
}

private void validDuplicatedVotes(Member member, BalanceOptions balanceOptions) {
balanceOptions.getOptions()
.forEach(balanceOption -> validDuplicatedVote(member, balanceOption));
}

private void validDuplicatedVote(Member member, BalanceOption balanceOption) {
Expand Down
28 changes: 28 additions & 0 deletions backend/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
spring:
config:
import: dev-secret.yml

datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${secret.datasource.url}:${secret.datasource.port}/${secret.datasource.database}?useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&autoReconnect=true&serverTimezone=Asia/Seoul&useLegacyDatetimeCode=false
username: ${secret.datasource.username}
password: ${secret.datasource.password}

jpa:
defer-datasource-initialization: true
hibernate:
ddl-auto: update
properties:
hibernate:
show_sql: true
format_sql: true
default_batch_fetch_size: 1000

cors:
origin: ${secret.cors.origin}

logging:
config: classpath:logback-dev.xml
location : ${secret.application.log.location}
discord:
webhook-url: ${secret.discord.webhook-url}
Empty file.
3 changes: 2 additions & 1 deletion backend/src/main/resources/logback-dev.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- ddangkong 패키지에 대한 로그를 파일에 출력하기 위한 설정 -->
<property name="LOG_PATH" value="logs"/>
<springProperty name="LOG_HOME_PATH" source="logging.location"/>
<property name="LOG_PATH" value="${LOG_HOME_PATH}/app-logs"/>
<property name="LOG_FILE" value="${LOG_PATH}/ddangkong.log"/>
<appender name="DDANGKONG_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE}</file>
Expand Down
Loading

0 comments on commit 94de7a0

Please sign in to comment.