-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from themoment-team/feature/popup
팝업 등록 api 추가
- Loading branch information
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/com/themoment/officialgsm/domain/popup/controller/PopupController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/themoment/officialgsm/domain/popup/dto/AddPopupRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/themoment/officialgsm/domain/popup/entity/Popup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/themoment/officialgsm/domain/popup/repository/PopupRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/themoment/officialgsm/domain/popup/service/PopupService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |