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

๐Ÿ”€ :: ํฌ์ธํŠธ ์ƒ์  ๋ฌผํ’ˆ ์‚ญ์ œ API ๊ตฌํ˜„ #48

Merged
merged 5 commits into from
Mar 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import andreas311.miso.domain.item.adapter.input.data.request.CreateItemRequest
import andreas311.miso.domain.item.adapter.input.data.request.EditItemRequest
import andreas311.miso.domain.item.adapter.input.mapper.ItemDataMapper
import andreas311.miso.domain.item.application.port.input.CreateItemUseCase
import andreas311.miso.domain.item.application.port.input.DeleteItemUseCase
import andreas311.miso.domain.item.application.port.input.EditItemUseCase
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
Expand All @@ -19,6 +21,7 @@ class ItemAdapter(
private val itemDataMapper: ItemDataMapper,
private val editItemUseCase: EditItemUseCase,
private val createItemUseCase: CreateItemUseCase,
private val deleteItemUseCase: DeleteItemUseCase
) {
@PostMapping
fun create(
Expand All @@ -28,6 +31,11 @@ class ItemAdapter(
createItemUseCase.execute(itemDataMapper toDto createItemRequest, multipartFile)
.let { ResponseEntity.status(HttpStatus.CREATED).build() }

@DeleteMapping("/{id}")
fun delete(@PathVariable id: Long): ResponseEntity<Void> =
deleteItemUseCase.execute(id)
.let { ResponseEntity.status(HttpStatus.NO_CONTENT).build() }

@PatchMapping("/{id}")
fun edit (
@PathVariable id: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ class CommandItemPersistenceAdapter(
val itemEntity = itemRepository.save(itemMapper toEntity item)
return itemMapper.toDomain(itemEntity)!!
}

override fun deleteItem(item: Item) {
val itemEntity = itemMapper toEntity item
return itemRepository.delete(itemEntity)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package andreas311.miso.domain.item.application.port.input

interface DeleteItemUseCase {
fun execute(id: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import andreas311.miso.domain.item.domain.Item

interface CommandItemPort {
fun saveItem(item: Item): Item

fun deleteItem(item: Item)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package andreas311.miso.domain.item.application.service

import andreas311.miso.common.annotation.RollbackService
import andreas311.miso.domain.item.application.exception.ItemNotFoundException
import andreas311.miso.domain.item.application.port.input.DeleteItemUseCase
import andreas311.miso.domain.item.application.port.output.CommandItemPort
import andreas311.miso.domain.item.application.port.output.QueryItemPort

@RollbackService
class DeleteItemService(
private val queryItemPort: QueryItemPort,
private val commandItemPort: CommandItemPort
): DeleteItemUseCase {
override fun execute(id: Long) {
val itemEntity = queryItemPort.findByIdOrNull(id)
?: throw ItemNotFoundException()

commandItemPort.deleteItem(itemEntity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,23 @@ class SecurityConfig(

.antMatchers(HttpMethod.POST, "/auth").permitAll()
.antMatchers(HttpMethod.POST, "/auth/signIn").permitAll()
.antMatchers(HttpMethod.DELETE, "/auth").permitAll()
.antMatchers(HttpMethod.PATCH, "/auth").permitAll()
.antMatchers(HttpMethod.DELETE, "/auth").permitAll()

.antMatchers(HttpMethod.POST, "/email").permitAll()

.antMatchers(HttpMethod.POST, "/item").hasAuthority("ROLE_ADMIN")
.antMatchers(HttpMethod.GET, "/item").authenticated()
.antMatchers(HttpMethod.GET, "/item/{id}").authenticated()
.antMatchers(HttpMethod.POST, "/item").authenticated()
.antMatchers(HttpMethod.PATCH, "/item/{id}").authenticated()
.antMatchers(HttpMethod.PATCH, "/item/{id}").hasAuthority("ROLE_ADMIN")
.antMatchers(HttpMethod.DELETE, "/item/{id}").hasAuthority("ROLE_ADMIN")

.antMatchers(HttpMethod.POST, "/user/give").authenticated()
.antMatchers(HttpMethod.GET, "/user").authenticated()
.antMatchers(HttpMethod.GET, "/user/point").authenticated()
.antMatchers(HttpMethod.POST, "/user/give").authenticated()

.antMatchers(HttpMethod.GET, "/purchase").authenticated()
.antMatchers(HttpMethod.POST, "/purchase/{id}").authenticated()
.antMatchers(HttpMethod.GET, "/purchase").authenticated()

.antMatchers(HttpMethod.POST, "/inquiry").authenticated()
.antMatchers(HttpMethod.GET, "/inquiry").authenticated()
Expand All @@ -66,10 +67,10 @@ class SecurityConfig(
.antMatchers(HttpMethod.GET, "/inquiry/{id}").authenticated()
.antMatchers(HttpMethod.PATCH, "/inquiry/respond/{id}").hasAuthority("ROLE_ADMIN")

.antMatchers(HttpMethod.POST, "/recyclables/process").authenticated()
.antMatchers(HttpMethod.GET, "/recyclables").authenticated()
.antMatchers(HttpMethod.GET, "/recyclables/search").authenticated()
.antMatchers(HttpMethod.GET, "/recyclables/all").authenticated()
.antMatchers(HttpMethod.POST, "/recyclables/process").authenticated()

.antMatchers(HttpMethod.POST, "/notification/save/{deviceToken}").authenticated()
.antMatchers(HttpMethod.GET, "/notification/{id}").authenticated()
Expand Down
Loading