Skip to content

Commit

Permalink
Fix: 주석처리한 이벤트 생성/수정 API 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
cmsong111 committed May 30, 2024
1 parent d64beaf commit 297af63
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 56 deletions.
39 changes: 10 additions & 29 deletions src/main/java/ac/kr/deu/connect/luck/event/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ public Event createEvent(EventRequestV2 eventRequest, String managerEmail) {
*
* @param id 이벤트 UID
* @param eventRequest 이벤트 생성 요청 폼
* @param multipartFile 이벤트 대표 이미지
* @param managerEmail 이벤트 매니저 이메일
* @return 수정된 이벤트
*/
public Event updateEvent(Long id, EventRequest eventRequest, MultipartFile multipartFile, String managerEmail) {
public Event updateEvent(Long id, EventRequestV2 eventRequest, String managerEmail) {
Event findEvent = eventRepository.findById(id).orElseThrow(
() -> new IllegalArgumentException("해당 이벤트가 존재하지 않습니다.")
);
Expand All @@ -112,37 +111,19 @@ public Event updateEvent(Long id, EventRequest eventRequest, MultipartFile multi
throw new IllegalArgumentException("해당 이벤트의 매니저가 아닙니다.");
}

if (multipartFile != null) {
String image = imageUploader.uploadImage(multipartFile).getData().getUrl();
if (eventRequest.getImage() != null) {
String image = imageUploader.uploadImage(eventRequest.getImage()).getData().getUrl();
findEvent.setImageUrl(image);
}
if (eventRequest.title() != null) {
findEvent.setTitle(eventRequest.title());
}

if (eventRequest.content() != null) {
findEvent.setContent(eventRequest.content());
}

if (eventRequest.zipCode() != null) {
findEvent.setZipCode(eventRequest.zipCode());
}

if (eventRequest.streetAddress() != null) {
findEvent.setStreetAddress(eventRequest.streetAddress());
}

if (eventRequest.detailAddress() != null) {
findEvent.setDetailAddress(eventRequest.detailAddress());
}
findEvent.setTitle(eventRequest.getTitle());
findEvent.setContent(eventRequest.getContent());
findEvent.setZipCode(eventRequest.getZipCode());
findEvent.setStreetAddress(eventRequest.getStreetAddress());
findEvent.setDetailAddress(eventRequest.getDetailAddress());
findEvent.setStartAt(eventRequest.getStartAt());
findEvent.setEndAt(eventRequest.getEndAt());

if (eventRequest.startAt() != null) {
findEvent.setStartAt(eventRequest.startAt());
}

if (eventRequest.endAt() != null) {
findEvent.setEndAt(eventRequest.endAt());
}
return eventRepository.save(findEvent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ac.kr.deu.connect.luck.event.dto.EventRequestV2;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -68,13 +69,13 @@ public String getEventUpdate(@PathVariable("id") Long id, Model model) {
}

@PostMapping("/update")
@PreAuthorize("hasRole('ROLE_EVENT_MANAGER')")
public String updateEventPost(
@RequestParam("eventId") Long id,
Principal principal,
EventRequest eventRequest,
@RequestParam("multipartFile") MultipartFile multipartFile
EventRequestV2 eventRequest
) {
eventService.updateEvent(id, eventRequest, multipartFile, principal.getName());
eventService.updateEvent(id, eventRequest, principal.getName());
return "redirect:/event/my";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ac.kr.deu.connect.luck.event.EventService;
import ac.kr.deu.connect.luck.event.EventStatus;
import ac.kr.deu.connect.luck.event.dto.EventDetailResponse;
import ac.kr.deu.connect.luck.event.dto.EventRequestV2;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -12,7 +13,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.security.Principal;
import java.util.List;
Expand All @@ -39,40 +39,34 @@ public ResponseEntity<EventDetailResponse> getEvent(@PathVariable Long id) {
return ResponseEntity.ok(eventService.getEvent(id));
}

//서비스 로직 수정함 레스트도 수정되어야할듯
/*@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
/**
* 이벤트 생성 Rest API
*
* @param eventRequest 이벤트 생성 요청 정보
* @param principal 로그인 한 사용자 정보
* @return 생성된 이벤트 정보
*/
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@PreAuthorize("hasRole('ROLE_EVENT_MANAGER')")
@Operation(summary = "이벤트 생성", description = "이벤트 생성\n이벤트 주소입력 시 카카오 우편번호 서비스를 사용해서 주소를 입력받아야함.")
public ResponseEntity<Event> createEvent(
@Parameter(description = "행사 이름") @RequestPart(value = "title") String title,
@Parameter(description = "이벤트 내용") @RequestPart(value = "content") String content,
@Parameter(description = "우편번호") @RequestPart(value = "zipCode") String zipCode,
@Parameter(description = "도로명주소") @RequestPart(value = "streetAddress") String streetAddress,
@Parameter(description = "상세주소") @RequestPart(value = "detailAddress") String detailAddress,
@Parameter(description = "시작일자 예시)2021-08-01T00:00:00") @RequestPart(value = "startAt") String startAt,
@Parameter(description = "종료일자 예시)2021-08-01T00:00:00") @RequestPart(value = "endAt") String endAt,
@Parameter(description = "이벤트 대표 이미지") @RequestPart(value = "image", required = false) MultipartFile multipartFile,
@ModelAttribute EventRequestV2 eventRequest,
Principal principal
) {
return ResponseEntity.ok(eventService.createEvent(title, content, zipCode, streetAddress, detailAddress, startAt, endAt, multipartFile, principal.getName()));
return ResponseEntity.ok(eventService.createEvent(eventRequest, principal.getName()));
}



@PatchMapping(value = "/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@PreAuthorize("hasRole('ROLE_EVENT_MANAGER')")
@Operation(summary = "이벤트 수정", description = "이벤트 수정")
public ResponseEntity<Event> updateEvent(
@Parameter(description = "이벤트 UID") @PathVariable(value = "id", required = false) Long id,
@Parameter(description = "행사 이름") @RequestPart(value = "title", required = false) String title,
@Parameter(description = "이벤트 내용") @RequestPart(value = "content", required = false) String content,
@Parameter(description = "우편번호") @RequestPart(value = "zipCode", required = false) String zipCode,
@Parameter(description = "도로명주소") @RequestPart(value = "streetAddress", required = false) String streetAddress,
@Parameter(description = "상세주소") @RequestPart(value = "detailAddress", required = false) String detailAddress,
@Parameter(description = "시작일자 예시)2021-08-01T00:00:00") @RequestPart(value = "startAt", required = false) String startAt,
@Parameter(description = "종료일자 예시)2021-08-01T00:00:00") @RequestPart(value = "endAt", required = false) String endAt,
@Parameter(description = "이벤트 대표 이미지") @RequestPart(value = "image", required = false) MultipartFile multipartFile,
@ModelAttribute EventRequestV2 eventRequest,
Principal principal) {
return ResponseEntity.ok(eventService.updateEvent(id, title, content, zipCode, streetAddress, detailAddress, startAt, endAt, multipartFile, principal.getName()));
}*/
return ResponseEntity.ok(eventService.updateEvent(id, eventRequest, principal.getName()));
}


@DeleteMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ac.kr.deu.connect.luck.event.dto

import io.swagger.v3.oas.annotations.media.Schema
import org.springframework.format.annotation.DateTimeFormat
import org.springframework.web.multipart.MultipartFile
import java.time.LocalDateTime

Expand All @@ -16,9 +17,11 @@ data class EventRequestV2(
val streetAddress: String,
@field:Schema(description = "상세 주소", example = "역삼동 123-456")
val detailAddress: String,
@field:Schema(description = "이벤트 시작일", example = "2021-01-01T00:00:00")
@field:Schema(description = "이벤트 시작일", example = "2021-01-01T00:00:00Z")
@field:DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
val startAt: LocalDateTime,
@field:Schema(description = "이벤트 종료일", example = "2021-01-01T23:59:59")
@field:Schema(description = "이벤트 종료일", example = "2021-01-01T23:59:59Z")
@field:DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
val endAt: LocalDateTime,
@field:Schema(description = "이미지", format = "binary")
var image: MultipartFile?
Expand Down

0 comments on commit 297af63

Please sign in to comment.