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
46 changes: 46 additions & 0 deletions .github/workflows/ci_local_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: local_package_test

on:
push:
branches: ["main"]
paths:
- "LocalPackage/**"
pull_request:
branches: ["**"]
paths:
- "LocalPackage/**"
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
env:
SWIFT_VERSION: "6.2"
SWIFT_TOOLCHAIN_DIR: /opt/hostedtoolcache/swift-Ubuntu
steps:
- uses: actions/checkout@v4.2.2

- name: Cache Swift toolchain
id: cache-swift
uses: actions/cache@v4
with:
path: ${{ env.SWIFT_TOOLCHAIN_DIR }}
key: swift-toolchain-${{ runner.os }}-${{ env.SWIFT_VERSION }}

- name: Setup Swift
if: steps.cache-swift.outputs.cache-hit != 'true'
uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ env.SWIFT_VERSION }}

- name: Restore Swift PATH from cache
if: steps.cache-swift.outputs.cache-hit == 'true'
run: |
SWIFT_BIN=$(find ${{ env.SWIFT_TOOLCHAIN_DIR }} -name swift -type f -path "*/usr/bin/swift" | head -1)
echo "$(dirname "$SWIFT_BIN")" >> $GITHUB_PATH

- name: Show Swift version
run: swift --version

- name: Run tests
run: swift test --package-path LocalPackage
2 changes: 2 additions & 0 deletions .prefire.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ test_configuration:
- UIKit
- SwiftUI
- MultipeerConnectivity
- HometeDomain

7 changes: 0 additions & 7 deletions CI.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
"identifier" : "BC1BB2672E909B8C001D168F",
"name" : "hometeSnapshotTests"
}
},
{
"target" : {
"containerPath" : "container:homete.xcodeproj",
"identifier" : "BCC854012DB74BBF00C9A44B",
"name" : "hometeTests"
}
}
],
"version" : 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "2630"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "HometeDomain"
BuildableName = "HometeDomain"
BlueprintName = "HometeDomain"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "HometeDomainTests"
BuildableName = "HometeDomainTests"
BlueprintName = "HometeDomainTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "HometeDomain"
BuildableName = "HometeDomain"
BlueprintName = "HometeDomain"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
11 changes: 6 additions & 5 deletions LocalPackage/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ import PackageDescription

let package = Package(
name: "LocalPackage",
platforms: [.iOS(.v17), .macOS(.v15)],
products: [
.library(
name: "LocalPackage",
targets: ["LocalPackage"]
name: "HometeDomain",
targets: ["HometeDomain"]
),
],
targets: [
.target(
name: "LocalPackage"
name: "HometeDomain"
),
.testTarget(
name: "LocalPackageTests",
dependencies: ["LocalPackage"]
name: "HometeDomainTests",
dependencies: ["HometeDomain"]
),
]
)
30 changes: 30 additions & 0 deletions LocalPackage/Sources/HometeDomain/Account/Account.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Account.swift
// homete
//
// Created by 佐藤汰一 on 2025/08/03.
//

// TODO: ダミー
public struct Account: Equatable, Codable, Sendable {

public let id: String
public let userName: String
public let fcmToken: String?
public let cohabitantId: String?

public init(id: String, userName: String, fcmToken: String?, cohabitantId: String?) {
self.id = id
self.userName = userName
self.fcmToken = fcmToken
self.cohabitantId = cohabitantId
}
}

public extension Account {

static func initial(auth: AccountAuthResult, userName: UserName, fcmToken: String?) -> Self {

return .init(id: auth.id, userName: userName.value, fcmToken: fcmToken, cohabitantId: nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,58 @@
// Created by 佐藤汰一 on 2025/08/03.
//

import SwiftUI
import Observation

@MainActor
@Observable
final class AccountStore {
private(set) var account: Account?
public final class AccountStore {

public private(set) var account: Account?

private let accountInfoClient: AccountInfoClient
init(
appDependencies: AppDependencies,

public init(
accountInfoClient: AccountInfoClient = .previewValue,
account: Account? = nil
) {
accountInfoClient = appDependencies.accountInfoClient

self.accountInfoClient = accountInfoClient
self.account = account
}

/// アカウント情報をロードし、オンメモリにキャッシュする
/// - Returns: ロードしたアカウント情報を返す(アカウントがない場合はnilを返す)
@discardableResult
func load(_ auth: AccountAuthResult) async -> Account? {
public func load(_ auth: AccountAuthResult) async -> Account? {

do {

account = try await accountInfoClient.fetch(auth.id)
}
catch {

print("failed to fetch account info: \(error)")
}

return account
}
func registerAccount(auth: AccountAuthResult, userName: UserName) async throws -> Account {

public func registerAccount(auth: AccountAuthResult, userName: UserName) async throws -> Account {

let newAccount = Account(id: auth.id, userName: userName.value, fcmToken: nil, cohabitantId: nil)
try await accountInfoClient.insertOrUpdate(newAccount)
account = newAccount
return newAccount
}
func updateFcmTokenIfNeeded(_ fcmToken: String) async {

public func updateFcmTokenIfNeeded(_ fcmToken: String) async {

// 保持しているFCMトークンと異なるFCMトークンに変わった場合は、アカウント情報も新しいトークンに更新する
guard let account,
account.fcmToken != fcmToken else { return }

do {

let updatedAccount = Account(
id: account.id,
userName: account.userName,
Expand All @@ -67,18 +67,18 @@ final class AccountStore {
self.account = updatedAccount
}
catch {

print("failed to update fcmToken: \(error)")
}
}
func registerCohabitantId(_ cohabitantId: String) async throws {

public func registerCohabitantId(_ cohabitantId: String) async throws {

guard let account else {

preconditionFailure("Not found account.")
}

let updatedAccount = Account(
id: account.id,
userName: account.userName,
Expand Down
18 changes: 18 additions & 0 deletions LocalPackage/Sources/HometeDomain/Account/LoginContext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// LoginContext.swift
// homete
//
// Created by 佐藤汰一 on 2025/12/27.
//

public struct LoginContext: Equatable {

public let account: Account

/// パートナー登録済みかどうか
public var hasCohabitant: Bool { account.cohabitantId != nil }

public init(account: Account) {
self.account = account
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
// Created by 佐藤汰一 on 2025/12/27.
//

struct UserName {
var value = ""
public struct UserName {
public var value = ""

private static let limitCharacters = 10
var remainingCharacters: Int {

public var remainingCharacters: Int {
return Self.limitCharacters - value.count
}
var isOverLimitCharacters: Bool {

public var isOverLimitCharacters: Bool {
return Self.limitCharacters < value.count
}
var canRegistration: Bool {

public var canRegistration: Bool {
return !value.isEmpty && !isOverLimitCharacters
}

public init(value: String = "") {
self.value = value
}
}
Loading
Loading