Skip to content

Commit

Permalink
Merge pull request #165 from cactacea/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
takeshishimada authored Nov 28, 2018
2 parents 692a913 + dd48439 commit 9f2ad19
Show file tree
Hide file tree
Showing 63 changed files with 461 additions and 367 deletions.
133 changes: 133 additions & 0 deletions core/src/main/resources/db/migration/cactacea/V20181109__#160.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
-- MySQL Workbench Synchronization
-- Generated: 2018-11-28 20:06
-- Model: New Model
-- Version: 1.0
-- Project: Name of the project
-- Author: TAKESHI SHIMADA

SET SQL_SAFE_UPDATES = 0;

ALTER SCHEMA `cactacea` DEFAULT COLLATE utf8_general_ci ;

ALTER TABLE `cactacea`.`account_feeds`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`account_groups`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`account_messages`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`account_reports`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`accounts`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`advertisement_settings`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`blocks`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`client_grant_types`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`clients`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`comment_likes`
COLLATE = utf8_general_ci ,
CHANGE COLUMN `posted_at` `liked_at` BIGINT(20) NOT NULL ;

ALTER TABLE `cactacea`.`comment_reports`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`comments`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`devices`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`feed_likes`
COLLATE = utf8_general_ci ,
CHANGE COLUMN `posted_at` `liked_at` BIGINT(20) NOT NULL ;

ALTER TABLE `cactacea`.`feed_mediums`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`feed_reports`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`feed_tags`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`feeds`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`followers`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`follows`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`friend_requests`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`friends`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`grant_types`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`group_invitations`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`group_reports`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`groups`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`mediums`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`messages`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`mutes`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`notifications`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`push_notification_settings`
COLLATE = utf8_general_ci ;

ALTER TABLE `cactacea`.`relationships`
COLLATE = utf8_general_ci ;

DROP TABLE IF EXISTS `cactacea`.`tickets` ;

ALTER TABLE `cactacea`.`account_reports`
ADD COLUMN `reported_at` BIGINT(20) NOT NULL DEFAULT 0 AFTER `report_content`;

ALTER TABLE `cactacea`.`comment_reports`
ADD COLUMN `reported_at` BIGINT(20) NOT NULL DEFAULT 0 AFTER `report_content`;

ALTER TABLE `cactacea`.`feed_reports`
ADD COLUMN `reported_at` BIGINT(20) NOT NULL DEFAULT 0 AFTER `report_content`;

ALTER TABLE `cactacea`.`group_reports`
ADD COLUMN `reported_at` BIGINT(20) NOT NULL DEFAULT 0 AFTER `report_content`;

ALTER TABLE `cactacea`.`groups`
ADD COLUMN `last_posted_at` BIGINT(20) NULL DEFAULT NULL AFTER `message_id`;

ALTER TABLE `cactacea`.`relationships`
CHANGE COLUMN `edited_display_name` `display_name` VARCHAR(50) NULL DEFAULT NULL ;

UPDATE `cactacea`.`accounts` set display_name = account_name where display_name is null;

