From 009d945b05bbb1359bf70a9391425e6f56702fa7 Mon Sep 17 00:00:00 2001 From: jeongmyeong Date: Sun, 20 Dec 2020 17:46:30 +0900 Subject: [PATCH 1/8] =?UTF-8?q?=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=8A=A4?= =?UTF-8?q?=ED=82=B4=20=EC=B4=88=EC=95=88.=20Ref=20#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/inputs/CreateLikeInput.java | 27 +++++++++++ .../graphql/CreateLikeMutationResolver.java | 22 +++++++++ .../web/graphql/LikeQueryResolver.java | 19 ++++++++ .../services/CreateLikeService.java | 26 ++++++++++ .../services/FindLikeByTrackIdService.java | 18 +++++++ .../soundcloud/like/domain/entities/Like.java | 47 +++++++++++++++++++ .../domain/repotitories/LikeRepository.java | 12 +++++ src/main/resources/schema.graphqls | 12 +++++ 8 files changed, 183 insertions(+) create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/inputs/CreateLikeInput.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeQueryResolver.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/services/FindLikeByTrackIdService.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java diff --git a/src/main/java/io/mtudy/soundcloud/like/application/inputs/CreateLikeInput.java b/src/main/java/io/mtudy/soundcloud/like/application/inputs/CreateLikeInput.java new file mode 100644 index 0000000..3518aa0 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/inputs/CreateLikeInput.java @@ -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; + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java new file mode 100644 index 0000000..14655ee --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java @@ -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); + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeQueryResolver.java b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeQueryResolver.java new file mode 100644 index 0000000..065124b --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeQueryResolver.java @@ -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); + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java b/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java new file mode 100644 index 0000000..d4e5d66 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java @@ -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() + )); + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/services/FindLikeByTrackIdService.java b/src/main/java/io/mtudy/soundcloud/like/application/services/FindLikeByTrackIdService.java new file mode 100644 index 0000000..56f5dcc --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/services/FindLikeByTrackIdService.java @@ -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); + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java b/src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java new file mode 100644 index 0000000..4bc3119 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java @@ -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; + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java new file mode 100644 index 0000000..d11dc60 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java @@ -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 { + public default Like findByTrackId(String trackId) { + return null; + } +} diff --git a/src/main/resources/schema.graphqls b/src/main/resources/schema.graphqls index ed8251e..b95ffb6 100644 --- a/src/main/resources/schema.graphqls +++ b/src/main/resources/schema.graphqls @@ -12,11 +12,23 @@ type Track { artworkUrl: String! } +type Like { + id : ID! + type : String! + typeId: String! +} + type Mutation { createTrack(input: CreateTrackInput!): Track + createLike(input: CreateLikeInput!): Like } input CreateTrackInput { title: String! artworkUrl: String! } + +input CreateLikeInput { + type: String! + typeId: String! +} From 901c1754a4c85f55446ceb2169fd0c1531d6340a Mon Sep 17 00:00:00 2001 From: jeongmyeong Date: Fri, 22 Jan 2021 13:49:33 +0900 Subject: [PATCH 2/8] separates like entities --- .../soundcloud/like/domain/entities/Like.java | 33 ++++++----------- .../like/domain/entities/PlaylistLike.java | 36 +++++++++++++++++++ .../like/domain/entities/TrackLike.java | 35 ++++++++++++++++++ .../like/domain/enums/LikeType.java | 13 +++++++ .../db/migration/V1__create_like_table.sql | 7 ++++ 5 files changed, 101 insertions(+), 23 deletions(-) create mode 100644 src/main/java/io/mtudy/soundcloud/like/domain/entities/PlaylistLike.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/domain/entities/TrackLike.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/domain/enums/LikeType.java create mode 100644 src/main/resources/db/migration/V1__create_like_table.sql diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java b/src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java index 4bc3119..480c2cd 100644 --- a/src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java +++ b/src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java @@ -2,32 +2,23 @@ import lombok.NoArgsConstructor; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; +import javax.persistence.*; @NoArgsConstructor -@Entity(name = "like") -public class Like { +@Entity +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "type", + discriminatorType = DiscriminatorType.STRING) +public abstract class Like { @Id @Column(columnDefinition = "VARCHAR(36)") - private String id; + protected String id; @Column(columnDefinition = "VARCHAR(36)") - private String authorId; + protected 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; - } + @Column(columnDefinition = "VARCHAR(36)") + protected String typeId; public String getId() { return id; @@ -37,10 +28,6 @@ public String getAuthorId() { return authorId; } - public String getType() { - return type; - } - public String getTypeId() { return typeId; } diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/entities/PlaylistLike.java b/src/main/java/io/mtudy/soundcloud/like/domain/entities/PlaylistLike.java new file mode 100644 index 0000000..d0c0cec --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/entities/PlaylistLike.java @@ -0,0 +1,36 @@ +package io.mtudy.soundcloud.like.domain.entities; + +import io.mtudy.soundcloud.like.domain.enums.LikeType; +import lombok.NoArgsConstructor; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +@NoArgsConstructor +@Entity(name = "playlistLike") +@DiscriminatorValue(LikeType.Values.PLAYLIST) +public final class PlaylistLike extends Like { + private PlaylistLike(Builder builder) { + this.id = builder.id; + this.typeId = builder.typeId; + this.authorId = builder.authorId; + } + + public final static class Builder { + private final String id; + + private final String typeId; + + private final String authorId; + + public Builder(String id, String typeId, String authorId) { + this.id = id; + this.typeId = typeId; + this.authorId = authorId; + } + + public PlaylistLike build() { + return new PlaylistLike(this); + } + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/entities/TrackLike.java b/src/main/java/io/mtudy/soundcloud/like/domain/entities/TrackLike.java new file mode 100644 index 0000000..95ecd74 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/entities/TrackLike.java @@ -0,0 +1,35 @@ +package io.mtudy.soundcloud.like.domain.entities; + +import io.mtudy.soundcloud.like.domain.enums.LikeType; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@NoArgsConstructor +@Entity(name = "trackLike") +@DiscriminatorValue(LikeType.Values.TRACK) +public final class TrackLike extends Like { + private TrackLike(Builder builder) { + this.id = builder.id; + this.typeId = builder.typeId; + this.authorId = builder.authorId; + } + + public final static class Builder { + private final String id; + + private final String typeId; + + private final String authorId; + + public Builder(String id, String typeId, String authorId) { + this.id = id; + this.typeId = typeId; + this.authorId = authorId; + } + + public TrackLike build() { + return new TrackLike(this); + } + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/enums/LikeType.java b/src/main/java/io/mtudy/soundcloud/like/domain/enums/LikeType.java new file mode 100644 index 0000000..53ded68 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/enums/LikeType.java @@ -0,0 +1,13 @@ +package io.mtudy.soundcloud.like.domain.enums; + +public enum LikeType { + TRACK(Values.TRACK), ALBUM(Values.ALBUM), PLAYLIST(Values.PLAYLIST); + + LikeType (String val) {} + + public static class Values { + public static final String TRACK = "TRACK"; + public static final String ALBUM = "ALBUM"; + public static final String PLAYLIST = "PLAYLIST"; + } +} diff --git a/src/main/resources/db/migration/V1__create_like_table.sql b/src/main/resources/db/migration/V1__create_like_table.sql new file mode 100644 index 0000000..70069b4 --- /dev/null +++ b/src/main/resources/db/migration/V1__create_like_table.sql @@ -0,0 +1,7 @@ +create table `like` ( + id varchar(36) not null, + authorId varchar(36) not null, + type varchar(36) not null, + typeId varchar(36) not null, + primary key (id) +) engine=InnoDB collate=utf8mb4_general_ci From 981c60f5a014ec909fbdbdc41e97d5262fac8649 Mon Sep 17 00:00:00 2001 From: jeongmyeong Date: Fri, 22 Jan 2021 13:51:39 +0900 Subject: [PATCH 3/8] update graphql scheme, resolver --- .../application/inputs/CreateLikeInput.java | 27 -------------- .../inputs/CreatePlaylistLikeInput.java | 19 ++++++++++ .../graphql/CreateLikeMutationResolver.java | 4 +-- .../web/graphql/LikeQueryResolver.java | 19 ---------- .../services/CreateLikeService.java | 16 +++++---- .../services/FindLikeByTrackIdService.java | 18 ---------- .../like/domain/entities/AlbumLike.java | 36 +++++++++++++++++++ src/main/resources/schema.graphqls | 7 ++-- 8 files changed, 69 insertions(+), 77 deletions(-) delete mode 100644 src/main/java/io/mtudy/soundcloud/like/application/inputs/CreateLikeInput.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/inputs/CreatePlaylistLikeInput.java delete mode 100644 src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeQueryResolver.java delete mode 100644 src/main/java/io/mtudy/soundcloud/like/application/services/FindLikeByTrackIdService.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/domain/entities/AlbumLike.java diff --git a/src/main/java/io/mtudy/soundcloud/like/application/inputs/CreateLikeInput.java b/src/main/java/io/mtudy/soundcloud/like/application/inputs/CreateLikeInput.java deleted file mode 100644 index 3518aa0..0000000 --- a/src/main/java/io/mtudy/soundcloud/like/application/inputs/CreateLikeInput.java +++ /dev/null @@ -1,27 +0,0 @@ -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; - } -} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/inputs/CreatePlaylistLikeInput.java b/src/main/java/io/mtudy/soundcloud/like/application/inputs/CreatePlaylistLikeInput.java new file mode 100644 index 0000000..de51d25 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/inputs/CreatePlaylistLikeInput.java @@ -0,0 +1,19 @@ +package io.mtudy.soundcloud.like.application.inputs; + +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@NoArgsConstructor +public class CreatePlaylistLikeInput { + @NotBlank + private String playlistId; + + public CreatePlaylistLikeInput(String playlistId) { + this.playlistId = playlistId; + } + + public String getPlaylistId() { + return playlistId; + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java index 14655ee..4230b7a 100644 --- a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java +++ b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java @@ -1,7 +1,7 @@ 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.inputs.CreatePlaylistLikeInput; import io.mtudy.soundcloud.like.application.services.CreateLikeService; import io.mtudy.soundcloud.like.domain.entities.Like; import org.springframework.stereotype.Component; @@ -16,7 +16,7 @@ public CreateLikeMutationResolver(CreateLikeService service) { this.service = service; } - public Like createLike(@Valid CreateLikeInput input) { + public Like createLike(@Valid CreatePlaylistLikeInput input) { return this.service.run(input); } } diff --git a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeQueryResolver.java b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeQueryResolver.java deleted file mode 100644 index 065124b..0000000 --- a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeQueryResolver.java +++ /dev/null @@ -1,19 +0,0 @@ -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); - } -} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java b/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java index d4e5d66..d85b210 100644 --- a/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java +++ b/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java @@ -1,7 +1,8 @@ package io.mtudy.soundcloud.like.application.services; -import io.mtudy.soundcloud.like.application.inputs.CreateLikeInput; +import io.mtudy.soundcloud.like.application.inputs.CreatePlaylistLikeInput; import io.mtudy.soundcloud.like.domain.entities.Like; +import io.mtudy.soundcloud.like.domain.entities.PlaylistLike; import io.mtudy.soundcloud.like.domain.repotitories.LikeRepository; import org.springframework.stereotype.Service; @@ -15,12 +16,13 @@ public CreateLikeService(LikeRepository repository) { this.repository = repository; } - public Like run(CreateLikeInput request) { - return this.repository.save(new Like( + public Like run(CreatePlaylistLikeInput request) { + var builder = new PlaylistLike.Builder( UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - request.getType(), - request.getTypeId() - )); + request.getPlaylistId(), + UUID.randomUUID().toString() + ); + + return this.repository.save(builder.build()); } } diff --git a/src/main/java/io/mtudy/soundcloud/like/application/services/FindLikeByTrackIdService.java b/src/main/java/io/mtudy/soundcloud/like/application/services/FindLikeByTrackIdService.java deleted file mode 100644 index 56f5dcc..0000000 --- a/src/main/java/io/mtudy/soundcloud/like/application/services/FindLikeByTrackIdService.java +++ /dev/null @@ -1,18 +0,0 @@ -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); - } -} diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/entities/AlbumLike.java b/src/main/java/io/mtudy/soundcloud/like/domain/entities/AlbumLike.java new file mode 100644 index 0000000..7b7fe67 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/entities/AlbumLike.java @@ -0,0 +1,36 @@ +package io.mtudy.soundcloud.like.domain.entities; + +import io.mtudy.soundcloud.like.domain.enums.LikeType; +import lombok.NoArgsConstructor; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +@NoArgsConstructor +@Entity(name = "albumLike") +@DiscriminatorValue(LikeType.Values.ALBUM) +public final class AlbumLike extends Like { + private AlbumLike(Builder builder) { + this.id = builder.id; + this.typeId = builder.typeId; + this.authorId = builder.authorId; + } + + public final static class Builder { + private final String id; + + private final String typeId; + + private final String authorId; + + public Builder(String id, String typeId, String authorId) { + this.id = id; + this.typeId = typeId; + this.authorId = authorId; + } + + public AlbumLike build() { + return new AlbumLike(this); + } + } +} diff --git a/src/main/resources/schema.graphqls b/src/main/resources/schema.graphqls index b95ffb6..2f13dde 100644 --- a/src/main/resources/schema.graphqls +++ b/src/main/resources/schema.graphqls @@ -20,7 +20,7 @@ type Like { type Mutation { createTrack(input: CreateTrackInput!): Track - createLike(input: CreateLikeInput!): Like + likePlaylist(input: likePlaylistInput!): Like } input CreateTrackInput { @@ -28,7 +28,6 @@ input CreateTrackInput { artworkUrl: String! } -input CreateLikeInput { - type: String! - typeId: String! +input likePlaylistInput { + playlistId: String! } From 9a50cb5710a0bb82b4a42f8310ee33566a68dcb2 Mon Sep 17 00:00:00 2001 From: jeongmyeong Date: Fri, 22 Jan 2021 13:55:43 +0900 Subject: [PATCH 4/8] remove repository unused method --- .../soundcloud/like/domain/repotitories/LikeRepository.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java index d11dc60..924f4c4 100644 --- a/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java +++ b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java @@ -6,7 +6,4 @@ @Repository public interface LikeRepository extends CrudRepository { - public default Like findByTrackId(String trackId) { - return null; - } } From b773f337e9d45aed9416987e1e3ed2e051183c01 Mon Sep 17 00:00:00 2001 From: jeongmyeong Date: Tue, 26 Jan 2021 13:00:36 +0900 Subject: [PATCH 5/8] entity update batch --- .../graphql/CreateLikeMutationResolver.java | 1 - .../services/CreateLikeService.java | 1 - .../like/domain/entities/AlbumLike.java | 51 ++++++++++-------- .../soundcloud/like/domain/entities/Like.java | 34 ------------ .../like/domain/entities/PlaylistLike.java | 51 ++++++++++-------- .../like/domain/entities/TrackLike.java | 52 +++++++++++-------- .../like/domain/enums/LikeType.java | 13 ----- .../domain/repotitories/LikeRepository.java | 1 - 8 files changed, 85 insertions(+), 119 deletions(-) delete mode 100644 src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java delete mode 100644 src/main/java/io/mtudy/soundcloud/like/domain/enums/LikeType.java diff --git a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java index 4230b7a..ada176e 100644 --- a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java +++ b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java @@ -3,7 +3,6 @@ import graphql.kickstart.tools.GraphQLMutationResolver; import io.mtudy.soundcloud.like.application.inputs.CreatePlaylistLikeInput; 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; diff --git a/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java b/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java index d85b210..f7fdeb8 100644 --- a/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java +++ b/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java @@ -1,7 +1,6 @@ package io.mtudy.soundcloud.like.application.services; import io.mtudy.soundcloud.like.application.inputs.CreatePlaylistLikeInput; -import io.mtudy.soundcloud.like.domain.entities.Like; import io.mtudy.soundcloud.like.domain.entities.PlaylistLike; import io.mtudy.soundcloud.like.domain.repotitories.LikeRepository; import org.springframework.stereotype.Service; diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/entities/AlbumLike.java b/src/main/java/io/mtudy/soundcloud/like/domain/entities/AlbumLike.java index 7b7fe67..27a10b3 100644 --- a/src/main/java/io/mtudy/soundcloud/like/domain/entities/AlbumLike.java +++ b/src/main/java/io/mtudy/soundcloud/like/domain/entities/AlbumLike.java @@ -1,36 +1,41 @@ package io.mtudy.soundcloud.like.domain.entities; -import io.mtudy.soundcloud.like.domain.enums.LikeType; import lombok.NoArgsConstructor; -import javax.persistence.DiscriminatorValue; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; @NoArgsConstructor -@Entity(name = "albumLike") -@DiscriminatorValue(LikeType.Values.ALBUM) -public final class AlbumLike extends Like { - private AlbumLike(Builder builder) { - this.id = builder.id; - this.typeId = builder.typeId; - this.authorId = builder.authorId; +@Entity +@Table(name = "album_like") +public class AlbumLike { + @Id + @Column(columnDefinition = "VARCHAR(36)") + private String id; + + @Column(columnDefinition = "VARCHAR(36)") + private String albumId; + + @Column(columnDefinition = "VARCHAR(36)") + private String authorId; + + public AlbumLike(String id, String albumId, String authorId) { + this.id = id; + this.albumId = albumId; + this.authorId = authorId; } - public final static class Builder { - private final String id; - - private final String typeId; - - private final String authorId; + public String getId() { + return id; + } - public Builder(String id, String typeId, String authorId) { - this.id = id; - this.typeId = typeId; - this.authorId = authorId; - } + public String getAlbumId() { + return albumId; + } - public AlbumLike build() { - return new AlbumLike(this); - } + public String getAuthorId() { + return authorId; } } diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java b/src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java deleted file mode 100644 index 480c2cd..0000000 --- a/src/main/java/io/mtudy/soundcloud/like/domain/entities/Like.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.mtudy.soundcloud.like.domain.entities; - -import lombok.NoArgsConstructor; - -import javax.persistence.*; - -@NoArgsConstructor -@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "type", - discriminatorType = DiscriminatorType.STRING) -public abstract class Like { - @Id - @Column(columnDefinition = "VARCHAR(36)") - protected String id; - - @Column(columnDefinition = "VARCHAR(36)") - protected String authorId; - - @Column(columnDefinition = "VARCHAR(36)") - protected String typeId; - - public String getId() { - return id; - } - - public String getAuthorId() { - return authorId; - } - - public String getTypeId() { - return typeId; - } -} diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/entities/PlaylistLike.java b/src/main/java/io/mtudy/soundcloud/like/domain/entities/PlaylistLike.java index d0c0cec..cc37158 100644 --- a/src/main/java/io/mtudy/soundcloud/like/domain/entities/PlaylistLike.java +++ b/src/main/java/io/mtudy/soundcloud/like/domain/entities/PlaylistLike.java @@ -1,36 +1,41 @@ package io.mtudy.soundcloud.like.domain.entities; -import io.mtudy.soundcloud.like.domain.enums.LikeType; import lombok.NoArgsConstructor; -import javax.persistence.DiscriminatorValue; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; @NoArgsConstructor -@Entity(name = "playlistLike") -@DiscriminatorValue(LikeType.Values.PLAYLIST) -public final class PlaylistLike extends Like { - private PlaylistLike(Builder builder) { - this.id = builder.id; - this.typeId = builder.typeId; - this.authorId = builder.authorId; +@Entity +@Table(name = "playlist_like") +public class PlaylistLike { + @Id + @Column(columnDefinition = "VARCHAR(36)") + private String id; + + @Column(columnDefinition = "VARCHAR(36)") + private String playlistId; + + @Column(columnDefinition = "VARCHAR(36)") + private String authorId; + + public PlaylistLike(String id, String playlistId, String authorId) { + this.id = id; + this.playlistId = playlistId; + this.authorId = authorId; } - public final static class Builder { - private final String id; - - private final String typeId; - - private final String authorId; + public String getId() { + return id; + } - public Builder(String id, String typeId, String authorId) { - this.id = id; - this.typeId = typeId; - this.authorId = authorId; - } + public String getPlaylistId() { + return playlistId; + } - public PlaylistLike build() { - return new PlaylistLike(this); - } + public String getAuthorId() { + return authorId; } } diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/entities/TrackLike.java b/src/main/java/io/mtudy/soundcloud/like/domain/entities/TrackLike.java index 95ecd74..902290e 100644 --- a/src/main/java/io/mtudy/soundcloud/like/domain/entities/TrackLike.java +++ b/src/main/java/io/mtudy/soundcloud/like/domain/entities/TrackLike.java @@ -1,35 +1,41 @@ package io.mtudy.soundcloud.like.domain.entities; -import io.mtudy.soundcloud.like.domain.enums.LikeType; import lombok.NoArgsConstructor; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; @NoArgsConstructor -@Entity(name = "trackLike") -@DiscriminatorValue(LikeType.Values.TRACK) -public final class TrackLike extends Like { - private TrackLike(Builder builder) { - this.id = builder.id; - this.typeId = builder.typeId; - this.authorId = builder.authorId; +@Entity +@Table(name = "track_like") +public class TrackLike { + @Id + @Column(columnDefinition = "VARCHAR(36)") + private String id; + + @Column(columnDefinition = "VARCHAR(36)") + private String trackId; + + @Column(columnDefinition = "VARCHAR(36)") + private String authorId; + + public TrackLike(String id, String trackId, String authorId) { + this.id = id; + this.trackId = trackId; + this.authorId = authorId; } - public final static class Builder { - private final String id; - - private final String typeId; - - private final String authorId; + public String getId() { + return id; + } - public Builder(String id, String typeId, String authorId) { - this.id = id; - this.typeId = typeId; - this.authorId = authorId; - } + public String getTrackId() { + return trackId; + } - public TrackLike build() { - return new TrackLike(this); - } + public String getAuthorId() { + return authorId; } } diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/enums/LikeType.java b/src/main/java/io/mtudy/soundcloud/like/domain/enums/LikeType.java deleted file mode 100644 index 53ded68..0000000 --- a/src/main/java/io/mtudy/soundcloud/like/domain/enums/LikeType.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.mtudy.soundcloud.like.domain.enums; - -public enum LikeType { - TRACK(Values.TRACK), ALBUM(Values.ALBUM), PLAYLIST(Values.PLAYLIST); - - LikeType (String val) {} - - public static class Values { - public static final String TRACK = "TRACK"; - public static final String ALBUM = "ALBUM"; - public static final String PLAYLIST = "PLAYLIST"; - } -} diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java index 924f4c4..fd6a7bc 100644 --- a/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java +++ b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java @@ -1,6 +1,5 @@ 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; From 82375fdcc1dac679cf9f69019fdc4e011b1e2cdf Mon Sep 17 00:00:00 2001 From: jeongmyeong Date: Tue, 26 Jan 2021 13:16:22 +0900 Subject: [PATCH 6/8] Service update batch --- .../application/inputs/LikeAlbumInput.java | 19 +++++++++++++ ...tLikeInput.java => LikePlaylistInput.java} | 4 +-- .../application/inputs/LikeTrackInput.java | 19 +++++++++++++ .../graphql/CreateLikeMutationResolver.java | 21 --------------- .../graphql/LikeAlbumMutationResolver.java | 22 +++++++++++++++ .../graphql/LikePlaylistMutationResolver.java | 22 +++++++++++++++ .../graphql/LikeTrackMutationResolver.java | 22 +++++++++++++++ .../services/CreateLikeService.java | 27 ------------------- .../services/LikeAlbumService.java | 23 ++++++++++++++++ .../services/LikePlaylistService.java | 23 ++++++++++++++++ .../services/LikeTrackService.java | 24 +++++++++++++++++ ...pository.java => AlbumLikeRepository.java} | 3 ++- .../repotitories/PlaylistLikeRepository.java | 9 +++++++ .../repotitories/TrackLikeRepository.java | 9 +++++++ src/main/resources/schema.graphqls | 25 ++++++++++++++--- 15 files changed, 217 insertions(+), 55 deletions(-) create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/inputs/LikeAlbumInput.java rename src/main/java/io/mtudy/soundcloud/like/application/inputs/{CreatePlaylistLikeInput.java => LikePlaylistInput.java} (76%) create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/inputs/LikeTrackInput.java delete mode 100644 src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeAlbumMutationResolver.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikePlaylistMutationResolver.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeTrackMutationResolver.java delete mode 100644 src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/services/LikeAlbumService.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/services/LikePlaylistService.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/application/services/LikeTrackService.java rename src/main/java/io/mtudy/soundcloud/like/domain/repotitories/{LikeRepository.java => AlbumLikeRepository.java} (56%) create mode 100644 src/main/java/io/mtudy/soundcloud/like/domain/repotitories/PlaylistLikeRepository.java create mode 100644 src/main/java/io/mtudy/soundcloud/like/domain/repotitories/TrackLikeRepository.java diff --git a/src/main/java/io/mtudy/soundcloud/like/application/inputs/LikeAlbumInput.java b/src/main/java/io/mtudy/soundcloud/like/application/inputs/LikeAlbumInput.java new file mode 100644 index 0000000..612db06 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/inputs/LikeAlbumInput.java @@ -0,0 +1,19 @@ +package io.mtudy.soundcloud.like.application.inputs; + +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@NoArgsConstructor +public class LikeAlbumInput { + @NotBlank + private String albumId; + + public LikeAlbumInput(String albumId) { + this.albumId = albumId; + } + + public String getAlbumId() { + return albumId; + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/inputs/CreatePlaylistLikeInput.java b/src/main/java/io/mtudy/soundcloud/like/application/inputs/LikePlaylistInput.java similarity index 76% rename from src/main/java/io/mtudy/soundcloud/like/application/inputs/CreatePlaylistLikeInput.java rename to src/main/java/io/mtudy/soundcloud/like/application/inputs/LikePlaylistInput.java index de51d25..2ad5bbe 100644 --- a/src/main/java/io/mtudy/soundcloud/like/application/inputs/CreatePlaylistLikeInput.java +++ b/src/main/java/io/mtudy/soundcloud/like/application/inputs/LikePlaylistInput.java @@ -5,11 +5,11 @@ import javax.validation.constraints.NotBlank; @NoArgsConstructor -public class CreatePlaylistLikeInput { +public class LikePlaylistInput { @NotBlank private String playlistId; - public CreatePlaylistLikeInput(String playlistId) { + public LikePlaylistInput(String playlistId) { this.playlistId = playlistId; } diff --git a/src/main/java/io/mtudy/soundcloud/like/application/inputs/LikeTrackInput.java b/src/main/java/io/mtudy/soundcloud/like/application/inputs/LikeTrackInput.java new file mode 100644 index 0000000..b701885 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/inputs/LikeTrackInput.java @@ -0,0 +1,19 @@ +package io.mtudy.soundcloud.like.application.inputs; + +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@NoArgsConstructor +public class LikeTrackInput { + @NotBlank + private String trackId; + + public LikeTrackInput(String trackId) { + this.trackId = trackId; + } + + public String getTrackId() { + return trackId; + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java deleted file mode 100644 index ada176e..0000000 --- a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/CreateLikeMutationResolver.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.mtudy.soundcloud.like.application.interfaces.web.graphql; - -import graphql.kickstart.tools.GraphQLMutationResolver; -import io.mtudy.soundcloud.like.application.inputs.CreatePlaylistLikeInput; -import io.mtudy.soundcloud.like.application.services.CreateLikeService; -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 CreatePlaylistLikeInput input) { - return this.service.run(input); - } -} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeAlbumMutationResolver.java b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeAlbumMutationResolver.java new file mode 100644 index 0000000..2110988 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeAlbumMutationResolver.java @@ -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.LikeAlbumInput; +import io.mtudy.soundcloud.like.application.services.LikeAlbumService; +import io.mtudy.soundcloud.like.domain.entities.AlbumLike; +import org.springframework.stereotype.Component; + +import javax.validation.Valid; + +@Component +public class LikeAlbumMutationResolver implements GraphQLMutationResolver { + private final LikeAlbumService service; + + public LikeAlbumMutationResolver(LikeAlbumService service) { + this.service = service; + } + + public AlbumLike likeAlbum(@Valid LikeAlbumInput input) { + return this.service.run(input); + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikePlaylistMutationResolver.java b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikePlaylistMutationResolver.java new file mode 100644 index 0000000..65cb0d8 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikePlaylistMutationResolver.java @@ -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.LikePlaylistInput; +import io.mtudy.soundcloud.like.application.services.LikePlaylistService; +import io.mtudy.soundcloud.like.domain.entities.PlaylistLike; +import org.springframework.stereotype.Component; + +import javax.validation.Valid; + +@Component +public class LikePlaylistMutationResolver implements GraphQLMutationResolver { + private final LikePlaylistService service; + + public LikePlaylistMutationResolver(LikePlaylistService service) { + this.service = service; + } + + public PlaylistLike likePlaylist(@Valid LikePlaylistInput input) { + return this.service.run(input); + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeTrackMutationResolver.java b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeTrackMutationResolver.java new file mode 100644 index 0000000..a4137a6 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/interfaces/web/graphql/LikeTrackMutationResolver.java @@ -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.LikeTrackInput; +import io.mtudy.soundcloud.like.application.services.LikeTrackService; +import io.mtudy.soundcloud.like.domain.entities.TrackLike; +import org.springframework.stereotype.Component; + +import javax.validation.Valid; + +@Component +public class LikeTrackMutationResolver implements GraphQLMutationResolver { + private final LikeTrackService service; + + public LikeTrackMutationResolver(LikeTrackService service) { + this.service = service; + } + + public TrackLike likeTrack(@Valid LikeTrackInput input) { + return this.service.run(input); + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java b/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java deleted file mode 100644 index f7fdeb8..0000000 --- a/src/main/java/io/mtudy/soundcloud/like/application/services/CreateLikeService.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.mtudy.soundcloud.like.application.services; - -import io.mtudy.soundcloud.like.application.inputs.CreatePlaylistLikeInput; -import io.mtudy.soundcloud.like.domain.entities.PlaylistLike; -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(CreatePlaylistLikeInput request) { - var builder = new PlaylistLike.Builder( - UUID.randomUUID().toString(), - request.getPlaylistId(), - UUID.randomUUID().toString() - ); - - return this.repository.save(builder.build()); - } -} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/services/LikeAlbumService.java b/src/main/java/io/mtudy/soundcloud/like/application/services/LikeAlbumService.java new file mode 100644 index 0000000..fbc6f58 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/services/LikeAlbumService.java @@ -0,0 +1,23 @@ +package io.mtudy.soundcloud.like.application.services; + +import io.mtudy.soundcloud.like.application.inputs.LikeAlbumInput; +import io.mtudy.soundcloud.like.domain.entities.AlbumLike; +import io.mtudy.soundcloud.like.domain.repotitories.AlbumLikeRepository; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +@Service +public class LikeAlbumService { + private final AlbumLikeRepository repository; + + public LikeAlbumService(AlbumLikeRepository repository) { + this.repository = repository; + } + + public AlbumLike run(LikeAlbumInput request) { + return this.repository.save(new AlbumLike( + UUID.randomUUID().toString(), request.getAlbumId(), UUID.randomUUID().toString() + )); + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/services/LikePlaylistService.java b/src/main/java/io/mtudy/soundcloud/like/application/services/LikePlaylistService.java new file mode 100644 index 0000000..e5b592e --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/services/LikePlaylistService.java @@ -0,0 +1,23 @@ +package io.mtudy.soundcloud.like.application.services; + +import io.mtudy.soundcloud.like.application.inputs.LikePlaylistInput; +import io.mtudy.soundcloud.like.domain.entities.PlaylistLike; +import io.mtudy.soundcloud.like.domain.repotitories.PlaylistLikeRepository; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +@Service +public class LikePlaylistService { + private final PlaylistLikeRepository repository; + + public LikePlaylistService(PlaylistLikeRepository repository) { + this.repository = repository; + } + + public PlaylistLike run(LikePlaylistInput request) { + return this.repository.save(new PlaylistLike( + UUID.randomUUID().toString(), request.getPlaylistId(), UUID.randomUUID().toString() + )); + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/application/services/LikeTrackService.java b/src/main/java/io/mtudy/soundcloud/like/application/services/LikeTrackService.java new file mode 100644 index 0000000..a5c5cf7 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/services/LikeTrackService.java @@ -0,0 +1,24 @@ +package io.mtudy.soundcloud.like.application.services; + +import io.mtudy.soundcloud.like.application.inputs.LikeAlbumInput; +import io.mtudy.soundcloud.like.application.inputs.LikeTrackInput; +import io.mtudy.soundcloud.like.domain.entities.TrackLike; +import io.mtudy.soundcloud.like.domain.repotitories.TrackLikeRepository; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +@Service +public class LikeTrackService { + private final TrackLikeRepository repository; + + public LikeTrackService(TrackLikeRepository repository) { + this.repository = repository; + } + + public TrackLike run(LikeTrackInput request) { + return this.repository.save(new TrackLike( + UUID.randomUUID().toString(), request.getTrackId(), UUID.randomUUID().toString() + )); + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/AlbumLikeRepository.java similarity index 56% rename from src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java rename to src/main/java/io/mtudy/soundcloud/like/domain/repotitories/AlbumLikeRepository.java index fd6a7bc..0b685ef 100644 --- a/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/LikeRepository.java +++ b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/AlbumLikeRepository.java @@ -1,8 +1,9 @@ package io.mtudy.soundcloud.like.domain.repotitories; +import io.mtudy.soundcloud.like.domain.entities.AlbumLike; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @Repository -public interface LikeRepository extends CrudRepository { +public interface AlbumLikeRepository extends CrudRepository { } diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/PlaylistLikeRepository.java b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/PlaylistLikeRepository.java new file mode 100644 index 0000000..4ebe43a --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/PlaylistLikeRepository.java @@ -0,0 +1,9 @@ +package io.mtudy.soundcloud.like.domain.repotitories; + +import io.mtudy.soundcloud.like.domain.entities.PlaylistLike; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PlaylistLikeRepository extends CrudRepository { +} diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/TrackLikeRepository.java b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/TrackLikeRepository.java new file mode 100644 index 0000000..9e7981d --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/TrackLikeRepository.java @@ -0,0 +1,9 @@ +package io.mtudy.soundcloud.like.domain.repotitories; + +import io.mtudy.soundcloud.like.domain.entities.TrackLike; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface TrackLikeRepository extends CrudRepository { +} diff --git a/src/main/resources/schema.graphqls b/src/main/resources/schema.graphqls index 2f13dde..9537abd 100644 --- a/src/main/resources/schema.graphqls +++ b/src/main/resources/schema.graphqls @@ -12,15 +12,24 @@ type Track { artworkUrl: String! } -type Like { +type PlaylistLike { id : ID! - type : String! - typeId: String! } +type AlbumLike { + id : ID! +} + +type TrackLike { + id : ID! +} + + type Mutation { createTrack(input: CreateTrackInput!): Track - likePlaylist(input: likePlaylistInput!): Like + likePlaylist(input: likePlaylistInput!): PlaylistLike + likeAlbum(input: likeAlbumInput!): AlbumLike + likeTrack(input: likeTrackInput!): TrackLike } input CreateTrackInput { @@ -31,3 +40,11 @@ input CreateTrackInput { input likePlaylistInput { playlistId: String! } + +input likeTrackInput { + trackId: String! +} + +input likeAlbumInput { + albumId: String! +} From fc4ede9d8fa3b78bd7699afc21857d4cf69e88c8 Mon Sep 17 00:00:00 2001 From: jeongmyeong Date: Tue, 26 Jan 2021 13:21:27 +0900 Subject: [PATCH 7/8] add migration file --- ...reate_like_table.sql => V1__create_album_like_table.sql} | 5 ++--- .../db/migration/V1__create_playlist_like_table.sql | 6 ++++++ .../resources/db/migration/V1__create_track_like_table.sql | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) rename src/main/resources/db/migration/{V1__create_like_table.sql => V1__create_album_like_table.sql} (59%) create mode 100644 src/main/resources/db/migration/V1__create_playlist_like_table.sql create mode 100644 src/main/resources/db/migration/V1__create_track_like_table.sql diff --git a/src/main/resources/db/migration/V1__create_like_table.sql b/src/main/resources/db/migration/V1__create_album_like_table.sql similarity index 59% rename from src/main/resources/db/migration/V1__create_like_table.sql rename to src/main/resources/db/migration/V1__create_album_like_table.sql index 70069b4..7f14711 100644 --- a/src/main/resources/db/migration/V1__create_like_table.sql +++ b/src/main/resources/db/migration/V1__create_album_like_table.sql @@ -1,7 +1,6 @@ -create table `like` ( +create table album_like ( id varchar(36) not null, authorId varchar(36) not null, - type varchar(36) not null, - typeId varchar(36) not null, + albumId varchar(36) not null, primary key (id) ) engine=InnoDB collate=utf8mb4_general_ci diff --git a/src/main/resources/db/migration/V1__create_playlist_like_table.sql b/src/main/resources/db/migration/V1__create_playlist_like_table.sql new file mode 100644 index 0000000..ebcaabd --- /dev/null +++ b/src/main/resources/db/migration/V1__create_playlist_like_table.sql @@ -0,0 +1,6 @@ +create table playlist_like ( + id varchar(36) not null, + authorId varchar(36) not null, + playlistId varchar(36) not null, + primary key (id) +) engine=InnoDB collate=utf8mb4_general_ci diff --git a/src/main/resources/db/migration/V1__create_track_like_table.sql b/src/main/resources/db/migration/V1__create_track_like_table.sql new file mode 100644 index 0000000..8bf5b27 --- /dev/null +++ b/src/main/resources/db/migration/V1__create_track_like_table.sql @@ -0,0 +1,6 @@ +create table track_like ( + id varchar(36) not null, + authorId varchar(36) not null, + trackId varchar(36) not null, + primary key (id) +) engine=InnoDB collate=utf8mb4_general_ci From 8c44822c3ec97c6971d9763f6b8bd3c787464a0e Mon Sep 17 00:00:00 2001 From: jeongmyeong Date: Tue, 26 Jan 2021 13:58:01 +0900 Subject: [PATCH 8/8] update migration filename --- .../{V1__create_track_table.sql => V1_1__create_track_table.sql} | 0 ...aylist_like_table.sql => V1_2__create_playlist_like_table.sql} | 0 ...ate_track_like_table.sql => V1_3__create_track_like_table.sql} | 0 ...ate_album_like_table.sql => V1_4__create_album_like_table.sql} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/main/resources/db/migration/{V1__create_track_table.sql => V1_1__create_track_table.sql} (100%) rename src/main/resources/db/migration/{V1__create_playlist_like_table.sql => V1_2__create_playlist_like_table.sql} (100%) rename src/main/resources/db/migration/{V1__create_track_like_table.sql => V1_3__create_track_like_table.sql} (100%) rename src/main/resources/db/migration/{V1__create_album_like_table.sql => V1_4__create_album_like_table.sql} (100%) diff --git a/src/main/resources/db/migration/V1__create_track_table.sql b/src/main/resources/db/migration/V1_1__create_track_table.sql similarity index 100% rename from src/main/resources/db/migration/V1__create_track_table.sql rename to src/main/resources/db/migration/V1_1__create_track_table.sql diff --git a/src/main/resources/db/migration/V1__create_playlist_like_table.sql b/src/main/resources/db/migration/V1_2__create_playlist_like_table.sql similarity index 100% rename from src/main/resources/db/migration/V1__create_playlist_like_table.sql rename to src/main/resources/db/migration/V1_2__create_playlist_like_table.sql diff --git a/src/main/resources/db/migration/V1__create_track_like_table.sql b/src/main/resources/db/migration/V1_3__create_track_like_table.sql similarity index 100% rename from src/main/resources/db/migration/V1__create_track_like_table.sql rename to src/main/resources/db/migration/V1_3__create_track_like_table.sql diff --git a/src/main/resources/db/migration/V1__create_album_like_table.sql b/src/main/resources/db/migration/V1_4__create_album_like_table.sql similarity index 100% rename from src/main/resources/db/migration/V1__create_album_like_table.sql rename to src/main/resources/db/migration/V1_4__create_album_like_table.sql