Skip to content

Commit

Permalink
Merge pull request #18 from KNU-CSE-APP/#9/Implementing-Rest-api
Browse files Browse the repository at this point in the history
Add Admin Page
  • Loading branch information
JunseokNoh authored Sep 24, 2021
2 parents b05ac1f + f2045fb commit 2ed0069
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 55 deletions.
1 change: 0 additions & 1 deletion KNU_CSE/KNU_CSE/Custom/Cell/ReplyCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class ReplyCell : UIView {
fatalError("init(coder:) has not been implemented")
}


func setImage(){
do {
if let loadedImage = self.reply.image, let url = URL(string: loadedImage){
Expand Down
10 changes: 5 additions & 5 deletions KNU_CSE/KNU_CSE/Custom/Delegate/DataDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
import Foundation
import UIKit

protocol BoardDataDelegate{
protocol BoardDataDelegate: AnyObject{
func sendBoardData(board:Board)
func deleteBoard(deleteBoard: @escaping ()->Void)
func editBoard(editBoard: @escaping ()->Void)
}

protocol CommentDataDelegate {
protocol CommentDataDelegate: AnyObject{
func sendComment(board:Board, comment:Comment)
}

protocol ReplyDataDelegate{
protocol ReplyDataDelegate: AnyObject{
func sendReply(comment:Comment?)
}

protocol ImageDelegate{
protocol ImageDelegate: AnyObject{
func sendImages(images:[UIImage], index:Int)
}

protocol BoardDataforEditDelegate{
protocol BoardDataforEditDelegate: AnyObject{
func sendBoard(board: Board?, images: [UIImage]?, imageURLs: [String]?, closure:@escaping ()->())
}
2 changes: 1 addition & 1 deletion KNU_CSE/KNU_CSE/Custom/View/CommentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SnapKit

class CommentView: UIStackView {

private var delegate:CommentDataDelegate?
weak var delegate:CommentDataDelegate?
private var storyboard:UIStoryboard?
private var navigationVC:UINavigationController?
private var isHiddenReplyBtn:Bool
Expand Down
2 changes: 1 addition & 1 deletion KNU_CSE/KNU_CSE/Network Service/Base/BaseApiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension BaseApiRequest{
// let port = "5002"
//
let ip = "3.34.14.12"
let port = ""
let port = "8089"

if port == ""{
return "http://\(ip)/\(domain)"
Expand Down
2 changes: 1 addition & 1 deletion KNU_CSE/KNU_CSE/View/Main/Board/Board/BoardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BoardView : BaseUIViewController, ViewProtocol{

var boardViewModel : BoardViewModel = BoardViewModel()
var cellRowHeight : CGFloat!
var boardDelegate:BoardDataDelegate?
weak var boardDelegate:BoardDataDelegate?

var boardTableView :UITableView!{
didSet{
Expand Down
21 changes: 13 additions & 8 deletions KNU_CSE/KNU_CSE/View/Main/Board/BoardDetail/BoardDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
class BoardDetailView:BaseUIViewController, ViewProtocol{

private var boardDetailViewModel = BoardDetailViewModel()
private var delegate:CommentDataDelegate?
weak var delegate:CommentDataDelegate?

private let commentPlaceHolder = "댓글을 입력해주세요."
private var stackViewSize: Int = 0
Expand All @@ -20,6 +20,7 @@ class BoardDetailView:BaseUIViewController, ViewProtocol{
private var textViewHeight:CGFloat!
private var textViewPadding:CGFloat = 5
private var imageWidth:CGFloat!
var test = 10

private lazy var rightBtn:UIBarButtonItem = {
var rightBtn = UIBarButtonItem(image: UIImage.init(systemName: "ellipsis")?.rotate(radians: .pi/2)?.withTintColor(UIColor.lightGray), style: .plain, target: self, action: #selector(addActionSheet))
Expand Down Expand Up @@ -242,13 +243,18 @@ class BoardDetailView:BaseUIViewController, ViewProtocol{
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.boardDetailViewModel.getBoardRequest()

// print("DetailView \(CFGetRetainCount(self))")
// print("stackView \(CFGetRetainCount(self.stackView))")
// print("photoScrollView \(CFGetRetainCount(self.photoView))")
// print("photoView \(CFGetRetainCount(self.photoView))")
//
// print("textFieldBtn \(CFGetRetainCount(self.textFieldBtn))")
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
print("DetailViwe \(CFGetRetainCount(self))")
print("stackView \(CFGetRetainCount(self.stackView))")
print("photoView \(CFGetRetainCount(self.photoView))")

}

func initUI(){
Expand Down Expand Up @@ -446,10 +452,9 @@ class BoardDetailView:BaseUIViewController, ViewProtocol{

var actionSheet = ActionSheet(viewController: self)
actionSheet.popUpActionSheet(edit_text: "게시글 수정", editAction: { [weak self] action in

self?.pushView(identifier: "BoardWriteView", typeOfVC: BoardWriteView.self){ VC in
VC.parentType = .Edit
var delegate: BoardDataforEditDelegate?
weak var delegate: BoardDataforEditDelegate?
delegate = VC
delegate?.sendBoard(board: (self?.boardDetailViewModel.board.value), images: (self?.uiImages), imageURLs: self?.boardDetailViewModel.board.value.images){ [weak self] in
self?.boardDetailViewModel.getBoardRequest()
Expand Down Expand Up @@ -616,8 +621,8 @@ extension BoardDetailView{
if let VC = self?.storyboard?.instantiateViewController(withIdentifier: "DetailImageView") as? DetailImageView, let images = self?.uiImages{
VC.modalPresentationStyle = .fullScreen
self?.present(VC, animated: true)
let delegate: ImageDelegate = VC
delegate.sendImages(images: images, index: i)
weak var delegate: ImageDelegate? = VC
delegate?.sendImages(images: images, index: i)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions KNU_CSE/KNU_CSE/View/Main/Board/BoardTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ extension BoardTabView:UICollectionViewDataSource, UICollectionViewDelegate{
}else if indexPath.row == 1{
boardVC.boardViewModel.category.value = "QNA"
boardVC.boardViewModel.getBoardsByPaging()
}else{

}else if indexPath.row == 2{
boardVC.boardViewModel.category.value = "ADMIN"
boardVC.boardViewModel.getBoardsByPaging()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ class DetailImageView:UIViewController, ViewProtocol{
var pageVC = PageViewController(transitionStyle: .scroll,navigationOrientation: .horizontal)
pageVC.dataSource = self
pageVC.delegate = self
pageVC.backBtn.addAction {
self.dismiss(animated: true)
pageVC.backBtn.addAction { [weak self] in
self?.dismiss(animated: true)
}
print(index, images)
let firstVC = instantiateViewController(image: images[index], index: self.index)
pageVC.setViewControllers([firstVC], direction: .forward, animated: true, completion: nil)
pageVC.didMove(toParent: self)
Expand All @@ -41,6 +40,10 @@ class DetailImageView:UIViewController, ViewProtocol{
super.viewDidLoad()
}

deinit {
print("deinit DetailImageView")
}

func initUI() {
self.view.backgroundColor = .black
}
Expand Down
64 changes: 34 additions & 30 deletions KNU_CSE/KNU_CSE/View/Main/Board/Reply/ReplyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import UIKit

class ReplyView:BaseUIViewController, ViewProtocol{

var delegate:ReplyDataDelegate?
weak var delegate:ReplyDataDelegate?

var replyViewModel = ReplyViewModel()
private var replyViewModel = ReplyViewModel()

let replyPlaceHolder = "답글을 입력해주세요."
var textViewHeight:CGFloat!
var textViewPadding:CGFloat = 5
var imageWidth:CGFloat!
private let replyPlaceHolder = "답글을 입력해주세요."
private var textViewHeight:CGFloat!
private var textViewPadding:CGFloat = 5
private var imageWidth:CGFloat!

var scrollView:UIScrollView!{
private var scrollView:UIScrollView!{
didSet{
scrollView.alwaysBounceVertical = true
let tap = UITapGestureRecognizer(target: view, action: #selector(UIView.endEditing))
Expand All @@ -27,29 +27,29 @@ class ReplyView:BaseUIViewController, ViewProtocol{
}
}

var boardContentView:UIView = UIView()
private var boardContentView:UIView = UIView()

var stackView:CommentView!{
private var stackView:CommentView!{
didSet{
stackView.axis = .vertical
stackView.distribution = .fill
}
}

var textFieldView:UIView!{
private var textFieldView:UIView!{
didSet{
textFieldView.backgroundColor = .white
}
}

var borderLine:UIView!{
private var borderLine:UIView!{
didSet{
borderLine.layer.borderWidth = 0.3
borderLine.layer.borderColor = UIColor.lightGray.cgColor
}
}

var textField:UITextView!{
private var textField:UITextView!{
didSet{
textField.delegate = self
textField.backgroundColor = UIColor.gray.withAlphaComponent(0.1)
Expand All @@ -67,7 +67,7 @@ class ReplyView:BaseUIViewController, ViewProtocol{
}
}

var placeholderLabel : UILabel!{
private var placeholderLabel : UILabel!{
didSet{
placeholderLabel.text = replyPlaceHolder
placeholderLabel.font = textField.font
Expand All @@ -76,14 +76,14 @@ class ReplyView:BaseUIViewController, ViewProtocol{
}
}

var textFieldBtn:UIButton!{
private var textFieldBtn:UIButton!{
didSet{
let image = UIImage(systemName: "paperplane.circle.fill")?.resized(toWidth: imageWidth)
textFieldBtn.setImage(image?.withTintColor(Color.mainColor), for: .normal)
textFieldBtn.tintColor = Color.mainColor
textFieldBtn.setTitleColor(Color.mainColor.withAlphaComponent(0.5), for: .highlighted)
textFieldBtn.addAction {
self.replyViewModel.writeReplyRequest()
textFieldBtn.addAction { [weak self] in
self?.replyViewModel.writeReplyRequest()
}
textFieldBtn.isHidden = true
}
Expand Down Expand Up @@ -111,6 +111,10 @@ class ReplyView:BaseUIViewController, ViewProtocol{
self.sendReplyToParent(comment: self.replyViewModel.comment.value)
}

deinit {
print("deinit ReplyView")
}

func initUI(){
scrollView = UIScrollView()

Expand Down Expand Up @@ -263,8 +267,8 @@ extension ReplyView:UITextViewDelegate{
}

func textViewBinding(){
replyViewModel.bind{ text in
self.replyViewModel.replyBody.content = text
replyViewModel.bind{ [weak self] text in
self?.replyViewModel.replyBody.content = text
}
}

Expand Down Expand Up @@ -305,17 +309,17 @@ extension ReplyView{
func BindingWriteReply(){
self.replyViewModel.writeReplyListener.binding(successHandler: { result in

}, failHandler: { Error in
}, failHandler: { [weak self] Error in
Alert(title: "실패", message: "네트워크 상태를 확인하세요", viewController: self).popUpDefaultAlert(action: nil)
}
, asyncHandler: {
self.indicator.viewController = self
self.indicator.startIndicator()
, asyncHandler: { [weak self] in
self?.indicator.viewController = self
self?.indicator.startIndicator()
}
, endHandler: {
self.replyViewModel.getCommentRequest()
self.indicator.stopIndicator()
self.completedWriteComment()
, endHandler: { [weak self] in
self?.replyViewModel.getCommentRequest()
self?.indicator.stopIndicator()
self?.completedWriteComment()
})
}

Expand All @@ -334,7 +338,7 @@ extension ReplyView{
}else{//댓글을 삭제한경우
self?.replyViewModel.comment.value = nil
}
}, failHandler: { Error in
}, failHandler: { [weak self] Error in
Alert(title: "실패", message: "네트워크 상태를 확인하세요", viewController: self).popUpDefaultAlert(action: nil)
}, asyncHandler: {

Expand All @@ -352,7 +356,7 @@ extension ReplyView{
}
}
}else if !result.success, let message = result.error?.message{
Alert(title: "실패", message: message, viewController: self!).popUpDefaultAlert(action: nil)
Alert(title: "실패", message: message, viewController: self).popUpDefaultAlert(action: nil)
}

}, failHandler: {[weak self] Error in
Expand All @@ -378,8 +382,8 @@ extension ReplyView{
, cancel_text: "취소")
}

self.stackView.setDeleteAlertAction{ commentId in
Alert(title: "삭제", message: "댓글을 삭제하겠습니까?", viewController: self).popUpNormalAlert(){ [weak self] action in
self.stackView.setDeleteAlertAction{ [weak self] commentId in
Alert(title: "삭제", message: "댓글을 삭제하겠습니까?", viewController: self).popUpNormalAlert(){ action in
self?.replyViewModel.removedCommentId = commentId
self?.replyViewModel.deleteCommentRequest(commentId: commentId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ extension ReservationView:UICollectionViewDataSource, UICollectionViewDelegate{
extension ReservationView:ClassDataDelegate{
func sendData(data: ClassRoom) {
self.reservationViewModel.setClassRoom(classRoom: data)
self.setNavigationTitle(title: "\(data.building)-\(data.roomId)")
self.setNavigationTitle(title: "\(data.building)-\(data.roomNum)")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class UserInformView:BaseUIViewController, ViewProtocol{
self?.addActionSheet()
}
}catch {}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extension ReservationCheckView : UITableViewDataSource{

extension ReservationCheckView:ReservationCheckDelegate{
func sendData(classRoom: ClassRoom, classSeat: ClassSeat) {
self.reservationCheckViewModel = ReservationCheckViewModel(email: "sdfsdfs", building: classRoom.building, classSeat: classSeat, classRoom: classRoom)
self.reservationCheckViewModel = ReservationCheckViewModel(email: "", building: classRoom.building, classSeat: classSeat, classRoom: classRoom)

contentList = [contentText.inform(classRoom.building,String(classRoom.roomNum),String(classSeat.seatNumber)), contentText.status("예약 완료"), contentText.startTime(""), contentText.endTime("")]
}
Expand Down

0 comments on commit 2ed0069

Please sign in to comment.