Skip to content

Commit

Permalink
Merge pull request #107 from Media-XI/ARTDEV-95-be-요구사항-변경에-따른-event-…
Browse files Browse the repository at this point in the history
…schedule-제거

Artdev 95 be 요구사항 변경에 따른 event schedule 제거
  • Loading branch information
haroya01 authored Dec 14, 2023
2 parents 8ed7a0a + d7c13eb commit 544a5f9
Show file tree
Hide file tree
Showing 32 changed files with 1,824 additions and 64 deletions.
126 changes: 126 additions & 0 deletions src/main/java/com/example/codebase/controller/EventController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.example.codebase.controller;

import com.example.codebase.domain.exhibition.dto.*;
import com.example.codebase.domain.exhibition.service.EventService;
import com.example.codebase.domain.image.service.ImageService;
import com.example.codebase.domain.member.entity.Member;
import com.example.codebase.domain.member.exception.NotFoundMemberException;
import com.example.codebase.job.JobService;
import com.example.codebase.util.SecurityUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.PositiveOrZero;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "Event", description = "이벤트 API")
@RestController
@RequestMapping("/api/events")
@Validated
public class EventController {

private final EventService eventService;

private final ImageService imageService;

private final JobService jobService;

@Autowired
public EventController(EventService eventService, ImageService imageService, JobService jobService) {
this.eventService = eventService;
this.imageService = imageService;
this.jobService = jobService;
}

@Operation(summary = "이벤트 생성", description = "이벤트 일정을 생성합니다.")
@PreAuthorize("isAuthenticated()")
@PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity createEvent(
@RequestPart(value = "dto") @Valid EventCreateDTO dto,
@RequestPart(value = "mediaFiles") List<MultipartFile> mediaFiles,
@RequestPart(value = "thumbnailFile") MultipartFile thumbnailFile)
throws Exception {
String username =
SecurityUtil.getCurrentUsername().orElseThrow(() -> new RuntimeException("로그인이 필요합니다."));

dto.validateDates();

Member member = eventService.findMemberByUserName(username);

if (!member.isSubmitedRoleInformation()) {
throw new RuntimeException("추가정보 입력한 사용자만 이벤트를 생성할 수 있습니다.");
}

imageService.uploadMedias(dto, mediaFiles);
imageService.uploadThumbnail(dto.getThumbnail(), thumbnailFile);

EventDetailResponseDTO event= eventService.createEvent(dto, member);

return new ResponseEntity(event, HttpStatus.CREATED);
}

@Operation(summary = "이벤트 목록 조회", description = "이벤트 목록을 조회합니다.")
@GetMapping
public ResponseEntity getEvent(
@ModelAttribute @Valid EventSearchDTO eventSearchDTO,
@PositiveOrZero @RequestParam(value = "page", defaultValue = "0") int page,
@PositiveOrZero @RequestParam(value = "size", defaultValue = "10") int size,
@RequestParam(defaultValue = "DESC", required = false) String sortDirection) {
eventSearchDTO.repeatTimeValidity();

EventPageInfoResponseDTO dtos = eventService.getEvents(eventSearchDTO, page, size, sortDirection);
return new ResponseEntity(dtos, HttpStatus.OK);
}

@Operation(summary = "이벤트 상세 조회", description = "이벤트 상세를 조회합니다.")
@GetMapping("/{eventId}")
public ResponseEntity getEventDetail(@PathVariable Long eventId) {
EventDetailResponseDTO eventDetailResponseDTO = eventService.getEventDetail(eventId);
return new ResponseEntity(eventDetailResponseDTO, HttpStatus.OK);
}

@Operation(summary = "이벤트 수정", description = "이벤트를 수정합니다.")
@PreAuthorize("isAuthenticated()")
@PutMapping("/{eventId}")
public ResponseEntity updateEvnet(
@PathVariable Long eventId,
@RequestBody @Valid EventUpdateDTO dto){
String username =
SecurityUtil.getCurrentUsername().orElseThrow(() -> new RuntimeException("로그인이 필요합니다."));

EventDetailResponseDTO eventDetailResponseDTO = eventService.updateEvent(eventId, dto, username);

return new ResponseEntity(eventDetailResponseDTO, HttpStatus.OK);
}

@Operation(summary = "이벤트 삭제", description = "이벤트를 삭제합니다.")
@PreAuthorize("isAuthenticated()")
@DeleteMapping("/{eventId}")
public ResponseEntity deleteEvent(@PathVariable Long eventId) {
String username =
SecurityUtil.getCurrentUsername().orElseThrow(() -> new RuntimeException("로그인이 필요합니다."));

eventService.deleteEvent(eventId, username);

return new ResponseEntity("이벤트가 삭제되었습니다.", HttpStatus.OK);
}

@Operation(summary = "수동 이벤트 크롤링 업데이트", description = "수동으로 공공데이터 포털에서 이벤트를 가져옵니다")
@PreAuthorize("isAuthenticated() AND hasRole('ROLE_ADMIN')")
@PostMapping("/crawling/event")
public ResponseEntity crawlingEvent() {
jobService.getEventListScheduler();

return new ResponseEntity("이벤트가 업데이트 되었습니다.", HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.codebase.controller;

import com.example.codebase.domain.exhibition.dto.*;
import com.example.codebase.domain.exhibition.service.EventService;
import com.example.codebase.domain.exhibition.service.ExhibitionService;
import com.example.codebase.domain.image.service.ImageService;
import com.example.codebase.job.JobService;
Expand All @@ -18,6 +19,7 @@
import jakarta.validation.Valid;
import jakarta.validation.constraints.PositiveOrZero;

import java.io.IOException;
import java.util.List;

@Tag(name = "Exhibition", description = "전시회 API")
Expand All @@ -29,12 +31,15 @@ public class ExhibitionController {

private final ImageService imageService;

private final EventService eventService;

private final JobService jobService;

@Autowired
public ExhibitionController(ExhibitionService exhibitionService, ImageService imageService, JobService jobService) {
public ExhibitionController(ExhibitionService exhibitionService, ImageService imageService, EventService eventService, JobService jobService) {
this.exhibitionService = exhibitionService;
this.imageService = imageService;
this.eventService = eventService;
this.jobService = jobService;
}

Expand Down Expand Up @@ -128,14 +133,21 @@ public ResponseEntity deleteEventSchedule(
}

@Operation(summary = "수동 이벤트 업데이트", description = "수동으로 공공데이터 포털에서 이벤트를 가져옵니다")
@PreAuthorize("isAuthenticated()")
@PreAuthorize("isAuthenticated() AND hasRole('ROLE_ADMIN')")
@PostMapping("/crawling/exhibition")
public ResponseEntity crawlingExhibition() {
if (!SecurityUtil.isAdmin()) {
throw new RuntimeException("관리자만 크롤링을 할 수 있습니다.");
}
public ResponseEntity crawlingExhibition() throws IOException {
jobService.getExhibitionListScheduler();

return new ResponseEntity("이벤트가 업데이트 되었습니다.", HttpStatus.OK);
}

@Operation(summary = "이벤트 스케줄 이동 작업", description = "이벤트 스케줄을 이동합니다.")
@PreAuthorize("isAuthenticated() AND hasRole('ROLE_ADMIN')")
@PostMapping("/move/event-schedule")
public ResponseEntity moveEventSchedule(){
eventService.moveEventSchedule();

return new ResponseEntity("이벤트 스케줄이 이동되었습니다.", HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -24,9 +25,30 @@ public class XmlDetailExhibitionData {
private String url;
private String phone;
private String imgUrl;

@XmlElement(defaultValue = "0.0")
private String gpsX;

@XmlElement(defaultValue = "0.0")
private String gpsY;

private String placeUrl;
private String placeAddr;
private String placeSeq;

public Double getLatitude() {
try {
return Double.parseDouble(gpsX);
} catch (NumberFormatException e) {
return 0.0;
}
}

public Double getLongitude() {
try {
return Double.parseDouble(gpsY);
} catch (NumberFormatException e) {
return 0.0;
}
}
}
Loading

0 comments on commit 544a5f9

Please sign in to comment.