Skip to content

Commit d0637a9

Browse files
authored
Merge pull request #160 from boostcampwm-2024/feat/#143-get-out-ugly-emoji
[FEAT/#143] 몬생긴 이모지를 교체했습니다
2 parents 4bcd608 + 316b8f2 commit d0637a9

File tree

12 files changed

+98
-40
lines changed

12 files changed

+98
-40
lines changed

PhotoGether/DataLayer/PhotoGetherData/PhotoGetherData/EmojiDTO.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@ import Foundation
22
import PhotoGetherDomainInterface
33

44
public struct EmojiDTO: Codable {
5-
let code: String
6-
let character: String
7-
let image: String
8-
let name: String
9-
let group: String
5+
let emoji, hexcode: String
6+
let group: EmojiGroup
107
let subgroup: String
8+
let annotation: String
9+
let tags, shortcodes, emoticons: [String]
10+
let directional, variation: Bool
11+
let variationBase: Bool?
12+
let unicode: Double
13+
let order: Int
14+
let skintone: Int?
15+
let skintoneCombination, skintoneBase: String?
1116
}
1217

1318
extension EmojiDTO {
1419
func toEntity() -> EmojiEntity {
1520
return .init(
16-
image: self.image,
17-
name: self.name
18-
)
21+
emoji: emoji,
22+
hexCode: hexcode,
23+
group: group,
24+
annotation: annotation
25+
)
1926
}
2027
}

PhotoGether/DataLayer/PhotoGetherData/PhotoGetherData/ShapeRepositoryImpl.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import PhotoGetherDomainInterface
44
import PhotoGetherNetwork
55

