From b122851967109443f5b49b2547d1433376da7155 Mon Sep 17 00:00:00 2001 From: gabang2 Date: Sun, 4 Aug 2024 14:56:31 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B6=94=EA=B0=80:=20sticker=20api=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sticker/controller/StickerController.java | 32 +++++++++++++++++++ .../sticker/dto/StickerRetrieveDto.java | 13 ++++++++ .../domain/sticker/entity/Sticker.java | 27 ++++++++++++++++ .../domain/sticker/mapper/StickerMapper.java | 14 ++++++++ .../sticker/repository/StickerRepository.java | 7 ++++ .../sticker/service/StickerService.java | 20 ++++++++++++ .../domain/ticket/dto/TicketRetrieveDto.java | 2 +- 7 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 src/main/java/project/backend/domain/sticker/controller/StickerController.java create mode 100644 src/main/java/project/backend/domain/sticker/dto/StickerRetrieveDto.java create mode 100644 src/main/java/project/backend/domain/sticker/entity/Sticker.java create mode 100644 src/main/java/project/backend/domain/sticker/mapper/StickerMapper.java create mode 100644 src/main/java/project/backend/domain/sticker/repository/StickerRepository.java create mode 100644 src/main/java/project/backend/domain/sticker/service/StickerService.java diff --git a/src/main/java/project/backend/domain/sticker/controller/StickerController.java b/src/main/java/project/backend/domain/sticker/controller/StickerController.java new file mode 100644 index 0000000..a9f224f --- /dev/null +++ b/src/main/java/project/backend/domain/sticker/controller/StickerController.java @@ -0,0 +1,32 @@ +package project.backend.domain.sticker.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import project.backend.domain.sticker.dto.StickerRetrieveDto; +import project.backend.domain.sticker.entity.Sticker; +import project.backend.domain.sticker.mapper.StickerMapper; +import project.backend.domain.sticker.service.StickerService; + +import java.util.List; + +@Api(tags = "스티커 API") +@RestController +@RequestMapping("/api/stickers") +@RequiredArgsConstructor +public class StickerController { + + private final StickerService stickerService; + private final StickerMapper stickerMapper; + + @ApiOperation(value = "스티커 리스트 조회") + @GetMapping + public ResponseEntity getSticker() { + List stickers = stickerService.getStickerList(); + List stickerRetrieveDtos = stickerMapper.stickersToStickerRetrieveDto(stickers); + return ResponseEntity.status(HttpStatus.OK).body(stickerRetrieveDtos); + } +} diff --git a/src/main/java/project/backend/domain/sticker/dto/StickerRetrieveDto.java b/src/main/java/project/backend/domain/sticker/dto/StickerRetrieveDto.java new file mode 100644 index 0000000..a158e2d --- /dev/null +++ b/src/main/java/project/backend/domain/sticker/dto/StickerRetrieveDto.java @@ -0,0 +1,13 @@ +package project.backend.domain.sticker.dto; + +import lombok.*; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class StickerRetrieveDto { + public String title; + public String content; +} diff --git a/src/main/java/project/backend/domain/sticker/entity/Sticker.java b/src/main/java/project/backend/domain/sticker/entity/Sticker.java new file mode 100644 index 0000000..3698626 --- /dev/null +++ b/src/main/java/project/backend/domain/sticker/entity/Sticker.java @@ -0,0 +1,27 @@ +package project.backend.domain.sticker.entity; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import project.backend.domain.common.entity.BaseEntity; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +@Getter +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +public class Sticker extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + public Long id; + public String imageUrl; + + @Builder + public Sticker(String imageUrl) { + this.imageUrl = imageUrl; + } +} diff --git a/src/main/java/project/backend/domain/sticker/mapper/StickerMapper.java b/src/main/java/project/backend/domain/sticker/mapper/StickerMapper.java new file mode 100644 index 0000000..7a95c61 --- /dev/null +++ b/src/main/java/project/backend/domain/sticker/mapper/StickerMapper.java @@ -0,0 +1,14 @@ +package project.backend.domain.sticker.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import project.backend.domain.sticker.dto.StickerRetrieveDto; +import project.backend.domain.sticker.entity.Sticker; + +import java.util.List; + +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface StickerMapper { + + List stickersToStickerRetrieveDto(List sticker); +} diff --git a/src/main/java/project/backend/domain/sticker/repository/StickerRepository.java b/src/main/java/project/backend/domain/sticker/repository/StickerRepository.java new file mode 100644 index 0000000..6b93713 --- /dev/null +++ b/src/main/java/project/backend/domain/sticker/repository/StickerRepository.java @@ -0,0 +1,7 @@ +package project.backend.domain.sticker.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import project.backend.domain.sticker.entity.Sticker; + +public interface StickerRepository extends JpaRepository { +} diff --git a/src/main/java/project/backend/domain/sticker/service/StickerService.java b/src/main/java/project/backend/domain/sticker/service/StickerService.java new file mode 100644 index 0000000..c48195c --- /dev/null +++ b/src/main/java/project/backend/domain/sticker/service/StickerService.java @@ -0,0 +1,20 @@ +package project.backend.domain.sticker.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import project.backend.domain.sticker.entity.Sticker; +import project.backend.domain.sticker.repository.StickerRepository; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Transactional +public class StickerService { + private final StickerRepository stickerRepository; + + public List getStickerList() { + return stickerRepository.findAll(); + } +} diff --git a/src/main/java/project/backend/domain/ticket/dto/TicketRetrieveDto.java b/src/main/java/project/backend/domain/ticket/dto/TicketRetrieveDto.java index bd98b39..bb99f4d 100644 --- a/src/main/java/project/backend/domain/ticket/dto/TicketRetrieveDto.java +++ b/src/main/java/project/backend/domain/ticket/dto/TicketRetrieveDto.java @@ -11,7 +11,7 @@ @NoArgsConstructor @AllArgsConstructor public class TicketRetrieveDto { - // TODO(sprint4) : Category, place 연결 미구현 상태 + // TODO(sprint4) : place 연결 미구현 상태 public Long id; public String title; public String mainImageUrl;