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

Feature/profile view #152

Merged
merged 12 commits into from
Dec 14, 2022
4 changes: 0 additions & 4 deletions DailyQuest/DailyQuest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@
9BED4DE8293FA01400C60631 /* ProfileViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BED4DE7293FA01400C60631 /* ProfileViewModel.swift */; };
9BED4DEA293FA92900C60631 /* UIImageView+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BED4DE9293FA92900C60631 /* UIImageView+.swift */; };
9BED4DEC2940EA8900C60631 /* UserImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BED4DEB2940EA8900C60631 /* UserImageView.swift */; };
9BED4DEE2941932200C60631 /* CameraIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BED4DED2941932200C60631 /* CameraIconView.swift */; };
9BED4DF12941C47D00C60631 /* RxGesture in Frameworks */ = {isa = PBXBuildFile; productRef = 9BED4DF02941C47D00C60631 /* RxGesture */; };
9BED4DF629470D8C00C60631 /* LaunchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BED4DF529470D8C00C60631 /* LaunchViewController.swift */; };
9BED4DFF2947109D00C60631 /* max.lottie.json in Resources */ = {isa = PBXBuildFile; fileRef = 9BED4DFE2947109C00C60631 /* max.lottie.json */; };
Expand Down Expand Up @@ -383,7 +382,6 @@
9BED4DE7293FA01400C60631 /* ProfileViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileViewModel.swift; sourceTree = "<group>"; };
9BED4DE9293FA92900C60631 /* UIImageView+.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImageView+.swift"; sourceTree = "<group>"; };
9BED4DEB2940EA8900C60631 /* UserImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserImageView.swift; sourceTree = "<group>"; };
9BED4DED2941932200C60631 /* CameraIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraIconView.swift; sourceTree = "<group>"; };
9BED4DF529470D8C00C60631 /* LaunchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchViewController.swift; sourceTree = "<group>"; };
9BED4DFE2947109C00C60631 /* max.lottie.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = max.lottie.json; sourceTree = "<group>"; };
A5003AB3293F5FEC00082A9C /* SignUpViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1084,7 +1082,6 @@
345687F729374D2500CA51E3 /* DayNamePickerView.swift */,
345687F92937815900CA51E3 /* QuantityView.swift */,
9BED4DEB2940EA8900C60631 /* UserImageView.swift */,
9BED4DED2941932200C60631 /* CameraIconView.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -1577,7 +1574,6 @@
349955122923220E007AB99E /* SwiftUIPreview.swift in Sources */,
9BD8CD022938418500E6EA2F /* LastFollowingCell.swift in Sources */,
3449AD6029222B3900B87619 /* UserInfoCell.swift in Sources */,
9BED4DEE2941932200C60631 /* CameraIconView.swift in Sources */,
34ACC32F291DE9C000741371 /* SceneDelegate.swift in Sources */,
34A529D829247A87001BAD34 /* HomeCoordinator.swift in Sources */,
3472E8F7294213BE00BB304F /* DefaultFriendQuestUseCase.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
{
"identity" : "lottie-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/airbnb/lottie-ios",
"location" : "https://github.com/airbnb/lottie-ios.git",
"state" : {
"revision" : "b4bd0604ded9574807f41b4004b57dd1226a30a4",
"version" : "3.5.0"
Expand Down
2 changes: 1 addition & 1 deletion DailyQuest/DailyQuest/Application/SyncManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final class SyncManager {

do {
let quests = try persistentStorage
.fetchEntities(type: QuestEntity.self, filter: nil)
.readEntities(type: QuestEntity.self, filter: nil)
.compactMap { $0.toDomain() }
single(.success(quests))
} catch let error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension RealmBrowseQuestsStorage: BrowseQuestsStorage {
}

do {
let browseQuests = try realmStorage.fetchEntities(type: BrowseQuestEntity.self)
let browseQuests = try realmStorage.readEntities(type: BrowseQuestEntity.self)
.compactMap { $0.toDomain() }
single(.success(browseQuests))
} catch let error {
Expand All @@ -44,7 +44,7 @@ extension RealmBrowseQuestsStorage: BrowseQuestsStorage {
let browseQuestEntity = BrowseQuestEntity(browseQuest: browseQuest)

do {
try realmStorage.saveEntity(entity: browseQuestEntity)
try realmStorage.createEntity(entity: browseQuestEntity)
single(.success(browseQuest))
} catch let error {
single(.failure(RealmStorageError.saveError(error)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension RealmQuestsStorage: QuestsStorage {
do {
for quest in quests {
let questEntity = QuestEntity(quest: quest)
try realmStorage.saveEntity(entity: questEntity)
try realmStorage.createEntity(entity: questEntity)
}
single(.success(quests))
} catch let error {
Expand All @@ -43,7 +43,7 @@ extension RealmQuestsStorage: QuestsStorage {
}
do {
let quests = try realmStorage
.fetchEntities(type: QuestEntity.self, filter: NSPredicate(format: "date == %@", date.toString))
.readEntities(type: QuestEntity.self, filter: NSPredicate(format: "date == %@", date.toString))
.compactMap { $0.toDomain() }
single(.success(quests))
} catch let error {
Expand Down Expand Up @@ -75,7 +75,7 @@ extension RealmQuestsStorage: QuestsStorage {
return Disposables.create()
}
do {
guard let entity = try realmStorage.findEntities(type: QuestEntity.self, filter: NSPredicate(format: "uuid == %@", questId as CVarArg)).first else {
guard let entity = try realmStorage.readEntities(type: QuestEntity.self, filter: NSPredicate(format: "uuid == %@", questId as CVarArg)).first else {
throw RealmStorageError.noDataError
}
let quest = entity.toDomain()
Expand All @@ -96,7 +96,7 @@ extension RealmQuestsStorage: QuestsStorage {
}

do {
let entities = try realmStorage.findEntities(type: QuestEntity.self, filter: NSPredicate(format: "groupId == %@", groupId as CVarArg))
let entities = try realmStorage.readEntities(type: QuestEntity.self, filter: NSPredicate(format: "groupId == %@", groupId as CVarArg))
let quests = entities.compactMap { $0.toDomain() }
for entity in entities {
try realmStorage.deleteEntity(entity: entity)
Expand All @@ -115,7 +115,7 @@ extension RealmQuestsStorage: QuestsStorage {
return Disposables.create()
}
do {
let entities = try realmStorage.fetchEntities(type: QuestEntity.self)
let entities = try realmStorage.readEntities(type: QuestEntity.self)
let quests = entities.compactMap { $0.toDomain() }
for entity in entities {
try realmStorage.deleteEntity(entity: entity)
Expand All @@ -137,7 +137,7 @@ extension RealmQuestsStorage: QuestsStorage {

do {
let quests = try realmStorage
.fetchEntities(type: QuestEntity.self, filter: nil)
.readEntities(type: QuestEntity.self, filter: nil)
.compactMap { $0.toDomain() }
single(.success(quests))
} catch let error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ enum RealmStorageError: Error {

final class RealmStorage {
static let shared = RealmStorage()

private let persistentContainer = try? Realm()

private init() {
// Realm file path
#if DEBUG
print(Realm.Configuration.defaultConfiguration.fileURL!)
print(Realm.Configuration.defaultConfiguration.fileURL!)
#endif
}
}

private let persistentContainer = try? Realm()

extension RealmStorage {
@discardableResult
func saveEntity<O: Object>(entity: O) throws -> O {
func createEntity<O: Object>(entity: O) throws -> O {
guard let persistentContainer = persistentContainer else {
throw RealmStorageError.realmObjectError
}
Expand All @@ -39,8 +40,8 @@ final class RealmStorage {
}
return entity
}

func fetchEntities<O: Object>(type: O.Type, filter: NSPredicate? = nil) throws -> [O] {
func readEntities<O: Object>(type: O.Type, filter: NSPredicate? = nil) throws -> [O] {
guard let persistentContainer = persistentContainer else {
throw RealmStorageError.realmObjectError
}
Expand All @@ -50,7 +51,7 @@ final class RealmStorage {
return Array(persistentContainer.objects(type))
}
}

@discardableResult
func updateEntity<O: Object>(entity: O) throws -> O {
guard let persistentContainer = persistentContainer else {
Expand All @@ -61,7 +62,7 @@ final class RealmStorage {
}
return entity
}

@discardableResult
func deleteEntity<O: Object>(entity: O) throws -> O {
guard let persistentContainer = persistentContainer else {
Expand All @@ -70,10 +71,10 @@ final class RealmStorage {
try persistentContainer.write {
persistentContainer.delete(entity)
}

return entity
}

@discardableResult
func deleteAllEntity<O: Object>(type: O.Type) throws -> [O] {
guard let persistentContainer = persistentContainer else {
Expand All @@ -86,12 +87,4 @@ final class RealmStorage {
}
return Array(persistentContainer.objects(type))
}

func findEntities<O: Object>(type: O.Type, filter: NSPredicate) throws -> [O] {
guard let persistentContainer = persistentContainer else {
throw RealmStorageError.realmObjectError
}
return Array(persistentContainer.objects(type).filter(filter))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension RealmUserInfoStorage: UserInfoStorage {
return Single<User>.create { [weak self] single in
do {
guard let realmStorage = self?.realmStorage else { throw RealmStorageError.realmObjectError }
guard let userInfoEntity = try realmStorage.fetchEntities(type: UserInfoEntity.self)
guard let userInfoEntity = try realmStorage.readEntities(type: UserInfoEntity.self)
.first else {
throw RealmStorageError.noDataError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ extension DefaultBrowseRepository: BrowseRepository {
/// Firebase μš°μ„ , μ‹€νŒ¨μ‹œ persistentStorage, persistentStorage도 μ‹€νŒ¨μ‹œ Errorλ°˜ν™˜
/// - Returns: Observable<[BrowseQuest]>
func fetch() -> Single<[BrowseQuest]> {
let uid = networkService.uid.value
return networkService.getAllowUsers(limit: 10)
.map { $0.toDomain() }
.flatMap(fetchBrowseQuestNetworkService(user:))
.filter { !$0.quests.isEmpty && uid != $0.user.uuid }
.filter { !$0.quests.isEmpty }
.toArray()
.do(afterSuccess: { [weak self] browseQuests in
guard let self = self else { return }
Expand Down
9 changes: 9 additions & 0 deletions DailyQuest/DailyQuest/Domain/Entities/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,13 @@ extension User {
introduce: self.introduce,
allow: self.allow)
}

func setIntroduce(introduce: String) -> User {
return User(uuid: self.uuid,
nickName: self.nickName,
profileURL: self.profileURL,
backgroundImageURL: self.backgroundImageURL,
introduce: introduce,
allow: self.allow)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,12 @@ extension DefaultUserUseCase: UserUseCase {
return userRepository.deleteUser()
.catchAndReturn(false)
}

func updateIntroduce(introduce: String) -> Single<Bool> {
userRepository.readUser()
.map { $0.setIntroduce(introduce: introduce) }
.flatMap(userRepository.updateUser(by:))
.map { _ in true }
.catchAndReturn(false)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ protocol UserUseCase {
func saveBackgroundImage(data: Data) -> Single<Bool>

func delete() -> Single<Bool>

func updateIntroduce(introduce: String) -> Single<Bool>
}
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,10 @@ extension FirebaseService {
do {
guard let querySnapshot = querySnapshot else { throw NetworkServiceError.noDataError }
for document in querySnapshot.documents {
let quest = try document.data(as: UserDTO.self)
observer.onNext(quest)
let user = try document.data(as: UserDTO.self)
if user.uuid != self.uid.value {
observer.onNext(user)
}
}
} catch let error {
observer.onError(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ final class FriendStatusView: UIView {
private(set) lazy var userNameLabel: UILabel = {
let userNameLabel = UILabel()
userNameLabel.text = "User name labelλ‹˜μ˜ Quest"
userNameLabel.font = .systemFont(ofSize: 22,weight: .bold)

return userNameLabel
}()

private(set) lazy var introduceLabel: UILabel = {
let introduceLabel = UILabel()
introduceLabel.text = "introduceLabel"
introduceLabel.textColor = .maxLightGrey
introduceLabel.textColor = .darkGray

return introduceLabel
}()
Expand Down
77 changes: 0 additions & 77 deletions DailyQuest/DailyQuest/Presentation/Home/View/CameraIconView.swift

This file was deleted.

12 changes: 0 additions & 12 deletions DailyQuest/DailyQuest/Presentation/Home/View/UserImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ final class UserImageView: UIView {
return userImage
}()

private lazy var cameraIcon: CameraIconView = {
return CameraIconView()
}()


override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -36,20 +32,12 @@ final class UserImageView: UIView {

private func addSubviews() {
addSubview(userImage)
addSubview(cameraIcon)
}

private func setupConstraints() {
userImage.snp.makeConstraints { make in
make.centerX.centerY.equalToSuperview()
make.width.height.equalTo(100)
}
cameraIcon.snp.makeConstraints { make in
make.left.equalTo(75)
make.top.equalTo(75)
}
self.snp.makeConstraints { make in
make.width.height.equalTo(110)
}
}
}
Loading