Skip to content

Commit

Permalink
#9 edit write, get board Api
Browse files Browse the repository at this point in the history
  • Loading branch information
JunseokNoh committed Aug 26, 2021
1 parent 50f8e3e commit b87ae64
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 99 deletions.
55 changes: 51 additions & 4 deletions KNU_CSE/KNU_CSE/Custom/Cell/FreeBoardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,26 @@ class FreeBoardCell : UITableViewCell {
}
}

var photoImage:UIImageView!{
didSet{
photoImage.image = UIImage(systemName: "photo")
photoImage.tintColor = .lightGray
}
}

var photoLabel:UILabel!{
didSet{
photoLabel.textAlignment = .left
photoLabel.textColor = UIColor.black
photoLabel.font = UIFont.systemFont(ofSize: 13, weight: .ultraLight)
photoLabel.sizeToFit()
photoLabel.text = ""
}
}

var commentImage:UIImageView!{
didSet{
let image = UIImage(systemName: "text.bubble.fill")
commentImage.image = image
commentImage.image = UIImage(systemName: "text.bubble.fill")
commentImage.tintColor = .lightGray
}
}
Expand Down Expand Up @@ -83,6 +99,7 @@ class FreeBoardCell : UITableViewCell {
self.setContentText(title: board.content)
self.setCommentText(title: String(board.commentCnt))
self.setCategoryText(title: board.category)
self.setImageLabel(count: self.board.images.count)
}
}

Expand All @@ -106,6 +123,8 @@ class FreeBoardCell : UITableViewCell {
titleLabel = UILabel()
contentLabel = UILabel()
categoryLabel = UILabel()
photoImage = UIImageView()
photoLabel = UILabel()
commentImage = UIImageView()
commentLabel = UILabel()
}
Expand All @@ -116,6 +135,8 @@ class FreeBoardCell : UITableViewCell {
self.contentView.addSubview(titleLabel)
self.contentView.addSubview(contentLabel)
self.contentView.addSubview(categoryLabel)
self.contentView.addSubview(photoImage)
self.contentView.addSubview(photoLabel)
self.contentView.addSubview(commentImage)
self.contentView.addSubview(commentLabel)
}
Expand Down Expand Up @@ -150,9 +171,16 @@ class FreeBoardCell : UITableViewCell {
make.height.equalTo(height*0.25)
}

