Skip to content

Commit

Permalink
Api-Release-v0.0.2-25
Browse files Browse the repository at this point in the history
Api-Release-v0.0.2-25
  • Loading branch information
imenuuu authored Dec 27, 2023
2 parents 972a432 + 9ee2e4a commit 6d45136
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public CommonResponse<List<BannerRes.BannerList>> uploadBanner(
@RequestPart MultipartFile bannerImage,
@RequestPart("bannerUploadDto") BannerReq.BannerUpload bannerUploadDto
){
return CommonResponse.onSuccess(adminBannerService.uploadBanner(BannerType.EVENT, bannerImage, bannerUploadDto));
return CommonResponse.onSuccess(adminBannerService.uploadBanner(BannerType.CONTENTS, bannerImage, bannerUploadDto));
}

@GetMapping("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ public void deleteBanner(Long bannerId) {
@Transactional
public void patchBanner(Long bannerId, BannerReq.BannerPatchDto bannerPatchDto, MultipartFile bannerImage) {
Banner banner = bannerAdaptor.findById(bannerId);
System.out.println(bannerPatchDto.getEndDate());
System.out.println(bannerPatchDto.getStartDate());
if(bannerPatchDto.isEditImage()){
s3UploadService.deleteFile(banner.getBannerImg());
String imgUrl = s3UploadService.uploadBannerImage(bannerImage);
banner.updateBanner(bannerPatchDto.getName(), banner.getStartDate(), banner.getEndDate(), imgUrl);
System.out.println(imgUrl);
banner.updateBanner(bannerPatchDto.getName(), bannerPatchDto.getStartDate(), bannerPatchDto.getEndDate(), imgUrl, bannerPatchDto.getContentsUrl());
}else{
banner.updateBanner(bannerPatchDto.getName(), banner.getStartDate(), banner.getEndDate(), banner.getBannerImg());
banner.updateBanner(bannerPatchDto.getName(), bannerPatchDto.getStartDate(), bannerPatchDto.getEndDate(), banner.getBannerImg(), bannerPatchDto.getContentsUrl());
}
bannerAdaptor.save(banner);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.matchapi.admin.event.service.AdminEventService;
import com.example.matchapi.event.dto.EventRes;
import com.example.matchcommon.reponse.CommonResponse;
import com.example.matchcommon.reponse.PageResponse;
import com.example.matchinfrastructure.config.s3.S3UploadService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -21,15 +22,28 @@
public class AdminEventController {
private final AdminEventService adminEventService;

@GetMapping("")
@Operation(summary = "ADMIN-09-01 이벤트 리스트 조회")
public CommonResponse<PageResponse<List<EventRes.EventList>>> getEventLists(
@RequestParam(required = false, defaultValue = "0") int page,
@RequestParam(required = false, defaultValue = "10") int size
){
return CommonResponse.onSuccess(adminEventService.getEventList(page, size));
}


@PostMapping("")
@Operation(summary = "ADMIN-09-01 이벤트 업로드")
public CommonResponse<String> uploadEventList(@RequestBody EventUploadReq eventUploadReq){
adminEventService.uploadEventList(eventUploadReq);
@Operation(summary = "ADMIN-09-02 이벤트 업로드")
public CommonResponse<String> uploadEventList(
@RequestPart("thumbnail") MultipartFile thumbnail,
@RequestPart("eventUploadReq") EventUploadReq eventUploadReq
){
adminEventService.uploadEventList(thumbnail, eventUploadReq);
return CommonResponse.onSuccess("업로드 성공");
}

@DeleteMapping("/{eventId}")
@Operation(summary = "ADMIN-09-02 이벤트 삭제")
@Operation(summary = "ADMIN-09-03 이벤트 삭제")
public CommonResponse<String> deleteEvent(@PathVariable Long eventId){
adminEventService.deleteEvent(eventId);
return CommonResponse.onSuccess("삭제 성공");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class EventUploadReq {
private String title;

private String smallTitle;

private String thumbnail;

private EventType eventType;

private LocalDate eventStartDate;
private LocalDate startDate;

private LocalDate eventEndDate;
private LocalDate endDate;

private List<ContentsList> contentsList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
import com.example.matchapi.common.model.ContentsList;
import com.example.matchapi.common.util.MessageHelper;
import com.example.matchapi.event.converter.EventConverter;
import com.example.matchapi.event.dto.EventRes;
import com.example.matchcommon.constants.enums.Topic;
import com.example.matchcommon.reponse.PageResponse;
import com.example.matchdomain.event.adaptor.EventAdaptor;
import com.example.matchdomain.event.adaptor.EventContentAdaptor;
import com.example.matchdomain.event.entity.Event;
import com.example.matchdomain.event.entity.EventContent;
import com.example.matchinfrastructure.config.s3.S3UploadService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.transaction.Transactional;
import java.util.ArrayList;
Expand All @@ -33,9 +37,10 @@ public class AdminEventService {

@Transactional
@CacheEvict(value = "eventCache", allEntries = true, cacheManager = "ehcacheManager")
public void uploadEventList(EventUploadReq eventUploadReq) {
public void uploadEventList(MultipartFile thumbnail, EventUploadReq eventUploadReq) {

Event event = eventAdaptor.save(eventConverter.convertToEventUpload(eventUploadReq, eventUploadReq.getThumbnail()));
String thumbnailUrl = s3UploadService.uploadOneImg("event", thumbnail);
Event event = eventAdaptor.save(eventConverter.convertToEventUpload(eventUploadReq, thumbnailUrl));

Long eventId = event.getId();

Expand Down Expand Up @@ -67,4 +72,9 @@ public void deleteEvent(Long eventId) {
}
eventAdaptor.deleteByEventId(eventId);
}

public PageResponse<List<EventRes.EventList>> getEventList(int page, int size) {
Page<Event> events = eventAdaptor.findEvent(page, size);
return new PageResponse<>(events.isLast(), events.getTotalPages(), eventConverter.convertToEventList(events.getContent()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
@RequiredArgsConstructor
public class ImageController {
private final S3UploadService s3UploadService;
@PostMapping(value = "",
consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public CommonResponse<String> imgUpload(
@ModelAttribute UploadFolder uploadFolder,
@ModelAttribute MultipartFile imgFile){
@RequestParam("uploadFolder") UploadFolder uploadFolder,
@RequestPart("imgFile") MultipartFile imgFile){
String url = s3UploadService.uploadOneImg(uploadFolder.getFolder(), imgFile);
return CommonResponse.onSuccess(url);
}
Expand Down
23 changes: 23 additions & 0 deletions Match-Api/src/main/java/com/example/matchapi/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package com.example.matchapi.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Configuration
Expand Down Expand Up @@ -48,4 +56,19 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
.addResourceLocations("classpath:/static/")
.setCacheControl(cacheControl);
}

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_JSON);
}

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new MappingJackson2HttpMessageConverter());
}

@Bean
public MultipartResolver multipartResolver() {
return new StandardServletMultipartResolver();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public Event convertToEventUpload(EventUploadReq eventUploadReq, String thumbnai
.eventType(eventUploadReq.getEventType())
.smallTitle(eventUploadReq.getSmallTitle())
.thumbnail(thumbnail)
.eventStartDate(eventUploadReq.getEventStartDate())
.eventEndDate(eventUploadReq.getEventEndDate())
.eventStartDate(eventUploadReq.getStartDate())
.eventEndDate(eventUploadReq.getEndDate())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public static class EventInfo{

private String smallTitle;


@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@DynamicUpdate
@BatchSize(size = 100)
@DynamicInsert
@ToString
public class Banner extends BaseEntity {
@Id
@Column(name = "id")
Expand All @@ -48,10 +49,12 @@ public class Banner extends BaseEntity {

private LocalDateTime endDate;

public void updateBanner(String name, LocalDateTime startDate, LocalDateTime endDate, String bannerImg) {
public void updateBanner(String name, LocalDateTime startDate, LocalDateTime endDate, String bannerImg,
String contentsUrl) {
this.name = name;
this.startDate = startDate;
this.endDate = endDate;
this.bannerImg = bannerImg;
this.contentsUrl = contentsUrl;
}
}

0 comments on commit 6d45136

Please sign in to comment.