Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Na worktype params #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.mutualmobile.praxisspringboot.controllers.orgs.UserWorkApi
import com.mutualmobile.praxisspringboot.data.ApiResponse
import com.mutualmobile.praxisspringboot.data.models.projects.DateRangeWorkRequest
import com.mutualmobile.praxisspringboot.data.models.projects.HarvestUserWork
import com.mutualmobile.praxisspringboot.data.models.projects.WorkType
import com.mutualmobile.praxisspringboot.services.orgs.UserWorkService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
Expand All @@ -22,7 +23,11 @@ class UserWorkApiImpl : UserWorkApi {
val result = userWorkService.getWorkLogsForDateRange(
startDate = dateRangeWorkRequest.startDate,
endDate = dateRangeWorkRequest.endDate,
userIds = dateRangeWorkRequest.userIds
userIds = dateRangeWorkRequest.userIds,
workType = dateRangeWorkRequest.workType?.let {
WorkType.valueOf(it)
}

)
if (result.data == null) {
ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ data class DateRangeWorkRequest(
val startDate: Date,
val endDate: Date,
// To be used as a filter for the output (if exists)
val userIds: List<String>? = null
val userIds: List<String>? = null,
val workType: String ? = null

)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ data class HarvestUserWork(
val note: String? = null
)



enum class WorkType(val type: String) {
BILLABLE("1"),
NONBILLABLE("2")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
package com.mutualmobile.praxisspringboot.repositories.orgs

import com.mutualmobile.praxisspringboot.entities.projects.DBUserWork
import java.util.Date
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import java.util.*

interface UserWorkRepository : JpaRepository<DBUserWork, String> {
fun findAllByWorkDateBetweenAndUserId(startDate: Date, endDate: Date, userId: String): List<DBUserWork>

@Query(
"SELECT * FROM user_work AS u WHERE u.work_date BETWEEN :startDate AND :endDate AND u.user_id=:userId AND u.work_type LIKE :workType",
nativeQuery = true
)
fun findAllByWorkDateBetweenAndUserId(
startDate: Date,
endDate: Date,
userId: String,
workType: String
): List<DBUserWork>

// TODO : Move getAllProjectIdsForUserId & getAllUserIdsForProjectId to their respective Repository (they don't belong here)
@Query(
value = "SELECT upa.project_id FROM user_project_assignment upa WHERE upa.user_id = :userId",
nativeQuery = true
)
fun getAllProjectIdsForUserId(userId: String): List<String> // List<ProjectId>

@Query(
value = "SELECT upa.user_id FROM user_project_assignment upa WHERE upa.project_id = :projectId",
nativeQuery = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package com.mutualmobile.praxisspringboot.services.orgs
import com.mutualmobile.praxisspringboot.data.ApiResponse
import com.mutualmobile.praxisspringboot.data.models.orgs.OrganizationProject
import com.mutualmobile.praxisspringboot.data.models.projects.HarvestUserWork
import com.mutualmobile.praxisspringboot.data.models.projects.WorkType
import java.util.Date

interface UserWorkService {
fun getWorkLogsForDateRange(
startDate: Date,
endDate: Date,
userIds: List<String>? = null
userIds: List<String>? = null,
workType: WorkType?=null
): ApiResponse<List<HarvestUserWork>>

fun getUserAssignedProjects(userId: String): ApiResponse<List<OrganizationProject>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mutualmobile.praxisspringboot.services.orgs.impl
import com.mutualmobile.praxisspringboot.data.ApiResponse
import com.mutualmobile.praxisspringboot.data.models.orgs.OrganizationProject
import com.mutualmobile.praxisspringboot.data.models.projects.HarvestUserWork
import com.mutualmobile.praxisspringboot.data.models.projects.WorkType
import com.mutualmobile.praxisspringboot.data.user.HarvestUserProjectAssignment
import com.mutualmobile.praxisspringboot.entities.orgs.DBOrgProjects
import com.mutualmobile.praxisspringboot.entities.projects.DBUserWork
Expand Down Expand Up @@ -46,9 +47,9 @@ class UserProjectServiceImpl : UserProjectService {
Pair(projectsRepository.findByIdOrNull(projectId), userRepository.findByIdOrNull(userId))

if (!errorProjectAssignmentIds.contains(errorPair)) {
errorPair.first?.let { project->
errorPair.second?.let { user->
errorProjectAssignmentIds.add(Pair(project,user))
errorPair.first?.let { project ->
errorPair.second?.let { user ->
errorProjectAssignmentIds.add(Pair(project, user))
}
}

Expand Down Expand Up @@ -127,7 +128,9 @@ fun DBUserWork.toHarvestUserWork() = HarvestUserWork(
userId = userId,
workDate = workDate,
workHours = workHours,
workType = workType,
workType = WorkType.values().find {
it.type == workType
}?.type ?: WorkType.NONBILLABLE.type,
note = note
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package com.mutualmobile.praxisspringboot.services.orgs.impl
import com.mutualmobile.praxisspringboot.data.ApiResponse
import com.mutualmobile.praxisspringboot.data.models.orgs.OrganizationProject
import com.mutualmobile.praxisspringboot.data.models.projects.HarvestUserWork
import com.mutualmobile.praxisspringboot.data.models.projects.WorkType
import com.mutualmobile.praxisspringboot.repositories.orgs.OrgProjectsRepository
import com.mutualmobile.praxisspringboot.repositories.orgs.UserWorkRepository
import com.mutualmobile.praxisspringboot.services.orgs.UserWorkService
import java.util.Date
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.util.*

@Service
class UserWorkServiceImpl : UserWorkService {
Expand All @@ -21,7 +22,8 @@ class UserWorkServiceImpl : UserWorkService {
override fun getWorkLogsForDateRange(
startDate: Date,
endDate: Date,
userIds: List<String>?
userIds: List<String>?,
workType: WorkType?
): ApiResponse<List<HarvestUserWork>> {
return try {
val listOfWork = mutableListOf<HarvestUserWork>()
Expand All @@ -30,7 +32,8 @@ class UserWorkServiceImpl : UserWorkService {
userWorkRepository.findAllByWorkDateBetweenAndUserId(
startDate = startDate,
endDate = endDate,
userId = userId
userId = userId,
workType = workType?.type?:"%"
).map { it.toHarvestUserWork() }
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ create table if not exists user_work
alter table user_work
owner to harvestapi;

alter table user_work add column if not exists workType varchar(1) not null default '1';
alter table user_work add column if not exists work_type varchar(1) not null default '1';