Skip to content

Commit

Permalink
Merge pull request #230 from Team-Smeme/feat/#229-coachingAPI
Browse files Browse the repository at this point in the history
[Feat] #229 Coaching Service 구현 및 테스트 코드 작성
  • Loading branch information
cchanmi authored Dec 3, 2024
2 parents 3e12678 + 016b4ef commit d599f0f
Show file tree
Hide file tree
Showing 27 changed files with 392 additions and 243 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/smeemDev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ jobs:
- uses: actions/checkout@v4
- name: Set Xcode version
run: sudo xcode-select -switch /Applications/Xcode_16.app
- name: List available devices
run: xcrun simctl list devices
- name: Resolve Dependencies
run: xcodebuild -resolvePackageDependencies
working-directory: ./Smeem-iOS
- name: Create Debug.xcconfig
run: echo "${{ secrets.DEBUG_CONFIG }}" > ./Smeem-iOS/Debug.xcconfig
- name: Build
run: xcodebuild build -project Smeem-iOS/Smeem-iOS.xcodeproj -scheme Smeem-Dev -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.2'
run: xcodebuild clean test -project Smeem-iOS/Smeem-iOS.xcodeproj -scheme Smeem-Dev -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.2'
8 changes: 8 additions & 0 deletions Smeem-iOS/Smeem-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@
4AB349522CF22AD30047C484 /* Auth */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Auth; sourceTree = "<group>"; };
4AB349532CF22AD90047C484 /* Badge */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Badge; sourceTree = "<group>"; };
4AB349562CF22BFF0047C484 /* EditUser */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = EditUser; sourceTree = "<group>"; };
4AB349BA2CF23B770047C484 /* Coaching */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Coaching; sourceTree = "<group>"; };
4AB349BC2CF23D210047C484 /* Coaching */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Coaching; sourceTree = "<group>"; };
4AF050CE2CE9DE010055BC3F /* Coaching */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Coaching; sourceTree = "<group>"; };
4AF050D72CEA01E20055BC3F /* DiaryComplete */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = DiaryComplete; sourceTree = "<group>"; };
4AF050D82CEA01EA0055BC3F /* Coaching */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Coaching; sourceTree = "<group>"; };
Expand Down Expand Up @@ -909,6 +911,7 @@
4A07F8D92B821523004185F2 /* Smeem-iOSTests */ = {
isa = PBXGroup;
children = (
4AB349BC2CF23D210047C484 /* Coaching */,
4AF78D9C2B84AB5D0098E1FA /* Base */,
4A07F8E12B821529004185F2 /* Onboarding */,
);
Expand Down Expand Up @@ -961,6 +964,7 @@
4A0EA45C2A014126006CCE52 /* NetworkDataModel */ = {
isa = PBXGroup;
children = (
4AB349BA2CF23B770047C484 /* Coaching */,
4AB349562CF22BFF0047C484 /* EditUser */,
4AB349532CF22AD90047C484 /* Badge */,
4AB349522CF22AD30047C484 /* Auth */,
Expand Down Expand Up @@ -1726,6 +1730,9 @@
dependencies = (
4A07F8DD2B821523004185F2 /* PBXTargetDependency */,
);
fileSystemSynchronizedGroups = (
4AB349BC2CF23D210047C484 /* Coaching */,
);
name = "Smeem-iOSTests";
productName = "Smeem-iOSTests";
productReference = 4A07F8D82B821523004185F2 /* Smeem-iOSTests.xctest */;
Expand Down Expand Up @@ -1753,6 +1760,7 @@
4AB349522CF22AD30047C484 /* Auth */,
4AB349532CF22AD90047C484 /* Badge */,
4AB349562CF22BFF0047C484 /* EditUser */,
4AB349BA2CF23B770047C484 /* Coaching */,
4AF050CE2CE9DE010055BC3F /* Coaching */,
4AF050D72CEA01E20055BC3F /* DiaryComplete */,
4AF050D82CEA01EA0055BC3F /* Coaching */,
Expand Down
31 changes: 0 additions & 31 deletions Smeem-iOS/Smeem-iOS/Global/Extensions/MoyaProvier+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,6 @@
import Foundation
import Moya

class ServiceNetwork {

static let shared = ServiceNetwork()

private init() {}

func request<T: Decodable, Target: TargetType>(_ target: Target) async throws -> T {
let provider = MoyaProvider<Target>(plugins: [MoyaLoggingPlugin()])

return try await withCheckedThrowingContinuation { continuation in
provider.request(target) { result in
switch result {
case .success(let response):
do {
try NetworkManager.statusCodeErrorHandling(statusCode: response.statusCode)
if let data = try response.map(GeneralResponse<T>.self).data {
continuation.resume(returning: data)
} else {
continuation.resume(throwing: SmeemError.clientError)
}
} catch {
continuation.resume(throwing: SmeemError.clientError)
}
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
}

extension MoyaProvider {
func request<T: Decodable>(_ target: Target) async throws -> T {
try await withCheckedThrowingContinuation { continuation in
Expand Down
2 changes: 1 addition & 1 deletion Smeem-iOS/Smeem-iOS/Global/HighlightModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct HighlightModifier: ViewModifier {
var attributedText = AttributedString(diaryText)

for (index, correction) in corrections.enumerated() {
if index == highlightIndex, let range = attributedText.range(of: correction.original_sentence) {
if index == highlightIndex, let range = attributedText.range(of: correction.originalSentence) {
attributedText[range].backgroundColor = Color(UIColor.point)
attributedText[range].foregroundColor = Color(UIColor.smeemWhite)
}
Expand Down
5 changes: 5 additions & 0 deletions Smeem-iOS/Smeem-iOS/Global/Literals/ColorLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ extension UIColor {
return UIColor(hex: "#171716", alpha: 0.3)
}

/// 400, 500 토스트
static var errorToastBackground: UIColor {
return UIColor(hex: "#171716")
}

static var summaryBackground: UIColor {
return UIColor(hex: "#FAFAFA")
}
Expand Down
2 changes: 2 additions & 0 deletions Smeem-iOS/Smeem-iOS/Global/Protocols/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ protocol Store {
associatedtype State

var state: State { get }

@MainActor
func send(action: Action)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct CoachingComparisonView: View {
textHeight = value
}

Text(coachingResponse.original_sentence)
Text(coachingResponse.originalSentence)
.font(Font.custom("Pretendard", size: 14)).fontWeight(.regular)
.frame(maxWidth: .infinity, alignment: .topLeading)
}
Expand All @@ -49,7 +49,7 @@ struct CoachingComparisonView: View {
.foregroundColor(Color(UIColor.point))
}

Text(coachingResponse.corrected_sentence)
Text(coachingResponse.correctedSentence)
.font(Font.custom("Pretendard", size: 14)).fontWeight(.medium)
.foregroundColor(Color(UIColor.point))
.frame(maxWidth: .infinity, alignment: .topLeading)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,24 @@ import SwiftUI

struct CoachingComparisonView: View {
@Binding var coachingResponse: CoachingResponse
@State private var textHeight: CGFloat = 0 // Text의 높이를 저장할 변수

var body: some View {
VStack(spacing: 20) {
VStack(alignment: .leading, spacing: 8) {
HStack {
Rectangle()
.frame(width: 2, height: textHeight)
.foregroundStyle(Color(UIColor.black))
HStack(spacing: 8) {

GeometryReader { geomerty in
Rectangle()
.frame(height: geomerty.size.height)
.foregroundStyle(Color(UIColor.black))
}
.frame(width: 2)

Text("나의 일기")
.font(Font.custom("Pretendard", size: 16).weight(.medium))
.foregroundColor(Color(UIColor.black))
.background(GeometryReader { geometry in
Color.clear
.preference(key: TextHeightPreferenceKey.self, value: geometry.size.height)
})
}
.onPreferenceChange(TextHeightPreferenceKey.self) { value in
textHeight = value

Spacer()
}

Text(coachingResponse.original_sentence)
Expand All @@ -39,14 +37,19 @@ struct CoachingComparisonView: View {
.padding(.trailing, 18)

VStack(alignment: .leading, spacing: 8) {
HStack {
Rectangle()
.frame(width: 2, height: textHeight)
.foregroundStyle(Color(UIColor.point))
HStack(spacing: 8) {
GeometryReader { geomerty in
Rectangle()
.frame(height: geomerty.size.height)
.foregroundStyle(Color(UIColor.point))
}
.frame(width: 2)

Text("고친 문장")
.font(Font.custom("Pretendard", size: 16).weight(.medium))
.foregroundColor(Color(UIColor.point))

Spacer()
}

Text(coachingResponse.corrected_sentence)
Expand All @@ -60,13 +63,6 @@ struct CoachingComparisonView: View {
}
}

struct TextHeightPreferenceKey: PreferenceKey {
static var defaultValue: CGFloat = 0
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}

//#Preview {
// CoachingComparisonView()
//}
25 changes: 25 additions & 0 deletions Smeem-iOS/Smeem-iOS/Network/API/Coaching/CoachingEndPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,28 @@ extension CoachingEndPoint: BaseTargetType {
}
}
}

extension CoachingEndPoint {
var sampleData: Data {
switch self {
case .coaching:
return Data(
"""
{
"success": true,
"message": "학습 코칭 성공",
"data": {
"corrections": [
{
"original_sentence": "original text",
"corrected_sentence": "corrected text",
"reason": "수정된 문구입니다.",
"is_corrected": true
}
]
}
}
""".utf8)
}
}
}
52 changes: 0 additions & 52 deletions Smeem-iOS/Smeem-iOS/Network/API/Coaching/CoachingResponse.swift

This file was deleted.

32 changes: 32 additions & 0 deletions Smeem-iOS/Smeem-iOS/Network/API/Coaching/CoachingService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// CoachingService.swift
// Smeem-iOS
//
// Created by 황찬미 on 11/24/24.
//

import Foundation
import Moya

final class CoachingService: CoachingServiceProtocol {

var coachingProvider: MoyaProvider<CoachingEndPoint>!
var detailDiaryProvider: MoyaProvider<DetailDiaryEndPoint>

init(coachingProvider: MoyaProvider<CoachingEndPoint> = MoyaProvider<CoachingEndPoint>(plugins: [MoyaLoggingPlugin()]),
detailDiaryProvider: MoyaProvider<DetailDiaryEndPoint> = MoyaProvider<DetailDiaryEndPoint>(plugins: [MoyaLoggingPlugin()])) {
self.coachingProvider = coachingProvider
self.detailDiaryProvider = detailDiaryProvider
}

func coachingPostAPI(diaryID: Int) async throws -> CoachingsResponse {
let result: CoachingsResponse = try await coachingProvider.request(CoachingEndPoint.coaching(diaryId: diaryID))
return result
}

func detailDiaryAPI(diaryID: Int) async throws -> DetailDiaryResponse {
let result: DetailDiaryResponse = try await detailDiaryProvider.request(DetailDiaryEndPoint.detailDiary(diaryID: diaryID))
return result
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CoachingServiceProtocol.swift
// Smeem-iOS
//
// Created by 황찬미 on 11/24/24.
//

import Foundation

protocol CoachingServiceProtocol {
func coachingPostAPI(diaryID: Int) async throws -> CoachingsResponse
func detailDiaryAPI(diaryID: Int) async throws -> DetailDiaryResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Moya
import Foundation

enum DetailDiaryEndPoint {
case detailDiary(diaryID: Int)
Expand Down Expand Up @@ -38,3 +39,27 @@ extension DetailDiaryEndPoint: BaseTargetType {
"Authorization": "Bearer " + UserDefaultsManager.accessToken]
}
}

extension DetailDiaryEndPoint {
var sampleData: Data {
switch self {
case .detailDiary:
return Data(
"""
{
"success": true,
"message": "학습 상세 조회",
"data": {
"diaryId": 0,
"topic": "주제",
"content": "일기 내용입니다",
"createdAt": "2024년 5월 18일",
"username": "찬미"
}
}
""".utf8)
case .deleteDiary:
return Data()
}
}
}
Loading

0 comments on commit d599f0f

Please sign in to comment.