Skip to content

Commit

Permalink
cactacea-core : Change displayName type Option[String] to String (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
TAKESHI SHIMADA committed Nov 28, 2018
1 parent 68e6800 commit e0406b1
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
-- 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`
Expand Down Expand Up @@ -123,4 +125,9 @@ 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 ;
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 @@ -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 @@ -70,7 +70,7 @@ object Account {
Account(
a.id,
a.accountName,
r.map(_.displayName).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 @@ -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 @@ -23,13 +23,12 @@ class AccountsDAO @Inject()(
def create(accountName: String,
password: String): Future[AccountId] = {

val displayName: Option[String] = Some(accountName)
val accountStatus = AccountStatusType.normally
val hashedPassword = hashService.hash(password)
val q = quote {
query[Accounts].insert(
_.accountName -> lift(accountName),
_.displayName -> lift(displayName),
_.displayName -> lift(accountName),
_.password -> lift(hashedPassword),
_.accountStatus -> lift(accountStatus)
).returning(_.id)
Expand All @@ -38,7 +37,7 @@ class AccountsDAO @Inject()(
}


def updateProfile(displayName: Option[String],
def updateProfile(displayName: String,
web: Option[String],
birthday: Option[Long],
location: Option[String],
Expand Down Expand Up @@ -194,13 +193,13 @@ class AccountsDAO @Inject()(

(for {
accounts <- run(q)
ids = accounts.map({ case (a, r) => a.id})
ids = accounts.map({ case (a, _) => a.id})
blocksCount <- blocksCountDAO.findRelationshipBlocks(ids, sessionId)
} yield (accounts, blocksCount))
.map({ case (accounts, blocksCount) =>
accounts.map({ case (a, r) =>
val b = blocksCount.find(_.id == a.id).getOrElse(RelationshipBlocksCount(a.id, 0L, 0L, 0L))
val displayName = r.map(_.displayName).getOrElse(a.displayName)
val displayName = r.flatMap(_.displayName).getOrElse(a.displayName)
val friendCount = a.friendCount - b.friendCount
val followCount = a.followCount - b.followCount
val followerCount = a.followerCount - b.followerCount
Expand Down Expand Up @@ -233,7 +232,7 @@ class AccountsDAO @Inject()(
val q2 = quote {
query[Accounts]
.filter({a => a.id != lift(by)})
.filter(a => (a.accountName like lift(un)) || a.displayName.exists(_ like lift(un)) || (lift(un) == ""))
.filter(a => (a.accountName like lift(un)) || (a.displayName like lift(un)) || (lift(un) == ""))
.filter(a => a.accountStatus == lift(status))
.filter(a => a.id < lift(s) || lift(s) == -1L)
.filter(a => query[Blocks].filter(b => b.accountId == lift(by) && b.by == a.id).isEmpty)
Expand All @@ -246,7 +245,7 @@ class AccountsDAO @Inject()(

(for {
accounts <- run(q2)
ids = accounts.map({ case (a, r) => a.id})
ids = accounts.map({ case (a, _) => a.id})
blocksCount <- blocksCountDAO.findRelationshipBlocks(ids, sessionId)
} yield (accounts, blocksCount))
.map({ case (accounts, blocksCount) =>
Expand All @@ -255,7 +254,7 @@ class AccountsDAO @Inject()(
val friendCount = a.friendCount - b.map(_.friendCount).getOrElse(0L)
val followCount = a.followCount - b.map(_.followCount).getOrElse(0L)
val followerCount = a.followerCount - b.map(_.followerCount).getOrElse(0L)
val displayName = r.map(_.displayName).getOrElse(a.displayName)
val displayName = r.flatMap(_.displayName).getOrElse(a.displayName)
val na = a.copy(
displayName = displayName,
friendCount = friendCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class PushNotificationsDAO @Inject()(db: DatabaseService) {
|| (f.by == af.accountId))})
.join(query[Accounts]).on({ case (((af, _), _), a) => a.id == af.by})
.join(query[Devices]).on({ case ((((af, _), _), _), d) => d.accountId == af.accountId && d.pushToken.isDefined})
.map({case ((((af, r), _), a), d) => (a.accountName, a.displayName, r.map(_.displayName), af.accountId, d.pushToken) })
.map({case ((((af, r), _), a), d) => (a.displayName, r.flatMap(_.displayName), af.accountId, d.pushToken) })
.distinct
}
run(q).map(_.map({ case (accountName, displayName, editedDisplayName, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName).getOrElse(accountName)
run(q).map(_.map({ case (displayName, editedDisplayName, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName)
val token = pushToken.get
PushNotifications(accountId, name, token, showContent = false)
}}))
Expand All @@ -47,11 +47,11 @@ class PushNotificationsDAO @Inject()(db: DatabaseService) {
.leftJoin(query[Relationships]).on((g, r) => r.accountId == g.by && r.by == g.accountId)
.join(query[Accounts]).on({ case ((g, _), a) => a.id == g.by})
.join(query[Devices]).on({ case (((g, _), _), d) => d.accountId == g.accountId && d.pushToken.isDefined})
.map({ case (((g, r), a), d) => (a.accountName, a.displayName, r.map(_.displayName), g.accountId, d.pushToken) })
.map({ case (((g, r), a), d) => (a.displayName, r.flatMap(_.displayName), g.accountId, d.pushToken) })
.distinct
}
run(q).map(_.map({ case (accountName, displayName, editedDisplayName, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName).getOrElse(accountName)
run(q).map(_.map({ case (displayName, editedDisplayName, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName)
val token = pushToken.get
PushNotifications(accountId, name, token, showContent = false)
}}))
Expand All @@ -64,11 +64,11 @@ class PushNotificationsDAO @Inject()(db: DatabaseService) {
.leftJoin(query[Relationships]).on((g, r) => r.accountId == g.by && r.by == g.accountId)
.join(query[Accounts]).on({ case ((g, _), a) => a.id == g.by})
.join(query[Devices]).on({ case (((g, _), _), d) => d.accountId == g.accountId && d.pushToken.isDefined})
.map({ case (((g, r), a), d) => (a.accountName, a.displayName, r.map(_.displayName), g.accountId, d.pushToken) })
.map({ case (((g, r), a), d) => (a.displayName, r.flatMap(_.displayName), g.accountId, d.pushToken) })
.distinct
}
run(q).map(_.map({ case (accountName, displayName, editedDisplayName, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName).getOrElse(accountName)
run(q).map(_.map({ case (displayName, editedDisplayName, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName)
val token = pushToken.get
PushNotifications(accountId, name, token, showContent = false)
}}))
Expand All @@ -85,11 +85,11 @@ class PushNotificationsDAO @Inject()(db: DatabaseService) {
.leftJoin(query[Relationships]).on({ case (((am, _), _), r) => r.accountId == am.by && r.by == am.accountId })
.join(query[Accounts]).on({ case ((((am, _), _), _), a) => a.id == am.by})
.join(query[Devices]).on({ case (((((am, _), _), _), _), d) => d.accountId == am.accountId && d.pushToken.isDefined})
.map({case (((((am, _), p), r), a), d) => (a.accountName, a.displayName, r.map(_.displayName), p.showMessage, am.accountId, d.pushToken) })
.map({case (((((am, _), p), r), a), d) => (a.displayName, r.flatMap(_.displayName), p.showMessage, am.accountId, d.pushToken) })
.distinct
}
run(q).map(_.map({ case (accountName, displayName, editedDisplayName, showMessage, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName).getOrElse(accountName)
run(q).map(_.map({ case (displayName, editedDisplayName, showMessage, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName)
val token = pushToken.get
PushNotifications(accountId, name, token, showMessage)
}}))
Expand All @@ -108,11 +108,11 @@ class PushNotificationsDAO @Inject()(db: DatabaseService) {
.leftJoin(query[Relationships]).on({ case ((c, f), r) => r.accountId == c.by && r.by == f.by})
.join(query[Accounts]).on({ case (((c, _), _), a) => a.id == c.by})
.join(query[Devices]).on({ case ((((_, f), _), _), d) => d.accountId == f.by && d.pushToken.isDefined})
.map({case ((((_, f), r), a), d) => (a.accountName, a.displayName, r.map(_.displayName), f.by, d.pushToken) })
.map({case ((((_, f), r), a), d) => (a.displayName, r.flatMap(_.displayName), f.by, d.pushToken) })
.distinct
}
run(q).map(_.map({ case (accountName, displayName, editedDisplayName, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName).getOrElse(accountName)
run(q).map(_.map({ case (displayName, editedDisplayName, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName)
val token = pushToken.get
PushNotifications(accountId, name, token, showContent = false)
}}))
Expand All @@ -127,11 +127,11 @@ class PushNotificationsDAO @Inject()(db: DatabaseService) {
.leftJoin(query[Relationships]).on({ case ((c, f), r) => r.accountId == c.by && r.by == f.by})
.join(query[Accounts]).on({ case (((c, _), _), a) => a.id == c.by})
.join(query[Devices]).on({ case ((((_, f), _), _), d) => d.accountId == f.by && d.pushToken.isDefined})
.map({case ((((_, f), r), a), d) => (a.accountName, a.displayName, r.map(_.displayName), f.by, d.pushToken) })
.map({case ((((_, f), r), a), d) => (a.displayName, r.flatMap(_.displayName), f.by, d.pushToken) })
.distinct
}
run(q).map(_.map({ case (accountName, displayName, editedDisplayName, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName).getOrElse(accountName)
run(q).map(_.map({ case (displayName, editedDisplayName, accountId, pushToken) => {
val name = editedDisplayName.getOrElse(displayName)
val token = pushToken.get
PushNotifications(accountId, name, token, showContent = false)
}}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.github.cactacea.backend.core.infrastructure.identifiers.{AccountId, Me
case class Accounts(
id: AccountId,
accountName: String,
displayName: Option[String],
displayName: String,
profileImage: Option[MediumId],
profileImageUrl: Option[String],
password: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class AccountsRepositorySpec extends RepositorySpec {
execute(accountsRepository.updateDisplayName(account.id, Some("new account name"), session.id.toSessionId))
val result = execute(accountsRepository.find(account.id, session.id.toSessionId))
assert(result.id == account.id)
assert(result.displayName == Some("new account name"))
assert(result.displayName == "new account name")

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SessionsRepositorySpec extends RepositorySpec {
test("signUp") {

val accountName = "SessionsRepositorySpec1"
val displayName = Some("SessionsRepositorySpec1")
val displayName = "SessionsRepositorySpec1"
val password = "password"
val udid = "0123456789012345678901234567890123456789"
val userAgent = Some("userAgent")
Expand All @@ -46,7 +46,7 @@ class SessionsRepositorySpec extends RepositorySpec {
test("signIn") {

val accountName = "SessionsRepositorySpec2"
val displayName = Some("SessionsRepositorySpec2")
val displayName = "SessionsRepositorySpec2"
val password = "password"
val udid = "0123456789012345678901234567890123456789"
val userAgent = Some("userAgent")
Expand All @@ -60,7 +60,6 @@ class SessionsRepositorySpec extends RepositorySpec {
test("invalid password signIn ") {

val accountName = "SessionsRepositorySpec3"
val displayName = Some("SessionsRepositorySpec3")
val password = "password"
val udid = "0123456789012345678901234567890123456789"
val userAgent = Some("userAgent")
Expand All @@ -75,7 +74,6 @@ class SessionsRepositorySpec extends RepositorySpec {

test("signOut") {
val accountName = "SessionsRepositorySpec4"
val displayName = Some("SessionsRepositorySpec4")
val password = "password"
val udid = "0123456789012345678901234567890123456789"
val userAgent = Some("userAgent")
Expand All @@ -87,7 +85,6 @@ class SessionsRepositorySpec extends RepositorySpec {
test("checkAccountStatus") {

val accountName = "SessionsRepositorySpec5"
val displayName = Some("SessionsRepositorySpec5")
val password = "password"
val udid = "0123456789012345678901234567890123456789"
val userAgent = Some("userAgent")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object FactoryHelper {
profileImage = None,
profileImageUrl = None,
accountName = accountName,
displayName = Some(accountName),
displayName = accountName,
password = "password",
accountStatus = AccountStatusType.normally,
followCount = 0L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ServiceSpec extends IntegrationTest with BeforeAndAfter with Logging {
val timeService = injector.instance[TimeService]

def signUp(accountName: String, password: String, udid: String) = {
execute(sessionService.signUp(accountName, password, "ffc1ded6f4570d557ad65f986684fc10c7f8d51f", Some("user-agent"), DeviceType.ios))
execute(sessionService.signUp(accountName, password, udid, Some("user-agent"), DeviceType.ios))
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,17 @@ class AccountsDAOSpec extends DAOSpec with Logging {
execute(accountsDAO.updateDisplayName(account2.id, Some("newUserName2"), sessionAccount.id.toSessionId))

val result1 = execute(accountsDAO.find(account1.id, sessionAccount.id.toSessionId))
assert(result1.get._1.displayName == Some("newUserName1"))
assert(result1.get._1.displayName == "newUserName1")
val result2 = execute(accountsDAO.find(account2.id, sessionAccount.id.toSessionId))
assert(result2.get._1.displayName == Some("newUserName2"))
assert(result2.get._1.displayName == "newUserName2")

execute(accountsDAO.updateDisplayName(account1.id, None, sessionAccount.id.toSessionId))
execute(accountsDAO.updateDisplayName(account2.id, None, sessionAccount.id.toSessionId))

val result3 = execute(accountsDAO.find(account1.id, sessionAccount.id.toSessionId))
assert(result3.get._1.displayName == None)
assert(result3.get._1.displayName == "AccountsDAOSpec12")
val result4 = execute(accountsDAO.find(account2.id, sessionAccount.id.toSessionId))
assert(result4.get._1.displayName == None)
assert(result4.get._1.displayName == "AccountsDAOSpec13")

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CommentsDAOSpec extends DAOSpec {

val feedId = execute(feedsDAO.create("message", None, None, FeedPrivacyType.everyone, false, None, sessionAccount1.id.toSessionId))
val commentId1 = execute(commentsDAO.create(feedId, "1" * 100, sessionAccount2.id.toSessionId))
val commentId2 = execute(commentsDAO.create(feedId, "2" * 100, sessionAccount1.id.toSessionId))
execute(commentsDAO.create(feedId, "2" * 100, sessionAccount1.id.toSessionId))

val exist1 = execute(commentsDAO.exist(commentId1, sessionAccount1.id.toSessionId))
val exist2 = execute(commentsDAO.exist(commentId1, sessionAccount1.id.toSessionId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.swagger.annotations.ApiModelProperty

case class PutSessionProfile (
@ApiModelProperty(value = "Display name.", required = true)
@Size(min = 1, max = 50) displayName: Option[String],
@Size(min = 1, max = 50) displayName: String,

@ApiModelProperty(value = "Profile URL.", required = true)
@Size(min = 0, max = 2038) web: Option[String],
Expand Down

0 comments on commit e0406b1

Please sign in to comment.