Skip to content

Commit

Permalink
UserService.getByUsername
Browse files Browse the repository at this point in the history
  • Loading branch information
kamenitxan committed Aug 16, 2024
1 parent 619febe commit ccd2ef3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import scala.util.Random
object UserService {
implicit val cls: Class[JakonUser] = classOf[JakonUser]

// language=SQL
val SQL_FIND_USER_BY_USERNAME = "SELECT * FROM JakonUser WHERE username = ?"

def getById(id: Int)(implicit conn: Connection): JakonUser = {
val stmt = conn.prepareStatement("SELECT * FROM JakonUser WHERE id = ?")
stmt.setInt(1, id)
Expand All @@ -29,6 +32,12 @@ object UserService {
DBHelper.selectSingleDeep(stmt)
}

def getByUsername(username: String)(implicit conn: Connection): JakonUser = {
val stmt = conn.prepareStatement(SQL_FIND_USER_BY_USERNAME)
stmt.setString(1, username)
DBHelper.selectSingleDeep(stmt)
}

def getAllUsers()(implicit conn: Connection): Seq[JakonUser] = {
val sql = "SELECT * FROM JakonUser JOIN AclRule AR ON JakonUser.acl_id = AR.id ORDER BY AR.id;"
val stmt = conn.createStatement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class ServiceTest extends TestBase {
})
}

test("UserService getByUsername") { _ =>
DBHelper.withDbConnection(implicit conn => {
val u = UserService.getByUsername(user.username)
assert(u != null)
})
}

test("JakonFileService getImages") { _ =>
DBHelper.withDbConnection(implicit conn => {
val images = JakonFileService.getImages()
Expand Down

0 comments on commit ccd2ef3

Please sign in to comment.