Skip to content

Commit

Permalink
[WEAV-122] 프로필 위젯 입력 관련 네트워크 레이어 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jisu15-kim committed Nov 13, 2024
1 parent 9e84319 commit 7e33230
Show file tree
Hide file tree
Showing 10 changed files with 1,450 additions and 63 deletions.
434 changes: 424 additions & 10 deletions OpenApiGenerator/Sources/OpenapiGenerated/Client.swift

Large diffs are not rendered by default.

781 changes: 776 additions & 5 deletions OpenApiGenerator/Sources/OpenapiGenerated/Types.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion OpenApiGenerator/Sources/openapi-generator-cli/3days-oas
Submodule 3days-oas updated 1 files
+173 −1 openapi.yaml
8 changes: 8 additions & 0 deletions Projects/Core/CommonKit/Sources/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,12 @@ public final class AppCoordinator: ObservableObject {
}
}
}

public func refreshMyUserInfo() async throws {
let userInfo = try await authService.requestMyUserInfo()
await MainActor.run {
self.userInfo = userInfo
AuthState.change(.login)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public class AuthServiceMock: AuthServiceProtocol {
jobOccupations: [],
distanceType: .anywhere,
allowSameCompany: nil
)
),
profileWidgets: []
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// ProfileService.swift
// CommonKit
//
// Created by 김지수 on 11/14/24.
// Copyright © 2024 com.weave. All rights reserved.
//

import Foundation
import CoreKit
import OpenapiGenerated
import Model

public protocol ProfileServiceProtocol {
func requestPutProfileWidget(
widgetType: Components.Schemas.ProfileWidgetType,
content: String
) async throws
}

public final class ProfileService {
public static let shared = ProfileService()
private init() {}
}

extension ProfileService: ProfileServiceProtocol {
public func requestPutProfileWidget(
widgetType: Components.Schemas.ProfileWidgetType,
content: String
) async throws {
let result = try await client.putProfileWidget(
body: .json(
.init(
_type: widgetType,
content: content
)
)
)
let _ = try result.ok
}
}
140 changes: 100 additions & 40 deletions Projects/Features/Home/Sources/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public struct ProfileView: View {
(Device.width - 36 - 12) / 2
}

private let columns = [
GridItem(.flexible(), spacing: 16),
GridItem(.flexible(), spacing: 16)
]

public init(userInfo: UserInfo) {
let model = ProfileModel()
let intent = ProfileIntent(
Expand Down Expand Up @@ -56,50 +61,105 @@ public struct ProfileView: View {
LeftAlignText("Introductions")
.typography(.en_medium_16)
.padding(.bottom, 14)
.padding(.bottom, 16)
.foregroundStyle(Color(hex: 0x5E5E5E))

ZStack {
Capsule()
.inset(by: 1)
.stroke(DesignCore.Colors.blue300, lineWidth: 1)
.fill(Color(hex: 0xF2F9FF))
LeftAlignText("프로필 위젯을 추가해 나를 더 소개해보세요!🙌")
.padding(.leading, 26)
.typography(.semibold_14)
.foregroundStyle(DesignCore.Colors.blue300)
}
.frame(height: 57)
.shadow(.default)
.padding(.bottom, 14)

ZStack {
RoundedRectangle(cornerRadius: 24)
.fill(.white)
// 비어있을 때의 뷰
if userInfo.profileWidgets.isEmpty {
ZStack {
Capsule()
.inset(by: 1)
.stroke(DesignCore.Colors.blue300, lineWidth: 1)
.fill(Color(hex: 0xF2F9FF))
LeftAlignText("프로필 위젯을 추가해 나를 더 소개해보세요!🙌")
.padding(.leading, 26)
.typography(.semibold_14)
.foregroundStyle(DesignCore.Colors.blue300)
}
.frame(height: 57)
.shadow(.default)
.padding(.bottom, 14)

RoundedRectangle(cornerRadius: 10)
.fill(DesignCore.Colors.grey50)
.strokeBorder(
style: StrokeStyle(
lineWidth: 3,
dash: [8, 8]
ZStack {
RoundedRectangle(cornerRadius: 24)
.fill(.white)

RoundedRectangle(cornerRadius: 10)
.fill(DesignCore.Colors.grey50)
.strokeBorder(
style: StrokeStyle(
lineWidth: 3,
dash: [8, 8]
)
)
)
.foregroundStyle(Color(hex: 0xE0DEDD))
.padding(.all, 8)

VStack {
Image(systemName: "plus")
.resizable()
.frame(width: 24, height: 24)
Text("프로필 위젯 추가하기")
.typography(.semibold_14)
.foregroundStyle(Color(hex: 0xE0DEDD))
.padding(.all, 8)

VStack {
Image(systemName: "plus")
.resizable()
.frame(width: 24, height: 24)
Text("프로필 위젯 추가하기")
.typography(.semibold_14)
}
.foregroundStyle(DesignCore.Colors.grey200)
}
.frame(height: widgetSize)
.shadow(.default)
.padding(.bottom, 36)
.onTapGesture {
isPresentWidgetSelectionView = true
}
} else {
LazyVGrid(columns: columns, spacing: 16) {
ForEach(userInfo.profileWidgets, id: \.self) { widget in
ZStack {
RoundedRectangle(cornerRadius: 24)
.fill(.white)
ProfileWidgetView(
title: widget.widgetType.title,
bodyText: widget.content,
titleColor: widget.widgetType.titleColor,
bodyColor: widget.widgetType.bodyColor,
gradientColors: widget.widgetType.gradationColors
)
.padding(.all, 4)
}
.shadow(.default)
.onTapGesture {

}
}

ZStack {
RoundedRectangle(cornerRadius: 24)
.fill(.white)

RoundedRectangle(cornerRadius: 10)
.fill(DesignCore.Colors.grey50)
.strokeBorder(
style: StrokeStyle(
lineWidth: 3,
dash: [8, 8]
)
)
.foregroundStyle(Color(hex: 0xE0DEDD))
.padding(.all, 8)

VStack {
Image(systemName: "plus")
.resizable()
.frame(width: 24, height: 24)
Text("프로필 위젯 추가하기")
.typography(.semibold_14)
}
.foregroundStyle(DesignCore.Colors.grey200)
}
.shadow(.default)
.onTapGesture {
isPresentWidgetSelectionView = true
}
}
.foregroundStyle(DesignCore.Colors.grey200)
}
.frame(height: widgetSize)
.shadow(.default)
.padding(.bottom, 36)
.onTapGesture {
isPresentWidgetSelectionView = true
}
}
.padding(.horizontal, 18)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ import Foundation
import CommonKit
import CoreKit
import Model
import NetworkKit

//MARK: - Intent
class WidgetWritingIntent {
private weak var model: WidgetWritingModelActionable?
private let input: DataModel
private let service: ProfileServiceProtocol

// MARK: Life cycle
init(
model: WidgetWritingModelActionable,
input: DataModel
input: DataModel,
service: ProfileServiceProtocol = ProfileService.shared
) {
self.input = input
self.model = model
self.service = service
model.setWidgetType(input.widgetType)
}
}
Expand Down Expand Up @@ -61,9 +65,26 @@ extension WidgetWritingIntent: WidgetWritingIntent.Intentable {
func onTapNextButton(state: any WidgetWritingModel.Stateful) {
guard let selectedWidget = state.selectedWidgetType else { return }
// 창닫기
model?.modalDismiss()

Task {
model?.setLoading(status: true)
do {
try await requestPutProfileWidget(
widget: selectedWidget,
content: state.widgetBodyText
)
try await AppCoordinator.shared.refreshMyUserInfo()
model?.setLoading(status: false)
model?.modalDismiss()
} catch {
print(error)
}
}
}


func requestPutProfileWidget(widget: WidgetType, content: String) async throws {
try await service.requestPutProfileWidget(
widgetType: widget.toDto,
content: content
)
}
}
34 changes: 32 additions & 2 deletions Projects/Model/Model/Sources/Auth/Domain/UserInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ public struct UserInfo {
public let phone: String
public let profile: UserInfoProfile
public let dreamPartner: DreamPartnerInfo
public let profileWidgets: [ProfileWidget]

public init(
id: String,
name: String,
phone: String,
profile: UserInfoProfile,
dreamPartner: DreamPartnerInfo
dreamPartner: DreamPartnerInfo,
profileWidgets: [ProfileWidget]
) {
self.id = id
self.name = name
self.phone = phone
self.profile = profile
self.dreamPartner = dreamPartner
self.profileWidgets = profileWidgets
}

public init(from dto: Components.Schemas.GetMyUserInfoResponse) {
Expand All @@ -36,6 +39,7 @@ public struct UserInfo {
self.phone = dto.phoneNumber
self.profile = .init(from: dto.profile)
self.dreamPartner = .init(from: dto.desiredPartner)
self.profileWidgets = dto.profileWidgets.map { .init(from: $0) }
}

public static var mock: UserInfo {
Expand All @@ -44,7 +48,8 @@ public struct UserInfo {
name: "김지수",
phone: "01012341234",
profile: .mock,
dreamPartner: .mock
dreamPartner: .mock,
profileWidgets: ProfileWidget.mock
)
}
}
Expand Down Expand Up @@ -136,3 +141,28 @@ public struct DreamPartnerInfo {
)
}
}

public struct ProfileWidget: Hashable {
public let widgetType: WidgetType
public let content: String

static var mock: [ProfileWidget] {
[
.init(widgetType: .body, content: "GOOD BODY"),
.init(widgetType: .smoking, content: "Heavy Smoker !!")
]
}

public init(
widgetType: WidgetType,
content: String
) {
self.widgetType = widgetType
self.content = content
}

public init(from dto: Components.Schemas.ProfileWidget) {
self.widgetType = WidgetType(from: dto._type)
self.content = dto.content
}
}
Loading

0 comments on commit 7e33230

Please sign in to comment.