Skip to content

Commit 1011c5d

Browse files
author
Robert Quander
committed
added entirely new feature: events. Checker following soon
1 parent b33a3ca commit 1011c5d

File tree

11 files changed

+783
-21
lines changed

11 files changed

+783
-21
lines changed

service/Sources/App/Middleware/NotFoundMiddleware.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ struct NotFoundMiddleware: Middleware {
1717
display: flex;
1818
justify-content: space-between;
1919
align-items: center;
20-
padding: 10px 20px;
20+
padding: 0px 0px;
2121
}
2222
.banner img { height: 30px; }
23-
h1 { font-size: 48px; margin-bottom: 10px; }
23+
h1 { font-size: 48px; margin-bottom: 0px; }
2424
p { font-size: 18px; }
2525
a {
2626
color: #57bcc7;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Fluent
2+
3+
struct CreateEvent: AsyncMigration {
4+
func prepare(on db: Database) async throws {
5+
try await db.schema("events")
6+
.id()
7+
.field("creator_id", .uuid, .required, .references("profiles", "id"))
8+
.field("title", .string, .required)
9+
.field("image_path", .string)
10+
.field("description", .string, .required)
11+
.field("event_date", .string, .required)
12+
.field("location", .string, .required)
13+
.field("notes", .string, .required)
14+
.field("event_key", .string, .required)
15+
.create()
16+
}
17+
18+
func revert(on db: Database) async throws {
19+
try await db.schema("events").delete()
20+
}
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Fluent
2+
3+
struct CreateEventInvite: AsyncMigration {
4+
func prepare(on db: Database) async throws {
5+
try await db.schema("event_invites")
6+
.id()
7+
.field("event_id", .uuid, .required, .references("events", "id", onDelete: .cascade))
8+
.field("profile_id", .uuid, .required, .references("profiles", "id", onDelete: .cascade))
9+
.unique(on: "event_id", "profile_id")
10+
.create()
11+
}
12+
13+
func revert(on db: Database) async throws {
14+
try await db.schema("event_invites").delete()
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Fluent
2+
3+
struct CreateEventRequest: AsyncMigration {
4+
func prepare(on db: Database) async throws {
5+
try await db.schema("event_requests")
6+
.id()
7+
.field("event_id", .uuid, .required, .references("events", "id", onDelete: .cascade))
8+
.field("profile_id", .uuid, .required, .references("profiles", "id", onDelete: .cascade))
9+
.unique(on: "event_id", "profile_id")
10+
.create()
11+
}
12+
13+
func revert(on db: Database) async throws {
14+
try await db.schema("event_requests").delete()
15+
}
16+
}

service/Sources/App/Models/CreateProfile.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct CreateProfile: AsyncMigration {
88
.field("bio", .string)
99
.field("home_id", .uuid, .required)
1010
.field("last_logged_in", .datetime)
11+
.field("keyfile", .string)
1112
.unique(on: "username")
1213
.create()
1314
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import Vapor
2+
import Fluent
3+
4+
final class Event: Model, Content {
5+
static let schema = "events"
6+
7+
@ID(key: .id)
8+
var id: UUID?
9+
10+
@Parent(key: "creator_id")
11+
var creator: Profile
12+
13+
@Field(key: "title")
14+
var title: String
15+
16+
@OptionalField(key: "image_path")
17+
var imagePath: String?
18+
19+
@Field(key: "description")
20+
var descriptionText: String
21+
22+
@Field(key: "event_date")
23+
var date: String
24+
25+
@Field(key: "location")
26+
var location: String
27+
28+
@Field(key: "notes")
29+
var notes: String
30+
31+
@Field(key: "event_key")
32+
var eventKey: String
33+
34+
@Siblings(through: EventInvite.self, from: \.$event, to: \.$profile)
35+
var invitees: [Profile]
36+
37+
@Siblings(through: EventRequest.self, from: \.$event, to: \.$profile)
38+
var requestors: [Profile]
39+
40+
init() {}
41+
42+
init(id: UUID? = nil, creatorID: UUID, title: String, imagePath: String?, description: String, date: String, location: String, notes: String, fullKey: String) {
43+
self.id = id
44+
self.$creator.id = creatorID
45+
self.title = title
46+
self.imagePath = imagePath
47+
self.descriptionText = description
48+
self.date = date
49+
self.location = location
50+
self.notes = notes
51+
let hash = SHA256.hash(data: Data(fullKey.utf8))
52+
self.eventKey = hash.prefix(1).map { String(format: "%02x", $0) }.joined()
53+
}
54+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Vapor
2+
import Fluent
3+
4+
final class EventInvite: Model {
5+
static let schema = "event_invites"
6+
7+
@ID(key: .id)
8+
var id: UUID?
9+
10+
@Parent(key: "event_id")
11+
var event: Event
12+
13+
@Parent(key: "profile_id")
14+
var profile: Profile
15+
16+
init() {}
17+
18+
init(eventID: UUID, profileID: UUID) {
19+
self.$event.id = eventID
20+
self.$profile.id = profileID
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Vapor
2+
import Fluent
3+
4+
final class EventRequest: Model {
5+
static let schema = "event_requests"
6+
7+
@ID(key: .id)
8+
var id: UUID?
9+
10+
@Parent(key: "event_id")
11+
var event: Event
12+
13+
@Parent(key: "profile_id")
14+
var profile: Profile
15+
16+
init() {}
17+
18+
init(eventID: UUID, profileID: UUID) {
19+
self.$event.id = eventID
20+
self.$profile.id = profileID
21+
}
22+
}

service/Sources/App/Models/Profile.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ final class Profile: Model, Content {
2525
@Field(key: "last_logged_in")
2626
var lastLoggedIn: Date?
2727

28+
@OptionalField(key: "keyfile")
29+
var keyfile: String?
30+
2831
//@Timestamp(key: "created_at", on: .create)
2932
//var createdAt: Date?
3033

@@ -34,12 +37,14 @@ final class Profile: Model, Content {
3437
username: String,
3538
bio: String? = nil,
3639
homeID: UUID,
37-
lastLoggedIn: Date? = nil)
40+
lastLoggedIn: Date? = nil,
41+
keyfile: String? = nil)
3842
{
3943
self.id = id
4044
self.username = username
4145
self.bio = bio
4246
self.homeID = homeID
4347
self.lastLoggedIn = lastLoggedIn
48+
self.keyfile = keyfile
4449
}
4550
}

service/Sources/App/configure.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public func configure(_ app: Application) throws {
2020
app.migrations.add(CreateProfileFollow())
2121
app.migrations.add(CreateToken())
2222
app.migrations.add(CreatePost())
23+
app.migrations.add(CreateEvent())
24+
app.migrations.add(CreateEventInvite())
25+
app.migrations.add(CreateEventRequest())
26+
27+
2328

2429
app.migrations.add(AddPostCounterToUser())
2530

0 commit comments

Comments
 (0)