Skip to content

Commit

Permalink
Merge pull request #45 from yangsubinn/feat/#39-ListDetailDomain
Browse files Browse the repository at this point in the history
[Feat] #39 - ListDetail 뷰 Domain, Data 구현
  • Loading branch information
yangsubinn authored Dec 18, 2022
2 parents 06d7016 + fe5bf60 commit cbd239f
Show file tree
Hide file tree
Showing 12 changed files with 244 additions and 85 deletions.
21 changes: 8 additions & 13 deletions SOPT-Stamp-iOS/Projects/Core/Sources/Literals/StringLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@ public struct I18N {
public static let networkError = "네트워크 오류가 발생했습니다."
public static let delete = "삭제"
public static let cancel = "취소"
public static let ok = "확인"
}

public struct TextFieldView {
public static let verify = "확인"
}

public struct Navi {
public static let post = "공지"
public struct Photo {
public static let authTitle = "앨범 접근 권한 거부"
public static let authMessage = "앨범 접근이 거부되었습니다. 앱의 일부 기능을 사용할 수 없습니다."
public static let moveToSetting = "권한 설정으로 이동하기"
public static let wrongAuth = "권한 설정이 이상하게 되었어요"
}

public struct Search {
public static let placeholder = "검색어 입력"
public static let cancel = "취소"
public static let countUnit = ""
public static let enterSearch = "검색어를 입력해 주세요."
public static let noSearchData = "등록된 게시물이 없습니다"
public struct TextFieldView {
public static let verify = "확인"
}

public struct Onboarding {
Expand Down Expand Up @@ -82,6 +78,5 @@ public struct I18N {
public static let editComplte = "수정 완료"

public static let deleteTitle = "달성한 미션을 삭제하시겠습니까?"

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,59 @@

import Combine

import Core
import Domain
import Network

public class ListDetailRepository {

// private let networkService: ListDetailServiceType
// private let cancelBag = Set<AnyCancellable>()
//
// public init(service: ListDetailServiceType) {
// self.networkService = service
// }
public init() {

private let networkService: MissionService
private let cancelBag = CancelBag()

public init(service: MissionService) {
self.networkService = service
}
}

extension ListDetailRepository: ListDetailRepositoryInterface {
public func fetchListDetail(missionId: Int) -> Driver<ListDetailModel> {
// TODO: - networkService.
return makeMockListDetailEntity()
}

public func postStamp(missionId: Int, stampData: ListDetailRequestModel) -> Driver<ListDetailModel> {
// TODO: - networkService.
return makeMockListDetailEntity()
}

public func putStamp(missionId: Int, stampData: ListDetailRequestModel) -> Driver<[String : Int]> {
// TODO: - networkService
return Just(["stampId": 11])
.setFailureType(to: Error.self)
.asDriver()
}

public func deleteStamp(stampId: Int) -> Driver<Bool> {
// TODO: - networkService
return Just(Bool.random())
.setFailureType(to: Error.self)
.asDriver()
}
}

extension ListDetailRepository {
private func makeMockListDetailEntity() -> Driver<ListDetailModel> {
let mockData = ListDetailEntity.init(
createdAt: "2022-01-22",
updatedAt: "2022-02-01",
id: 1,
contents: "안녕하세요",
images: ["https://avatars.githubusercontent.com/u/81167570?v=4"],
userID: 3,
missionID: 2)
let date = mockData.toDomain()
return Just(date)
.setFailureType(to: Error.self)
.asDriver()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import Domain
import Network

extension ListDetailEntity {

public func toDomain() -> ListDetailModel {
return ListDetailModel.init()
// TODO: - date 형식 확인하고 변형
return ListDetailModel.init(image: self.images.first ?? "",
content: self.contents,
date: self.updatedAt ?? self.createdAt)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import Foundation

public struct ListDetailModel {

public init() {

public let image, content, date: String

public init(image: String, content: String, date: String) {
self.image = image
self.content = content
self.date = date
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved.
//

import Core

import Combine

public protocol ListDetailRepositoryInterface {

func fetchListDetail(missionId: Int) -> Driver<ListDetailModel>
func postStamp(missionId: Int, stampData: ListDetailRequestModel) -> Driver<ListDetailModel>
func putStamp(missionId: Int, stampData: ListDetailRequestModel) -> Driver<[String: Int]>
func deleteStamp(stampId: Int) -> Driver<Bool>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,60 @@
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved.
//

import Core

import Combine

public protocol ListDetailUseCase {

func fetchListDetail(missionId: Int)
func postStamp(missionId: Int, stampData: ListDetailRequestModel)
func putStamp(missionId: Int, stampData: ListDetailRequestModel)
func deleteStamp(stampId: Int)
var listDetailModel: PassthroughSubject<ListDetailModel, Error> { get set }
var editSuccess: PassthroughSubject<Bool, Error> { get set }
var deleteSuccess: PassthroughSubject<Bool, Error> { get set }
}

public class DefaultListDetailUseCase {

private let repository: ListDetailRepositoryInterface
private var cancelBag = Set<AnyCancellable>()
private var cancelBag = CancelBag()

public var listDetailModel = PassthroughSubject<ListDetailModel, Error>()
public var editSuccess = PassthroughSubject<Bool, Error>()
public var deleteSuccess = PassthroughSubject<Bool, Error>()

public init(repository: ListDetailRepositoryInterface) {
self.repository = repository
}
}

extension DefaultListDetailUseCase: ListDetailUseCase {

public func fetchListDetail(missionId: Int) {
repository.fetchListDetail(missionId: missionId)
.sink { model in
self.listDetailModel.send(model)
}.store(in: self.cancelBag)
}

public func postStamp(missionId: Int, stampData: ListDetailRequestModel) {
repository.postStamp(missionId: missionId, stampData: stampData)
.sink { model in
self.listDetailModel.send(model)
}.store(in: self.cancelBag)
}

public func putStamp(missionId: Int, stampData: ListDetailRequestModel) {
repository.putStamp(missionId: missionId, stampData: stampData)
.sink { result in
self.editSuccess.send(result.isEmpty ? false : true)
}.store(in: self.cancelBag)
}

public func deleteStamp(stampId: Int) {
repository.deleteStamp(stampId: stampId)
.sink { success in
self.deleteSuccess.send(success)
}.store(in: self.cancelBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@

import Foundation

public struct ListDetailEntity {
public struct ListDetailEntity: Codable {
public let createdAt: String
public let updatedAt: String?
public let id: Int
public let contents: String
public let images: [String]
public let userID, missionID: Int

enum CodingKeys: String, CodingKey {
case createdAt, updatedAt, id, contents, images
case userID = "userId"
case missionID = "missionId"
}

public init(createdAt: String, updatedAt: String, id: Int, contents: String, images: [String], userID: Int, missionID: Int) {
self.createdAt = createdAt
self.updatedAt = updatedAt
self.id = id
self.contents = contents
self.images = images
self.userID = userID
self.missionID = missionID
}
}
Loading

0 comments on commit cbd239f

Please sign in to comment.