66
final public class ShapeRepositoryImpl: ShapeRepository {
7-
public func fetchEmojiList() -> AnyPublisher<[EmojiEntity], Never> {
8-
return localDataSource.fetchEmojiData(EmojiEndPoint())
7+
public func fetchEmojiList(_ group: EmojiGroup) -> AnyPublisher<[EmojiEntity], Never> {
8+
return localDataSource.fetchEmojiData(EmojiEndPoint(group: group))
99
.catch { [weak self] _ -> AnyPublisher<[EmojiDTO], Never> in
1010
guard let self else { return Just([]).eraseToAnyPublisher() }
1111

12-
return remoteDataSource.fetchEmojiData(EmojiEndPoint())
12+
return remoteDataSource.fetchEmojiData(EmojiEndPoint(group: group))
1313
.replaceError(with: [])
1414
.eraseToAnyPublisher()
1515
}
@@ -27,17 +27,22 @@ final public class ShapeRepositoryImpl: ShapeRepository {
2727
self.localDataSource = localDataSource
2828
self.remoteDataSource = remoteDataSource
2929
}
30+
3031
}
3132

33+
3234
fileprivate struct EmojiEndPoint: EndPoint {
33-
var baseURL: URL { URL(string: "https://api.api-ninjas.com")! }
34-
var path: String { "v1/emoji" }
35+
let group: EmojiGroup
36+
37+
var baseURL: URL { URL(string: "https://www.emoji.family")! }
38+
var path: String { "api/emojis" }
3539
var method: HTTPMethod { .get }
36-
/// offset 기준 30개씩 호출
37-
var parameters: [String: Any]? { ["group": "objects", "offset": 0] }
38-
var headers: [String: String]? {
39-
let apiKey = Bundle.main.object(forInfoDictionaryKey: "EMOJI_API_KEY") as? String ?? ""
40-
return ["X-Api-Key": apiKey]
41-
}
40+
var parameters: [String: Any]? { ["group": group.rawValue] }
41+
var headers: [String: String]? { nil }
4242
var body: Encodable? { nil }
43+
44+
init(group: EmojiGroup) {
45+
self.group = group
46+
}
4347
}
48+

PhotoGether/DomainLayer/PhotoGetherDomain/PhotoGetherDomain/UseCaseImpl/FetchEmojiListUseCaseImpl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import Foundation
33
import PhotoGetherDomainInterface
44

55
public final class FetchEmojiListUseCaseImpl: FetchEmojiListUseCase {
6-
public func execute() -> AnyPublisher<[EmojiEntity], Never> {
7-
return shapeRepository.fetchEmojiList()
6+
public func execute(_ group: EmojiGroup) -> AnyPublisher<[EmojiEntity], Never> {
7+
return shapeRepository.fetchEmojiList(group)
88
}
99

1010
private let shapeRepository: ShapeRepository
Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
11
import Foundation
22

33
public struct EmojiEntity: Decodable {
4-
public let image: String
5-
public let name: String
6-
7-
public init(image: String, name: String) {
8-
self.image = image
9-
self.name = name
4+
public let emoji: String
5+
public let hexCode: String
6+
public let group: EmojiGroup
7+
public let annotation: String
8+
public var emojiURL: URL? {
9+
guard let emojiURL = URL(string: "https://www.emoji.family/api/emojis")
10+
else { return nil }
11+
12+
let style = EmojiStyle.twemoji.rawValue
13+
let ext = "png"
14+
let size = "128"
15+
16+
return emojiURL
17+
.appendingPathComponent(hexCode)
18+
.appendingPathComponent(style)
19+
.appendingPathComponent(ext)
20+
.appendingPathComponent(size)
21+
}
22+
23+
public init(
24+
emoji: String,
25+
hexCode: String,
26+
group: EmojiGroup,
27+
annotation: String
28+
) {
29+
self.emoji = emoji
30+
self.hexCode = hexCode
31+
self.group = group
32+
self.annotation = annotation
33+
}
34+
35+
private enum EmojiStyle: String {
36+
case noto, twemoji, openmoji, blobmoji, fluent, fluentflat
1037
}
1138
}
39+
40+
public enum EmojiGroup: String, Codable {
41+
case smileysEmotion = "smileys-emotion"
42+
case peopleBody = "people-body"
43+
case component = "component"
44+
case animalsNature = "animals-nature"
45+
case foodDrink = "food-drink"
46+
case travelPlaces = "travel-places"
47+
case activities = "activities"
48+
case objects = "objects"
49+
case symbols = "symbols"
50+
}

PhotoGether/DomainLayer/PhotoGetherDomain/PhotoGetherDomainInterface/Repository/ShapeRepository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import Combine
22
import Foundation
33

44
public protocol ShapeRepository {
5-
func fetchEmojiList() -> AnyPublisher<[EmojiEntity], Never>
5+
func fetchEmojiList(_ group: EmojiGroup) -> AnyPublisher<[EmojiEntity], Never>
66
}

PhotoGether/DomainLayer/PhotoGetherDomain/PhotoGetherDomainInterface/UseCase/FetchEmojiListUseCase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import Combine
22
import Foundation
33

44
public protocol FetchEmojiListUseCase {
5-
func execute() -> AnyPublisher<[EmojiEntity], Never>
5+
func execute(_ group: EmojiGroup) -> AnyPublisher<[EmojiEntity], Never>
66
}

PhotoGether/PresentationLayer/EditPhotoRoomFeature/EditPhotoRoomFeature/Source/EditPhotoRoomGuestViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ public class EditPhotoRoomGuestViewController: BaseViewController, ViewControlle
120120
private func createStickerEntity(by entity: EmojiEntity) {
121121
let imageSize: CGFloat = 72
122122
let frame = calculateCenterPosition(imageSize: imageSize)
123+
guard let emojiURL = entity.emojiURL else { return }
123124

124125
let newSticker = StickerEntity(
125-
image: entity.image,
126+
image: emojiURL.absoluteString,
126127
frame: frame,
127128
owner: nil,
128129
latestUpdated: Date()

PhotoGether/PresentationLayer/EditPhotoRoomFeature/EditPhotoRoomFeature/Source/EditPhotoRoomHostViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ public class EditPhotoRoomHostViewController: BaseViewController, ViewController
140140
private func createStickerEntity(by entity: EmojiEntity) {
141141
let imageSize: CGFloat = 72
142142
let frame = calculateCenterPosition(imageSize: imageSize)
143+
guard let emojiURL = entity.emojiURL else { return }
143144

144145
let newSticker = StickerEntity(
145-
image: entity.image,
146+
image: emojiURL.absoluteString,
146147
frame: frame,
147148
owner: nil,
148149
latestUpdated: Date()

PhotoGether/PresentationLayer/EditPhotoRoomFeature/EditPhotoRoomFeature/Source/StickerBottomSheetViewController.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public final class StickerBottomSheetViewController: UIViewController, ViewContr
7878
.sink { [weak self] event in
7979
switch event {
8080
case .emoji(let entity):
81-
// TODO: 이모지 전달
8281
self?.sendEmoji(by: entity)
8382
}
8483
}
@@ -122,14 +121,12 @@ extension StickerBottomSheetViewController: UICollectionViewDataSource {
122121
_ collectionView: UICollectionView,
123122
cellForItemAt indexPath: IndexPath
124123
) -> UICollectionViewCell {
125-
guard let cell = collectionView.dequeueReusableCell(
126-
withReuseIdentifier: StickerCollectionViewCell.identifier,
127-
for: indexPath
128-
) as? StickerCollectionViewCell,
124+
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: StickerCollectionViewCell.identifier,
125+
for: indexPath) as? StickerCollectionViewCell,
129126
let emojiEntity = viewModel.emojiList.value[safe: indexPath.item]
130127
else { return UICollectionViewCell() }
131128

132-
cell.setupImage(by: emojiEntity)
129+
cell.setImage(by: emojiEntity)
133130

134131
return cell
135132
}

PhotoGether/PresentationLayer/EditPhotoRoomFeature/EditPhotoRoomFeature/Source/StickerBottomSheetViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public final class StickerBottomSheetViewModel {
2828
}
2929

3030
private func bind() {
31-
fetchEmojiListUseCase.execute()
31+
fetchEmojiListUseCase.execute(.objects)
3232
.sink { [weak self] emojiEntities in
3333
self?.emojiList.send(emojiEntities)
3434
}

0 commit comments

Comments
 (0)