Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] CommunityRepository 구현 #531

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
44 changes: 44 additions & 0 deletions HappyAnding/HappyAnding/Model/Answer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Answer.swift
// HappyAnding
//
// Created by 임정욱 on 4/4/24.
//

import Foundation

struct Answer: Identifiable, Codable, Equatable, Hashable {

let id: String
let postId : String
let createdAt: String
let author: String

var content: String
var isAccepted: Bool
var images: [String]
var thumbnailImages: [String]
var likedBy: [String:Bool]
var likeCount: Int

init(content: String, author: String, postId:String) {

self.id = UUID().uuidString
self.createdAt = Date().getDate()

self.content = content
self.isAccepted = false
self.author = author
self.postId = postId
self.images = []
self.thumbnailImages = []

self.likeCount = 0
self.likedBy = [:]
}

var dictionary: [String: Any] {
let data = (try? JSONEncoder().encode(self)) ?? Data()
return (try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]) ?? [:]
}
}
44 changes: 44 additions & 0 deletions HappyAnding/HappyAnding/Model/CommunityComment.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// CommunityComment.swift
// HappyAnding
//
// Created by 임정욱 on 4/4/24.
//

import Foundation


struct CommunityComment: Identifiable, Codable, Equatable, Hashable {

let id: String
let createdAt: String
let postId: String
let author: String
let parent: String?

var content: String
var likeCount: Int
var likedBy: [String:Bool]
var isAccepted: Bool

init(content: String, author: String,postId : String, parent: String? = nil) {

self.id = UUID().uuidString
self.createdAt = Date().getDate()

self.content = content
self.author = author
self.parent = parent
self.postId = postId

self.likeCount = 0
self.likedBy = [:]
self.isAccepted = false
}

var dictionary: [String: Any] {
let data = (try? JSONEncoder().encode(self)) ?? Data()
return (try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]) ?? [:]
}

}
47 changes: 47 additions & 0 deletions HappyAnding/HappyAnding/Model/Post.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Post.swift
// HappyAnding
//
// Created by 임정욱 on 4/4/24.
//

import Foundation

struct Post: Identifiable, Codable, Equatable, Hashable {

let id : String
let type: PostType
let createdAt: String
let author: String

var content: String
var shortcuts: [String]
var images: [String]
var thumbnailImages: [String]
var likedBy: [String:Bool]
var likeCount: Int
var commentCount: Int

init(type: PostType, content: String, author: String, shortcuts: [String] = []) {

self.id = UUID().uuidString
self.createdAt = Date().getDate()

self.type = type
self.content = content
self.author = author
self.shortcuts = shortcuts
self.images = []
self.thumbnailImages = []

self.likeCount = 0
self.commentCount = 0
self.likedBy = [:]

}

var dictionary: [String: Any] {
let data = (try? JSONEncoder().encode(self)) ?? Data()
return (try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]) ?? [:]
}
}
13 changes: 13 additions & 0 deletions HappyAnding/HappyAnding/Model/PostType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// PostType.swift
// HappyAnding
//
// Created by 임정욱 on 4/4/24.
//

import Foundation

enum PostType: String, Codable {
case General = "General"
case Question = "Question"
}
Loading