ALTER TABLE `cactacea`.`accounts`
CHANGE COLUMN `display_name` `display_name` VARCHAR(50) NOT NULL DEFAULT ' ' ;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait InjectionService {
def signedIn(authentication: Account): Future[Unit]
def signedOut(sessionId: SessionId): Future[Unit]
def accountNameUpdated(accountName: String, sessionId: SessionId): Future[Unit]
def profileUpdated(displayName: Option[String], web: Option[String], birthday: Option[Long], location: Option[String],
def profileUpdated(displayName: String, web: Option[String], birthday: Option[Long], location: Option[String],
bio: Option[String], sessionId: SessionId): Future[Unit]
def profileImageUpdated(profileImageUri: Option[String], sessionId: SessionId): Future[Unit]
def passwordUpdated(sessionId: SessionId): Future[Unit]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DefaultInjectionService extends InjectionService {
Future.Unit
}

override def profileUpdated(displayName: Option[String],
override def profileUpdated(displayName: String,
web: Option[String],
birthday: Option[Long],
location: Option[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AccountsService @Inject()(
}
}

def update(displayName: Option[String],
def update(displayName: String,
web: Option[String],
birthday: Option[Long],
location: Option[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@ class SessionsService @Inject()(
) {

def signUp(accountName: String,
displayName: Option[String],
password: String,
udid: String,
web: Option[String],
birthday: Option[Long],
location: Option[String],
bio: Option[String],
userAgent: Option[String],
deviceType: DeviceType): Future[Account] = {

db.transaction {
for {
a <- sessionsRepository.signUp(accountName, displayName, password, udid, deviceType, web, birthday, location, bio, userAgent)
a <- sessionsRepository.signUp(accountName, password, udid, deviceType, userAgent)
_ <- actionService.signedUp(a)
} yield (a)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.github.cactacea.backend.core.infrastructure.models._

case class Account(id: AccountId,
accountName: String,
displayName: Option[String],
displayName: String,
profileImageUrl: Option[String],
friend: Boolean,
friendRequestInProgress: Boolean,
Expand Down Expand Up @@ -51,11 +51,11 @@ object Account {
}

def apply(a: Accounts, r: Option[Relationships], fl: FeedLikes): Account = {
apply(a, r, None, fl.postedAt)
apply(a, r, None, fl.likedAt)
}

def apply(a: Accounts, r: Option[Relationships], c: CommentLikes): Account = {
apply(a, r, None, c.postedAt)
apply(a, r, None, c.likedAt)
}

def apply(a: Accounts, r: Option[Relationships]): Account = {
Expand All @@ -70,7 +70,7 @@ object Account {
Account(
a.id,
a.accountName,
r.map(_.editedDisplayName).getOrElse(a.displayName),
r.flatMap(_.displayName).getOrElse(a.displayName),
a.profileImageUrl,
r.map(_.friend).getOrElse(false),
r.map(_.inProgress).getOrElse(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ case class Feed(
contentWarning: Boolean,
contentDeleted: Boolean,
postedAt: Long,
likedAt: Option[Long],
next: Long
)

Expand Down Expand Up @@ -50,7 +51,8 @@ object Feed {
contentWarning = false,
contentDeleted = true,
postedAt = f.postedAt,
next = fl.map(_.postedAt).getOrElse(f.postedAt)
likedAt = fl.map(_.likedAt),
next = fl.map(_.likedAt).getOrElse(f.postedAt)
)
}
case _ => {
Expand All @@ -68,7 +70,8 @@ object Feed {
contentWarning = f.contentWarning,
contentDeleted = false,
postedAt = f.postedAt,
next = fl.map(_.postedAt).getOrElse(f.postedAt)
likedAt = fl.map(_.likedAt),
next = fl.map(_.likedAt).getOrElse(f.postedAt)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ case class Group(
invitationOnly: Boolean,
authorityType: GroupAuthorityType,
accountCount: Long,
lastPostedAt: Option[Long],
organizedAt: Long,
next: Long
)
Expand All @@ -22,7 +23,7 @@ object Group {
}

def apply(ag: AccountGroups, g: Groups, m: Option[Messages], am: Option[AccountMessages]): Group = {
apply(g, m, am, None, None, None, None)
apply(g, m, am, None, None, None, Some(ag))
}

def apply(g: Groups, m: Option[Messages], am: Option[AccountMessages], a: Option[Accounts], r: Option[Relationships]): Group = {
Expand Down Expand Up @@ -63,6 +64,7 @@ object Group {
authorityType = g.authorityType,
accountCount = g.accountCount,
organizedAt = g.organizedAt,
lastPostedAt = g.lastPostedAt,
next = ag.map(_.joinedAt).getOrElse(g.organizedAt)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AccountsRepository @Inject()(
accountsDAO.updatePassword(oldPassword, newPassword, sessionId)
}

def updateProfile(displayName: Option[String],
def updateProfile(displayName: String,
web: Option[String],
birthday: Option[Long],
location: Option[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class MessagesRepository @Inject()(
for {
_ <- validationDAO.existGroupAccount(sessionId.toAccountId, groupId)
a <- groupAccountsDAO.findCount(groupId)
id <- messagesDAO.create(groupId, Some(message), a, None, sessionId)
_ <- groupsDAO.update(groupId, Some(id), sessionId)
(id, postedAt) <- messagesDAO.create(groupId, Some(message), a, None, sessionId)
_ <- groupsDAO.update(groupId, id, postedAt, sessionId)
_ <- accountMessagesDAO.create(groupId, id, sessionId)
_ <- accountGroupsDAO.updateUnreadCount(groupId)
} yield (id)
Expand All @@ -45,8 +45,8 @@ class MessagesRepository @Inject()(
_ <- validationDAO.existGroupAccount(sessionId.toAccountId, groupId)
_ <- validationDAO.existMediums(mediumId, sessionId)
a <- groupAccountsDAO.findCount(groupId)
id <- messagesDAO.create(groupId, None, a, Some(mediumId), sessionId)
_ <- groupsDAO.update(groupId, Some(id), sessionId)
(id, postedAt) <- messagesDAO.create(groupId, None, a, Some(mediumId), sessionId)
_ <- groupsDAO.update(groupId, id, postedAt, sessionId)
_ <- accountMessagesDAO.create(groupId, id, sessionId)
_ <- accountGroupsDAO.updateUnreadCount(groupId)
} yield (id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class NotificationsRepository @Inject()(

def findAll(since: Option[Long], offset: Option[Int], count: Option[Int], locales: Seq[Locale], sessionId: SessionId): Future[List[Notification]] = {
notificationsDAO.findAll(since, offset, count, sessionId).map(_.map({ case (n, a, r) =>
val displayName = r.map(_.editedDisplayName).getOrElse(a.accountName)
val displayName = r.map(_.displayName).getOrElse(a.accountName)
val message = notificationMessagesService.getNotificationMessage(n.notificationType, locales, displayName)
Notification(n, message)
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,14 @@ class SessionsRepository @Inject()(
) {

def signUp(accountName: String,
displayName: Option[String],
password: String,
udid: String,
deviceType: DeviceType,
web: Option[String],
birthday: Option[Long],
location: Option[String],
bio: Option[String],
userAgent: Option[String]): Future[Account] = {

val account = for {
_ <- validationDAO.notExistAccountName(accountName)
accountId <- accountsDAO.create(accountName, displayName, password, web, birthday, location, bio)
accountId <- accountsDAO.create(accountName, password)
sessionId = accountId.toSessionId
_ <- devicesDAO.create(udid, deviceType, userAgent, sessionId)
_ <- notificationSettingsDAO.create(true, true, true, true, true, true, sessionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package io.github.cactacea.backend.core.infrastructure.dao
import com.google.inject.{Inject, Singleton}
import com.twitter.util.Future
import io.github.cactacea.backend.core.application.components.services.DatabaseService
import io.github.cactacea.backend.core.application.services.TimeService
import io.github.cactacea.backend.core.domain.enums.ReportType
import io.github.cactacea.backend.core.infrastructure.identifiers._
import io.github.cactacea.backend.core.infrastructure.models._

@Singleton
class AccountReportsDAO @Inject()(db: DatabaseService) {
class AccountReportsDAO @Inject()(db: DatabaseService, timeService: TimeService) {

import db._

Expand All @@ -21,13 +22,15 @@ class AccountReportsDAO @Inject()(db: DatabaseService) {
}

def create(accountId: AccountId, reportType: ReportType, reportContent: Option[String], sessionId: SessionId): Future[AccountReportId] = {
val reportedAt = timeService.currentTimeMillis()
val by = sessionId.toAccountId
val q = quote {
query[AccountReports].insert(
_.accountId -> lift(accountId),
_.by -> lift(by),
_.reportType -> lift(reportType),
_.reportContent -> lift(reportContent)
_.reportContent -> lift(reportContent),
_.reportedAt -> lift(reportedAt)
).returning(_.id)
}
run(q)
Expand Down
Loading

0 comments on commit 9f2ad19

Please sign in to comment.