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/LikePlaylistInput.java b/src/main/java/io/mtudy/soundcloud/like/application/inputs/LikePlaylistInput.java new file mode 100644 index 0000000..2ad5bbe --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/application/inputs/LikePlaylistInput.java @@ -0,0 +1,19 @@ +package io.mtudy.soundcloud.like.application.inputs; + +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@NoArgsConstructor +public class LikePlaylistInput { + @NotBlank + private String playlistId; + + public LikePlaylistInput(String playlistId) { + this.playlistId = playlistId; + } + + public String getPlaylistId() { + return 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/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/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/entities/AlbumLike.java b/src/main/java/io/mtudy/soundcloud/like/domain/entities/AlbumLike.java new file mode 100644 index 0000000..27a10b3 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/entities/AlbumLike.java @@ -0,0 +1,41 @@ +package io.mtudy.soundcloud.like.domain.entities; + +import lombok.NoArgsConstructor; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@NoArgsConstructor +@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 String getId() { + return id; + } + + public String getAlbumId() { + return albumId; + } + + public String getAuthorId() { + return authorId; + } +} 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..cc37158 --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/entities/PlaylistLike.java @@ -0,0 +1,41 @@ +package io.mtudy.soundcloud.like.domain.entities; + +import lombok.NoArgsConstructor; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@NoArgsConstructor +@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 String getId() { + return id; + } + + public String getPlaylistId() { + return playlistId; + } + + 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 new file mode 100644 index 0000000..902290e --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/entities/TrackLike.java @@ -0,0 +1,41 @@ +package io.mtudy.soundcloud.like.domain.entities; + +import lombok.NoArgsConstructor; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@NoArgsConstructor +@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 String getId() { + return id; + } + + public String getTrackId() { + return trackId; + } + + public String getAuthorId() { + return authorId; + } +} diff --git a/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/AlbumLikeRepository.java b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/AlbumLikeRepository.java new file mode 100644 index 0000000..0b685ef --- /dev/null +++ b/src/main/java/io/mtudy/soundcloud/like/domain/repotitories/AlbumLikeRepository.java @@ -0,0 +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 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/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_2__create_playlist_like_table.sql b/src/main/resources/db/migration/V1_2__create_playlist_like_table.sql new file mode 100644 index 0000000..ebcaabd --- /dev/null +++ b/src/main/resources/db/migration/V1_2__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_3__create_track_like_table.sql b/src/main/resources/db/migration/V1_3__create_track_like_table.sql new file mode 100644 index 0000000..8bf5b27 --- /dev/null +++ b/src/main/resources/db/migration/V1_3__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 diff --git a/src/main/resources/db/migration/V1_4__create_album_like_table.sql b/src/main/resources/db/migration/V1_4__create_album_like_table.sql new file mode 100644 index 0000000..7f14711 --- /dev/null +++ b/src/main/resources/db/migration/V1_4__create_album_like_table.sql @@ -0,0 +1,6 @@ +create table album_like ( + id varchar(36) not null, + authorId varchar(36) not null, + albumId varchar(36) not null, + primary key (id) +) engine=InnoDB collate=utf8mb4_general_ci diff --git a/src/main/resources/schema.graphqls b/src/main/resources/schema.graphqls index ed8251e..9537abd 100644 --- a/src/main/resources/schema.graphqls +++ b/src/main/resources/schema.graphqls @@ -12,11 +12,39 @@ type Track { artworkUrl: String! } +type PlaylistLike { + id : ID! +} + +type AlbumLike { + id : ID! +} + +type TrackLike { + id : ID! +} + + type Mutation { createTrack(input: CreateTrackInput!): Track + likePlaylist(input: likePlaylistInput!): PlaylistLike + likeAlbum(input: likeAlbumInput!): AlbumLike + likeTrack(input: likeTrackInput!): TrackLike } input CreateTrackInput { title: String! artworkUrl: String! } + +input likePlaylistInput { + playlistId: String! +} + +input likeTrackInput { + trackId: String! +} + +input likeAlbumInput { + albumId: String! +}