Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions EATSSU/App/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,25 @@
/// 다시 시도해주세요.
"notification_error_unknown_description" = "Please try again.";

// MARK: - Notification Inbox (알림함)

/// "알림"
"notification.inboxTitle" = "Notifications";
/// "모두 읽음"
"notification.readAll" = "Mark all as read";
/// "새로운 알림이 없어요."
"notification.emptyTitle" = "No new notifications.";
/// "찜한 메뉴가 나오면 알림으로 알려드릴게요!"
"notification.emptySubtitle" = "We'll notify you when a saved menu is served!";
/// "7일 전 알림까지 확인할 수 있어요"
"notification.retentionNotice" = "Notifications from the last 7 days are shown";
/// "방금 전"
"notification.justNow" = "Just now";
/// "%d시간 전"
"notification.hoursAgo" = "%dh ago";
/// "알림을 불러오지 못했어요."
"notification.loadFailed" = "Couldn't load notifications.";


// MARK: - Restaurant

Expand Down
19 changes: 19 additions & 0 deletions EATSSU/App/Resources/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,25 @@
/// 다시 시도해주세요.
"notification_error_unknown_description" = "もう一度お試しください。";

// MARK: - Notification Inbox (알림함)

/// "알림"
"notification.inboxTitle" = "通知";
/// "모두 읽음"
"notification.readAll" = "すべて既読";
/// "새로운 알림이 없어요."
"notification.emptyTitle" = "新しい通知はありません。";
/// "찜한 메뉴가 나오면 알림으로 알려드릴게요!"
"notification.emptySubtitle" = "お気に入りのメニューが出たらお知らせします!";
/// "7일 전 알림까지 확인할 수 있어요"
"notification.retentionNotice" = "7日前までの通知を確認できます";
/// "방금 전"
"notification.justNow" = "たった今";
/// "%d시간 전"
"notification.hoursAgo" = "%d時間前";
/// "알림을 불러오지 못했어요."
"notification.loadFailed" = "通知を読み込めませんでした。";


// MARK: - Restaurant

Expand Down
19 changes: 19 additions & 0 deletions EATSSU/App/Resources/ko.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,25 @@
/// 다시 시도해주세요.
"notification_error_unknown_description" = "다시 시도해주세요.";

// MARK: - Notification Inbox (알림함)

/// "알림"
"notification.inboxTitle" = "알림";
/// "모두 읽음"
"notification.readAll" = "모두 읽음";
/// "새로운 알림이 없어요."
"notification.emptyTitle" = "새로운 알림이 없어요.";
/// "찜한 메뉴가 나오면 알림으로 알려드릴게요!"
"notification.emptySubtitle" = "찜한 메뉴가 나오면 알림으로 알려드릴게요!";
/// "7일 전 알림까지 확인할 수 있어요"
"notification.retentionNotice" = "7일 전 알림까지 확인할 수 있어요";
/// "방금 전"
"notification.justNow" = "방금 전";
/// "%d시간 전"
"notification.hoursAgo" = "%d시간 전";
/// "알림을 불러오지 못했어요."
"notification.loadFailed" = "알림을 불러오지 못했어요.";


// MARK: - Restaurant

Expand Down
19 changes: 19 additions & 0 deletions EATSSU/App/Resources/vi.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,25 @@
/// 다시 시도해주세요.
"notification_error_unknown_description" = "Vui lòng thử lại.";

// MARK: - Notification Inbox (알림함)

/// "알림"
"notification.inboxTitle" = "Thông báo";
/// "모두 읽음"
"notification.readAll" = "Đánh dấu đã đọc tất cả";
/// "새로운 알림이 없어요."
"notification.emptyTitle" = "Không có thông báo mới.";
/// "찜한 메뉴가 나오면 알림으로 알려드릴게요!"
"notification.emptySubtitle" = "Chúng tôi sẽ báo khi món đã lưu được phục vụ!";
/// "7일 전 알림까지 확인할 수 있어요"
"notification.retentionNotice" = "Hiển thị thông báo trong 7 ngày gần nhất";
/// "방금 전"
"notification.justNow" = "Vừa xong";
/// "%d시간 전"
"notification.hoursAgo" = "%d giờ trước";
/// "알림을 불러오지 못했어요."
"notification.loadFailed" = "Không thể tải thông báo.";


// MARK: - Restaurant

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// NotificationDTO.swift
// EATSSU
//
// Created by 황상환 on 11/7/26.
//

import Foundation

/// 알림함 항목 (`GET /notifications`)
struct NotificationItemDTO: Codable, Equatable {
let notificationId: Int
/// 알림 종류. 현재는 `MENU_FAVORITE`만 온다
let type: String
/// 제목·본문은 조회 시점의 사용자 언어로 만들어진다
let title: String
let body: String
/// 알림을 누르면 이동할 식단 날짜 (yyyyMMdd)
let date: String
/// 이동할 시간대 (MORNING / LUNCH / DINNER)
let timePart: String?
let isRead: Bool
/// 알림 생성 시각. 서버(한국) 시간이며 타임존 표기가 없다 (예: `2026-11-02T11:00:00`)
let createdAt: String
}

