Skip to content

Commit

Permalink
[Merge] Merge branch 'develop' into feature/TeamSparker#129
Browse files Browse the repository at this point in the history
# Conflicts:
#	Spark-iOS/Spark-iOS/Source/NetworkServices/Room/RoomService.swift
#	Spark-iOS/Spark-iOS/Source/ViewControllers/Login/LoginVC.swift
  • Loading branch information
hyun99999 committed Jan 19, 2022
2 parents 75dd110 + 0cf632c commit 6fa95f6
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 22 deletions.
14 changes: 3 additions & 11 deletions Spark-iOS/Spark-iOS/Source/NetworkModels/Auth/Login.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,11 @@ import Foundation
// MARK: - Login

struct Login: Codable {
let accesstoken: Accesstoken

enum CodingKeys: String, CodingKey {
case accesstoken
}
}

// MARK: - Accesstoken

struct Accesstoken: Codable {
let accesstoken: String
let accesstoken: String?
let isNew: Bool

enum CodingKeys: String, CodingKey {
case accesstoken
case isNew
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class AuthAPI {

switch statusCode {
case 200:
return .success(decodedData.message)
return .success(decodedData.data ?? "None-Data")
case 400..<500:
return .requestErr(decodedData.message)
case 500:
Expand Down
15 changes: 15 additions & 0 deletions Spark-iOS/Spark-iOS/Source/NetworkServices/Room/RoomAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,21 @@ public class RoomAPI {
}
}

func setPurpose(roomID: Int, moment: String, purpose: String, completion: @escaping(NetworkResult<Any>) -> Void) {
roomProvider.request(.setPurpose(roomID: roomID, moment: moment, purpose: purpose)) { result in
switch result {
case .success(let response):
let statusCode = response.statusCode
let data = response.data
let networkResult = self.judgeStatus(by: statusCode, data)
completion(networkResult)

case .failure(let err):
print(err)
}
}
}

private func judgeStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<String>.self, from: data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum RoomService {
case startRoom(roomID: Int)
case setConsiderRest(roomID: Int, statusType: String)
case habitRoomDetailFetch(roomID: Int)
case setPurpose(roomID: Int, moment: String, purpose: String)
}

extension RoomService: TargetType {
Expand Down Expand Up @@ -49,6 +50,8 @@ extension RoomService: TargetType {
return "/room/\(roomID)/status"
case .habitRoomDetailFetch(let roomID):
return "/room/\(roomID)"
case .setPurpose(let roomID, _, _):
return "/room/\(roomID)/purpose"
}
}

Expand All @@ -74,6 +77,8 @@ extension RoomService: TargetType {
return .post
case .habitRoomDetailFetch:
return .get
case .setPurpose:
return .patch
}
}

Expand Down Expand Up @@ -108,6 +113,9 @@ extension RoomService: TargetType {
return .requestParameters(parameters: ["statusType": statusType], encoding: JSONEncoding.default)
case .habitRoomDetailFetch:
return .requestPlain
case .setPurpose(_, let moment, let purpose):
return .requestParameters(parameters: ["moment": moment, "purpose": purpose],
encoding: JSONEncoding.default)
}
}

Expand All @@ -130,8 +138,10 @@ extension RoomService: TargetType {
case .startRoom:
return Const.Header.authorizationHeader
case .setConsiderRest:
return Const.Header.authorizationHeader
case .habitRoomDetailFetch:
return Const.Header.authorizationHeader
case .habitRoomDetailFetch:
case .setPurpose:
return Const.Header.authorizationHeader
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ class GoalWritingVC: UIViewController {
let goalLineView = UIView()
let goalCountLabel = UILabel()
let completeButton = UIButton()
var titleText = "아침독서"

var maxLength: Int = 15
var titleText: String?
var roomId: Int?
var moment: String?
var purpose: String?

// MARK: - View Life Cycles

Expand All @@ -38,6 +42,8 @@ class GoalWritingVC: UIViewController {
setLayout()
setNotification()
setAddTarget()
setInitTextField(textField: whenTextField, countLabel: whenCountLabel, lineView: whenLineView)
setInitTextField(textField: goalTextField, countLabel: goalCountLabel, lineView: goalLineView)
}

// MARK: - Methods
Expand All @@ -49,7 +55,7 @@ class GoalWritingVC: UIViewController {
titleLabel.font = .h3Subtitle
titleLabel.textColor = .sparkBlack

subTitleLabel.text = "\(titleText) 습관방에서의 \n시간과 목표를 적어 보세요!"
subTitleLabel.text = "\(titleText ?? "기본") 습관방에서의 \n시간과 목표를 적어 보세요!"
subTitleLabel.numberOfLines = 2
subTitleLabel.font = .krRegularFont(ofSize: 18)
subTitleLabel.textColor = .sparkDarkGray
Expand All @@ -76,13 +82,15 @@ class GoalWritingVC: UIViewController {
completeButton.backgroundColor = .sparkGray
completeButton.isEnabled = false

whenTextField.text = "\(moment ?? "")"
whenTextField.borderStyle = .none
whenTextField.delegate = self
whenLineView.backgroundColor = .sparkGray
whenCountLabel.text = "0/15"
whenCountLabel.font = .p2SubtitleEng
whenCountLabel.textColor = .sparkDarkGray

goalTextField.text = "\(purpose ?? "")"
goalTextField.borderStyle = .none
goalTextField.delegate = self
goalLineView.backgroundColor = .sparkGray
Expand Down Expand Up @@ -134,6 +142,21 @@ class GoalWritingVC: UIViewController {
}
}

private func setInitTextField(textField: UITextField, countLabel: UILabel, lineView: UIView) {
if textField.hasText {
countLabel.text = "\(String(describing: textField.text?.count ?? 0))/15"

let attributedString = NSMutableAttributedString(string: countLabel.text ?? "")
attributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.sparkPinkred, range: ((countLabel.text ?? "") as NSString).range(of: "\(String(describing: textField.text?.count ?? 0))"))

countLabel.textColor = .sparkDarkGray
countLabel.attributedText = attributedString
lineView.backgroundColor = .sparkPinkred

ableButton()
}
}

@objc
private func textFieldDidChange(_ notification: Notification) {
if let textField = notification.object as? UITextField {
Expand Down Expand Up @@ -205,7 +228,7 @@ class GoalWritingVC: UIViewController {
// MARK: - 화면전환
@objc
func touchCompleteButton() {
print("작성 완료")
setPurposeWithAPI(moment: whenTextField.text ?? "", purpose: goalTextField.text ?? "")
}

@objc
Expand All @@ -214,6 +237,28 @@ class GoalWritingVC: UIViewController {
}
}

// MARK: - Network

extension GoalWritingVC {
func setPurposeWithAPI(moment: String, purpose: String) {
RoomAPI.shared.setPurpose(roomID: roomId ?? 0, moment: moment, purpose: purpose) { response in
switch response {
case .success(let message):
print("setPurposeWithAPI - success: \(message)")
self.dismiss(animated: true, completion: nil)
case .requestErr(let message):
print("setPurposeWithAPI - requestErr: \(message)")
case .pathErr:
print("setPurposeWithAPI - pathErr")
case .serverErr:
print("setPurposeWithAPI - serverErr")
case .networkFail:
print("setPurposeWithAPI - networkFail")
}
}
}
}

// MARK: - UITextFieldDelegate
extension GoalWritingVC: UITextFieldDelegate {
/// 여백 클릭 시
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,17 @@ extension LoginVC {
AuthAPI.shared.login(socialID: userID, fcmToken: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.fcmToken) ?? "") { response in
switch response {
case .success(let data):
if let message = data as? String {
if message == "회원가입을 하지 않은 사용자입니다" {
if let data = data as? Login {
if data.isNew {
// 회원가입을 하지 않은 사용자입니다.
guard let nextVC = UIStoryboard(name: Const.Storyboard.Name.profileSetting, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.profileSetting) as? ProfileSettingVC else { return }

nextVC.modalPresentationStyle = .fullScreen

self.present(nextVC, animated: true, completion: nil)
} else {
// 회원 정보를 불러왔습니다

// 회원 정보를 불러왔습니다.
UserDefaults.standard.set(data.accesstoken, forKey: Const.UserDefaultsKey.accessToken)

guard let nextVC = UIStoryboard(name: Const.Storyboard.Name.mainTabBar, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.mainTabBar) as? MainTBC else { return }

Expand Down
15 changes: 13 additions & 2 deletions Spark-iOS/Spark-iOS/Source/ViewControllers/Waiting/WaitingVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class WaitingVC: UIViewController {
var roomName: String?
var roomCode: String?
var roomId: Int?
var userMoment: String?
var userPurpose: String?

// MARK: - View Life Cycles

Expand Down Expand Up @@ -186,6 +188,11 @@ class WaitingVC: UIViewController {
guard let nextVC = UIStoryboard(name: Const.Storyboard.Name.goalWriting, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.goalWriting) as? GoalWritingVC else { return }

nextVC.modalPresentationStyle = .fullScreen
nextVC.titleText = roomName
nextVC.roomId = roomId
nextVC.moment = userMoment
nextVC.purpose = userPurpose

present(nextVC, animated: true, completion: nil)
}

Expand Down Expand Up @@ -246,6 +253,10 @@ extension WaitingVC {
// 사용자 본인 이름
self.nicknameLabel.text = user.nickname

// 사용자 목표, 시간
self.userPurpose = user.purpose
self.userMoment = user.moment

// 본인 방장 여부
if user.isHost {
self.startButton.isHidden = false
Expand All @@ -255,8 +266,8 @@ extension WaitingVC {

// 목표가 있을 경우, 목표와 시간 세팅
if user.isPurposeSet {
self.timeLabel.text = "시간 \(user.moment)"
self.goalLabel.text = "목표 \(user.purpose)"
self.timeLabel.text = "시간 \(String(describing: user.moment!))"
self.goalLabel.text = "목표 \(String(describing: user.purpose!))"
self.timeLabel.partFontChange(targetString: "시간", font: .p1Title)
self.goalLabel.partFontChange(targetString: "목표", font: .p1Title)
} else {
Expand Down

0 comments on commit 6fa95f6

Please sign in to comment.