-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: 노래 등록 조회, 파트 등록, 킬링파트 조회 기능 구현 * refactor: 테스트 인자 값 변경 이미지URL 에서 비디오 URL 로 변경 때 오타 수정 * refactor: RequiredArgsConstructor 로 변경, propagation 설정 제거 * refactor: 정적 팩토리 메서드명 변경 notPersisted 에서 forSave persisted 에서 saved * refactor: 부모 예외 명시 * refactor: 같은 길이의 동일한 시작 파트 검증 로직 변경 * refactor: request validation 어노테이션 변경 * refactor: 부정연산자 제거를 위한 메서드 변경 * refactor: 확장성을 위해 정렬된 상태를 가지지 않게 변경 킬링파트의 최대 갯수 상수 분리 * refactor: Song 에 Parts 의존성 추가 * refactor: 정확한 명시를 위해 Repository 어노테이션 추가 * fix: Integer 에 붙어있는 @notblank 어노테이션 수정 * refactor: 불변 필드에 final 키워드 추가 * refactor: Part 중복 검증 로직 추가 * refactor: JPA 를 사용하는 테스트를 위한 추상 클래스 추가, DisplayName 수정
- Loading branch information
1 parent
628efb5
commit 4a2337f
Showing
39 changed files
with
2,055 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,42 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' version '3.1.1' | ||
id 'io.spring.dependency-management' version '1.1.0' | ||
id 'java' | ||
id 'org.springframework.boot' version '3.1.1' | ||
id 'io.spring.dependency-management' version '1.1.0' | ||
} | ||
|
||
group = 'shook' | ||
version = '0.0.1-SNAPSHOT' | ||
|
||
java { | ||
sourceCompatibility = '17' | ||
sourceCompatibility = '17' | ||
} | ||
|
||
configurations { | ||
compileOnly { | ||
extendsFrom annotationProcessor | ||
} | ||
compileOnly { | ||
extendsFrom annotationProcessor | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
} | ||
|
||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
compileOnly 'org.projectlombok:lombok' | ||
runtimeOnly 'com.h2database:h2' | ||
runtimeOnly 'com.mysql:mysql-connector-j' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'org.springframework.boot:spring-boot-starter-validation' | ||
|
||
compileOnly 'org.projectlombok:lombok' | ||
|
||
runtimeOnly 'com.h2database:h2' | ||
runtimeOnly 'com.mysql:mysql-connector-j' | ||
|
||
annotationProcessor 'org.projectlombok:lombok' | ||
|
||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
backend/src/main/java/shook/shook/part/application/PartService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package shook.shook.part.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import shook.shook.part.application.dto.PartRegisterRequest; | ||
import shook.shook.part.domain.Part; | ||
import shook.shook.part.domain.PartLength; | ||
import shook.shook.part.domain.Vote; | ||
import shook.shook.part.domain.repository.PartRepository; | ||
import shook.shook.part.domain.repository.VoteRepository; | ||
import shook.shook.part.exception.PartException; | ||
import shook.shook.song.domain.Song; | ||
import shook.shook.song.domain.repository.SongRepository; | ||
import shook.shook.song.exception.SongException; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Service | ||
public class PartService { | ||
|
||
private final SongRepository songRepository; | ||
private final PartRepository partRepository; | ||
private final VoteRepository voteRepository; | ||
|
||
@Transactional | ||
public void register(final PartRegisterRequest request) { | ||
final Song song = songRepository.findById(request.getSongId()) | ||
.orElseThrow(SongException.SongNotExistException::new); | ||
|
||
final int startSecond = request.getStartSecond(); | ||
final PartLength partLength = PartLength.findBySecond(request.getLength()); | ||
final Part part = Part.forSave(startSecond, partLength, song); | ||
|
||
if (song.isUniquePart(part)) { | ||
addPartAndVote(song, part); | ||
return; | ||
} | ||
voteToExistPart(song, part); | ||
} | ||
|
||
private void addPartAndVote(final Song song, final Part part) { | ||
song.addPart(part); | ||
partRepository.save(part); | ||
|
||
final Vote newVote = Vote.forSave(part); | ||
part.vote(newVote); | ||
voteRepository.save(newVote); | ||
} | ||
|
||
private void voteToExistPart(final Song song, final Part part) { | ||
final Part existPart = song.getSameLengthPartStartAt(part) | ||
.orElseThrow(PartException.PartNotExistException::new); | ||
|
||
final Vote newVote = Vote.forSave(existPart); | ||
existPart.vote(newVote); | ||
voteRepository.save(newVote); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
backend/src/main/java/shook/shook/part/application/dto/PartRegisterRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package shook.shook.part.application.dto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
import jakarta.validation.constraints.PositiveOrZero; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor | ||
@Getter | ||
public class PartRegisterRequest { | ||
|
||
@NotNull | ||
@PositiveOrZero | ||
private Integer startSecond; | ||
|
||
@NotNull | ||
@Positive | ||
private Integer length; | ||
|
||
@NotNull | ||
@Positive | ||
private Long songId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.