Skip to content

Commit 3290bb4

Browse files
committed
Feat: Home 화면에서 감정 구슬 보여주기 (#T3-130)
1 parent c1d9f2d commit 3290bb4

14 files changed

Lines changed: 144 additions & 17 deletions

File tree

Projects/DataSource/Sources/DTO/EmotionResponseDTO.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import Domain
99
import Foundation
1010

1111
struct EmotionResponseDTO: Decodable {
12-
let type: String
13-
let name: String
14-
let imageUrl: String
12+
let type: String?
13+
let name: String?
14+
let imageUrl: String?
1515

1616
enum CodingKeys: String, CodingKey {
1717
case type = "emotionMarbleType"
@@ -21,7 +21,13 @@ struct EmotionResponseDTO: Decodable {
2121
}
2222

2323
extension EmotionResponseDTO {
24-
func toEmotionEntity() -> EmotionEntity {
24+
func toEmotionEntity() -> EmotionEntity? {
25+
guard
26+
let type,
27+
let name,
28+
let imageUrl
29+
else { return nil }
30+
2531
return EmotionEntity(
2632
emotionType: type,
2733
emotionName: name,

Projects/DataSource/Sources/Endpoint/EmotionEndpoint.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
enum EmotionEndpoint {
99
case fetchEmotions
10+
case fetchEmotion(date: String)
1011
case registerEmotion(emotion: String)
1112
}
1213

@@ -16,12 +17,20 @@ extension EmotionEndpoint: Endpoint {
1617
}
1718

1819
var path: String {
19-
return baseURL
20+
switch self {
21+
case .fetchEmotions:
22+
return baseURL
23+
case .fetchEmotion(let date):
24+
return baseURL + "/\(date)"
25+
case .registerEmotion(let emotion):
26+
return baseURL
27+
}
2028
}
2129

2230
var method: HTTPMethod {
2331
switch self {
2432
case .fetchEmotions: .get
33+
case .fetchEmotion: .get
2534
case .registerEmotion: .post
2635
}
2736
}
@@ -42,6 +51,8 @@ extension EmotionEndpoint: Endpoint {
4251
switch self {
4352
case .fetchEmotions:
4453
return [:]
54+
case .fetchEmotion:
55+
return [:]
4556
case .registerEmotion(let emotion):
4657
return ["emotionMarbleType": emotion]
4758
}

Projects/DataSource/Sources/Repository/EmotionRepository.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ final class EmotionRepository: EmotionRepositoryProtocol {
1919
return emotionEntities
2020
}
2121

22+
func fetchEmotion(date: String) async throws -> EmotionEntity? {
23+
let endpoint = EmotionEndpoint.fetchEmotion(date: date)
24+
guard let response = try await networkService.request(endpoint: endpoint, type: EmotionResponseDTO.self)
25+
else { throw NetworkError.unknown(description: "Emotion Reponse를 받아오지 못했습니다.") }
26+
27+
let emotionEntity = response.toEmotionEntity()
28+
return emotionEntity
29+
}
30+
2231
func registerEmotion(emotion: String) async throws -> [RecommendedRoutineEntity] {
2332
let endpoint = EmotionEndpoint.registerEmotion(emotion: emotion)
2433
guard let response = try await networkService.request(endpoint: endpoint, type: RecommendedRoutineListResponseDTO.self)

Projects/Domain/Sources/Protocol/Repository/EmotionRepositoryProtocol.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public protocol EmotionRepositoryProtocol {
1010
/// 감정 구슬 목록을 불러옵니다.
1111
/// - Returns: 조회된 감정 구슬 목록
1212
func fetchEmotions() async throws -> [EmotionEntity]
13+
14+
/// 해당하는 날짜에 등록한 감정 구슬을 조회합니다.
15+
/// - Parameter date: 조회하고 싶은 날짜 (yyyy-MM-dd)
16+
/// - Returns: 등록한 감정 구슬
17+
func fetchEmotion(date: String) async throws -> EmotionEntity?
1318

1419
/// 감정 구슬을 등록합니다.
1520
/// - Parameter emotion: 감정 구슬 String 값

Projects/Domain/Sources/Protocol/UseCase/EmotionUseCaseProtocol.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
// Created by 최정인 on 7/28/25.
66
//
77

8+
import Foundation
9+
810
public protocol EmotionUseCaseProtocol {
911
/// 감정 구슬 목록을 불러옵니다.
1012
/// - Returns: 조회된 감정 구슬 목록
1113
func fetchEmotions() async throws -> [EmotionEntity]
14+
15+
/// 해당하는 날짜에 등록된 감정 구슬을 조회합니다.
16+
/// - Parameter date: 조회하고 싶은 날짜
17+
/// - Returns: 감정 구슬
18+
func fetchEmotion(date: Date) async throws -> EmotionEntity?
1219
}

Projects/Domain/Sources/UseCase/Emotion/EmotionUseCase.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// Created by 최정인 on 7/28/25.
66
//
77

8+
import Foundation
9+
import Shared
10+
811
public final class EmotionUseCase: EmotionUseCaseProtocol {
912
private let emotionRepository: EmotionRepositoryProtocol
1013

@@ -16,4 +19,11 @@ public final class EmotionUseCase: EmotionUseCaseProtocol {
1619
let emotions = try await emotionRepository.fetchEmotions()
1720
return emotions
1821
}
22+
23+
public func fetchEmotion(date: Date) async throws -> EmotionEntity? {
24+
let dateString = date.convertToString(dateType: .yearMonthDate)
25+
26+
let emotion = try await emotionRepository.fetchEmotion(date: dateString)
27+
return emotion
28+
}
1929
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "default_emotion_graphic.png",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"filename" : "default_emotion_graphic@2x.png",
10+
"idiom" : "universal",
11+
"scale" : "2x"
12+
},
13+
{
14+
"filename" : "default_emotion_graphic@3x.png",
15+
"idiom" : "universal",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"author" : "xcode",
21+
"version" : 1
22+
}
23+
}
38.5 KB
Loading
124 KB
Loading
251 KB
Loading

0 commit comments

Comments
 (0)