diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 7fe840d..b95b525 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,16 +1,24 @@ + + # *Name of the PR* -## :recycle: Current situation +## :recycle: Current situation & Problem *Describe the current situation (if possible with and exemplary (or real) code snippet and/or where this is used)* ## :bulb: Proposed solution -*Describe the solution (if possible with and exemplary (or real) code snippet)* - -### Problem that is solved -*Provide a description and link issues that are solved* +*Describe the solution and how this affects the project and internal structure* -### Implications -*Describe the implications, e.g. refactoring* +## :gear: Release Notes +*Add a short summary of the feature as well as possible migration guides if this is a breaking change so this section can be added to the release notes.* +*Include code snippets that provide examples of the feature implemented if it appends or changes the public interface.* ## :heavy_plus_sign: Additional Information *Provide some additional information if possible* diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index b20e968..b7d0ad4 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,20 +1,30 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + branches: [release] name-template: '$NEXT_PATCH_VERSION' tag-template: '$NEXT_PATCH_VERSION' categories: - - title: '🚀 Features' + - title: 'Semantic Version Major' + labels: + - 'needs version bump' + - title: 'Semantic Version Minor' labels: - 'feature' - 'enhancement' - - title: '🐛 Bug Fixes' + - title: 'Other Changes' labels: - 'fix' - 'bugfix' - 'bug' - - title: '🧰 Maintenance' - label: 'chore' + - 'documentation' change-template: '- $TITLE @$AUTHOR (#$NUMBER)' template: | ## Changes - $CHANGES + $CHANGES \ No newline at end of file diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f536695..88ab79d 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,3 +1,11 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + name: Build and Test on: @@ -7,14 +15,12 @@ on: pull_request: branches: - develop + workflow_dispatch: jobs: macosclient: name: macOS Client runs-on: macos-11 - defaults: - run: - working-directory: ./App steps: - uses: actions/checkout@v2 - uses: maxim-lobanov/setup-xcode@v1.1 @@ -26,34 +32,48 @@ jobs: run: swift --version - name: Build and test run: xcodebuild test -scheme App -destination 'platform=iOS Simulator,OS=15.0,name=iPhone 12' - macoswebservices: - name: macOS WebService + macoswebservice: + name: macOS WebService ${{ matrix.configuration }} runs-on: macos-11 defaults: run: working-directory: ./WebService + strategy: + fail-fast: false + matrix: + configuration: [debug, release] steps: - uses: actions/checkout@v2 - - uses: maxim-lobanov/setup-xcode@v1.1 + - uses: maxim-lobanov/setup-xcode@v1.2.3 with: xcode-version: latest + - uses: actions/cache@v2 + with: + path: .build + key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} - name: Check Xcode version run: xcodebuild -version - name: Check Swift version run: swift --version - - name: Build and test - run: swift test + - name: Release Build + if: matrix.configuration == 'release' + run: swift build -c release + - name: Debug Build + if: matrix.configuration == 'debug' + run: swift build -c debug linuxwebservices: - name: Linux WebService ${{ matrix.linux }} + name: Linux ${{ matrix.linux }} ${{ matrix.configuration }} runs-on: ubuntu-latest container: - image: swift:${{ matrix.linux }} - strategy: - matrix: - linux: [latest, focal, amazonlinux2, centos8] + image: swiftlang/swift:nightly-5.5-${{ matrix.linux }} defaults: run: working-directory: ./WebService + strategy: + fail-fast: false + matrix: + linux: [bionic, focal, amazonlinux2, centos8] + configuration: [debug, release, release_testing] steps: - uses: actions/checkout@v2 - name: Install libsqlite3 @@ -65,7 +85,18 @@ jobs: - name: Install libsqlite3 if: startsWith( matrix.linux, 'centos' ) run: yum update -y --nobest && yum install -y sqlite-devel + - uses: actions/cache@v2 + with: + path: .build + key: ${{ runner.os }}-${{matrix.linux}}-spm-${{ hashFiles('**/Package.resolved') }} - name: Check Swift version run: swift --version - - name: Build and test - run: swift test -Xswiftc -Xfrontend -Xswiftc -sil-verify-none + - name: Release Build + if: matrix.configuration == 'release' + run: swift build -c release + - name: Release Build & Test + if: matrix.configuration == 'release_testing' + run: swift test -c release -Xswiftc -enable-testing + - name: Debug Build & Test + if: matrix.configuration == 'debug' + run: swift test -c debug diff --git a/.github/workflows/docker-compose.yml b/.github/workflows/docker-compose.yml index 2a9ba11..f58fbcb 100644 --- a/.github/workflows/docker-compose.yml +++ b/.github/workflows/docker-compose.yml @@ -1,3 +1,11 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + name: Build Docker Compose on: diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2bbea04..a335fed 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,9 +1,17 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + name: Build Docker Image on: - push: - tags: - - '*.*.*' + release: + types: [published] + workflow_dispatch: jobs: docker: diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index bc6ee09..7ba5ea1 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -1,9 +1,17 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + name: Release Drafter on: push: branches: - - release + - develop jobs: update_release_draft: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e0f9849..092e27a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,11 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + name: Create Release on: @@ -9,7 +17,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: GH Release + - name: Create GitHub Release uses: softprops/action-gh-release@v0.1.5 env: GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} diff --git a/.github/workflows/reuseaction.yml b/.github/workflows/reuseaction.yml new file mode 100644 index 0000000..9e868bc --- /dev/null +++ b/.github/workflows/reuseaction.yml @@ -0,0 +1,22 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + +name: REUSE Compliance Check + +on: + pull_request: + workflow_dispatch: + +jobs: + reuse: + name: REUSE Compliance Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: REUSE Compliance Check + uses: fsfe/reuse-action@v1 diff --git a/.github/workflows/spm-update.yml b/.github/workflows/spm-update.yml new file mode 100644 index 0000000..1a43968 --- /dev/null +++ b/.github/workflows/spm-update.yml @@ -0,0 +1,46 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + +name: Swift Package Update + +on: + schedule: + - cron: '0 0 * * 1' + workflow_dispatch: + +jobs: + createPR: + name: Create Pull Request + container: + image: swiftlang/swift:nightly-5.5-focal + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Check Swift version + run: swift --version + - name: Update Swift Packages Gateway + run: cd ./Shared && swift package update + - name: Update Swift Packages Database + run: cd ./WebService && swift package update + - name: Update Swift Packages Xcode Projekt + run: | + rm -f Example.xcworkspace/xcshareddata/swiftpm/Package.resolved + xcodebuild -resolvePackageDependencies + - uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.ACCESS_TOKEN }} + commit-message: Update dependencies + title: Update dependencies + body: Update the Swift Package dependencies. + delete-branch: true + base: develop + branch: bots/update-dependencies + assignees: ApodiniBot + committer: ApodiniBot + author: ApodiniBot + reviewers: PSchmiedmayer diff --git a/.github/workflows/swiftlint.yml b/.github/workflows/swiftlint.yml index 717a773..68d1c30 100644 --- a/.github/workflows/swiftlint.yml +++ b/.github/workflows/swiftlint.yml @@ -1,21 +1,26 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + name: SwiftLint on: pull_request: - paths: - - '.github/workflows/swiftlint.yml' - - '.swiftlint.yml' - - '**/*.swift' + workflow_dispatch: jobs: swiftlint: + name: SwiftLint runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: GitHub Action for SwiftLint - uses: norio-nomura/action-swiftlint@3.1.0 + uses: norio-nomura/action-swiftlint@3.2.1 with: args: --strict env: DIFF_BASE: ${{ github.base_ref }} - diff --git a/.gitignore b/.gitignore index d1ed539..feb4cbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,62 +1,25 @@ -# Build generated -build/ -DerivedData/ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# -# System files -.DS_Store - -# Xcode -*.moved-aside -xcuserdata/ -*.xccheckout -*.xcscmblueprint - -# Other -*.pbxuser -!default.pbxuser -*.mode1v3 -!default.mode1v3 -*.mode2v3 -!default.mode2v3 -*.perspectivev3 -!default.perspectivev3 - -# Obj-C/Swift specific -*.hmap -*.ipa -*.dSYM.zip -*.dSYM - -# Playgrounds -timeline.xctimeline -playground.xcworkspace +# Apodini .gitignore File # Swift Package Manager -# -# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +*.xcodeproj .swiftpm .build/ +!App/App.xcodeproj -# CocoaPods -# -# We recommend adding the Pods directory to your .gitignore. However -# you should judge for yourself, the pros and cons are mentioned at: -# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control -Pods/ +# IDE related folders +.idea -# Carthage -# -# Add this line if you want to avoid checking in source code from Carthage dependencies. -Carthage/Checkouts -Carthage/Build +# Xcode User settings +xcuserdata/ -# fastlane -# -# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the -# screenshots whenever they are needed. -# For more information about the recommended setup visit: -# https://docs.fastlane.tools/best-practices/source-control/#source-control -fastlane/report.xml -fastlane/Preview.html -fastlane/screenshots/**/*.png -fastlane/test_output \ No newline at end of file +# Other files +.DS_Store +.env \ No newline at end of file diff --git a/.swiftlint.yml b/.swiftlint.yml index 43f2431..c7b4fba 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,8 +1,17 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + # Apodini SwiftLint file Apodini -# The whitelist_rules configuration also includes rules that are enabled by default to provide a good overview of all rules. +# The only_rules configuration also includes rules that are enabled by default to provide a good overview of all rules. only_rules: - attributes + # Attributes should be on their own lines in functions and types, but on the same line as variables and imports. - anyobject_protocol # Prefer using AnyObject over class for class-only protocols. - array_init @@ -27,6 +36,8 @@ only_rules: # Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. - comma # There should be no space before and one after any comma. + - comment_spacing + # Prefer at least one space after slashes for comments. - compiler_protocol_init # The initializers declared in compiler protocols such as ExpressibleByArrayLiteral shouldn't be called directly. - computed_accessors_order @@ -77,6 +88,8 @@ only_rules: # Number of associated values in an enum case should be low - explicit_init # Explicitly calling .init() should be avoided. + - fallthrough + # Fallthrough should be avoided. - fatal_error_message # A fatalError call should have a message. - file_length @@ -116,6 +129,8 @@ only_rules: # Implicitly unwrapped optionals should be avoided when possible. - inclusive_language # Identifiers should use inclusive language that avoids discrimination against groups of people based on race, gender, or socioeconomic status + - indentation_width + # Indent code using either one tab or the configured amount of spaces, unindent to match previous indentations. Don’t indent the first line. - inert_defer # If defer is at the end of its parent scope, it will be executed right where it is anyway. - is_disjoint @@ -158,14 +173,18 @@ only_rules: # Modifier order should be consistent. - multiline_arguments # Arguments should be either on the same line, or one per line. + - multiline_arguments_brackets + # Multiline arguments should have their surrounding brackets in a new line. - multiline_function_chains # Chained function calls should be either on the same line, or one per line. - multiline_literal_brackets # Multiline literals should have their surrounding brackets in a new line. - multiline_parameters # Functions and methods parameters should be either on the same line, or one per line. + - multiline_parameters_brackets + # Multiline parameters should have their surrounding brackets in a new line. - nesting - # Types and statements should only be nested to a certain level deep. + # Types and functions should only be nested to a certain level deep. # See nesting below for the exact configuration. - nimble_operator # Prefer Nimble operator overloads over free matcher functions. @@ -197,6 +216,8 @@ only_rules: # Combine multiple pattern matching bindings by moving keywords out of tuples. - prefer_self_type_over_type_of_self # Prefer Self over type(of: self) when accessing properties or calling methods. + - prefer_zero_over_explicit_init + # Prefer .zero over explicit init with zero parameters (e.g. CGPoint(x: 0, y: 0)) - private_action # IBActions should be private. - private_outlet @@ -241,6 +262,8 @@ only_rules: # Test files should contain a single QuickSpec or XCTestCase class. - sorted_first_last # Prefer using `min()`` or `max()`` over `sorted().first` or `sorted().last` + - sorted_imports + # Imports should be sorted. - statement_position # Else and catch should be on the same line, one space after the previous declaration. - static_operator @@ -269,9 +292,13 @@ only_rules: - type_body_length # Type bodies should not span too many lines. # See large_tuple below for the exact configuration. + - type_contents_order + # Specifies the order of subtypes, properties, methods & more within a type. - type_name # Type name should only contain alphanumeric characters, start with an uppercase character and span between 3 and 40 characters in length. # Excluded types are listed below. + - unavailable_function + # Unimplemented functions should be marked as unavailable. - unneeded_break_in_switch # Avoid using unneeded break statements. - unneeded_parentheses_in_closure_argument @@ -309,8 +336,8 @@ only_rules: # Don’t include vertical whitespace (empty line) after opening braces. - void_return # Prefer -> Void over -> (). - - weak_delegate - # Delegates should be weak to avoid reference cycles. + - xct_specific_matcher + # Prefer specific XCTest matchers over XCTAssertEqual and XCTAssertNotEqual - xctfail_message # An XCTFail call should include a description of the assertion. - yoda_condition @@ -318,7 +345,7 @@ only_rules: excluded: # paths to ignore during linting. Takes precedence over `included`. - .build - - TestWebService/.build + - .xcodebuild - .swiftpm closure_body_length: # Closure bodies should not span too many lines. @@ -346,6 +373,12 @@ identifier_name: - id - ok - or + - p8 + - of + - s3 + - at + - to + - in large_tuple: # Tuples shouldn't have too many members. Create a custom type instead. - 2 # warning - default: 2 @@ -359,10 +392,10 @@ line_length: # Lines should not span too many characters. ignores_function_declarations: false # default: false ignores_interpolated_strings: true # default: false -nesting: # Types should be nested at most 2 level deep, and statements should be nested at most 5 levels deep. +nesting: # Types should be nested at most 2 level deep, and functions should be nested at most 5 levels deep. type_level: warning: 2 # warning - default: 1 - statement_level: + function_level: warning: 5 # warning - default: 5 trailing_closure: diff --git a/App/App.xcodeproj/project.pbxproj.license b/App/App.xcodeproj/project.pbxproj.license new file mode 100644 index 0000000..90eccee --- /dev/null +++ b/App/App.xcodeproj/project.pbxproj.license @@ -0,0 +1,6 @@ + +This source file is part of the Apodini Example open source project + +SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) + +SPDX-License-Identifier: MIT diff --git a/App/App.xcodeproj/project.xcworkspace/contents.xcworkspacedata.license b/App/App.xcodeproj/project.xcworkspace/contents.xcworkspacedata.license new file mode 100644 index 0000000..90eccee --- /dev/null +++ b/App/App.xcodeproj/project.xcworkspace/contents.xcworkspacedata.license @@ -0,0 +1,6 @@ + +This source file is part of the Apodini Example open source project + +SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) + +SPDX-License-Identifier: MIT diff --git a/App/App.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist.license b/App/App.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist.license new file mode 100644 index 0000000..90eccee --- /dev/null +++ b/App/App.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist.license @@ -0,0 +1,6 @@ + +This source file is part of the Apodini Example open source project + +SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) + +SPDX-License-Identifier: MIT diff --git a/App/App.xcodeproj/xcshareddata/xcschemes/App.xcscheme.license b/App/App.xcodeproj/xcshareddata/xcschemes/App.xcscheme.license new file mode 100644 index 0000000..90eccee --- /dev/null +++ b/App/App.xcodeproj/xcshareddata/xcschemes/App.xcscheme.license @@ -0,0 +1,6 @@ + +This source file is part of the Apodini Example open source project + +SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) + +SPDX-License-Identifier: MIT diff --git a/App/App/ContactCell.swift b/App/App/ContactCell.swift index 4e99912..8821307 100644 --- a/App/App/ContactCell.swift +++ b/App/App/ContactCell.swift @@ -1,5 +1,13 @@ -import SwiftUI +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Model +import SwiftUI struct ContactCell: View { @EnvironmentObject private var model: Model diff --git a/App/App/ContactDetailsView.swift b/App/App/ContactDetailsView.swift index f6da638..15fa68a 100644 --- a/App/App/ContactDetailsView.swift +++ b/App/App/ContactDetailsView.swift @@ -1,6 +1,14 @@ -import SwiftUI -import Model +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Combine +import Model +import SwiftUI struct ContactDetailsView: View { @EnvironmentObject private var model: Model diff --git a/App/App/ContentView.swift b/App/App/ContentView.swift index 2694f3a..0aa4234 100644 --- a/App/App/ContentView.swift +++ b/App/App/ContentView.swift @@ -1,5 +1,13 @@ -import SwiftUI +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Model +import SwiftUI struct ContentView: View { @EnvironmentObject private var model: Model @@ -39,7 +47,7 @@ struct ContentView_Previews: PreviewProvider { static var previews: some View { ForEach(ColorScheme.allCases, id: \.self) { colorScheme in - ContentView().colorScheme(colorScheme) + ContentView().colorScheme(colorScheme) }.environmentObject(model) } } diff --git a/App/App/EditContact.swift b/App/App/EditContact.swift index bff7431..d54dec8 100644 --- a/App/App/EditContact.swift +++ b/App/App/EditContact.swift @@ -1,6 +1,15 @@ -import SwiftUI -import Model +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Combine +import Model +import SwiftUI + struct EditContact: View { @Environment(\.presentationMode) private var presentationMode @@ -9,14 +18,11 @@ struct EditContact: View { @State private var loadingCancellable: AnyCancellable? + var navigationTitle: String { viewModel.id == nil ? "Create New Contact" : "Edit Contact" } - init(_ model: Model, id: Contact.ID) { - viewModel = EditContactViewModel(model, id: id) - } - var body: some View { NavigationView { self.form @@ -36,14 +42,6 @@ struct EditContact: View { } } - private func save() { - loadingCancellable = viewModel.save().sink { _ in } - } - - private func delete() { - loadingCancellable = viewModel.delete().sink { _ in } - } - private var form: some View { Form { Section(header: Text("Name")) { @@ -75,6 +73,20 @@ struct EditContact: View { } } } + + + init(_ model: Model, id: Contact.ID) { + viewModel = EditContactViewModel(model, id: id) + } + + + private func save() { + loadingCancellable = viewModel.save().sink { _ in } + } + + private func delete() { + loadingCancellable = viewModel.delete().sink { _ in } + } } struct EditContact_Previews: PreviewProvider { diff --git a/App/App/EditContactViewModel.swift b/App/App/EditContactViewModel.swift index 322ef2a..3e9f958 100644 --- a/App/App/EditContactViewModel.swift +++ b/App/App/EditContactViewModel.swift @@ -1,6 +1,14 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + +import Combine import Foundation import Model -import Combine class EditContactViewModel: ObservableObject { @Published var name: String = "" diff --git a/App/App/EditResidence.swift b/App/App/EditResidence.swift index fdbdb1b..cc79e93 100644 --- a/App/App/EditResidence.swift +++ b/App/App/EditResidence.swift @@ -1,6 +1,15 @@ -import SwiftUI +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Combine import Model +import SwiftUI + struct EditResidence: View { @Environment(\.presentationMode) private var presentationMode @@ -9,14 +18,11 @@ struct EditResidence: View { @State private var loadingCancellable: AnyCancellable? + var navigationTitle: String { viewModel.id == nil ? "Create New Residence" : "Residence" } - init(_ model: Model, contact: Contact, id: Residence.ID) { - viewModel = EditResidenceViewModel(model, contact: contact, id: id) - } - var body: some View { NavigationView { self.form @@ -54,6 +60,12 @@ struct EditResidence: View { } } + + init(_ model: Model, contact: Contact, id: Residence.ID) { + viewModel = EditResidenceViewModel(model, contact: contact, id: id) + } + + private func save() { loadingCancellable = viewModel.save().sink { _ in } } diff --git a/App/App/EditResidenceViewModel.swift b/App/App/EditResidenceViewModel.swift index b87e847..5351955 100644 --- a/App/App/EditResidenceViewModel.swift +++ b/App/App/EditResidenceViewModel.swift @@ -1,6 +1,14 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + +import Combine import Foundation import Model -import Combine class EditResidenceViewModel: ObservableObject { @Published var address: String = "" @@ -40,11 +48,13 @@ class EditResidenceViewModel: ObservableObject { return Fail(error: ServiceError.saveFailed(Residence.self)).eraseToAnyPublisher() } - let residence = Residence(id: self.id, - address: self.address, - postalCode: self.postalCode, - country: self.country, - contact: contactID) + let residence = Residence( + id: self.id, + address: self.address, + postalCode: self.postalCode, + country: self.country, + contact: contactID + ) return model.save(residence) .map { diff --git a/App/App/ResidenceCell.swift b/App/App/ResidenceCell.swift index 43fbb72..4dbc5d8 100644 --- a/App/App/ResidenceCell.swift +++ b/App/App/ResidenceCell.swift @@ -1,5 +1,13 @@ -import SwiftUI +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Model +import SwiftUI struct ResidenceCell: View { @EnvironmentObject private var model: Model diff --git a/App/App/SampleApp.swift b/App/App/SampleApp.swift index 454585b..8e31ff9 100644 --- a/App/App/SampleApp.swift +++ b/App/App/SampleApp.swift @@ -1,6 +1,14 @@ -import SwiftUI -import Model +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Foundation +import Model +import SwiftUI @main diff --git a/App/AppTests/AppTests.swift b/App/AppTests/AppTests.swift index 13699d0..0663e2b 100644 --- a/App/AppTests/AppTests.swift +++ b/App/AppTests/AppTests.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + @testable import App import Combine @testable import Model diff --git a/App/AppUITests/AppUITests.swift b/App/AppUITests/AppUITests.swift index bf41a1e..32d0e80 100644 --- a/App/AppUITests/AppUITests.swift +++ b/App/AppUITests/AppUITests.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import XCTest diff --git a/App/ExampleModel/.gitignore b/App/ExampleModel/.gitignore deleted file mode 100644 index bb460e7..0000000 --- a/App/ExampleModel/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.DS_Store -/.build -/Packages -/*.xcodeproj -xcuserdata/ -DerivedData/ -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata diff --git a/App/ExampleModel/Package.swift b/App/ExampleModel/Package.swift index aa1546a..404179c 100644 --- a/App/ExampleModel/Package.swift +++ b/App/ExampleModel/Package.swift @@ -1,4 +1,12 @@ -// swift-tools-version:5.3 +// swift-tools-version:5.5 + +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// import PackageDescription @@ -6,7 +14,8 @@ import PackageDescription let package = Package( name: "Model", platforms: [ - .macOS(.v11), .iOS(.v14) + .macOS(.v12), + .iOS(.v15) ], products: [ .library( diff --git a/App/ExampleModel/README.md b/App/ExampleModel/README.md deleted file mode 100644 index 3d677e7..0000000 --- a/App/ExampleModel/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Model - -A description of this package. diff --git a/App/ExampleModel/Sources/Model/Exports.swift b/App/ExampleModel/Sources/Model/Exports.swift index 5abe0c3..ba2791f 100644 --- a/App/ExampleModel/Sources/Model/Exports.swift +++ b/App/ExampleModel/Sources/Model/Exports.swift @@ -1 +1,9 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + @_exported import Shared diff --git a/App/ExampleModel/Sources/Model/Extensions/Array.swift b/App/ExampleModel/Sources/Model/Extensions/Array.swift index 1783394..a6f050d 100644 --- a/App/ExampleModel/Sources/Model/Extensions/Array.swift +++ b/App/ExampleModel/Sources/Model/Extensions/Array.swift @@ -1,9 +1,9 @@ // -// NetworkManager+ArrayExtensions.swift -// Model +// This source file is part of the Apodini Example open source project // -// Created by Paul Schmiedmayer on 10/11/19. -// Copyright © 2020 TUM LS1. All rights reserved. +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT // import Foundation diff --git a/App/ExampleModel/Sources/Model/Extensions/Future.swift b/App/ExampleModel/Sources/Model/Extensions/Future.swift index 979c6db..cbc79b5 100644 --- a/App/ExampleModel/Sources/Model/Extensions/Future.swift +++ b/App/ExampleModel/Sources/Model/Extensions/Future.swift @@ -1,9 +1,9 @@ // -// Future.swift -// Model +// This source file is part of the Apodini Example open source project // -// Created by Paul Schmiedmayer on 4/9/20. -// Copyright © 2020 TUM LS1. All rights reserved. +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT // import Combine diff --git a/App/ExampleModel/Sources/Model/Extensions/Publisher.swift b/App/ExampleModel/Sources/Model/Extensions/Publisher.swift index 060e334..2e20ab8 100644 --- a/App/ExampleModel/Sources/Model/Extensions/Publisher.swift +++ b/App/ExampleModel/Sources/Model/Extensions/Publisher.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Combine extension Publisher where Output == Void { @@ -7,7 +15,6 @@ extension Publisher where Output == Void { /// - parameter receiveComplete: The closure to execute on completion. /// - Returns: A cancellable instance; used when you end assignment of the received value. Deallocation of the result will tear down the subscription stream. public func sink(receiveCompletion: @escaping ((Subscribers.Completion) -> Void)) -> AnyCancellable { - sink(receiveCompletion: receiveCompletion, - receiveValue: { }) + sink(receiveCompletion: receiveCompletion, receiveValue: { }) } } diff --git a/App/ExampleModel/Sources/Model/LocalStorageModel/LocalFileStorable.swift b/App/ExampleModel/Sources/Model/LocalStorageModel/LocalFileStorable.swift index 58aa444..6684671 100644 --- a/App/ExampleModel/Sources/Model/LocalStorageModel/LocalFileStorable.swift +++ b/App/ExampleModel/Sources/Model/LocalStorageModel/LocalFileStorable.swift @@ -1,9 +1,9 @@ // -// LocalFileStorable.swift -// Model +// This source file is part of the Apodini Example open source project // -// Created by Paul Schmiedmayer on 10/11/19. -// Copyright © 2020 TUM LS1. All rights reserved. +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT // import Foundation diff --git a/App/ExampleModel/Sources/Model/LocalStorageModel/LocalStorageModel.swift b/App/ExampleModel/Sources/Model/LocalStorageModel/LocalStorageModel.swift index 76867f4..73680b1 100644 --- a/App/ExampleModel/Sources/Model/LocalStorageModel/LocalStorageModel.swift +++ b/App/ExampleModel/Sources/Model/LocalStorageModel/LocalStorageModel.swift @@ -1,13 +1,13 @@ // -// LocalStorageModel.swift -// Model +// This source file is part of the Apodini Example open source project // -// Created by Paul Schmiedmayer on 3/23/20. -// Copyright © 2020 TUM LS1. All rights reserved. +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT // -import Foundation import Combine +import Foundation import Shared @@ -20,8 +20,7 @@ public class LocalStorageModel: Model { /// Creates a `Model` that stores information locally on the filesystem public convenience init() { - self.init(contacts: Contact.loadFromFile(), - residencies: Residence.loadFromFile()) + self.init(contacts: Contact.loadFromFile(), residencies: Residence.loadFromFile()) // Subscribe to the `Publisher` provided by the `@Published` property wrapper and store the // `Account`s and `Transaction`s on disk once we receive a new value diff --git a/App/ExampleModel/Sources/Model/MockModel.swift b/App/ExampleModel/Sources/Model/MockModel.swift index 2c88f36..a00b589 100644 --- a/App/ExampleModel/Sources/Model/MockModel.swift +++ b/App/ExampleModel/Sources/Model/MockModel.swift @@ -1,7 +1,30 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Foundation import Shared public class MockModel: LocalStorageModel { + public convenience init() { + let hans = Contact(id: .init(), name: "Hans Santoso", birthday: Date(timeIntervalSince1970: 20000000)) + let paul = Contact(id: .init(), name: "Paul Schmiedmayer", birthday: Date(timeIntervalSince1970: 10000000)) + + let contacts = [hans, paul].sorted() + + let residencies = [ + MockModel.createHomeGermany(hans), + MockModel.createHomeFrance(hans), + MockModel.createHomeAustria(paul) + ] + self.init(contacts: contacts, residencies: residencies) + } + + private static func createHomeGermany(_ contact: Contact) -> Residence { guard let contactId = contact.id else { fatalError("Tried to creeate a Residence with a Contact which's id is nil") @@ -22,18 +45,4 @@ public class MockModel: LocalStorageModel { } return Residence(id: UUID(), address: "Getreidegasse 9", postalCode: "5020", country: "Austria", contact: contactId) } - - public convenience init() { - let hans = Contact(id: .init(), name: "Hans Santoso", birthday: Date(timeIntervalSince1970: 20000000)) - let paul = Contact(id: .init(), name: "Paul Schmiedmayer", birthday: Date(timeIntervalSince1970: 10000000)) - - let contacts = [hans, paul].sorted() - - let residencies = [ - MockModel.createHomeGermany(hans), - MockModel.createHomeFrance(hans), - MockModel.createHomeAustria(paul) - ] - self.init(contacts: contacts, residencies: residencies) - } } diff --git a/App/ExampleModel/Sources/Model/Model.swift b/App/ExampleModel/Sources/Model/Model.swift index 6c07883..d253c11 100644 --- a/App/ExampleModel/Sources/Model/Model.swift +++ b/App/ExampleModel/Sources/Model/Model.swift @@ -1,12 +1,13 @@ // -// Model.swift -// SampleApp +// This source file is part of the Apodini Example open source project // -// Created by Hans Santoso on 04.05.21. +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT // -import Foundation import Combine +import Foundation import Shared diff --git a/App/ExampleModel/Sources/Model/Models/Contact.swift b/App/ExampleModel/Sources/Model/Models/Contact.swift index 7398d47..c87f1b4 100644 --- a/App/ExampleModel/Sources/Model/Models/Contact.swift +++ b/App/ExampleModel/Sources/Model/Models/Contact.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Foundation import Shared diff --git a/App/ExampleModel/Sources/Model/Models/Residence.swift b/App/ExampleModel/Sources/Model/Models/Residence.swift index 95b1575..adf45e1 100644 --- a/App/ExampleModel/Sources/Model/Models/Residence.swift +++ b/App/ExampleModel/Sources/Model/Models/Residence.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Foundation import Shared diff --git a/App/ExampleModel/Sources/Model/RestfulModel/NetworkManager.swift b/App/ExampleModel/Sources/Model/RestfulModel/NetworkManager.swift index 57e6f60..990be3b 100644 --- a/App/ExampleModel/Sources/Model/RestfulModel/NetworkManager.swift +++ b/App/ExampleModel/Sources/Model/RestfulModel/NetworkManager.swift @@ -1,5 +1,13 @@ -import Foundation +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Combine +import Foundation enum NetworkManager { struct DataWrapper: Decodable { @@ -27,10 +35,12 @@ enum NetworkManager { /// - authorization: The value that should be added the `Authorization` header field /// - body: The HTTP body that should be added to the `URLRequest` /// - Returns: The created `URLRequest` - static func urlRequest(_ method: String, - url: URL, - authorization: String? = authorization, - body: Data? = nil) -> URLRequest { + static func urlRequest( + _ method: String, + url: URL, + authorization: String? = authorization, + body: Data? = nil + ) -> URLRequest { var urlRequest = URLRequest(url: url) urlRequest.httpMethod = method urlRequest.addValue("application/json", forHTTPHeaderField: "Content-Type") @@ -46,11 +56,11 @@ enum NetworkManager { /// - route: The route to get the `Element` from /// - authorization: The `String` that should written in the `Authorization` header field /// - Returns: An `AnyPublisher` that contains the `Element` from the server or or an `Error` in the case of an error - static func getElement(on route: URL, - authorization: String? = authorization) -> AnyPublisher { - URLSession.shared.dataTaskPublisher(for: - urlRequest("GET", url: route, authorization: authorization) - ) + static func getElement( + on route: URL, + authorization: String? = authorization + ) -> AnyPublisher { + URLSession.shared.dataTaskPublisher(for: urlRequest("GET", url: route, authorization: authorization)) .map(\.data) .decode(type: DataWrapper.self, decoder: decoder) .map(\.data) @@ -63,8 +73,10 @@ enum NetworkManager { /// - route: The route to get the `Element`s from /// - authorization: The `String` that should written in the `Authorization` header field /// - Returns: An `AnyPublisher` that contains an `Array` of `Element` from the server or an empty `Array` in the case of an error - static func getElements(on route: URL, - authorization: String? = authorization) -> AnyPublisher<[Element], Error> { + static func getElements( + on route: URL, + authorization: String? = authorization + ) -> AnyPublisher<[Element], Error> { getElement(on: route, authorization: authorization) .eraseToAnyPublisher() } @@ -75,12 +87,12 @@ enum NetworkManager { /// - route: The route to get the `Element`s from /// - authorization: The `String` that should written in the `Authorization` header field /// - Returns: An `AnyPublisher` that contains the created `Element` from the server or an `Error` in the case of an error - static func postElement(_ element: T, - authorization: String? = authorization, - on route: URL) -> AnyPublisher { - URLSession.shared.dataTaskPublisher(for: - urlRequest("POST", url: route, authorization: authorization, body: try? encoder.encode(element)) - ) + static func postElement( + _ element: T, + authorization: String? = authorization, + on route: URL + ) -> AnyPublisher { + URLSession.shared.dataTaskPublisher(for: urlRequest("POST", url: route, authorization: authorization, body: try? encoder.encode(element))) .map(\.data) .decode(type: DataWrapper.self, decoder: decoder) .map(\.data) @@ -94,12 +106,12 @@ enum NetworkManager { /// - route: The route to get the `Element`s from /// - authorization: The `String` that should written in the `Authorization` header field /// - Returns: An `AnyPublisher` that contains the updated `Element` from the server or an `Error` in the case of an error - static func putElement(_ element: T, - authorization: String? = authorization, - on route: URL) -> AnyPublisher { - URLSession.shared.dataTaskPublisher(for: - urlRequest("PUT", url: route, authorization: authorization, body: try? encoder.encode(element)) - ) + static func putElement( + _ element: T, + authorization: String? = authorization, + on route: URL + ) -> AnyPublisher { + URLSession.shared.dataTaskPublisher(for: urlRequest("PUT", url: route, authorization: authorization, body: try? encoder.encode(element))) .map(\.data) .decode(type: DataWrapper.self, decoder: decoder) .map(\.data) @@ -112,11 +124,11 @@ enum NetworkManager { /// - route: The route that identifes the resource /// - authorization: The `String` that should written in the `Authorization` header field /// - Returns: An `AnyPublisher` that contains indicates of the deletion was successful - static func delete(at route: URL, - authorization: String? = authorization) -> AnyPublisher { - URLSession.shared.dataTaskPublisher(for: - urlRequest("DELETE", url: route, authorization: authorization) - ) + static func delete( + at route: URL, + authorization: String? = authorization + ) -> AnyPublisher { + URLSession.shared.dataTaskPublisher(for: urlRequest("DELETE", url: route, authorization: authorization)) .tryMap { _, response in guard let response = response as? HTTPURLResponse, 200..<299 ~= response.statusCode else { throw URLError(.cannotRemoveFile) diff --git a/App/ExampleModel/Sources/Model/RestfulModel/Restful.swift b/App/ExampleModel/Sources/Model/RestfulModel/Restful.swift index 2ad9ab5..edfc017 100644 --- a/App/ExampleModel/Sources/Model/RestfulModel/Restful.swift +++ b/App/ExampleModel/Sources/Model/RestfulModel/Restful.swift @@ -1,5 +1,13 @@ -import Foundation +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Combine +import Foundation protocol Restful: Codable & Identifiable & Comparable { static var route: URL { get } @@ -19,14 +27,14 @@ extension Restful where Self.ID == UUID? { .eraseToAnyPublisher() } + static func delete(id: Self.ID) -> AnyPublisher { + NetworkManager.delete(at: Self.route.appendingPathComponent(id?.uuidString ?? "")) + } + func post() -> AnyPublisher { NetworkManager.postElement(self, on: Self.route) .eraseToAnyPublisher() } - - static func delete(id: Self.ID) -> AnyPublisher { - NetworkManager.delete(at: Self.route.appendingPathComponent(id?.uuidString ?? "")) - } func put() -> AnyPublisher { NetworkManager.putElement(self, on: Self.route.appendingPathComponent(self.id?.uuidString ?? "")) diff --git a/App/ExampleModel/Sources/Model/RestfulModel/RestfulModel.swift b/App/ExampleModel/Sources/Model/RestfulModel/RestfulModel.swift index 706da8d..5dd53fe 100644 --- a/App/ExampleModel/Sources/Model/RestfulModel/RestfulModel.swift +++ b/App/ExampleModel/Sources/Model/RestfulModel/RestfulModel.swift @@ -1,5 +1,13 @@ -import Foundation +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Combine +import Foundation import Shared @@ -12,8 +20,7 @@ public class RestfulModel: LocalStorageModel { }() public convenience init() { - self.init(contacts: Contact.loadFromFile(), - residencies: Residence.loadFromFile()) + self.init(contacts: Contact.loadFromFile(), residencies: Residence.loadFromFile()) $contacts .sink { @@ -94,25 +101,29 @@ public class RestfulModel: LocalStorageModel { private func refresh() { Contact.get() - .sink(receiveCompletion: { completion in + .sink( + receiveCompletion: { completion in if case .failure = completion { self.serverError = .loadingFailed(Contact.self) } }, receiveValue: { contacts in self.contacts = contacts - }) + } + ) .store(in: &cancellables) Residence.get() - .sink(receiveCompletion: { completion in + .sink( + receiveCompletion: { completion in if case .failure = completion { self.serverError = .loadingFailed(Residence.self) } }, receiveValue: { residencies in self.residencies = residencies - }) + } + ) .store(in: &cancellables) } } diff --git a/App/ExampleModel/Sources/Model/ServiceError.swift b/App/ExampleModel/Sources/Model/ServiceError.swift index ff180b0..9ae2d24 100644 --- a/App/ExampleModel/Sources/Model/ServiceError.swift +++ b/App/ExampleModel/Sources/Model/ServiceError.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Combine import Foundation diff --git a/App/ExampleModel/Tests/ModelTests/ExampleModelTests.swift b/App/ExampleModel/Tests/ModelTests/ExampleModelTests.swift index a66cc0f..b4a8354 100644 --- a/App/ExampleModel/Tests/ModelTests/ExampleModelTests.swift +++ b/App/ExampleModel/Tests/ModelTests/ExampleModelTests.swift @@ -1,5 +1,13 @@ -import XCTest +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + @testable import Model +import XCTest final class ModelTests: XCTestCase { diff --git a/App/fastlane/.gitignore b/App/fastlane/.gitignore deleted file mode 100644 index b388bc0..0000000 --- a/App/fastlane/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*/ -report.xml diff --git a/App/fastlane/Appfile b/App/fastlane/Appfile deleted file mode 100644 index 275dbf0..0000000 --- a/App/fastlane/Appfile +++ /dev/null @@ -1,13 +0,0 @@ -# For more information about the Appfile, see: -# https://docs.fastlane.tools/advanced/#appfile - - -for_lane :bamboo do - app_identifier "de.tum.in.www1.ios21.example.nils" # FIXME Enterprise Bundle Identifier - - # Nothing to change here - team_id "WCM2L8RG39" - apple_dev_portal_id "ls1.itg@in.tum.de" - team_name "iPhone Distribution: Technische Universitat Munchen" - -end diff --git a/App/fastlane/Fastfile b/App/fastlane/Fastfile deleted file mode 100644 index e8e2b97..0000000 --- a/App/fastlane/Fastfile +++ /dev/null @@ -1,142 +0,0 @@ -# This file contains the fastlane.tools configuration -# You can find the documentation at https://docs.fastlane.tools -# -# For a list of all available actions, check out -# -# https://docs.fastlane.tools/actions -# - -# Uncomment the line if you want fastlane to automatically update itself -# update_fastlane - -default_platform(:ios) - -platform :ios do - - desc "[local] Build only" - lane :build do - - # Resolve the Swift Package Manager dependencies - xcodebuild( - build: false, - xcargs: "-resolvePackageDependencies", - ) - - # Build the application without tests - xcodebuild( - configuration: "Debug", - clean: true, - build: true, - build_settings: { - "CODE_SIGNING_ALLOWED" => "NO", - "CODE_SIGNING_REQUIRED" => "NO", - "CODE_SIGN_IDENTITY" => "", - "CODE_SIGN_ENTITLEMENTS" => "", - } - ) - end - - desc "[local] Run Unit and UI Tests" - lane :test do - - # Run UI and Unit Tests - scan( - clean: true, - ) - end - - desc "[ci] Default bamboo configuration" - lane :bamboo do - - ########################################## - # Environment Setup - ########################################## - - # Unlock the agent keychain to gain access to the necessary certificates - unlock_keychain( - path: ENV['bamboo_KeyChain'], - password: ENV['bamboo_KeyChainPassword'], - ) - - # Setup Fastlane Variables - ENV['FASTLANE_PASSWORD'] = ENV['bamboo_FASTLANE_PASSWORD'] # Necessary for Developer Protal login - ENV['FASTLANE_SESSION'] = ENV['bamboo_FASTLANE_SESSION_PASSWORD'] # Necessary for 2FA - - - ########################################## - # Prototyper Setup - ########################################## - - # Location of the info.plist in the folder structure - INFO_PLIST = sh("find .. -name Info.plist -type f -not -path */Pods/* -not -path *Test* | head -n 1 | cut -c 2-").strip - - # Prototyper Buildstring to identify releases - ENV['PROTOTYPER_BUILDSTRING'] = sh("date", "+%y%m%d_%H%M").rstrip + "-build" + (ENV['bamboo_buildNumber'] ||= "") + "-" + (ENV['bamboo_repository_branch_name'] ||= "") - - puts "#############################################" - puts INFO_PLIST - puts ENV['PROTOTYPER_BUILDSTRING'] - puts "#############################################" - - # Write Prototyper BuildString to Info.plist - set_info_plist_value( - path: INFO_PLIST, - key: "CFBundleVersion", - value: "$(PROTOTYPER_BUILDSTRING)" - ) - - # Create BuildString file as Artifact - sh "echo $PROTOTYPER_BUILDSTRING > BuildString.txt" - sh "mv BuildString.txt ../" - - - ########################################## - # Provisioning Profile - ########################################## - - # Invoke fastlane sigh to get the app provisioned - get_provisioning_profile - - ########################################## - # Project Setup - ########################################## - - # Update AppID for enterprise team - update_app_identifier( - plist_path: INFO_PLIST - ) - - # Update Xcode Project to use maunual code signing - update_code_signing_settings( - use_automatic_signing: false, - ) - - # Define correct Provisioning Profile in Xcode Project - update_project_provisioning( - build_configuration: "Release" - ) - - ########################################## - # Swift Package Manager - ########################################## - - # Resolve the Swift Package Manager dependencies - xcodebuild( - build: false, - xcargs: "-resolvePackageDependencies", - ) - - ########################################## - # Code sign and Build - ########################################## - - # Build the app - build_ios_app( - clean: true, - output_name: "BuildedApplication.ipa", - export_method: "enterprise", - configuration: "Release" - ) - - end -end diff --git a/App/fastlane/Gymfile b/App/fastlane/Gymfile deleted file mode 100644 index afb8a34..0000000 --- a/App/fastlane/Gymfile +++ /dev/null @@ -1,15 +0,0 @@ -# For more information about this configuration visit -# https://github.com/fastlane/fastlane/tree/master/gym#gymfile - -# In general, you can use the options available -# fastlane gym --help - -# Remove the # in front of the line to enable the option - -scheme "App" - -# Nothing to change here - -codesigning_identity "iPhone Distribution: Technische Universitat Munchen" -clean true -output_directory "./" diff --git a/App/fastlane/Scanfile b/App/fastlane/Scanfile deleted file mode 100644 index 4393410..0000000 --- a/App/fastlane/Scanfile +++ /dev/null @@ -1,4 +0,0 @@ -# For more information about the Scanfile, see: -# https://docs.fastlane.tools/actions/run_tests/#scanfile - -devices(["iPhone 8", "iPhone 12 Pro Max"]) # FIXME diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 0000000..dff9370 --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,16 @@ + + +Apodini Example contributors +==================== + +* [Paul Schmiedmayer](https://github.com/PSchmiedmayer) +* [Philipp Zagar](https://github.com/philippzagar) +* [Hans Santoso](https://github.com/hansfilbert) diff --git a/Example.xcworkspace/contents.xcworkspacedata.license b/Example.xcworkspace/contents.xcworkspacedata.license new file mode 100644 index 0000000..90eccee --- /dev/null +++ b/Example.xcworkspace/contents.xcworkspacedata.license @@ -0,0 +1,6 @@ + +This source file is part of the Apodini Example open source project + +SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) + +SPDX-License-Identifier: MIT diff --git a/Example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist.license b/Example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist.license new file mode 100644 index 0000000..90eccee --- /dev/null +++ b/Example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist.license @@ -0,0 +1,6 @@ + +This source file is part of the Apodini Example open source project + +SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) + +SPDX-License-Identifier: MIT diff --git a/Example.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Example.xcworkspace/xcshareddata/swiftpm/Package.resolved index f6ec5a4..53f60b1 100644 --- a/Example.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Example.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -2,7 +2,7 @@ "object": { "pins": [ { - "package": "APNSwift", + "package": "apnswift", "repositoryURL": "https://github.com/kylebrowning/APNSwift.git", "state": { "branch": null, @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/Apodini/Apodini.git", "state": { "branch": null, - "revision": "c1193105f1a4b7320bbd3f5c404e6110746b31d8", - "version": "0.3.0" + "revision": "e6a943b0db29b2df5c0c139ab993e57752bf22b7", + "version": "0.5.0" } }, { @@ -46,15 +46,6 @@ "version": "1.3.1" } }, - { - "package": "BSON", - "repositoryURL": "https://github.com/OpenKitten/BSON.git", - "state": { - "branch": null, - "revision": "5ef02954ff53960ae6fba46cd03c7bee51deb62e", - "version": "7.0.27" - } - }, { "package": "console-kit", "repositoryURL": "https://github.com/vapor/console-kit.git", @@ -82,15 +73,6 @@ "version": "1.14.0" } }, - { - "package": "fluent", - "repositoryURL": "https://github.com/vapor/fluent.git", - "state": { - "branch": null, - "revision": "5810a409eb0271a576f68887fa6713dae3985056", - "version": "4.3.1" - } - }, { "package": "fluent-kit", "repositoryURL": "https://github.com/vapor/fluent-kit.git", @@ -100,33 +82,6 @@ "version": "1.13.0" } }, - { - "package": "fluent-mongo-driver", - "repositoryURL": "https://github.com/vapor/fluent-mongo-driver.git", - "state": { - "branch": null, - "revision": "ce519013f51439773fe668d6575888665b0e2dda", - "version": "1.0.2" - } - }, - { - "package": "fluent-mysql-driver", - "repositoryURL": "https://github.com/vapor/fluent-mysql-driver.git", - "state": { - "branch": null, - "revision": "699e164880387349bf04c2329fe53097524a5904", - "version": "4.0.0" - } - }, - { - "package": "fluent-postgres-driver", - "repositoryURL": "https://github.com/vapor/fluent-postgres-driver.git", - "state": { - "branch": null, - "revision": "afe159ce915e752ab5f5b76479dc78a17051ce73", - "version": "2.1.3" - } - }, { "package": "fluent-sqlite-driver", "repositoryURL": "https://github.com/vapor/fluent-sqlite-driver.git", @@ -154,15 +109,6 @@ "version": "4.2.2" } }, - { - "package": "MongoKitten", - "repositoryURL": "https://github.com/OpenKitten/MongoKitten.git", - "state": { - "branch": null, - "revision": "8a98326aca11c29d87a8bf1538679bb5ad9fd733", - "version": "6.6.6" - } - }, { "package": "multipart-kit", "repositoryURL": "https://github.com/vapor/multipart-kit.git", @@ -172,33 +118,6 @@ "version": "4.2.1" } }, - { - "package": "mysql-kit", - "repositoryURL": "https://github.com/vapor/mysql-kit.git", - "state": { - "branch": null, - "revision": "fe836ecd52815ed1399e654b5365c108ff1638fd", - "version": "4.1.0" - } - }, - { - "package": "mysql-nio", - "repositoryURL": "https://github.com/vapor/mysql-nio.git", - "state": { - "branch": null, - "revision": "4cbef4c0903c9792ff1f8dc4b55532276fa70c99", - "version": "1.3.2" - } - }, - { - "package": "NioDNS", - "repositoryURL": "https://github.com/OpenKitten/NioDNS.git", - "state": { - "branch": null, - "revision": "7517b774d48833f04869fcde668d2f338fadc464", - "version": "2.0.6" - } - }, { "package": "OpenAPIKit", "repositoryURL": "https://github.com/mattpolzin/OpenAPIKit.git", @@ -208,33 +127,6 @@ "version": "2.4.0" } }, - { - "package": "OpenCombine", - "repositoryURL": "https://github.com/OpenCombine/OpenCombine.git", - "state": { - "branch": null, - "revision": "28993ae57de5a4ea7e164787636cafad442d568c", - "version": "0.12.0" - } - }, - { - "package": "postgres-kit", - "repositoryURL": "https://github.com/vapor/postgres-kit.git", - "state": { - "branch": null, - "revision": "13f6c735cf9a9053011d03e77e2a81802ad6c680", - "version": "2.3.0" - } - }, - { - "package": "postgres-nio", - "repositoryURL": "https://github.com/vapor/postgres-nio.git", - "state": { - "branch": null, - "revision": "33eea144f465a48b17f4c63573c40d33824fdde4", - "version": "1.5.2" - } - }, { "package": "RichJSONParser", "repositoryURL": "https://github.com/omochi/RichJSONParser.git", @@ -402,8 +294,8 @@ "repositoryURL": "https://github.com/apple/swift-nio.git", "state": { "branch": null, - "revision": "d79e33308b0ac83326b0ead0ea6446e604b8162d", - "version": "2.30.0" + "revision": "9a992ee3de1f8da9f2968fc96b26714834f3105f", + "version": "2.31.1" } }, { diff --git a/Example.xcworkspace/xcshareddata/swiftpm/Package.resolved.license b/Example.xcworkspace/xcshareddata/swiftpm/Package.resolved.license new file mode 100644 index 0000000..90eccee --- /dev/null +++ b/Example.xcworkspace/xcshareddata/swiftpm/Package.resolved.license @@ -0,0 +1,6 @@ + +This source file is part of the Apodini Example open source project + +SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) + +SPDX-License-Identifier: MIT diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..4b2cb50 --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Paul Schmiedmayer and the project authors (see CONTRIBUTORS.md) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 7eef237..f894448 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ + + # Apodini Example [![DOI](https://zenodo.org/badge/375610092.svg)](https://zenodo.org/badge/latestdoi/375610092) diff --git a/Shared/.gitignore b/Shared/.gitignore deleted file mode 100644 index a573037..0000000 --- a/Shared/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.DS_Store -.build -.xcodeproj -.swiftpm diff --git a/Shared/Package.resolved.license b/Shared/Package.resolved.license new file mode 100644 index 0000000..90eccee --- /dev/null +++ b/Shared/Package.resolved.license @@ -0,0 +1,6 @@ + +This source file is part of the Apodini Example open source project + +SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) + +SPDX-License-Identifier: MIT diff --git a/Shared/Package.swift b/Shared/Package.swift index b7ab8e3..2cff4d8 100644 --- a/Shared/Package.swift +++ b/Shared/Package.swift @@ -1,4 +1,12 @@ -// swift-tools-version:5.3 +// swift-tools-version:5.5 + +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// import PackageDescription @@ -6,8 +14,8 @@ import PackageDescription let package = Package( name: "Shared", platforms: [ - .macOS(.v11), - .iOS(.v14) + .macOS(.v12), + .iOS(.v15) ], products: [ .library( diff --git a/Shared/README.md b/Shared/README.md deleted file mode 100644 index 4cf9513..0000000 --- a/Shared/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Shared - -A description of this package. diff --git a/Shared/Sources/Shared/Extensions/DateFormatter.swift b/Shared/Sources/Shared/Extensions/DateFormatter.swift index 97b309f..a89a292 100644 --- a/Shared/Sources/Shared/Extensions/DateFormatter.swift +++ b/Shared/Sources/Shared/Extensions/DateFormatter.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Foundation extension DateFormatter { diff --git a/Shared/Sources/Shared/Migrations/ContactMigration.swift b/Shared/Sources/Shared/Migrations/ContactMigration.swift index 92db7f7..c088ef7 100644 --- a/Shared/Sources/Shared/Migrations/ContactMigration.swift +++ b/Shared/Sources/Shared/Migrations/ContactMigration.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import FluentKit diff --git a/Shared/Sources/Shared/Migrations/ResidenceMigration.swift b/Shared/Sources/Shared/Migrations/ResidenceMigration.swift index e3c5081..5a99e5a 100644 --- a/Shared/Sources/Shared/Migrations/ResidenceMigration.swift +++ b/Shared/Sources/Shared/Migrations/ResidenceMigration.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import FluentKit public struct ResidenceMigration: Migration { diff --git a/Shared/Sources/Shared/Models/Contact.swift b/Shared/Sources/Shared/Models/Contact.swift index 1a13289..0b64c11 100644 --- a/Shared/Sources/Shared/Models/Contact.swift +++ b/Shared/Sources/Shared/Models/Contact.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import FluentKit import Foundation diff --git a/Shared/Sources/Shared/Models/Residence.swift b/Shared/Sources/Shared/Models/Residence.swift index abd4b46..2326e20 100644 --- a/Shared/Sources/Shared/Models/Residence.swift +++ b/Shared/Sources/Shared/Models/Residence.swift @@ -1,5 +1,13 @@ -import Foundation +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import FluentKit +import Foundation // MARK: Residence diff --git a/Shared/Tests/LinuxMain.swift b/Shared/Tests/LinuxMain.swift deleted file mode 100644 index 08ae2ac..0000000 --- a/Shared/Tests/LinuxMain.swift +++ /dev/null @@ -1,7 +0,0 @@ -// A LinuxMain.swift file is no longer needed since `swift test --enable-test-discovery` is possible -// Provide an error message when testing on Linux with no automatic test discovery -#error(""" - ----------------------------------------------------- - Please test with `swift test --enable-test-discovery` - ----------------------------------------------------- - """) diff --git a/Shared/Tests/SharedTests/SampleSharedTests.swift b/Shared/Tests/SharedTests/SampleSharedTests.swift index 0f7db22..f599ae0 100644 --- a/Shared/Tests/SharedTests/SampleSharedTests.swift +++ b/Shared/Tests/SharedTests/SampleSharedTests.swift @@ -1,5 +1,13 @@ -import XCTest +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + @testable import Shared +import XCTest final class SharedTests: XCTestCase { diff --git a/WebService/.gitignore b/WebService/.gitignore deleted file mode 100644 index a573037..0000000 --- a/WebService/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.DS_Store -.build -.xcodeproj -.swiftpm diff --git a/WebService/.swiftlint.yml b/WebService/.swiftlint.yml deleted file mode 100644 index 9050484..0000000 --- a/WebService/.swiftlint.yml +++ /dev/null @@ -1,391 +0,0 @@ -# Apodini SwiftLint file Apodini - -# The whitelist_rules configuration also includes rules that are enabled by default to provide a good overview of all rules. -only_rules: - - attributes - - anyobject_protocol - # Prefer using AnyObject over class for class-only protocols. - - array_init - # Prefer using Array(seq) over seq.map { $0 } to convert a sequence into an Array. - - block_based_kvo - # Prefer the new block based KVO API with keypaths when using Swift 3.2 or later. - - class_delegate_protocol - # Delegate protocols should be class-only so they can be weakly referenced. - - closing_brace - # Closing brace with closing parenthesis should not have any whitespaces in the middle. - - closure_body_length - # Closure bodies should not span too many lines. - - closure_end_indentation - # Closure end should have the same indentation as the line that started it. - - closure_parameter_position - # Closure parameters should be on the same line as opening brace. - - closure_spacing - # Closure expressions should have a single space inside each brace. - - collection_alignment - # All elements in a collection literal should be vertically aligned - - colon - # Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. - - comma - # There should be no space before and one after any comma. - - compiler_protocol_init - # The initializers declared in compiler protocols such as ExpressibleByArrayLiteral shouldn't be called directly. - - computed_accessors_order - # Getter and setters in computed properties and subscripts should be in a consistent order. - - conditional_returns_on_newline - # Conditional statements should always return on the next line - - contains_over_filter_count - # Prefer contains over comparing filter(where:).count to 0. - - contains_over_filter_is_empty - # Prefer contains over using filter(where:).isEmpty - - contains_over_first_not_nil - # Prefer `contains` over `first(where:) != nil` - - contains_over_range_nil_comparison - # Prefer contains over range(of:) != nil and range(of:) == nil - - control_statement - # if, for, guard, switch, while, and catch statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses. - - convenience_type - # Types used for hosting only static members should be implemented as a caseless enum to avoid instantiation. - - cyclomatic_complexity - # Complexity of function bodies should be limited. - - discarded_notification_center_observer - # When registering for a notification using a block, the opaque observer that is returned should be stored so it can be removed later. - - discouraged_direct_init - # Discouraged direct initialization of types that can be harmful. e.g. UIDevice(), Bundle() - - discouraged_optional_boolean - # Prefer non-optional booleans over optional booleans. - - discouraged_optional_collection - # Prefer empty collection over optional collection. - - duplicate_imports - # Duplicate Imports - - dynamic_inline - # Avoid using 'dynamic' and '@inline(__always)' together. - - empty_collection_literal - # Prefer checking isEmpty over comparing collection to an empty array or dictionary literal. - - empty_count - # Prefer checking `isEmpty` over comparing `count` to zero. - - empty_enum_arguments - # Arguments can be omitted when matching enums with associated types if they are not used. - - empty_parameters - # Prefer () -> over Void ->. - - empty_parentheses_with_trailing_closure - # When using trailing closures, empty parentheses should be avoided after the method call. - - empty_string - # Prefer checking `isEmpty` over comparing string to an empty string literal. - - empty_xctest_method - # Empty XCTest method should be avoided. - - enum_case_associated_values_count - # Number of associated values in an enum case should be low - - explicit_init - # Explicitly calling .init() should be avoided. - - fatal_error_message - # A fatalError call should have a message. - - file_length - # Files should not span too many lines. - # See file_length below for the exact configuration. - - first_where - # Prefer using ``.first(where:)`` over ``.filter { }.first` in collections. - - flatmap_over_map_reduce - # Prefer flatMap over map followed by reduce([], +). - - for_where - # where clauses are preferred over a single if inside a for. - - force_cast - # Force casts should be avoided. - - force_try - # Force tries should be avoided. - - force_unwrapping - # Force unwrapping should be avoided. - - function_body_length - # Functions bodies should not span too many lines. - # See function_body_length below for the exact configuration. - - function_parameter_count - # Number of function parameters should be low. - # See function_parameter_count below for the exact configuration. - - generic_type_name - # Generic type name should only contain alphanumeric characters, start with an uppercase character and span between 1 and 20 characters in length. - - identical_operands - # Comparing two identical operands is likely a mistake. - - identifier_name - # Identifier names should only contain alphanumeric characters and start with a lowercase character or should only contain capital letters. - # In an exception to the above, variable names may start with a capital letter when they are declared static and immutable. - # Variable names should not be too long or too short. Excluded names are listed below. - - implicit_getter - # Computed read-only properties and subscripts should avoid using the get keyword. - - implicit_return - # Prefer implicit returns in closures. - - implicitly_unwrapped_optional - # Implicitly unwrapped optionals should be avoided when possible. - - inclusive_language - # Identifiers should use inclusive language that avoids discrimination against groups of people based on race, gender, or socioeconomic status - - inert_defer - # If defer is at the end of its parent scope, it will be executed right where it is anyway. - - is_disjoint - # Prefer using Set.isDisjoint(with:) over Set.intersection(_:).isEmpty. - - joined_default_parameter - # Discouraged explicit usage of the default separator. - - large_tuple - # Tuples shouldn't have too many members. Create a custom type instead. - # See large_tuple below for the exact configuration. - - last_where - # Prefer using .last(where:) over .filter { }.last in collections. - - leading_whitespace - # Files should not contain leading whitespace. - - legacy_cggeometry_functions - # CGGeometry: Struct extension properties and methods are preferred over legacy functions - - legacy_constant - # Struct-scoped constants are preferred over legacy global constants (CGSize, CGRect, NSPoint, ...). - - legacy_constructor - # Swift constructors are preferred over legacy convenience functions (CGPointMake, CGSizeMake, UIOffsetMake, ...). - - legacy_hashing - # Prefer using the hash(into:) function instead of overriding hashValue - - legacy_multiple - # Prefer using the isMultiple(of:) function instead of using the remainder operator (%). - - legacy_nsgeometry_functions - # Struct extension properties and methods are preferred over legacy functions - - legacy_random - # Prefer using type.random(in:) over legacy functions. - - line_length - # Lines should not span too many characters. - # See line_length below for the exact configuration. - - literal_expression_end_indentation - # Array and dictionary literal end should have the same indentation as the line that started it. - - lower_acl_than_parent - # Ensure definitions have a lower access control level than their enclosing parent - - mark - # MARK comment should be in valid format. e.g. '// MARK: ...' or '// MARK: - ...' - - missing_docs - # Declarations should be documented. - - modifier_order - # Modifier order should be consistent. - - multiline_arguments - # Arguments should be either on the same line, or one per line. - - multiline_function_chains - # Chained function calls should be either on the same line, or one per line. - - multiline_literal_brackets - # Multiline literals should have their surrounding brackets in a new line. - - multiline_parameters - # Functions and methods parameters should be either on the same line, or one per line. - - nesting - # Types and functions should only be nested to a certain level deep. - # See nesting below for the exact configuration. - - nimble_operator - # Prefer Nimble operator overloads over free matcher functions. - - no_fallthrough_only - # Fallthroughs can only be used if the case contains at least one other statement. - - no_space_in_method_call - # Don’t add a space between the method name and the parentheses. - - notification_center_detachment - # An object should only remove itself as an observer in deinit. - - nslocalizedstring_key - # Static strings should be used as key in NSLocalizedString in order to genstrings work. - - nsobject_prefer_isequal - # NSObject subclasses should implement isEqual instead of ==. - - object_literal - # Prefer object literals over image and color inits. - - opening_brace - # Opening braces should be preceded by a single space and on the same line as the declaration. - - operator_usage_whitespace - # Operators should be surrounded by a single whitespace when they are being used. - - operator_whitespace - # Operators should be surrounded by a single whitespace when defining them. - - optional_enum_case_matching - # Matching an enum case against an optional enum without ‘?’ is supported on Swift 5.1 and above. - - orphaned_doc_comment - # A doc comment should be attached to a declaration. - - overridden_super_call - # Some overridden methods should always call super - - pattern_matching_keywords - # Combine multiple pattern matching bindings by moving keywords out of tuples. - - prefer_self_type_over_type_of_self - # Prefer Self over type(of: self) when accessing properties or calling methods. - - private_action - # IBActions should be private. - - private_outlet - # IBOutlets should be private to avoid leaking UIKit to higher layers. - - private_over_fileprivate - # Prefer private over fileprivate declarations. - - private_unit_test - # Unit tests marked private are silently skipped. - - prohibited_super_call - # Some methods should not call super ( - # NSFileProviderExtension: providePlaceholder(at:completionHandler:) - # NSTextInput doCommand(by:) - # NSView updateLayer() - # UIViewController loadView()) - - protocol_property_accessors_order - # When declaring properties in protocols, the order of accessors should be get set. - - reduce_boolean - # Prefer using .allSatisfy() or .contains() over reduce(true) or reduce(false) - - reduce_into - # Prefer reduce(into:_:) over reduce(_:_:) for copy-on-write types - - redundant_discardable_let - # Prefer _ = foo() over let _ = foo() when discarding a result from a function. - - redundant_nil_coalescing - # nil coalescing operator is only evaluated if the lhs is nil, coalescing operator with nil as rhs is redundant - - redundant_objc_attribute - # Objective-C attribute (@objc) is redundant in declaration. - - redundant_optional_initialization - # Initializing an optional variable with nil is redundant. - - redundant_set_access_control - # Property setter access level shouldn't be explicit if it's the same as the variable access level. - - redundant_string_enum_value - # String enum values can be omitted when they are equal to the enumcase name. - - redundant_type_annotation - # Variables should not have redundant type annotation - - redundant_void_return - # Returning Void in a function declaration is redundant. - - return_arrow_whitespace - # Return arrow and return type should be separated by a single space or on a separate line. - - shorthand_operator - # Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning. - - single_test_class - # Test files should contain a single QuickSpec or XCTestCase class. - - sorted_first_last - # Prefer using `min()`` or `max()`` over `sorted().first` or `sorted().last` - - statement_position - # Else and catch should be on the same line, one space after the previous declaration. - - static_operator - # Operators should be declared as static functions, not free functions. - - superfluous_disable_command - # SwiftLint ‘disable’ commands are superfluous when the disabled rule would not have triggered a violation in the disabled region. Use “ - ” if you wish to document a command. - - switch_case_alignment - # Case statements should vertically align with their enclosing switch statement, or indented if configured otherwise. - - syntactic_sugar - # Shorthand syntactic sugar should be used, i.e. [Int] instead of Array. - - todo - # TODOs and FIXMEs should be resolved. - - toggle_bool - # Prefer someBool.toggle() over someBool = !someBool. - - trailing_closure - # Trailing closure syntax should be used whenever possible. - - trailing_comma - # Trailing commas in arrays and dictionaries should be avoided/enforced. - - trailing_newline - # Files should have a single trailing newline. - - trailing_semicolon - # Lines should not have trailing semicolons. - - trailing_whitespace - # Lines should not have trailing whitespace. - # Ignored lines are specified below. - - type_body_length - # Type bodies should not span too many lines. - # See large_tuple below for the exact configuration. - - type_name - # Type name should only contain alphanumeric characters, start with an uppercase character and span between 3 and 40 characters in length. - # Excluded types are listed below. - - unneeded_break_in_switch - # Avoid using unneeded break statements. - - unneeded_parentheses_in_closure_argument - # Parentheses are not needed when declaring closure arguments. - - untyped_error_in_catch - # Catch statements should not declare error variables without type casting. - - unused_capture_list - # Unused reference in a capture list should be removed. - - unused_closure_parameter - # Unused parameter in a closure should be replaced with _. - - unused_control_flow_label - # Unused control flow label should be removed. - - unused_declaration - # Declarations should be referenced at least once within all files linted. - - unused_enumerated - # When the index or the item is not used, .enumerated() can be removed. - - unused_import - # All imported modules should be required to make the file compile. - - unused_optional_binding - # Prefer != nil over let _ = - - unused_setter_value - # Setter value is not used. - - valid_ibinspectable - # @IBInspectable should be applied to variables only, have its type explicit and be of a supported type - - vertical_parameter_alignment - # Function parameters should be aligned vertically if they're in multiple lines in a declaration. - - vertical_parameter_alignment_on_call - # Function parameters should be aligned vertically if they're in multiple lines in a method call. - - vertical_whitespace - # Limit vertical whitespace to a single empty line. - # See vertical_whitespace below for the exact configuration. - - vertical_whitespace_closing_braces - # Don’t include vertical whitespace (empty line) before closing braces. - - vertical_whitespace_opening_braces - # Don’t include vertical whitespace (empty line) after opening braces. - - void_return - # Prefer -> Void over -> (). - # - weak_delegate (we don't really use the delegate pattern anywhere and the name-collision with our own 'Delegate' is annoying) - # Delegates should be weak to avoid reference cycles. - - xctfail_message - # An XCTFail call should include a description of the assertion. - - yoda_condition - # The variable should be placed on the left, the constant on the right of a comparison operator. - -excluded: # paths to ignore during linting. Takes precedence over `included`. - - .build - - TestWebService/.build - - .swiftpm - -closure_body_length: # Closure bodies should not span too many lines. - - 35 # warning - default: 20 - - 35 # error - default: 100 - -enum_case_associated_values_count: # Number of associated values in an enum case should be low - - 5 # warning - default: 5 - - 5 # error - default: 6 - -file_length: # Files should not span too many lines. - - 500 # warning - default: 400 - - 500 # error - default: 1000 - -function_body_length: # Functions bodies should not span too many lines. - - 50 # warning - default: 40 - - 50 # error - default: 100 - -function_parameter_count: # Number of function parameters should be low. - - 5 # warning - default: 5 - - 5 # error - default: 8 - -identifier_name: - excluded: # excluded names - - id - - ok - - or - - p8 - - of - - s3 - - at - -large_tuple: # Tuples shouldn't have too many members. Create a custom type instead. - - 2 # warning - default: 2 - - 2 # error - default: 3 - -line_length: # Lines should not span too many characters. - warning: 150 # default: 120 - error: 150 # default: 200 - ignores_comments: true # default: false - ignores_urls: true # default: false - ignores_function_declarations: false # default: false - ignores_interpolated_strings: true # default: false - -nesting: # Types should be nested at most 2 level deep, and functions should be nested at most 5 levels deep. - type_level: - warning: 2 # warning - default: 1 - function_level: - warning: 5 # warning - default: 5 - -trailing_closure: - only_single_muted_parameter: true - -type_body_length: # Type bodies should not span too many lines. - - 250 # warning - default: 200 - - 250 # error - default: 200 - -type_name: - excluded: # excluded names - - ID - -trailing_whitespace: - ignores_empty_lines: true # default: false - ignores_comments: true # default: false - -unused_optional_binding: - ignore_optional_try: true - -vertical_whitespace: # Limit vertical whitespace to a single empty line. - max_empty_lines: 2 # warning - default: 1 \ No newline at end of file diff --git a/WebService/Dockerfile b/WebService/Dockerfile index e7a726b..ae2c4a5 100644 --- a/WebService/Dockerfile +++ b/WebService/Dockerfile @@ -1,7 +1,15 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + # ================================ # Build image # ================================ -FROM swift:5.4-focal as build +FROM swiftlang/swift:nightly-5.5-focal as build # Install OS updates and, if needed, sqlite3 RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \ @@ -17,7 +25,7 @@ WORKDIR /build COPY . . # Build everything, with optimizations -RUN swift build -Xswiftc -Xfrontend -Xswiftc -sil-verify-none -c release --package-path ./WebService +RUN swift build -c release --package-path ./WebService # Switch to the staging area WORKDIR /staging @@ -42,7 +50,7 @@ RUN mkdir database # ================================ # Run image # ================================ -FROM swift:5.4-focal-slim +FROM swiftlang/swift:nightly-5.5-focal-slim # Make sure all system packages are up to date. RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \ diff --git a/WebService/Package.resolved.license b/WebService/Package.resolved.license new file mode 100644 index 0000000..90eccee --- /dev/null +++ b/WebService/Package.resolved.license @@ -0,0 +1,6 @@ + +This source file is part of the Apodini Example open source project + +SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) + +SPDX-License-Identifier: MIT diff --git a/WebService/Package.swift b/WebService/Package.swift index bac1639..90b01d4 100644 --- a/WebService/Package.swift +++ b/WebService/Package.swift @@ -1,17 +1,26 @@ -// swift-tools-version:5.4 +// swift-tools-version:5.5 + +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// import PackageDescription let package = Package( name: "WebService", platforms: [ - .macOS(.v11) + .macOS(.v12) ], products: [ .executable(name: "WebService", targets: ["WebService"]) ], dependencies: [ - .package(url: "https://github.com/Apodini/Apodini.git", .upToNextMinor(from: "0.3.0")), + .package(url: "https://github.com/Apodini/Apodini.git", .upToNextMinor(from: "0.5.0")), + .package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.1.0"), .package(path: "../Shared") ], targets: [ @@ -28,14 +37,15 @@ let package = Package( .product(name: "ApodiniREST", package: "Apodini"), .product(name: "ApodiniOpenAPI", package: "Apodini"), .product(name: "ApodiniDatabase", package: "Apodini"), + .product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver"), .product(name: "Shared", package: "Shared") ] ), .testTarget( name: "ExampleWebServiceTests", dependencies: [ - //.product(name: "XCTApodini", package: "Apodini"), - //.product(name: "XCTApodiniDatabase", package: "Apodini"), + // .product(name: "XCTApodini", package: "Apodini"), + // .product(name: "XCTApodiniDatabase", package: "Apodini"), .target(name: "ExampleWebService") ] ) diff --git a/WebService/README.md b/WebService/README.md deleted file mode 100644 index 8ebe23e..0000000 --- a/WebService/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# WebService - -A description of this package. diff --git a/WebService/Sources/ExampleWebService/Components/ContactComponent.swift b/WebService/Sources/ExampleWebService/Components/ContactComponent.swift index abff717..0bd1d13 100644 --- a/WebService/Sources/ExampleWebService/Components/ContactComponent.swift +++ b/WebService/Sources/ExampleWebService/Components/ContactComponent.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import Shared diff --git a/WebService/Sources/ExampleWebService/Components/ContactHandler/CreateContact.swift b/WebService/Sources/ExampleWebService/Components/ContactHandler/CreateContact.swift index cf9a49a..e728306 100644 --- a/WebService/Sources/ExampleWebService/Components/ContactHandler/CreateContact.swift +++ b/WebService/Sources/ExampleWebService/Components/ContactHandler/CreateContact.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import FluentKit import Shared diff --git a/WebService/Sources/ExampleWebService/Components/ContactHandler/DeleteContact.swift b/WebService/Sources/ExampleWebService/Components/ContactHandler/DeleteContact.swift index 8e3b1bf..996232e 100644 --- a/WebService/Sources/ExampleWebService/Components/ContactHandler/DeleteContact.swift +++ b/WebService/Sources/ExampleWebService/Components/ContactHandler/DeleteContact.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import FluentKit import Shared diff --git a/WebService/Sources/ExampleWebService/Components/ContactHandler/GetContact.swift b/WebService/Sources/ExampleWebService/Components/ContactHandler/GetContact.swift index 229f2a4..9dc15b7 100644 --- a/WebService/Sources/ExampleWebService/Components/ContactHandler/GetContact.swift +++ b/WebService/Sources/ExampleWebService/Components/ContactHandler/GetContact.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import FluentKit import Shared diff --git a/WebService/Sources/ExampleWebService/Components/ContactHandler/GetContacts.swift b/WebService/Sources/ExampleWebService/Components/ContactHandler/GetContacts.swift index 43d55d0..708a6f5 100644 --- a/WebService/Sources/ExampleWebService/Components/ContactHandler/GetContacts.swift +++ b/WebService/Sources/ExampleWebService/Components/ContactHandler/GetContacts.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import FluentKit import Shared diff --git a/WebService/Sources/ExampleWebService/Components/ContactHandler/UpdateContact.swift b/WebService/Sources/ExampleWebService/Components/ContactHandler/UpdateContact.swift index 79f20de..44eb819 100644 --- a/WebService/Sources/ExampleWebService/Components/ContactHandler/UpdateContact.swift +++ b/WebService/Sources/ExampleWebService/Components/ContactHandler/UpdateContact.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import FluentKit import Shared diff --git a/WebService/Sources/ExampleWebService/Components/ResidenceComponent.swift b/WebService/Sources/ExampleWebService/Components/ResidenceComponent.swift index 5b8d254..4400fa6 100644 --- a/WebService/Sources/ExampleWebService/Components/ResidenceComponent.swift +++ b/WebService/Sources/ExampleWebService/Components/ResidenceComponent.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import Shared diff --git a/WebService/Sources/ExampleWebService/Components/ResidenceHandler/CreateResidence.swift b/WebService/Sources/ExampleWebService/Components/ResidenceHandler/CreateResidence.swift index b6b03a2..de35610 100644 --- a/WebService/Sources/ExampleWebService/Components/ResidenceHandler/CreateResidence.swift +++ b/WebService/Sources/ExampleWebService/Components/ResidenceHandler/CreateResidence.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import FluentKit import Shared diff --git a/WebService/Sources/ExampleWebService/Components/ResidenceHandler/DeleteResidence.swift b/WebService/Sources/ExampleWebService/Components/ResidenceHandler/DeleteResidence.swift index 6270275..d0dfd9d 100644 --- a/WebService/Sources/ExampleWebService/Components/ResidenceHandler/DeleteResidence.swift +++ b/WebService/Sources/ExampleWebService/Components/ResidenceHandler/DeleteResidence.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import FluentKit import Shared diff --git a/WebService/Sources/ExampleWebService/Components/ResidenceHandler/GetResidence.swift b/WebService/Sources/ExampleWebService/Components/ResidenceHandler/GetResidence.swift index 21b8c90..5a86ce4 100644 --- a/WebService/Sources/ExampleWebService/Components/ResidenceHandler/GetResidence.swift +++ b/WebService/Sources/ExampleWebService/Components/ResidenceHandler/GetResidence.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import FluentKit import Shared diff --git a/WebService/Sources/ExampleWebService/Components/ResidenceHandler/GetResidencies.swift b/WebService/Sources/ExampleWebService/Components/ResidenceHandler/GetResidencies.swift index ca8386d..3085f7e 100644 --- a/WebService/Sources/ExampleWebService/Components/ResidenceHandler/GetResidencies.swift +++ b/WebService/Sources/ExampleWebService/Components/ResidenceHandler/GetResidencies.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import FluentKit import Shared diff --git a/WebService/Sources/ExampleWebService/Example.swift b/WebService/Sources/ExampleWebService/Example.swift index dfc7bf3..aa85f81 100644 --- a/WebService/Sources/ExampleWebService/Example.swift +++ b/WebService/Sources/ExampleWebService/Example.swift @@ -1,9 +1,18 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini +import ApodiniDatabase import ApodiniOpenAPI import ApodiniREST -import ApodiniDatabase -import Shared import ArgumentParser +import FluentSQLiteDriver +import Shared public struct Example: WebService { @@ -11,8 +20,6 @@ public struct Example: WebService { var port: Int = 80 @Option(help: "The path the database file should be saved in") var databasePath: String = "./example.sqlite" - @Flag(help: "Set to true if you want to revert the database migrations") - var revertDatabaseMigrations = false public var configuration: Configuration { @@ -24,17 +31,10 @@ public struct Example: WebService { // Defines on which hostname and port the webservice should be bound to, configurable via CLI-arguments, else defaults HTTPConfiguration(port: port) - // If the appropriate CLI flag is passed, revert the database migrations - if revertDatabaseMigrations { - DatabaseRevertConfiguration(.sqlite(.file(databasePath))) - .addMigrations(ContactMigration()) - .addMigrations(ResidenceMigration()) - } else { - // Setup of example database (in this case SQlite) and add migrations to create the respective tables - DatabaseConfiguration(.sqlite(.file(databasePath))) - .addMigrations(ContactMigration()) - .addMigrations(ResidenceMigration()) - } + // Setup of example database (in this case SQlite) and add migrations to create the respective tables + DatabaseConfiguration(.sqlite(.file(databasePath)), as: .sqlite) + .addMigrations(ContactMigration()) + .addMigrations(ResidenceMigration()) } public var content: some Component { diff --git a/WebService/Sources/ExampleWebService/Mediators/ContactMediator.swift b/WebService/Sources/ExampleWebService/Mediators/ContactMediator.swift index 6b1efeb..65b4d24 100644 --- a/WebService/Sources/ExampleWebService/Mediators/ContactMediator.swift +++ b/WebService/Sources/ExampleWebService/Mediators/ContactMediator.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import Foundation import Shared diff --git a/WebService/Sources/ExampleWebService/Mediators/ResidenceMediator.swift b/WebService/Sources/ExampleWebService/Mediators/ResidenceMediator.swift index 80a7b95..704f748 100644 --- a/WebService/Sources/ExampleWebService/Mediators/ResidenceMediator.swift +++ b/WebService/Sources/ExampleWebService/Mediators/ResidenceMediator.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import Shared diff --git a/WebService/Sources/ExampleWebService/Model/Contact+Content.swift b/WebService/Sources/ExampleWebService/Model/Contact+Content.swift index b1f44da..795df11 100644 --- a/WebService/Sources/ExampleWebService/Model/Contact+Content.swift +++ b/WebService/Sources/ExampleWebService/Model/Contact+Content.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import Shared diff --git a/WebService/Sources/ExampleWebService/Model/DatabaseModel.swift b/WebService/Sources/ExampleWebService/Model/DatabaseModel.swift index 34b373f..8d44126 100644 --- a/WebService/Sources/ExampleWebService/Model/DatabaseModel.swift +++ b/WebService/Sources/ExampleWebService/Model/DatabaseModel.swift @@ -1,8 +1,9 @@ // -// DatabaseModel.swift -// +// This source file is part of the Apodini Example open source project // -// Created by Paul Schmiedmayer on 6/6/21. +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT // import Apodini diff --git a/WebService/Sources/ExampleWebService/Model/DatabaseRevertConfiguration.swift b/WebService/Sources/ExampleWebService/Model/DatabaseRevertConfiguration.swift deleted file mode 100644 index 7cfd662..0000000 --- a/WebService/Sources/ExampleWebService/Model/DatabaseRevertConfiguration.swift +++ /dev/null @@ -1,83 +0,0 @@ -import Apodini -import ApodiniDatabase -import Fluent -@_implementationOnly import FluentSQLiteDriver -@_implementationOnly import FluentMySQLDriver -@_implementationOnly import FluentPostgresDriver -@_implementationOnly import FluentMongoDriver - -public final class DatabaseRevertConfiguration: Configuration { - private let type: DatabaseType - private(set) var migrations: [Migration] = [] - - public var databaseID: DatabaseID { - switch type { - case .defaultMongoDB: - return .mongo - case .defaultMySQL, .mySQL: - return .mysql - case .defaultPostgreSQL, .postgreSQL: - return .psql - case .sqlite: - return .sqlite - } - } - - /// Initializes a new database configuration - /// - /// - Parameters: - /// - type: The database type specified by an `DatabaseType`object. - public init(_ type: DatabaseType) { - self.type = type - } - - public func configure(_ app: Application) { - do { - let databases = app.databases - let factory = try databaseFactory(for: self.type) - databases.use(factory, as: databaseID) - app.migrations.add(migrations) - try app.autoRevert().wait() - } catch { - app.logger.error("Could not revert the database: \(error)") - } - } - - /// A modifier to add one or more `Migrations` to the database. The given `Migrations` need to conform to the `Vapor.Migration ` class. - /// - /// - Parameters: - /// - migrations: One or more `Migration` objects that should be migrated by the database - public func addMigrations(_ migrations: Migration...) -> Self { - self.migrations.append(contentsOf: migrations) - return self - } - - private func databaseFactory(for type: DatabaseType) throws -> Fluent.DatabaseConfigurationFactory { - switch type { - case .defaultMongoDB(let conString): - return try .mongo(connectionString: conString) - case .sqlite(let config): - let sqliteConfiguration: SQLiteConfiguration - switch config { - case .memory: - sqliteConfiguration = .init(storage: .memory) - case .file(let path): - sqliteConfiguration = .init(storage: .file(path: path)) - } - return .sqlite(sqliteConfiguration) - case .defaultPostgreSQL(let conString): - return try .postgres(url: conString) - case let .postgreSQL(hostName, port, username, password, database, configuration): - return .postgres(hostname: hostName, - port: port, - username: username, - password: password, - database: database, - tlsConfiguration: configuration) - case .defaultMySQL(let conString): - return try .mysql(url: conString) - case let .mySQL(hostname, username, password, database, configuration): - return .mysql(hostname: hostname, username: username, password: password, database: database, tlsConfiguration: configuration) - } - } -} diff --git a/WebService/Sources/ExampleWebService/Model/Residence+Content.swift b/WebService/Sources/ExampleWebService/Model/Residence+Content.swift index c783598..14acb82 100644 --- a/WebService/Sources/ExampleWebService/Model/Residence+Content.swift +++ b/WebService/Sources/ExampleWebService/Model/Residence+Content.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import Apodini import Shared diff --git a/WebService/Sources/WebService/main.swift b/WebService/Sources/WebService/main.swift index 98e10c0..6dd8b06 100644 --- a/WebService/Sources/WebService/main.swift +++ b/WebService/Sources/WebService/main.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + import ExampleWebService diff --git a/WebService/Tests/ExampleWebServiceTests/ContactHandlerTests.swift b/WebService/Tests/ExampleWebServiceTests/ContactHandlerTests.swift index 8833248..f865fd7 100644 --- a/WebService/Tests/ExampleWebServiceTests/ContactHandlerTests.swift +++ b/WebService/Tests/ExampleWebServiceTests/ContactHandlerTests.swift @@ -1,3 +1,11 @@ +// +// This source file is part of the Apodini Example open source project +// +// SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + #if canImport(XCTApodini) && canImport(XCTApodiniDatabase) @testable import ExampleWebService import Shared diff --git a/docker-compose-development.yml b/docker-compose-development.yml index 81bd679..fefc386 100644 --- a/docker-compose-development.yml +++ b/docker-compose-development.yml @@ -1,3 +1,11 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + version: '3.9' services: diff --git a/docker-compose.yml b/docker-compose.yml index 0dd2d66..b5578be 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,11 @@ +# +# This source file is part of the Apodini Example open source project +# +# SPDX-FileCopyrightText: 2018-2021 Paul Schmiedmayer and project authors (see CONTRIBUTORS.md) +# +# SPDX-License-Identifier: MIT +# + version: '3.9' services: