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

⚡️ :: 자원봉사 일정 수정 구현 #32

Closed
wants to merge 8 commits into from
Closed
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
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.time.LocalDate
import java.util.*
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.FetchType.*
import javax.persistence.FetchType
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.JoinColumn
Expand All @@ -33,8 +33,13 @@ class Schedule (

user: User
) {
@ManyToOne(fetch = LAZY)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", columnDefinition = "BINARY(16)", nullable = false)
var user = user
protected set

fun updateSchedule(title: String, date: LocalDate) {
this.title = title
this.date = date
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.sharing.domain.schedule.exception

import com.example.sharing.global.error.exception.ErrorCode
import com.example.sharing.global.error.exception.SharingException

class ScheduleNotFoundException : SharingException(ErrorCode.SCHEDULE_NOT_FOUND) {
companion object {
@JvmField
val EXCEPTION = ScheduleNotFoundException()
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
package com.example.sharing.domain.schedule.presentation

import com.example.sharing.domain.schedule.presentation.dto.request.CreateScheduleRequest
import com.example.sharing.domain.schedule.presentation.dto.request.UpdateScheduleRequest
import com.example.sharing.domain.schedule.service.CreateScheduleService
import org.springframework.http.HttpStatus
import com.example.sharing.domain.schedule.service.UpdateScheduleService
import org.springframework.http.HttpStatus.*
import org.springframework.web.bind.annotation.*
import java.util.*
import javax.validation.Valid

@RequestMapping("/schedules")
@RestController
class ScheduleController (
private val createScheduleService: CreateScheduleService,
private val updateScheduleService: UpdateScheduleService,
) {
@ResponseStatus(HttpStatus.CREATED)
@ResponseStatus(CREATED)
@PostMapping
fun createSchedule(@RequestBody @Valid request: CreateScheduleRequest) {
createScheduleService.execute(request)
}

@ResponseStatus(NO_CONTENT)
@PatchMapping("/{schedule-id}")
fun updateSchedule(@PathVariable ("schedule-id") scheduleId: UUID, @RequestBody @Valid request: UpdateScheduleRequest) {
updateScheduleService.execute(scheduleId, request)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.sharing.domain.schedule.presentation.dto.request

import org.hibernate.validator.constraints.Length
import java.time.LocalDate
import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotNull
Expand All @@ -9,7 +10,7 @@ data class CreateScheduleRequest (
@field:NotBlank(message = "title는 Null, 공백을 허용하지 않습니다.")
@field:Size(max = 10, message = "title는 10자 이하여야 합니다.")
val title: String,

@field:NotNull
val date: LocalDate
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.sharing.domain.schedule.presentation.dto.request

import java.time.LocalDate
import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotNull
import javax.validation.constraints.Size

class UpdateScheduleRequest (
@field:NotBlank(message = "title는 Null, 공백, 띄어쓰기를 허용하지 않습니다.")
@field:Size(max = 10, message = "title은 10자 이하여야 합니다.")
var title: String,

@field:NotNull
val date: LocalDate
)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.sharing.domain.schedule.service

import com.example.sharing.domain.feed.exception.FeedNotFoundException
import com.example.sharing.domain.feed.exception.NotValidUserException
import com.example.sharing.domain.schedule.domain.repository.ScheduleRepository
import com.example.sharing.domain.schedule.presentation.dto.request.UpdateScheduleRequest
import com.example.sharing.domain.user.domain.User
import com.example.sharing.domain.user.facade.UserFacade
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*

@Service
class UpdateScheduleService(
val userFacade: UserFacade,
val scheduleRepository: ScheduleRepository,
) {
@Transactional
fun execute(scheduleId: UUID, request: UpdateScheduleRequest) {
val user: User = userFacade.getCurrentUser()
val schedule = scheduleRepository.findById(scheduleId)
.orElseThrow { FeedNotFoundException.EXCEPTION }

if (user.id != schedule.user.id) {
throw NotValidUserException.EXCEPTION
}

schedule.updateSchedule(request.title, request.date)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum class ErrorCode(

USER_NOT_FOUND(404, "User Not Found"),
FEED_NOT_FOUND(404, "Feed Not Found"),
SCHEDULE_NOT_FOUND(404, "Schedule Not Found"),
USER_INTEREST_AREA_NOT_FOUND(404, "User Interest Area Not Found"),

ALREADY_ACCOUNT_ID_EXISTS(409, "Already Account Id Exists"),
Expand Down