Skip to content

Commit

Permalink
merge: (#733) 봉사 신청/ 관리 API
Browse files Browse the repository at this point in the history
  • Loading branch information
4mjeo authored Sep 19, 2024
2 parents f771f90 + d7a0d89 commit 4c4a2d7
Show file tree
Hide file tree
Showing 48 changed files with 1,205 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package team.aliens.dms.domain.volunteer.dto.request

data class CreateVolunteerRequest(
val name: String,
val content: String,
val availableSex: String,
val availableGrade: String,
val score: Int,
val optionalScore: Int,
val maxApplicants: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package team.aliens.dms.domain.volunteer.dto.request

import java.util.UUID

data class UpdateVolunteerRequest(
val name: String,
val content: String,
val availableSex: String,
val availableGrade: String,
val score: Int,
val optionalScore: Int,
val maxApplicants: Int,
val volunteerId: UUID
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package team.aliens.dms.domain.volunteer.dto.response

import java.util.UUID

data class ApplyVolunteerResponse(
val volunteerApplicationId: UUID
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package team.aliens.dms.domain.volunteer.dto.response

import team.aliens.dms.domain.student.model.Sex
import team.aliens.dms.domain.volunteer.model.GradeCondition
import team.aliens.dms.domain.volunteer.model.Volunteer
import team.aliens.dms.domain.volunteer.model.VolunteerApplication
import team.aliens.dms.domain.volunteer.spi.vo.CurrentVolunteerApplicantVO
import team.aliens.dms.domain.volunteer.spi.vo.VolunteerApplicantVO
import java.util.UUID

data class QueryMyVolunteerApplicationResponse(
val volunteerApplications: List<VolunteerApplicationResponse>
) {
companion object {
fun of(
applicationsWithVolunteers: List<Pair<VolunteerApplication, Volunteer>>
): QueryMyVolunteerApplicationResponse {
return QueryMyVolunteerApplicationResponse(
volunteerApplications = applicationsWithVolunteers.map { (application, volunteer) ->
VolunteerApplicationResponse.of(application, volunteer)
}
)
}
}
}

data class VolunteerApplicationResponse(
val id: UUID,
val volunteerId: UUID,
val approved: Boolean,
val name: String,
) {
companion object {
fun of(volunteerApplication: VolunteerApplication, volunteer: Volunteer): VolunteerApplicationResponse {
return VolunteerApplicationResponse(
id = volunteerApplication.id,
volunteerId = volunteerApplication.volunteerId,
approved = volunteerApplication.approved,
name = volunteer.name
)
}
}
}

data class VolunteerResponse(
val id: UUID,
val name: String,
val content: String,
val score: Int,
val optionalScore: Int,
val maxApplicants: Int,
val availableSex: Sex,
val availableGrade: GradeCondition
) {
companion object {
fun of(volunteer: Volunteer): VolunteerResponse {
return VolunteerResponse(
id = volunteer.id,
name = volunteer.name,
content = volunteer.content,
score = volunteer.score,
optionalScore = volunteer.optionalScore,
maxApplicants = volunteer.maxApplicants,
availableSex = volunteer.availableSex,
availableGrade = volunteer.availableGrade
)
}
}
}

data class VolunteersResponse(
val volunteers: List<VolunteerResponse>
)

data class VolunteerApplicantResponse(
val id: UUID,
val gcd: String,
val name: String,
) {
companion object {
fun of(applicants: VolunteerApplicantVO) = VolunteerApplicantResponse(
id = applicants.id,
gcd = applicants.gcn,
name = applicants.name
)
}
}

data class VolunteerApplicantsResponse(
val applicants: List<VolunteerApplicantResponse>
)

data class CurrentVolunteerApplicantResponse(
val volunteerName: String,
val applicants: List<VolunteerApplicantResponse>
) {
companion object {
fun of(currentVolunteerApplicant: CurrentVolunteerApplicantVO) = CurrentVolunteerApplicantResponse(
volunteerName = currentVolunteerApplicant.volunteerName,
applicants = currentVolunteerApplicant.applicants
.map { VolunteerApplicantResponse.of(it) }
)
}
}

data class CurrentVolunteerApplicantsResponse(
val volunteers: List<CurrentVolunteerApplicantResponse>
)

data class AvailableVolunteerResponse(
val id: UUID,
val name: String,
val content: String,
val score: Int,
val optionalScore: Int,
val maxApplicants: Int
) {
companion object {
fun of(volunteer: Volunteer): AvailableVolunteerResponse {
return AvailableVolunteerResponse(
id = volunteer.id,
name = volunteer.name,
content = volunteer.content,
score = volunteer.score,
optionalScore = volunteer.optionalScore,
maxApplicants = volunteer.maxApplicants
)
}
}
}

data class AvailableVolunteersResponse(
val volunteers: List<AvailableVolunteerResponse>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package team.aliens.dms.domain.volunteer.exception

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class VolunteerErrorCode(
private val status: Int,
private val message: String,
private val sequence: Int
) : ErrorProperty {

VOLUNTEER_APPLICATION_NOT_FOUND(ErrorStatus.NOT_FOUND, "Volunteer Application Not Found", 1),
VOLUNTEER_NOT_FOUND(ErrorStatus.NOT_FOUND, "Volunteer Not Found", 2),

VOLUNTEER_APPLICATION_ALREADY_ASSIGNED(ErrorStatus.CONFLICT, "Volunteer Application Already Assigned", 1),
VOLUNTEER_APPLICATION_NOT_ASSIGNED(ErrorStatus.CONFLICT, "Volunteer Application Not Assigned", 2)
;

override fun status(): Int = status
override fun message(): String = message
override fun code(): String = "Volunteer-$status-$sequence"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package team.aliens.dms.domain.volunteer.exception

import team.aliens.dms.common.error.DmsException

object VolunteerApplicationNotFoundException : DmsException(
VolunteerErrorCode.VOLUNTEER_APPLICATION_NOT_FOUND
)

object VolunteerApplicationAlreadyAssigned : DmsException(
VolunteerErrorCode.VOLUNTEER_APPLICATION_ALREADY_ASSIGNED
)

object VolunteerApplicationNotAssigned : DmsException(
VolunteerErrorCode.VOLUNTEER_APPLICATION_NOT_ASSIGNED
)

object VolunteerNotFoundException : DmsException(
VolunteerErrorCode.VOLUNTEER_NOT_FOUND
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package team.aliens.dms.domain.volunteer.model

enum class GradeCondition {
ALL,
FIRST,
SECOND,
THIRD,
FIRSTANDSECOND,
SECONDANDTHIRD,
FIRSTANDTHIRD
enum class GradeCondition(
val grades: Set<Int>
) {
ALL(setOf(1, 2, 3)),
FIRST(setOf(1)),
SECOND(setOf(2)),
THIRD(setOf(3)),
FIRST_SECOND(setOf(1, 2)),
SECOND_THIRD(setOf(2, 3)),
FIRST_THIRD(setOf(1, 3))
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ data class Volunteer(

val maxApplicants: Int,

val sexCondition: Sex,
val availableSex: Sex,

val gradeCondition: GradeCondition,
val availableGrade: GradeCondition,

override val schoolId: UUID
) : SchoolIdDomain
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package team.aliens.dms.domain.volunteer.model

import team.aliens.dms.common.annotation.Aggregate
import team.aliens.dms.domain.volunteer.exception.VolunteerApplicationAlreadyAssigned
import team.aliens.dms.domain.volunteer.exception.VolunteerApplicationNotAssigned
import java.util.UUID

@Aggregate
Expand All @@ -12,6 +14,17 @@ data class VolunteerApplication(

val volunteerId: UUID,

val approved: Boolean
val approved: Boolean,
) {
fun checkIsNotApproved() {
if (approved) {
throw VolunteerApplicationAlreadyAssigned
}
}

)
fun checkIsApproved() {
if (!approved) {
throw VolunteerApplicationNotAssigned
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package team.aliens.dms.domain.volunteer.service

import team.aliens.dms.domain.volunteer.model.Volunteer
import team.aliens.dms.domain.volunteer.model.VolunteerApplication

interface CommandVolunteerService {

fun saveVolunteerApplication(volunteerApplication: VolunteerApplication): VolunteerApplication

fun deleteVolunteerApplication(volunteerApplication: VolunteerApplication)

fun saveVolunteer(volunteer: Volunteer): Volunteer

fun deleteVolunteer(volunteer: Volunteer)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package team.aliens.dms.domain.volunteer.service

import team.aliens.dms.common.annotation.Service
import team.aliens.dms.domain.volunteer.model.Volunteer
import team.aliens.dms.domain.volunteer.model.VolunteerApplication
import team.aliens.dms.domain.volunteer.spi.CommandVolunteerApplicationPort
import team.aliens.dms.domain.volunteer.spi.CommandVolunteerPort

@Service
class CommandVolunteerServiceImpl(
private val commandVolunteerApplicationPort: CommandVolunteerApplicationPort,
private val commandVolunteerPort: CommandVolunteerPort
) : CommandVolunteerService {

override fun saveVolunteerApplication(volunteerApplication: VolunteerApplication): VolunteerApplication =
commandVolunteerApplicationPort.saveVolunteerApplication(volunteerApplication)

override fun deleteVolunteerApplication(volunteerApplication: VolunteerApplication) {
commandVolunteerApplicationPort.deleteVolunteerApplication(volunteerApplication)
}

override fun saveVolunteer(volunteer: Volunteer): Volunteer =
commandVolunteerPort.saveVolunteer(volunteer)

override fun deleteVolunteer(volunteer: Volunteer) {
commandVolunteerPort.deleteVolunteer(volunteer)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package team.aliens.dms.domain.volunteer.service

import team.aliens.dms.domain.volunteer.model.Volunteer
import team.aliens.dms.domain.volunteer.model.VolunteerApplication
import team.aliens.dms.domain.volunteer.spi.vo.CurrentVolunteerApplicantVO
import team.aliens.dms.domain.volunteer.spi.vo.VolunteerApplicantVO
import java.util.UUID

interface GetVolunteerService {

fun getVolunteerApplicationById(volunteerApplicationId: UUID): VolunteerApplication

fun getVolunteerById(volunteerId: UUID): Volunteer

fun getVolunteerByStudentId(studentId: UUID): List<Volunteer>

fun getAllVolunteersBySchoolId(schoolId: UUID): List<Volunteer>

fun getAllApplicantsByVolunteerId(volunteerId: UUID): List<VolunteerApplicantVO>

fun getAllApplicantsBySchoolIdGroupByVolunteer(schoolId: UUID): List<CurrentVolunteerApplicantVO>

fun getAllVolunteers(): List<Volunteer>

fun getVolunteerApplicationsWithVolunteersByStudentId(studentId: UUID): List<Pair<VolunteerApplication, Volunteer>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package team.aliens.dms.domain.volunteer.service

import team.aliens.dms.common.annotation.Service
import team.aliens.dms.domain.volunteer.exception.VolunteerApplicationNotFoundException
import team.aliens.dms.domain.volunteer.exception.VolunteerNotFoundException
import team.aliens.dms.domain.volunteer.model.Volunteer
import team.aliens.dms.domain.volunteer.model.VolunteerApplication
import team.aliens.dms.domain.volunteer.spi.QueryVolunteerApplicationPort
import team.aliens.dms.domain.volunteer.spi.QueryVolunteerPort
import team.aliens.dms.domain.volunteer.spi.vo.CurrentVolunteerApplicantVO
import team.aliens.dms.domain.volunteer.spi.vo.VolunteerApplicantVO
import java.util.UUID

@Service
class GetVolunteerServiceImpl(
private val queryVolunteerApplicationPort: QueryVolunteerApplicationPort,
private val queryVolunteerPort: QueryVolunteerPort,
) : GetVolunteerService {

override fun getVolunteerApplicationById(volunteerApplicationId: UUID): VolunteerApplication =
queryVolunteerApplicationPort.queryVolunteerApplicationById(volunteerApplicationId)
?: throw VolunteerApplicationNotFoundException

override fun getVolunteerById(volunteerId: UUID): Volunteer =
queryVolunteerPort.queryVolunteerById(volunteerId)
?: throw VolunteerNotFoundException

override fun getVolunteerByStudentId(studentId: UUID): List<Volunteer> =
queryVolunteerPort.queryVolunteerByStudentId(studentId)

override fun getAllVolunteersBySchoolId(schoolId: UUID): List<Volunteer> =
queryVolunteerPort.queryAllVolunteersBySchoolId(schoolId)

override fun getAllApplicantsByVolunteerId(volunteerId: UUID): List<VolunteerApplicantVO> =
queryVolunteerApplicationPort.queryAllApplicantsByVolunteerId(volunteerId)

override fun getAllApplicantsBySchoolIdGroupByVolunteer(schoolId: UUID): List<CurrentVolunteerApplicantVO> =
queryVolunteerApplicationPort.queryAllApplicantsBySchoolIdGroupByVolunteer(schoolId)

override fun getAllVolunteers(): List<Volunteer> =
queryVolunteerPort.queryAllVolunteers()

override fun getVolunteerApplicationsWithVolunteersByStudentId(studentId: UUID): List<Pair<VolunteerApplication, Volunteer>> {
return queryVolunteerApplicationPort.getVolunteerApplicationsWithVolunteersByStudentId(studentId)
}
}
Loading

0 comments on commit 4c4a2d7

Please sign in to comment.