Skip to content

Commit

Permalink
Merge pull request #123 from themoment-team/feature/popup
Browse files Browse the repository at this point in the history
팝업 등록 api 추가
  • Loading branch information
jangwooooo authored Dec 4, 2023
2 parents d934987 + cbfc14f commit 8a2797e
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.themoment.officialgsm.domain.popup.controller;

import com.themoment.officialgsm.domain.popup.dto.AddPopupRequest;
import com.themoment.officialgsm.domain.popup.service.PopupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/popup")
@RequiredArgsConstructor
public class PopupController {

private final PopupService popupService;

@PostMapping
@Operation(
summary = "팝업 등록 요청",
description = "팝업을 등록하는 api",
tags = {"Popup Controller"}
)
public ResponseEntity<Void> popupAdd(
@Parameter(
name = "info", description = "popup의 링크와 만료기간 - form-data", in = ParameterIn.PATH
)
@RequestPart(value = "info", required = true) AddPopupRequest addPopupRequest,
@Parameter(
name = "image", description = "popup의 image - form-data", in = ParameterIn.PATH,
content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA_VALUE)
)
@RequestPart(value = "image", required = true) MultipartFile image
) {
popupService.addPopup(addPopupRequest, image);
return new ResponseEntity<>(HttpStatus.CREATED);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.themoment.officialgsm.domain.popup.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
public class AddPopupRequest {

private String link;

private LocalDateTime expirationDateTime;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.themoment.officialgsm.domain.popup.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Popup {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "popup_seq")
private Long popupSeq;

@Column(name = "image_url", nullable = false)
private String imageUrl;

@Column(name = "link", nullable = true)
private String link;

@Column(name = "expiration_date_time", nullable = false)
private LocalDateTime expirationDateTime;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.themoment.officialgsm.domain.popup.repository;

import com.themoment.officialgsm.domain.popup.entity.Popup;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PopupRepository extends JpaRepository<Popup, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.themoment.officialgsm.domain.popup.service;

import com.themoment.officialgsm.domain.board.dto.FileDto;
import com.themoment.officialgsm.domain.popup.dto.AddPopupRequest;
import com.themoment.officialgsm.domain.popup.entity.Popup;
import com.themoment.officialgsm.domain.popup.repository.PopupRepository;
import com.themoment.officialgsm.global.util.AwsS3Util;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PopupService {

private final PopupRepository popupRepository;
private final AwsS3Util awsS3Util;

@Transactional
public void addPopup(AddPopupRequest addPopupRequest, MultipartFile image) {
FileDto fileDto = awsS3Util.fileUploadProcess(List.of(image)).get(0);
Popup popup = Popup.builder()
.imageUrl(fileDto.getFileUrl())
.link(addPopupRequest.getLink())
.expirationDateTime(addPopupRequest.getExpirationDateTime())
.build();

popupRepository.save(popup);
}
}

0 comments on commit 8a2797e

Please sign in to comment.