Skip to content

Commit

Permalink
Feat: 주민 상담 내역 삭제 기능 추가 및 제공한 약 엔티티 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
noeyoes authored May 5, 2024
2 parents e3842a4 + 89189b2 commit 3cb3138
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface ConsultRepository extends JpaRepository<ConsultContentInfo, Lon
List<ConsultContentInfo> findAllByPatientId(PatientInfo patientId);

Optional<ConsultContentInfo> findByConsultId(Long consultId);

Optional<ConsultContentInfo> deleteByConsultId(Long consultId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,16 @@ public ResponseEntity<?> updateConsultInfo(@RequestBody ConsultUpdateRequestDto
}
}


@DeleteMapping("/patient/consultDelete")
public ResponseEntity<?> deleteConsultInfo(@RequestParam Long consultId) {
try {
consultService.delete(consultId);
return ResponseEntity.status(HttpStatus.OK).body("주민 상담 상세 내용 삭제 완료");
} catch (IllegalArgumentException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("상담 정보를 찾을 수 없습니다.");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("주민 상담 내용 삭제 중 오류 발생: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.medicare.neulpeum.domain.entity;

import jakarta.persistence.*;
import lombok.*;

import static jakarta.persistence.FetchType.LAZY;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "providedDrugInfo")
public class ProvidedDrugInfo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, name = "providedId")
private Long id;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "drugInfo", nullable = false)
private DrugInfo drugId;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "consultContentInfo", nullable = false)
private ConsultContentInfo consultId;

@Column(nullable = false)
private Long providedAmount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public interface ConsultService {

void update(ConsultUpdateRequestDto consultUpdateRequestDto);

void delete(Long consultId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@ public void update(ConsultUpdateRequestDto consultUpdateRequestDto) {
}
}


@Override
public void delete(Long consultId) {
Optional<ConsultContentInfo> optionalConsultContentInfo = consultRepository.findByConsultId(consultId);
if (optionalConsultContentInfo.isPresent()) {
consultRepository.deleteByConsultId(consultId);
}
}
}

0 comments on commit 3cb3138

Please sign in to comment.