/// `GET /notifications/unread`
struct UnreadNotificationDTO: Codable {
let hasUnread: Bool
}
62 changes: 62 additions & 0 deletions EATSSU/App/Sources/Data/Network/Router/NotificationRouter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// NotificationRouter.swift
// EATSSU
//
// Created by 황상환 on 11/7/26.
//

import Foundation

import Moya

/// 알림함 API (로그인 필요). 서버는 최근 7일(식단 날짜 기준) 찜 메뉴 알림만 보관한다
enum NotificationRouter {
/// 알림 목록 (최신순). 제목·본문은 조회 시점의 사용자 언어로 내려온다
case getNotifications
/// 안 읽은 알림이 있는지 (학식 탭 알림 아이콘의 점 표시)
case hasUnread
/// 알림 하나 읽음 처리. 이미 읽었어도 성공
case read(notificationId: Int)
/// 내 알림 모두 읽음 처리
case readAll
}

extension NotificationRouter: TargetType {
var baseURL: URL {
URL(string: Config.baseURL)!
}

var path: String {
switch self {
case .getNotifications:
"/notifications"
case .hasUnread:
"/notifications/unread"
case let .read(notificationId):
"/notifications/\(notificationId)/read"
case .readAll:
"/notifications/read-all"
}
}

var method: Moya.Method {
switch self {
case .getNotifications, .hasUnread:
.get
case .read, .readAll:
.patch
}
}

var task: Moya.Task {
.requestPlain
}

var headers: [String: String]? {
["Content-Type": "application/json"]
}

var validationType: ValidationType {
.successCodes
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// NotificationInboxService.swift
// EATSSU
//
// Created by 황상환 on 11/7/26.
//

import Foundation

/// 알림함 API 호출 모음. 알림함 화면, 학식 탭 알림 아이콘, 푸시 탭 읽음 처리가 함께 쓴다
enum NotificationInboxService {

static func fetchNotifications(completion: @escaping (Result<[NotificationItemDTO], Error>) -> Void) {
NetworkService.shared.request(
NotificationRouter.getNotifications,
responseType: [NotificationItemDTO].self,
useAuth: true,
completion: completion
)
}

static func fetchHasUnread(completion: @escaping (Result<Bool, Error>) -> Void) {
NetworkService.shared.request(
NotificationRouter.hasUnread,
responseType: UnreadNotificationDTO.self,
useAuth: true
) { result in
completion(result.map { $0.hasUnread })
}
}

/// 읽음 처리 뒤 `.didUpdateNotificationReadState`를 보내 학식 탭 알림 아이콘이 점을 갱신하게 한다
static func markRead(notificationId: Int, completion: ((Result<Bool, Error>) -> Void)? = nil) {
NetworkService.shared.request(
NotificationRouter.read(notificationId: notificationId),
responseType: Bool.self,
useAuth: true
) { result in
if case .success = result {
NotificationCenter.default.post(name: .didUpdateNotificationReadState, object: nil)
}
completion?(result)
}
}

static func markAllRead(completion: @escaping (Result<Bool, Error>) -> Void) {
NetworkService.shared.request(
NotificationRouter.readAll,
responseType: Bool.self,
useAuth: true
) { result in
if case .success = result {
NotificationCenter.default.post(name: .didUpdateNotificationReadState, object: nil)
}
completion(result)
}
}
}
9 changes: 8 additions & 1 deletion EATSSU/App/Sources/Notification/PushRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ struct PushRoute {
let date: Date
/// 찜 알림에만 있다. 없으면(일반 학식 알림) 현재 시각 기준 시간대를 그대로 쓴다
let mealTime: MealTime?
/// 알림함 항목 id. 있으면 알림을 누른 시점에 읽음 처리한다 (서버가 알림함을 지원하기 전 푸시에는 없다)
let notificationId: Int?

/// 서버 푸시 data: `type`(MENU_FAVORITE / DAILY_MENU), `date`(yyyyMMdd), `timePart`(찜 알림만)
/// 서버 푸시 data: `type`(MENU_FAVORITE / DAILY_MENU), `date`(yyyyMMdd), `timePart`(찜 알림만), `notificationId`(문자열)
init?(userInfo: [AnyHashable: Any]) {
guard let type = userInfo["type"] as? String,
Self.supportedTypes.contains(type),
let dateString = userInfo["date"] as? String,
let date = Self.dateFormatter.date(from: dateString) else { return nil }
self.date = date
self.mealTime = (userInfo["timePart"] as? String).flatMap(MealTime.init(rawValue:))
self.notificationId = (userInfo["notificationId"] as? String).flatMap(Int.init)
}

private static let supportedTypes: Set<String> = ["MENU_FAVORITE", "DAILY_MENU"]
Expand Down Expand Up @@ -90,6 +93,10 @@ final class PushRouter {
guard let tabBarController = Self.currentTabBarController() else { return }
self.pendingRoute = nil
tabBarController.showHomeMenu(on: pending.route.date, mealTime: pending.route.mealTime)
// 푸시를 눌러 들어왔으면 알림함에서도 읽은 것으로 표시한다
if let notificationId = pending.route.notificationId {
NotificationInboxService.markRead(notificationId: notificationId)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,22 @@ final class HomeViewController: BaseViewController {
return imageView
}()

/// 알림함 진입 버튼. 안 읽은 알림이 있으면 점이 있는 아이콘을 보여준다
/// 디자인: 24×24 아이콘, 우측 24, 로고와 세로 중앙 정렬. 터치 영역은 44
private let notificationButton: UIButton = {
let button = UIButton(type: .custom)
button.setImage(EATSSUDesignAsset.Images.icBell.image, for: .normal)
button.accessibilityLabel = TextLiteral.Notification.inboxTitle
button.accessibilityIdentifier = "home.notificationButton"
return button
}()

private let tabmanController = CustomTimeTabController()
private let homeCalendarView = HomeCalendarView()

/// 안 읽은 알림 조회 요청마다 증가. 연달아 보낸 요청의 응답 순서가 뒤바뀌어도 마지막 요청만 배지에 반영한다
private var unreadBadgeRequestID = 0

// MARK: - Life Cycle

override func viewDidLoad() {
Expand All @@ -45,6 +58,7 @@ final class HomeViewController: BaseViewController {
configureUI()
setLayout()
registerTabman()
addUnreadBadgeObservers()
}

override func viewDidAppear(_ animated: Bool) {
Expand All @@ -62,6 +76,9 @@ final class HomeViewController: BaseViewController {
addNewDayObserver()

self.tabBarController?.tabBar.isHidden = false
// 알림함은 로그인한 사용자만 쓸 수 있어 비로그인이면 아이콘을 숨긴다
notificationButton.isHidden = !TokenStore.hasAccessToken
refreshUnreadBadge()
}

override func viewWillDisappear(_ animated: Bool) {
Expand All @@ -88,6 +105,7 @@ final class HomeViewController: BaseViewController {

override func configureUI() {
view.addSubview(logoImageView)
view.addSubview(notificationButton)
view.addSubview(homeCalendarView)
}

Expand All @@ -98,13 +116,58 @@ final class HomeViewController: BaseViewController {
make.height.equalTo(28)
}

notificationButton.snp.makeConstraints { make in
make.centerY.equalTo(logoImageView)
// 44 터치 영역 안에 24 아이콘이 가운데 오므로 우측 여백 24 = 14 + 10
make.trailing.equalToSuperview().inset(14)
make.size.equalTo(44)
}

homeCalendarView.snp.makeConstraints { make in
make.top.equalTo(logoImageView.snp.bottom).offset(13)
make.leading.trailing.equalToSuperview()
make.height.equalTo(80)
}
}

override func setButtonEvent() {
notificationButton.addTarget(self, action: #selector(didTapNotificationButton), for: .touchUpInside)
}

// MARK: - Notification Inbox

@objc private func didTapNotificationButton() {
navigationController?.pushViewController(NotificationInboxViewController(), animated: true)
}

/// 안 읽은 알림 여부를 다시 확인하는 시점: 화면 진입, 앱 활성화, 사용 중 푸시 도착, 알림 읽음 처리
private func addUnreadBadgeObservers() {
let names: [Notification.Name] = [
UIApplication.didBecomeActiveNotification,
.didReceivePushNotification,
.didUpdateNotificationReadState
]
names.forEach {
NotificationCenter.default.addObserver(self, selector: #selector(refreshUnreadBadge), name: $0, object: nil)
}
}

@objc private func refreshUnreadBadge() {
// 푸시 도착(`willPresent`) 알림은 메인 큐 호출이 보장되지 않아 메인으로 옮긴다
guard Thread.isMainThread else {
DispatchQueue.main.async { self.refreshUnreadBadge() }
return
}
guard TokenStore.hasAccessToken else { return }
unreadBadgeRequestID += 1
let requestID = unreadBadgeRequestID
NotificationInboxService.fetchHasUnread { [weak self] result in
guard let self, requestID == self.unreadBadgeRequestID, case .success(let hasUnread) = result else { return }
let image = hasUnread ? EATSSUDesignAsset.Images.icBellUnread.image : EATSSUDesignAsset.Images.icBell.image
self.notificationButton.setImage(image, for: .normal)
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

// MARK: - Tabman Setup

private func registerTabman() {
Expand Down
Loading
Loading