self.commentLabel.snp.makeConstraints{ make in
self.photoImage.snp.makeConstraints{ make in
make.top.equalTo(self.contentLabel.snp.bottom).offset(3)
make.right.equalToSuperview().offset(-20)
make.right.equalTo(photoLabel.snp.left).offset(-5)
make.height.equalTo(height*0.15)
make.width.equalTo(height*0.15)
}

self.photoLabel.snp.makeConstraints{ make in
make.top.equalTo(self.contentLabel.snp.bottom).offset(3)
make.right.equalTo(commentImage.snp.left).offset(-10)
make.height.equalTo(height*0.15)
//make.width.equalTo(height*0.15)
}
Expand All @@ -164,6 +192,13 @@ class FreeBoardCell : UITableViewCell {
make.width.equalTo(height*0.15)
}

self.commentLabel.snp.makeConstraints{ make in
make.top.equalTo(self.contentLabel.snp.bottom).offset(3)
make.right.equalToSuperview().offset(-20)
make.height.equalTo(height*0.15)
//make.width.equalTo(height*0.15)
}

self.categoryLabel.snp.makeConstraints{ make in
make.top.equalTo(self.contentLabel.snp.bottom).offset(3)
make.left.equalToSuperview().offset(20)
Expand Down Expand Up @@ -198,6 +233,18 @@ extension FreeBoardCell{
func setCategoryText(title : String){
categoryLabel.text = "#\(title)"
}

func setImageLabel(count: Int){
if count == 0 {
photoImage.isHidden = true
photoLabel.isHidden = true
}
else if count > 0{
photoLabel.text = "\(String(count))"
photoImage.isHidden = false
photoLabel.isHidden = false
}
}
}


Expand Down
35 changes: 33 additions & 2 deletions KNU_CSE/KNU_CSE/Custom/Cell/ImageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class ImageCell : UICollectionViewCell {
}()

var imageURL: String = ""
var calledType: CalledType!{
didSet{
self.setUpConstraints()
}
}

override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -47,7 +52,7 @@ class ImageCell : UICollectionViewCell {
func draw(){
initUI()
addView()
setUpConstraints()

}

func initUI(){
Expand All @@ -56,10 +61,23 @@ class ImageCell : UICollectionViewCell {

func addView(){
self.contentView.addSubview(self.imageView)
self.contentView.addSubview(self.deleteBtn)
}

func setUpConstraints(){
switch calledType {
case .boardWrite:
self.constraintsOfBoardWrite()
case .boardDetail:
self.constraintsOfBoardDetail()
case .none:
break
}

}

func constraintsOfBoardWrite(){
self.contentView.addSubview(self.deleteBtn)

self.imageView.snp.makeConstraints{ make in
make.width.height.equalTo(80)
}
Expand All @@ -71,10 +89,23 @@ class ImageCell : UICollectionViewCell {
make.width.height.equalTo(btnSize)
}
}

func constraintsOfBoardDetail(){
self.imageView.snp.makeConstraints{ make in
make.width.height.equalTo(100)
}
}

enum CalledType{
case boardWrite
case boardDetail
}
}

extension ImageCell{
func setImage(image: UIImage) {
self.image = image
}
}


40 changes: 40 additions & 0 deletions KNU_CSE/KNU_CSE/Custom/View/CommentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit
import Foundation
import SnapKit

class CommentView: UIStackView {

Expand All @@ -19,6 +20,32 @@ class CommentView: UIStackView {
var deleteAction:((Int)->Void)?
var stackViews:[UIView] = []

var borderLine:UIView = {
var borderLine = UIView()
borderLine.layer.borderWidth = 0.5
borderLine.layer.borderColor = UIColor.lightGray.cgColor

return borderLine
}()

lazy var label : UILabel = {
var label = UILabel()
label.text = "작성된 댓글이 없습니다"
label.font = UIFont.systemFont(ofSize: 20, weight: .thin)
label.tintColor = .lightGray
label.textAlignment = .center

self.addSubview(self.borderLine)
self.borderLine.snp.makeConstraints{ make in
make.top.equalToSuperview()
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.height.equalTo(0.5)
}

return label
}()

init(storyboard:UIStoryboard?, navigationVC:UINavigationController?, currentVC:UIViewController, isHiddenReplyBtn:Bool){
self.storyboard = storyboard
self.navigationVC = navigationVC
Expand All @@ -31,6 +58,19 @@ class CommentView: UIStackView {
fatalError("init(coder:) has not been implemented")
}

func addInitialView(){
self.addSubview(self.label)
self.label.snp.makeConstraints{ make in
make.left.right.equalToSuperview()
make.height.equalTo(200)
}
}

func removeInitialView(){
self.label.removeFromSuperview()
self.label.snp.removeConstraints()
}

/// StackView에 CommentCell, ReplyCell 추가
func InitToStackView(comments:[Comment], board:Board){
for i in 0..<comments.count{
Expand Down
15 changes: 10 additions & 5 deletions KNU_CSE/KNU_CSE/View/Main/Board/Board/BoardModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,52 @@
import Foundation

class Board:BaseObject{
var image:String

var boardId : Int
var category : String
var title : String
var content : String
var author : String
var time : String
var profileImg: String
var commentCnt:Int
var images: [String]

let categoryDict:[String:String] = ["FREE":"자유게시판", "QNA":"질의응답"]

init(image:String, boardId:Int, category:String, title:String, content:String, author:String, time:String, commentCnt:Int) {
self.image = image
init(boardId:Int, category:String, title:String, content:String, author:String, time:String, profileImg:String, commentCnt:Int, images: [String]) {
self.boardId = boardId
self.category = category
self.title = title
self.content = content
self.author = author
self.time = time
self.profileImg = profileImg
self.commentCnt = commentCnt
self.images = images
super.init()
}

required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
// self.image = (try? container.decode(String.self, forKey: .image)) ?? ""
self.image = ""
self.boardId = (try? container.decode(Int.self, forKey: .boardId)) ?? 0
self.category = (try? container.decode(String.self, forKey: .category)) ?? ""
self.title = (try? container.decode(String.self, forKey: .title)) ?? ""
self.content = (try? container.decode(String.self, forKey: .content)) ?? ""
self.author = (try? container.decode(String.self, forKey: .author)) ?? ""
self.time = (try? container.decode(String.self, forKey: .time)) ?? ""
self.profileImg = (try? container.decode(String.self, forKey: .profileImg)) ?? ""
self.commentCnt = (try? container.decode(Int.self, forKey: .commentCnt)) ?? 0
self.images = (try? container.decode([String].self, forKey: .images)) ?? []

super.init()

self.category = categoryDict[category] ?? categoryDict["FREE"]!
}

enum CodingKeys: CodingKey {
case image, boardId, category, title, content, author, time, commentCnt
case boardId, category, title, content, author, time, profileImg, commentCnt, images
}
}

6 changes: 3 additions & 3 deletions KNU_CSE/KNU_CSE/View/Main/Board/Board/BoardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ extension BoardView : UITableViewDataSource{
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: FreeBoardCell.identifier, for: indexPath) as! FreeBoardCell

let board = self.boardViewModel.boards[indexPath.row]
cell.selectionStyle = .none
cell.board = board
cell.board = self.boardViewModel.boards[indexPath.row]
cell.height = self.cellRowHeight * 0.115
cell.selectionStyle = .none

return cell
}

Expand Down
1 change: 0 additions & 1 deletion KNU_CSE/KNU_CSE/View/Main/Board/Board/BoardViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct BoardViewModel{
var BoardsByPagingAction: BaseAction<BoardsWithPaging, errorHandler> = BaseAction()
var getBoardAction:BaseAction<[Board], errorHandler> = BaseAction()


var boards : [Board] = []
var category:Observable<String> = Observable("FREE")
var page:Int = 0
Expand Down
Loading

0 comments on commit b87ae64

Please sign in to comment.