Skip to content

Commit

Permalink
Fix user & fetch user info
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhello0507 committed Oct 4, 2024
1 parent 789a3b1 commit 038a6a1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.bestswlkh0310.graduating.graduatingserver.core.user.User

data class UserRes(
val username: String,
val nickname: String,
val nickname: String?,
) {
companion object {
fun of(user: User) = UserRes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import jakarta.persistence.*
class User(
id: Long = 0,
username: String,
nickname: String,
nickname: String?,
role: UserRole = UserRole.USER,
platformType: PlatformType
) {
Expand Down
4 changes: 2 additions & 2 deletions Graduating-iOS/Data/Network/UserService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public class UserService {
public static let shared = UserService()
let netRunnner = DefaultNetRunner<UserEndpoint>()

func getMe() -> AnyPublisher<User, MoyaError> {
public func getMe() -> AnyPublisher<User, MoyaError> {
netRunnner.deepDive(.getMe, res: User.self)
}

func editUser(_ req: EditUserReq) -> AnyPublisher<VoidDTO, MoyaError> {
public func editUser(_ req: EditUserReq) -> AnyPublisher<VoidDTO, MoyaError> {
netRunnner.deepDive(.editUser(req), res: VoidDTO.self)
}
}
1 change: 1 addition & 0 deletions Graduating-iOS/Graduating/Feature/Main/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct MainView: View {
fetchMeals()
fetchGraduating()
selectedTab = data[0]
appState.fetchCurrentUser()
}
.onChange(of: appState.graduating) {
selectedTab = .home
Expand Down
8 changes: 8 additions & 0 deletions Graduating-iOS/Graduating/Feature/Observable/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ final class AppState: BaseViewModel {
}
}
@Published var graduatingFetchFailure = false
@Published var currentUser: User?

private var observer: NSKeyValueObservation?
override init() {
Expand All @@ -67,4 +68,11 @@ final class AppState: BaseViewModel {
}
.store(in: &subscriptions)
}

func fetchCurrentUser() {
UserService.shared.getMe()
.ignoreError()
.assign(to: \.currentUser, on: self)
.store(in: &subscriptions)
}
}
4 changes: 2 additions & 2 deletions Graduating-iOS/Model/User/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Foundation

public struct User: ModelProtocol {
public let username: String
public let nickname: String
public let nickname: String?

public init(username: String, nickname: String) {
public init(username: String, nickname: String?) {
self.username = username
self.nickname = nickname
}
Expand Down

0 comments on commit 038a6a1

Please sign in to comment.