-
Notifications
You must be signed in to change notification settings - Fork 0
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
좋아요 스킴 초안. Ref #1 #6
Open
JeongmyeongzZ
wants to merge
8
commits into
main
Choose a base branch
from
feature/1-likes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
009d945
좋아요 스킴 초안. Ref #1
JeongmyeongzZ 901c175
separates like entities
JeongmyeongzZ 981c60f
update graphql scheme, resolver
JeongmyeongzZ 9a50cb5
remove repository unused method
JeongmyeongzZ b773f33
entity update batch
JeongmyeongzZ 82375fd
Service update batch
JeongmyeongzZ fc4ede9
add migration file
JeongmyeongzZ 8c44822
update migration filename
JeongmyeongzZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/io/mtudy/soundcloud/like/application/inputs/CreateLikeInput.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 io.mtudy.soundcloud.like.application.inputs; | ||
|
||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
@NoArgsConstructor | ||
public class CreateLikeInput { | ||
@NotBlank | ||
private String type; | ||
|
||
@NotBlank | ||
private String typeId; | ||
|
||
public CreateLikeInput(String type, String typeId) { | ||
this.type = type; | ||
this.typeId = typeId; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getTypeId() { | ||
return typeId; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.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,22 @@ | ||
package io.mtudy.soundcloud.like.application.interfaces.web.graphql; | ||
|
||
import graphql.kickstart.tools.GraphQLMutationResolver; | ||
import io.mtudy.soundcloud.like.application.inputs.CreateLikeInput; | ||
import io.mtudy.soundcloud.like.application.services.CreateLikeService; | ||
import io.mtudy.soundcloud.like.domain.entities.Like; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.validation.Valid; | ||
|
||
@Component | ||
public class CreateLikeMutationResolver implements GraphQLMutationResolver { | ||
private final CreateLikeService service; | ||
|
||
public CreateLikeMutationResolver(CreateLikeService service) { | ||
this.service = service; | ||
} | ||
|
||
public Like createLike(@Valid CreateLikeInput input) { | ||
return this.service.run(input); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...n/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeQueryResolver.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,19 @@ | ||
package io.mtudy.soundcloud.like.application.interfaces.web.graphql; | ||
|
||
import graphql.kickstart.tools.GraphQLQueryResolver; | ||
import io.mtudy.soundcloud.like.application.services.FindLikeByTrackIdService; | ||
import io.mtudy.soundcloud.like.domain.entities.Like; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class LikeQueryResolver implements GraphQLQueryResolver { | ||
private final FindLikeByTrackIdService service; | ||
|
||
public LikeQueryResolver(FindLikeByTrackIdService service) { | ||
this.service = service; | ||
} | ||
|
||
public Like like(String id) { | ||
return this.service.run(id); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.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,26 @@ | ||
package io.mtudy.soundcloud.like.application.services; | ||
|
||
import io.mtudy.soundcloud.like.application.inputs.CreateLikeInput; | ||
import io.mtudy.soundcloud.like.domain.entities.Like; | ||
import io.mtudy.soundcloud.like.domain.repotitories.LikeRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
public class CreateLikeService { | ||
private final LikeRepository repository; | ||
|
||
public CreateLikeService(LikeRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
public Like run(CreateLikeInput request) { | ||
return this.repository.save(new Like( | ||
UUID.randomUUID().toString(), | ||
UUID.randomUUID().toString(), | ||
request.getType(), | ||
request.getTypeId() | ||
)); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/io/mtudy/soundcloud/like/application/services/FindLikeByTrackIdService.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,18 @@ | ||
package io.mtudy.soundcloud.like.application.services; | ||
|
||
import io.mtudy.soundcloud.like.domain.entities.Like; | ||
import io.mtudy.soundcloud.like.domain.repotitories.LikeRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class FindLikeByTrackIdService { | ||
private final LikeRepository repository; | ||
|
||
public FindLikeByTrackIdService(LikeRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
public Like run(String id) { | ||
return this.repository.findByTrackId(id); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.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,47 @@ | ||
package io.mtudy.soundcloud.like.domain.entities; | ||
|
||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
|
||
@NoArgsConstructor | ||
@Entity(name = "like") | ||
public class Like { | ||
@Id | ||
@Column(columnDefinition = "VARCHAR(36)") | ||
private String id; | ||
|
||
@Column(columnDefinition = "VARCHAR(36)") | ||
private String authorId; | ||
|
||
@Column | ||
private String type; | ||
|
||
@Column | ||
private String typeId; | ||
|
||
public Like(String id, String authorId, String type, String typeId) { | ||
this.id = id; | ||
this.authorId = authorId; | ||
this.type = type; | ||
this.typeId = typeId; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getAuthorId() { | ||
return authorId; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getTypeId() { | ||
return typeId; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.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,12 @@ | ||
package io.mtudy.soundcloud.like.domain.repotitories; | ||
|
||
import io.mtudy.soundcloud.like.domain.entities.Like; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface LikeRepository extends CrudRepository<Like, String> { | ||
public default Like findByTrackId(String trackId) { | ||
return null; | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기 어떤 코드인지 설명해주실 수 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
별도로 얘기했으나, 남기는 게 좋을 거 같아 코멘트 남겨둡니다.
현재 trackId가 현재 엔티티 컬럼에 존재하지 않고, 보통 인터페이스에서 컬럼명으로 whereColumn으로 메서드를 정의하면 컴파일 시점에 알아서 관련 코드를 만들어 줍니다.
그리고, 보통 단일 객체를 찾을 땐 JPA 인터페이스에서 기본적으로
Optional<Entity>
를 리턴하는데 이렇게 추가되는 메서드에도 옵셔널을 쓰는 게 좋을 거 같은데 어떨까요?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코멘트 남겨주셨던 부분은 우선, 삭제했습니다 !