Skip to content

Commit

Permalink
#9 set write Reply Request Api
Browse files Browse the repository at this point in the history
  • Loading branch information
JunseokNoh committed Aug 12, 2021
1 parent dd79198 commit c339ea6
Show file tree
Hide file tree
Showing 55 changed files with 278 additions and 250 deletions.
32 changes: 26 additions & 6 deletions KNU_CSE/KNU_CSE.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
681D382026ADAE85000D9FE8 /* ReplyViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 681D381F26ADAE85000D9FE8 /* ReplyViewModel.swift */; };
681D382326ADC5D4000D9FE8 /* BoardSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 681D382226ADC5D4000D9FE8 /* BoardSearchView.swift */; };
681D382626ADC61D000D9FE8 /* BoardWriteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 681D382526ADC61D000D9FE8 /* BoardWriteView.swift */; };
686889C626C55F6800486985 /* CommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 686889C526C55F6800486985 /* CommentView.swift */; };
68C7629126B96EFA00792498 /* CategoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C7629026B96EFA00792498 /* CategoryCell.swift */; };
68C7629326B99F7F00792498 /* ResponseBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C7629226B99F7F00792498 /* ResponseBody.swift */; };
68C7629626BC0CAE00792498 /* BaseViewModelChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C7629526BC0CAE00792498 /* BaseViewModelChange.swift */; };
Expand Down Expand Up @@ -166,6 +167,7 @@
681D381F26ADAE85000D9FE8 /* ReplyViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReplyViewModel.swift; sourceTree = "<group>"; };
681D382226ADC5D4000D9FE8 /* BoardSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoardSearchView.swift; sourceTree = "<group>"; };
681D382526ADC61D000D9FE8 /* BoardWriteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoardWriteView.swift; sourceTree = "<group>"; };
686889C526C55F6800486985 /* CommentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentView.swift; sourceTree = "<group>"; };
68C7629026B96EFA00792498 /* CategoryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryCell.swift; sourceTree = "<group>"; };
68C7629226B99F7F00792498 /* ResponseBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseBody.swift; sourceTree = "<group>"; };
68C7629526BC0CAE00792498 /* BaseViewModelChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewModelChange.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -413,6 +415,25 @@
path = BoardWrite;
sourceTree = "<group>";
};
686889C326C5524400486985 /* View */ = {
isa = PBXGroup;
children = (
68F1A5FA26A01028007B4B86 /* SignIn */,
68F1A5F026A0090B007B4B86 /* SignUp */,
68F861E426B2EE9100934BD2 /* FindPw */,
68F1A61026A31169007B4B86 /* Main */,
);
path = View;
sourceTree = "<group>";
};
686889C426C55F4900486985 /* View */ = {
isa = PBXGroup;
children = (
686889C526C55F6800486985 /* CommentView.swift */,
);
path = View;
sourceTree = "<group>";
};
68C7629426BC0CA200792498 /* Base */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -467,10 +488,7 @@
children = (
68F1A5F426A0090B007B4B86 /* Custom */,
68F1A60126A0A72D007B4B86 /* Color */,
68F1A5FA26A01028007B4B86 /* SignIn */,
68F1A5F026A0090B007B4B86 /* SignUp */,
68F861E426B2EE9100934BD2 /* FindPw */,
68F1A61026A31169007B4B86 /* Main Tab */,
686889C326C5524400486985 /* View */,
68F1A5E726A008FF007B4B86 /* Network Service */,
68F1A5B726A0088B007B4B86 /* AppDelegate.swift */,
68F1A5B926A0088B007B4B86 /* SceneDelegate.swift */,
Expand Down Expand Up @@ -524,6 +542,7 @@
68F1A5F426A0090B007B4B86 /* Custom */ = {
isa = PBXGroup;
children = (
686889C426C55F4900486985 /* View */,
68C762A926C4222F00792498 /* Observable */,
681D37CB26A47FC7000D9FE8 /* Delegate */,
681D37C226A4542F000D9FE8 /* Cell */,
Expand Down Expand Up @@ -596,7 +615,7 @@
path = Alert;
sourceTree = "<group>";
};
68F1A61026A31169007B4B86 /* Main Tab */ = {
68F1A61026A31169007B4B86 /* Main */ = {
isa = PBXGroup;
children = (
68D5448F26A40E220072C2A4 /* KNU Notice */,
Expand All @@ -606,7 +625,7 @@
681D37B326A413AD000D9FE8 /* MyPage */,
68F1A61126A3120D007B4B86 /* TabView.swift */,
);
path = "Main Tab";
path = Main;
sourceTree = "<group>";
};
68F1A61526A344E2007B4B86 /* KeyChain */ = {
Expand Down Expand Up @@ -984,6 +1003,7 @@
68F1A61226A3120D007B4B86 /* TabView.swift in Sources */,
68F1A5BA26A0088B007B4B86 /* SceneDelegate.swift in Sources */,
68C7629A26BC403700792498 /* BaseAction.swift in Sources */,
686889C626C55F6800486985 /* CommentView.swift in Sources */,
681D380F26A9FC51000D9FE8 /* CommentCell.swift in Sources */,
68F1A5F626A0090B007B4B86 /* SignUpModel.swift in Sources */,
681D381E26ADAC4F000D9FE8 /* ReplyView.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions KNU_CSE/KNU_CSE/Custom/Cell/ReplyCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class ReplyCell : UIView {
}
}

var reply:Reply
var reply:Comment

init(reply:Reply) {
init(reply:Comment) {
self.reply = reply
super.init(frame: CGRect())
self.setImage()
Expand Down
4 changes: 4 additions & 0 deletions KNU_CSE/KNU_CSE/Custom/Delegate/DataDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ protocol BoardDataDelegate{
protocol CommentDataDelegate {
func sendComment(board:Board, comment:Comment)
}

protocol ReplyDataDelegate{
func sendReply(replys:[Comment])
}
101 changes: 101 additions & 0 deletions KNU_CSE/KNU_CSE/Custom/View/CommentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//
// CommentView.swift
// KNU_CSE
//
// Created by junseok on 2021/08/12.
//

import UIKit
import Foundation

class CommentView: UIStackView {

var delegate:CommentDataDelegate?
var storyboard:UIStoryboard?
var navigationVC:UINavigationController?
var isHiddenReplyBtn:Bool

init(storyboard:UIStoryboard?, navigationVC:UINavigationController?, isHiddenReplyBtn:Bool){
self.storyboard = storyboard
self.navigationVC = navigationVC
self.isHiddenReplyBtn = isHiddenReplyBtn
super.init(frame: CGRect.zero)
}

required init(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

/// StackView에 CommentCell, ReplyCell 추가
func InitToStackView(comments:[Comment], board:Board){
for i in 0..<comments.count{
let comment = comments[i]
self.addCommentToStackView(comment,board)
}
}

func addCommentToStackView(_ comment:Comment, _ board:Board){
DispatchQueue.main.async {
let commentView = CommentCell(comment: comment)
commentView.replyBtn.isHidden = self.isHiddenReplyBtn
commentView.replyBtn.addAction {
self.pushView(board, comment)
}
self.addArrangedSubview(commentView)
if let replyList = comment.replyList{
for j in 0..<replyList.count{
let reply = comment.replyList[j]
let replyView = ReplyCell(reply: reply)
self.addArrangedSubview(replyView)
}
}
}
}

func addReplyToStackView(_ reply:Comment){
DispatchQueue.main.async {
let replyView = ReplyCell(reply: reply)
self.addArrangedSubview(replyView)
}
}

func insertReplyToStackView(reply:Comment, index:Int){
DispatchQueue.main.async {
let replyView = ReplyCell(reply: reply)
self.insertArrangedSubview(replyView, at: index)
}
}

func updateToStackView(Comments:[Comment], replys:[Comment], board:Board){
var targetIndex = 0

guard replys.count > 0 else{
return
}

for comment in Comments{
targetIndex += 1
if comment.commentId == replys[0].parentId{
if let replyList = comment.replyList{
targetIndex += replyList.count
targetIndex -= replys.count
}

for reply in replys{
insertReplyToStackView(reply: reply, index: targetIndex)
targetIndex += 1
}
break
}
}
}
}

extension CommentView{
func pushView(_ board:Board, _ comment:Comment){
let pushVC = self.storyboard?.instantiateViewController(withIdentifier: "ReplyView") as? ReplyView
self.navigationVC?.pushViewController(pushVC!, animated: true)
self.delegate = pushVC
self.delegate?.sendComment(board:board, comment: comment)
}
}
87 changes: 0 additions & 87 deletions KNU_CSE/KNU_CSE/Main Tab/Board/Reply/ReplyViewModel.swift

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Comment:BaseObject{
var author:String!
var content:String!
var time:String!
var replyList:[Reply]!
var replyList:[Comment]!

var image:String!

Expand All @@ -36,7 +36,7 @@ class Comment:BaseObject{
self.content = (try? container.decode(String.self, forKey: .content)) ?? ""
self.time = (try? container.decode(String.self, forKey: .time)) ?? ""
self.image = (try? container.decode(String.self, forKey: .image)) ?? ""
self.replyList = (try? container.decode([Reply].self, forKey: .replyList))
self.replyList = (try? container.decode([Comment].self, forKey: .replyList)) ?? []
super.init()
}

Expand All @@ -46,26 +46,6 @@ class Comment:BaseObject{

}

struct Reply:Codable{
var boardId:Int!
var commentId:Int
var parentId:Int!
var author:String!
var content:String!
var time:String!
var replyList:[Reply]!

var image:String!

init(image:String, commentId:Int, content:String, time:String, author:String) {
self.image = image
self.commentId = commentId
self.content = content
self.time = time
self.author = author
}
}

class CommentTextModel:BaseObject{
var boardId:Int!
var content:String!
Expand Down
Loading

0 comments on commit c339ea6

Please sign in to comment.