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

πŸ”€ 172 delete enrolled service #173

Merged
merged 9 commits into from
Jun 18, 2023
Merged
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 @@ -20,7 +20,8 @@ class ClientController(
private val registerClientService: RegisterClientService,
private val deleteClientService: DeleteClientService,
private val getClientsByServiceNameService: GetClientsByServiceNameService,
private val updateAnyClientService: UpdateAnyClientService
private val updateAnyClientService: UpdateAnyClientService,
private val deleteClientsService: DeleteClientsService
) {

@PostMapping
Expand Down Expand Up @@ -64,4 +65,10 @@ class ClientController(
updateAnyClientService.execute(id, clientUpdateDto)
return ResponseEntity.noContent().build()
}

@DeleteMapping
fun deleteSeveralClient(@RequestParam(value = "ids") ids: List<Long>): ResponseEntity<Void> {
esperar marked this conversation as resolved.
Show resolved Hide resolved
deleteClientsService.execute(ids)
return ResponseEntity.noContent().build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import com.msg.gauth.domain.user.User
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import java.util.*

interface ClientRepository: JpaRepository<Client, Long> {
interface ClientRepository: JpaRepository<Client, Long>, CustomClientRepository {
fun findAllByCreatedBy(createdBy: User): List<Client>
fun findByIdAndCreatedBy(clientId: Long, createdBy: User): Client?
fun findByClientId(clientId: String): Client?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.msg.gauth.domain.client.repository

import com.msg.gauth.domain.user.User

interface CustomClientRepository {
fun deleteAllByIdsAndCreatedBy(ids: List<Long>, createdBy: User)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.msg.gauth.domain.client.repository

import com.msg.gauth.domain.client.QClient.client
import com.msg.gauth.domain.user.User
import com.querydsl.core.types.dsl.BooleanExpression
import com.querydsl.jpa.impl.JPAQueryFactory
import org.springframework.stereotype.Repository

@Repository
class CustomClientRepositoryImpl(
private val jpaQueryFactory: JPAQueryFactory
): CustomClientRepository {
override fun deleteAllByIdsAndCreatedBy(ids: List<Long>, createdBy: User) {
jpaQueryFactory.delete(client)
.where(client.id.`in`(ids), client.createdBy.eq(createdBy))
.execute()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.msg.gauth.domain.client.service

import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.util.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(rollbackFor = [Exception::class])
class DeleteClientsService(
private val clientRepository: ClientRepository,
private val userUtil: UserUtil
) {
fun execute(ids: List<Long>) {
val user = userUtil.fetchCurrentUser()
clientRepository.deleteAllByIdsAndCreatedBy(ids, user)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class SecurityConfig(
.antMatchers(HttpMethod.DELETE, "/client/{id}").authenticated()
.antMatchers(HttpMethod.GET, "/client/search").hasRole("ADMIN")
.antMatchers(HttpMethod.PATCH, "/client/{id}/patch").hasRole("ADMIN")
.antMatchers(HttpMethod.DELETE, "/client").authenticated()

// Admin
.antMatchers(HttpMethod.POST, "/admin/parsing-member").hasRole("ADMIN")
Expand Down