Skip to content

Commit

Permalink
♻️ refactor: swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
sun-yryr committed Jan 1, 2022
1 parent 8f0630d commit 3aa5e72
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Sources/App/Commands/ScrapingAgqrCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ struct ScrapingAgqr: Command {
defer {
context.console.info("End Process")
}

let promise = context.application.eventLoopGroup.next().makePromise(of: Void.self)
promise.completeWithTask {
await self.asyncRun(using: context, signature: signature)
}

try promise.futureResult.wait()
}

func asyncRun(using context: CommandContext, signature: Signature) async {
let response = await client.execute(app: context.application, url: signature.url)
guard let response = response else {
Expand Down
5 changes: 2 additions & 3 deletions Sources/App/Jobs/ImportProgramGuideJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ struct ImportProgramGuideJob: ScheduledJob {
await self.asyncRun(context: context)
}
return promise.futureResult

}
func asyncRun(context: QueueContext) async -> Void {

func asyncRun(context: QueueContext) async {
let responses = await client.fetchWeekly(app: context.application)
for response in responses {
guard let response = response else {
Expand Down
14 changes: 8 additions & 6 deletions Sources/App/Repositories/ProgramGuideRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import Fluent
import Vapor

protocol ProgramGuideSaving {
func save(_ items: [ProgramGuide], app: Application) async -> Void
func save(_ items: [ProgramGuide], app: Application) async
}

struct ProgramGuideRepository: ProgramGuideSaving {
func save(_ items: [ProgramGuide], app: Application) async -> Void {
func save(_ items: [ProgramGuide], app: Application) async {
for programGuide in items {
do {
let insertedProgram = try await upsertProgram(programGuide.program, app.db)
Expand All @@ -16,7 +16,8 @@ struct ProgramGuideRepository: ProgramGuideSaving {
insertedPersonalities.append(p)
}
for personality in insertedPersonalities {
let isAttached = try? await insertedProgram.$personalities.isAttached(to: personality, on: app.db)
let isAttached = try? await insertedProgram.$personalities.isAttached(
to: personality, on: app.db)
if isAttached == false {
try await insertedProgram.$personalities.attach(personality, on: app.db)
}
Expand All @@ -38,18 +39,19 @@ struct ProgramGuideRepository: ProgramGuideSaving {
program.id = targetProgram?.id
// idを挿入するだけだとうまくupdateできなかったため、判定要素を上書きする
program._$id.exists = targetProgram != nil

try await program.save(on: db)
return program
}

/// 名前を基準に(unique)insert or updateを行う.
func upsertPersonality(_ personality: Personality, _ db: Database) async throws -> Personality {
let targetPersonality = try? await Personality
let targetPersonality =
try? await Personality
.query(on: db)
.filter(\.$name == personality.name)
.first()

personality.id = targetPersonality?.id
// idを挿入するだけだとうまくupdateできなかったため、判定要素を上書きする
personality._$id.exists = targetPersonality != nil
Expand Down
2 changes: 1 addition & 1 deletion Sources/App/Services/DownloadAgqrProgramGuide.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct DownloadAgqrProgramGuide {
return await self.execute(app: app, url: url)
}
}

for await response in group {
responses.append(response)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/App/configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public func configure(_ app: Application) throws {
allowedOrigin: .all,
allowedMethods: [.GET, .OPTIONS, .HEAD],
allowedHeaders: [
.accept, .contentType, .origin, .xRequestedWith, .userAgent, .accessControlAllowOrigin
.accept, .contentType, .origin, .xRequestedWith, .userAgent, .accessControlAllowOrigin,
]
)
app.middleware.use(CORSMiddleware(configuration: corsConfiguration))
Expand Down
12 changes: 6 additions & 6 deletions tools/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"repositoryURL": "https://github.com/apple/swift-argument-parser.git",
"state": {
"branch": null,
"revision": "83b23d940471b313427da226196661856f6ba3e0",
"version": "0.4.4"
"revision": "e1465042f195f374b94f915ba8ca49de24300a0d",
"version": "1.0.2"
}
},
{
"package": "swift-format",
"repositoryURL": "https://github.com/apple/swift-format",
"state": {
"branch": "swift-5.4-branch",
"revision": "9c15831b798d767c9af0927a931de5d557004936",
"branch": "swift-5.5-branch",
"revision": "f872223e16742fd97fabd319fbf4a939230cc796",
"version": null
}
},
Expand All @@ -24,8 +24,8 @@
"repositoryURL": "https://github.com/apple/swift-syntax",
"state": {
"branch": null,
"revision": "2fff9fc25cdc059379b6bd309377cfab45d8520c",
"version": "0.50400.0"
"revision": "75e60475d9d8fd5bbc16a12e0eaa2cb01b0c322e",
"version": "0.50500.0"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions tools/Package.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// swift-tools-version:5.2
// swift-tools-version:5.5
import PackageDescription

let package = Package(
name: "Tools",
dependencies: [
.package(url: "https://github.com/apple/swift-format", .branch("swift-5.4-branch")),
.package(url: "https://github.com/apple/swift-format", .branch("swift-5.5-branch")),
// .package(url: "https://github.com/realm/SwiftLint.git", .upToNextMajor(from: "0.43.1"))
]
)

0 comments on commit 3aa5e72

Please sign in to comment.