Skip to content

Commit

Permalink
feat: delete moit (#118)
Browse files Browse the repository at this point in the history
* feat: moit delete

* chore: add Authorization header in http file

* chore: set moitId path parameter in http file
  • Loading branch information
SeongYunKim authored Aug 4, 2023
1 parent 729d7c7 commit 17d367d
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion http/fine.http
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Fine 리스트 조회
GET {{moit-api}}/api/v1/moit/{{moitId}}/fine
GET {{moit-api}}/api/v1/moit/1/fine
Authorization: {{authorizationHeader}}

### Fine 평가
POST {{moit-api}}/api/v1/moit/{{moitId}}/fine/{{fineId}}/evaluate
Expand Down
10 changes: 10 additions & 0 deletions http/moit.http
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Moit Create
POST {{moit-api}}/api/v1/moit
Authorization: {{authorizationHeader}}
Content-Type: application/json

{
Expand All @@ -24,6 +25,7 @@ Content-Type: application/json

### Moit Join
POST {{moit-api}}/api/v1/moit/join
Authorization: {{authorizationHeader}}
Content-Type: application/json

{
Expand All @@ -33,12 +35,20 @@ Content-Type: application/json

### My Moits
GET {{moit-api}}/api/v1/moit
Authorization: {{authorizationHeader}}

### Moit Join Users
GET {{moit-api}}/api/v1/moit/{{moitId}}/users
Authorization: {{authorizationHeader}}

### Moit Details
GET {{moit-api}}/api/v1/moit/{{moitId}}
Authorization: {{authorizationHeader}}

### Moit Attendance
GET {{moit-api}}/api/v1/moit/{{moitId}}/attendance
Authorization: {{authorizationHeader}}

### Moit Delete
DELETE {{moit-api}}/api/v1/moit/{{moitId}}
Authorization: {{authorizationHeader}}
6 changes: 6 additions & 0 deletions http/study.http
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
### 스터디 출석 키워드 조회
GET {{moit-api}}/api/v1/study/{{studyId}}/attendance/keyword
Authorization: {{authorizationHeader}}

### 스터디 출석 상태 조회
GET {{moit-api}}/api/v1/study/{{studyId}}/attendance/status
Authorization: {{authorizationHeader}}

### 스터디 출석 키워드 등록
POST {{moit-api}}/api/v1/study/{{studyId}}/attendance/keyword/register
Authorization: {{authorizationHeader}}
Content-Type: application/json

{
Expand All @@ -14,6 +17,7 @@ Content-Type: application/json

### 스터디 출석 키워드 인증
POST {{moit-api}}/api/v1/study/{{studyId}}/attendance/keyword/verify
Authorization: {{authorizationHeader}}
Content-Type: application/json

{
Expand All @@ -22,6 +26,8 @@ Content-Type: application/json

### 스터디 출석 초기화
POST {{moit-api}}/api/v1/study/{{studyId}}/attendance/initialize
Authorization: {{authorizationHeader}}

### 스터디 첫 출석자 존재 여부 조회
GET {{moit-api}}/api/v1/study/{{studyId}}/attendance/is-first
Authorization: {{authorizationHeader}}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.validation.Valid
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
Expand Down Expand Up @@ -91,4 +92,13 @@ class MoitController(
return MoitApiResponse.success()
}

@Operation(summary = "Moit 삭제", description = "Moit 삭제 API")
@DeleteMapping("/{moitId}")
fun deleteMoit(
@GetAuth userInfo: UserInfo,
@PathVariable("moitId") moitId: Long,
): MoitApiResponse<Unit> {
return MoitApiResponse.success(moitFacade.deleteMoit(userId = userInfo.id, moitId = moitId))
}

}
4 changes: 4 additions & 0 deletions moit-api/src/main/kotlin/com/mashup/moit/facade/MoitFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class MoitFacade(
moitService.addMoitImage(moit.id, moitImageUrl)
}

fun deleteMoit(userId: Long, moitId: Long) {
moitService.deleteMoit(userId = userId, moitId = moitId)
}

private fun getMoitByInvitationCode(invitationCode: String): Moit {
return moitService.getMoitByInvitationCode(invitationCode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ abstract class BaseEntity {
lateinit var updatedAt: LocalDateTime

@Column(name = "is_deleted", nullable = false)
val isDeleted: Boolean = false
var isDeleted: Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import jakarta.persistence.Column
import jakarta.persistence.Embedded
import jakarta.persistence.Entity
import jakarta.persistence.Table
import org.hibernate.annotations.Where
import java.time.LocalDate

@Table(name = "moit")
@Entity
@Where(clause = "is_deleted = false")
class MoitEntity(
@Column(name = "name", nullable = false)
val name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mashup.moit.domain.moit
import com.mashup.moit.common.exception.MoitException
import com.mashup.moit.common.exception.MoitExceptionType
import com.mashup.moit.domain.usermoit.UserMoitRepository
import com.mashup.moit.domain.usermoit.UserMoitRole
import org.apache.commons.lang3.RandomStringUtils
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand Down Expand Up @@ -95,4 +96,17 @@ class MoitService(
.apply { this.profileUrl = moitImageUrl }
}

@Transactional
fun deleteMoit(userId: Long, moitId: Long) {
userMoitRepository.findByMoitIdAndRole(moitId = moitId, role = UserMoitRole.MASTER)
?.takeIf { it.userId == userId }
?.run {
moitRepository.findById(moitId)
.orElseThrow { MoitException.of(MoitExceptionType.NOT_EXIST) }
.apply { this.isDeleted = true }
// TODO 삭제 고도화 시, 트랜잭션 밖으로 빼는 것을 고려
userMoitRepository.findAllByMoitId(moitId)
.forEach { it.isDeleted = true }
} ?: throw MoitException.of(MoitExceptionType.ONLY_MOIT_MASTER)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.Table
import org.hibernate.annotations.Where

@Table(name = "user_moit")
@Entity
@Where(clause = "is_deleted = false")
class UserMoitEntity(
@Column(name = "moit_id", nullable = false)
val moitId: Long,
Expand Down

0 comments on commit 17d367d

Please sign in to comment.