From 3e8b5c8bf78b3198b4da302864962d275fef5186 Mon Sep 17 00:00:00 2001 From: YJU Date: Thu, 4 Apr 2024 01:51:32 +0900 Subject: [PATCH] =?UTF-8?q?[Init]=20#520=20-=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EB=B0=8F=20=EB=AA=A8=EB=8D=B8=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HappyAnding/HappyAnding/Model/Answer.swift | 33 ++++++++ .../HappyAnding/Model/CommunityComment.swift | 34 +++++++++ HappyAnding/HappyAnding/Model/Post.swift | 42 +++++++++++ .../Repository/CommunityRepository.swift | 75 +++++++++++++++++++ 4 files changed, 184 insertions(+) create mode 100644 HappyAnding/HappyAnding/Model/Answer.swift create mode 100644 HappyAnding/HappyAnding/Model/CommunityComment.swift create mode 100644 HappyAnding/HappyAnding/Model/Post.swift create mode 100644 HappyAnding/HappyAnding/Repository/CommunityRepository.swift diff --git a/HappyAnding/HappyAnding/Model/Answer.swift b/HappyAnding/HappyAnding/Model/Answer.swift new file mode 100644 index 00000000..88b1f4a4 --- /dev/null +++ b/HappyAnding/HappyAnding/Model/Answer.swift @@ -0,0 +1,33 @@ +// +// Answer.swift +// HappyAnding +// +// Created by 임정욱 on 4/4/24. +// + +import Foundation + +struct Answer: Identifiable, Codable, Equatable, Hashable { + var id = UUID().uuidString + var body: String = "" + var postedBy: String = "" + var postedAt:[String] = [Date().getDate()] + var images: [String] = [] + var likesCount: Int = 0 + var isAccepted: Bool = false + var comments: [String] = [] + + var dictionary: [String: Any] { + let data = (try? JSONEncoder().encode(self)) ?? Data() + return (try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]) ?? [:] + } + + init(body: String, postedBy: String, images: [String] = [], likesCount: Int = 0, isAccepted: Bool = false, comments: [String] = []) { + self.body = body + self.postedBy = postedBy + self.images = images + self.likesCount = likesCount + self.isAccepted = isAccepted + self.comments = comments + } +} diff --git a/HappyAnding/HappyAnding/Model/CommunityComment.swift b/HappyAnding/HappyAnding/Model/CommunityComment.swift new file mode 100644 index 00000000..82e993a3 --- /dev/null +++ b/HappyAnding/HappyAnding/Model/CommunityComment.swift @@ -0,0 +1,34 @@ +// +// CommunityComment.swift +// HappyAnding +// +// Created by 임정욱 on 4/4/24. +// + +import Foundation + + +struct CommunityComment: Identifiable, Codable, Equatable, Hashable { + var id: String = UUID().uuidString + var body: String + var author: String + var postedAt: String = Date().getDate() + var likesCount: Int = 0 + var isAccepted: Bool = false + var comments: [String] = [] + + + var dictionary: [String: Any] { + let data = (try? JSONEncoder().encode(self)) ?? Data() + return (try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]) ?? [:] + } + + + init(body: String, author: String, images: [String] = [], likesCount: Int = 0, isAccepted: Bool = false, comments: [String] = []) { + self.body = body + self.author = author + self.likesCount = likesCount + self.isAccepted = isAccepted + self.comments = comments + } +} diff --git a/HappyAnding/HappyAnding/Model/Post.swift b/HappyAnding/HappyAnding/Model/Post.swift new file mode 100644 index 00000000..b53a4e34 --- /dev/null +++ b/HappyAnding/HappyAnding/Model/Post.swift @@ -0,0 +1,42 @@ +// +// Post.swift +// HappyAnding +// +// Created by 임정욱 on 4/4/24. +// + +import Foundation + +struct Post: Identifiable, Codable, Equatable, Hashable { + var id = UUID().uuidString + var type: String = "" + var title: String = "" + var body: String = "" + var postedBy: String + var postedAt:[String] = [Date().getDate()] + var images: [String] = [] + var likesCount: Int = 0 + var commentsCount: Int + var tags: [String] = [] + var comments: [String] = [] + var answers: [String] = [] + + + var dictionary: [String: Any] { + let data = (try? JSONEncoder().encode(self)) ?? Data() + return (try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]) ?? [:] + } + + init(type: String, title: String, body: String, postedBy: String, images: [String], likesCount: Int, commentsCount: Int, tags: [String], comments: [String], answers: [String]) { + self.type = type + self.title = title + self.body = body + self.postedBy = postedBy + self.images = images + self.likesCount = likesCount + self.commentsCount = commentsCount + self.tags = tags + self.comments = comments + self.answers = answers + } +} diff --git a/HappyAnding/HappyAnding/Repository/CommunityRepository.swift b/HappyAnding/HappyAnding/Repository/CommunityRepository.swift new file mode 100644 index 00000000..76782463 --- /dev/null +++ b/HappyAnding/HappyAnding/Repository/CommunityRepository.swift @@ -0,0 +1,75 @@ +// +// File.swift +// HappyAnding +// +// Created by 임정욱 on 4/3/24. +// + +import Foundation +import FirebaseCore +import FirebaseFirestore +import FirebaseFirestoreSwift +import FirebaseAuth + + + +class CommunityRepository { + + private let db = Firestore.firestore() + + + + +//MARK: - 글 관련 함수 + + func getPosts() { + + } + + func createPost() { + + } + + func updatePost() { + + } + + func deletePost() { + + } + + func likePost() { + + } + + func unLikePost() { + + } + + +//MARK: - 댓글 관련 함수 + + func getComments() { + + } + + func createComment() { + + } + + func updateComment() { + + } + + func deleteComment() { + + } + + func likeComment() { + + } + + func unLikeComment() { + + } +}