Skip to content
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

Add ktlint #33

Merged
merged 5 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ jobs:
name: Run Lint Test
command: ./gradlew lintDebug
- store_artifacts:
path: presentation/build/reports
path: presentation/build/reports
- run:
name: Run Ktlint
command: ./gradlew ktlint
- store_artifacts:
path: ktlint/build/reports
2 changes: 2 additions & 0 deletions data/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

apply from: "../ktlint.gradle"

android {
compileSdkVersion Versions.compile_sdk
defaultConfig {
Expand Down
3 changes: 1 addition & 2 deletions data/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sanogueralorenzo.data" />
<manifest package="com.sanogueralorenzo.data" />
12 changes: 7 additions & 5 deletions data/src/main/java/com/sanogueralorenzo/data/model/Comment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import com.sanogueralorenzo.domain.model.Comment
import com.squareup.moshi.Json
import javax.inject.Inject

data class CommentEntity(@Json(name = "postId") val postId: String,
@Json(name = "id") val id: String,
@Json(name = "name") val name: String,
@Json(name = "email") val email: String,
@Json(name = "body") val body: String)
data class CommentEntity(
@Json(name = "postId") val postId: String,
@Json(name = "id") val id: String,
@Json(name = "name") val name: String,
@Json(name = "email") val email: String,
@Json(name = "body") val body: String
)

class CommentMapper @Inject constructor() {

Expand Down
10 changes: 6 additions & 4 deletions data/src/main/java/com/sanogueralorenzo/data/model/Post.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import com.sanogueralorenzo.domain.model.Post
import com.squareup.moshi.Json
import javax.inject.Inject

data class PostEntity(@Json(name = "userId") val userId: String,
@Json(name = "id") val id: String,
@Json(name = "title") val title: String,
@Json(name = "body") val body: String)
data class PostEntity(
@Json(name = "userId") val userId: String,
@Json(name = "id") val id: String,
@Json(name = "title") val title: String,
@Json(name = "body") val body: String
)

class PostMapper @Inject constructor() {

Expand Down
59 changes: 34 additions & 25 deletions data/src/main/java/com/sanogueralorenzo/data/model/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,40 @@ import com.sanogueralorenzo.domain.model.User
import com.squareup.moshi.Json
import javax.inject.Inject

data class UserEntity(@Json(name = "id") val id: String,
@Json(name = "name") val name: String,
@Json(name = "username") val username: String,
@Json(name = "email") val email: String,
@Json(name = "address") val addressEntity: AddressEntity,
@Json(name = "phone") val phone: String,
@Json(name = "website") val website: String,
@Json(name = "company") val companyEntity: CompanyEntity)

data class AddressEntity(@Json(name = "street") val street: String,
@Json(name = "suite") val suite: String,
@Json(name = "city") val city: String,
@Json(name = "zipcode") val zipcode: String,
@Json(name = "geo") val geoEntity: GeoEntity)

data class GeoEntity(@Json(name = "lat") val lat: String,
@Json(name = "lng") val lng: String)

data class CompanyEntity(@Json(name = "name") val name: String,
@Json(name = "catchPhrase") val catchPhrase: String,
@Json(name = "bs") val bs: String)

class UserMapper @Inject constructor(private val addressMapper: AddressMapper,
private val companyMapper: CompanyMapper) {
data class UserEntity(
@Json(name = "id") val id: String,
@Json(name = "name") val name: String,
@Json(name = "username") val username: String,
@Json(name = "email") val email: String,
@Json(name = "address") val addressEntity: AddressEntity,
@Json(name = "phone") val phone: String,
@Json(name = "website") val website: String,
@Json(name = "company") val companyEntity: CompanyEntity
)

data class AddressEntity(
@Json(name = "street") val street: String,
@Json(name = "suite") val suite: String,
@Json(name = "city") val city: String,
@Json(name = "zipcode") val zipcode: String,
@Json(name = "geo") val geoEntity: GeoEntity
)

data class GeoEntity(
@Json(name = "lat") val lat: String,
@Json(name = "lng") val lng: String
)

data class CompanyEntity(
@Json(name = "name") val name: String,
@Json(name = "catchPhrase") val catchPhrase: String,
@Json(name = "bs") val bs: String
)

class UserMapper @Inject constructor(
private val addressMapper: AddressMapper,
private val companyMapper: CompanyMapper
) {

fun mapToDomain(entity: UserEntity): User = User(id = entity.id,
name = entity.name,
Expand All @@ -55,7 +65,6 @@ class UserMapper @Inject constructor(private val addressMapper: AddressMapper,
fun mapToEntity(list: List<User>): List<UserEntity> = list.map { mapToEntity(it) }
}


class AddressMapper @Inject constructor(private val mapper: GeoMapper) {

fun mapToDomain(entity: AddressEntity): Address = Address(street = entity.street,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class CommentRepositoryImpl @Inject constructor(private val api: CommentsApi,
private val cache: Cache<List<CommentEntity>>,
private val mapper: CommentMapper) : CommentRepository {
class CommentRepositoryImpl @Inject constructor(
private val api: CommentsApi,
private val cache: Cache<List<CommentEntity>>,
private val mapper: CommentMapper
) : CommentRepository {
override val key = "Comment List"

override fun get(postId: String, refresh: Boolean): Single<List<Comment>> = when (refresh) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class PostRepositoryImpl @Inject constructor(private val api: PostsApi,
private val cache: Cache<List<PostEntity>>,
private val mapper: PostMapper) : PostRepository {
class PostRepositoryImpl @Inject constructor(
private val api: PostsApi,
private val cache: Cache<List<PostEntity>>,
private val mapper: PostMapper
) : PostRepository {
override val key = "Post List"

override fun get(refresh: Boolean): Single<List<Post>> = when (refresh) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class UserRepositoryImpl @Inject constructor(private val api: UsersApi,
private val cache: Cache<List<UserEntity>>,
private val mapper: UserMapper) : UserRepository {
class UserRepositoryImpl @Inject constructor(
private val api: UsersApi,
private val cache: Cache<List<UserEntity>>,
private val mapper: UserMapper
) : UserRepository {
override val key = "User List"

override fun get(refresh: Boolean): Single<List<User>> = when (refresh) {
Expand Down
14 changes: 12 additions & 2 deletions data/src/test/java/com/sanogueralorenzo/data/TestModels.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package com.sanogueralorenzo.data

import com.sanogueralorenzo.data.model.*
import com.sanogueralorenzo.domain.model.*
import com.sanogueralorenzo.data.model.AddressEntity
import com.sanogueralorenzo.data.model.CommentEntity
import com.sanogueralorenzo.data.model.CompanyEntity
import com.sanogueralorenzo.data.model.GeoEntity
import com.sanogueralorenzo.data.model.PostEntity
import com.sanogueralorenzo.data.model.UserEntity
import com.sanogueralorenzo.domain.model.Address
import com.sanogueralorenzo.domain.model.Comment
import com.sanogueralorenzo.domain.model.Company
import com.sanogueralorenzo.domain.model.Geo
import com.sanogueralorenzo.domain.model.Post
import com.sanogueralorenzo.domain.model.User

fun createUserEntity(): UserEntity = UserEntity("1", "name", "username", "email", createAddressEntity(), "phone", "website", createCompanyEntity())
fun createGeoEntity(): GeoEntity = GeoEntity("0.0", "0.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package com.sanogueralorenzo.data.repository

import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.verify
import com.sanogueralorenzo.data.cache.Cache
import com.sanogueralorenzo.data.createCommentEntity
import com.sanogueralorenzo.data.model.CommentEntity
Expand All @@ -11,7 +12,6 @@ import com.sanogueralorenzo.data.remote.CommentsApi
import io.reactivex.Single
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.*
import org.mockito.Mockito.`when` as _when

class CommentRepositoryImplTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package com.sanogueralorenzo.data.repository

import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.times
import com.nhaarman.mockito_kotlin.verify
import com.sanogueralorenzo.data.cache.Cache
import com.sanogueralorenzo.data.createPostEntity
import com.sanogueralorenzo.data.model.PostEntity
Expand All @@ -11,7 +13,6 @@ import com.sanogueralorenzo.data.remote.PostsApi
import io.reactivex.Single
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.*
import org.mockito.Mockito.`when` as _when

class PostRepositoryImplTest {
Expand Down Expand Up @@ -99,7 +100,6 @@ class PostRepositoryImplTest {
test.assertValue(mapper.mapToDomain(remoteItem))
}


@Test
fun `get posts remote success`() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
package com.sanogueralorenzo.data.repository

import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.times
import com.nhaarman.mockito_kotlin.verify
import com.sanogueralorenzo.data.cache.Cache
import com.sanogueralorenzo.data.createUserEntity
import com.sanogueralorenzo.data.model.*
import com.sanogueralorenzo.data.model.AddressMapper
import com.sanogueralorenzo.data.model.CompanyMapper
import com.sanogueralorenzo.data.model.GeoMapper
import com.sanogueralorenzo.data.model.UserEntity
import com.sanogueralorenzo.data.model.UserMapper
import com.sanogueralorenzo.data.remote.UsersApi
import io.reactivex.Single
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.*
import org.mockito.Mockito.`when` as _when

class UserRepositoryImplTest {
Expand Down Expand Up @@ -98,7 +103,6 @@ class UserRepositoryImplTest {
test.assertValue(mapper.mapToDomain(remoteItem))
}


@Test
fun `get users remote success`() {
// given
Expand Down
2 changes: 2 additions & 0 deletions domain/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
apply plugin: 'java-library'
apply plugin: 'kotlin'

apply from: "../ktlint.gradle"

dependencies {
implementation Libraries.kotlin_stdlib
implementation Libraries.rxkotlin
Expand Down
10 changes: 6 additions & 4 deletions domain/src/main/java/com/sanogueralorenzo/domain/model/Post.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sanogueralorenzo.domain.model

data class Post(val userId: String,
val id: String,
val title: String,
val body: String)
data class Post(
val userId: String,
val id: String,
val title: String,
val body: String
)
44 changes: 26 additions & 18 deletions domain/src/main/java/com/sanogueralorenzo/domain/model/User.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package com.sanogueralorenzo.domain.model

data class User(val id: String,
val name: String,
val username: String,
val email: String,
val address: Address,
val phone: String,
val website: String,
val company: Company)
data class User(
val id: String,
val name: String,
val username: String,
val email: String,
val address: Address,
val phone: String,
val website: String,
val company: Company
)

data class Address(val street: String,
val suite: String,
val city: String,
val zipcode: String,
val geo: Geo)
data class Address(
val street: String,
val suite: String,
val city: String,
val zipcode: String,
val geo: Geo
)

data class Geo(val lat: String,
val lng: String)
data class Geo(
val lat: String,
val lng: String
)

data class Company(val name: String,
val catchPhrase: String,
val bs: String)
data class Company(
val name: String,
val catchPhrase: String,
val bs: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ import javax.inject.Inject
*/
data class CombinedUserPost(val user: User, val post: Post)

class UsersPostsUseCase @Inject constructor(private val userRepository: UserRepository,
private val postRepository: PostRepository,
private val mapper: UserPostMapper) {
class UsersPostsUseCase @Inject constructor(
private val userRepository: UserRepository,
private val postRepository: PostRepository,
private val mapper: UserPostMapper
) {

fun get(refresh: Boolean): Single<List<CombinedUserPost>> = Single.zip(userRepository.get(refresh), postRepository.get(refresh),
BiFunction { userList, postList -> mapper.map(userList, postList) })
}

class UserPostUseCase @Inject constructor(private val userRepository: UserRepository,
private val postRepository: PostRepository,
private val mapper: UserPostMapper) {
class UserPostUseCase @Inject constructor(
private val userRepository: UserRepository,
private val postRepository: PostRepository,
private val mapper: UserPostMapper
) {

fun get(userId: String, postId: String, refresh: Boolean): Single<CombinedUserPost> = Single.zip(userRepository.get(userId, refresh), postRepository.get(postId, refresh),
BiFunction { user, post -> mapper.map(user, post) })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.sanogueralorenzo.domain

import com.sanogueralorenzo.domain.model.*
import com.sanogueralorenzo.domain.model.Address
import com.sanogueralorenzo.domain.model.Comment
import com.sanogueralorenzo.domain.model.Company
import com.sanogueralorenzo.domain.model.Geo
import com.sanogueralorenzo.domain.model.Post
import com.sanogueralorenzo.domain.model.User

fun createUser(): User = User("1", "name", "username", "email", createAddress(), "phone", "website", createCompany())
fun createGeo(): Geo = Geo("0.0", "0.0")
Expand Down
Loading