[Epic] Implement Cat List page
Opened this issue · 2 comments
ashalva commented
Cat List
We need to implement totally new page about cat as a service.
The API: https://cataas.com/
- Add new list item in main page
- Once user clicks on the item redirect to CatList page
- Cat List page should have list with all possible tags
- Once user taps on tag we open new page where we show all cats within the tag.
- If user taps on any cat we show the image with concrete tag, the request.
Technical Implementation
UI
- Create new files
CatTagsListView
andCatTagsListViewModel
- Add new list item in main page which will open empty
CatTagsListView
CatTagsListView
has the simple list of cat tags
which must be fetched from https://cataas.com/api/tags
. See section API for more details. Once user taps on any tag we need to open the detail page, so:
- Create the
CatTagsDetailView
andCatTagsDetailViewModel
- We are showing each each cat category as a separate section. Each section should contain: owner information and all tags within the category.
- Tapping on tag we show the image with concrete tag
Models
DTOs
- Create
CatTagDetailDTO
under Services/DTOs
struct CatTagDetailDTO: Codable {
let id: String
let tags: [String]
let owner: String
let createdAt: String
let updatedAt: String
enum CodingKeys: String, CodingKey {
case id = "_id"
case tags, owner, createdAt, updatedAt
}
}
Business Models
- Create new model named
CatTagDetail
under Services/BusinessModels. The model should have basic properties.
struct CatTagDetail {
let owner: String?
let tags: [String]
let createdAt: String
let updatedAt: String
}
API
- Create
CatListService
in Network/Services folder - Create
CatTagMapper
underNetwork/Mappers
- Create endpoint
getCatTags() -> AnyPublisher<[String], Error>
it should return the array of tags. The url: https://cataas.com/api/tags - Create endpoint
getCatTagsDetail(tag: String) -> Future<CatTag, Error>
. The url: https://cataas.com/api/cats?tags=cute - Whenever user taps on each cat details tag we need to use
ImageLoader
to load the image in the app
ashalva commented
1st Sprint
1st PR
- Create new files CatTagsListView and CatTagsListViewModel
- Add new list item in main page which will open empty CatTagsListView
2nd PR
- Create model CatTag with name property
- Create array of models in viewmodel
- Show this array in view
ashalva commented
Sprint 2
Sprint goal 🎯
We need to show real cat tags which are fetched from the server. Whenever user opens the cat tag list we need to show loading view and after that show tags. If request fails, we need to show error view.
Leftovers from previous sprint:
- Rename
CatTagDetail
toCatTag
Pull Request 1 - Create service
You can always check RedditService
for references.
- Create
CatListService
file, we will need one protocolCatListServing
and classCatListService
. It can be in the same file. - Add function in
CatListServing
,func getCatTags() -> AnyPublisher<[CatTag], Error>
- Define
catTagApiURL
constant which will have a valuehttps://cataas.com/api/
- Implement same function in
CatListService
👇
func getCatTags() -> AnyPublisher<[CatTag], Error> {
let request = Endpoint<[String]>(baseURL: catTagApiURL)
.appendingPathParameter("tags")
.usingDefaultParameters()
return try! request
.usingMethod(.GET)
.build()
.asFuture()
.map {
$0.map { tag in CatTag(name: tag) }
}
.eraseToAnyPublisher()
}
Pull Request 2 - Show real cat tags
- Add service property in viewmodel
- Remove fake data from array of
CatTag
- Create function
getCatTags()
in viewmodel and callCatListService
's new function you have implemented above. - Check how
RedditViewModel
calls service function. You will need to changereceiveCompletion
andreceiveValue
callbacks.
Pull Request 3 - Show loading and error states
- Add new @published properties in viewmodel:
isLoading
,hasError
- Whenever
getCatTags()
is called we need to setisLoading
to true - Whenever we receive the response (
receiveCompletion
orreceiveValue
is called) we need to set it back to false - Whenever error happens we need to set
hasError
to true, otherwise false.