Skip to content

Commit

Permalink
Merge pull request #24 from potenday-23/feature/ticket_folder
Browse files Browse the repository at this point in the history
Feature : ํ‹ฐ์ผ“ ํด๋” ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ ์ถ”๊ฐ€
  • Loading branch information
rrosiee authored Jul 31, 2024
2 parents 78edd50 + 68bc226 commit f0d61e5
Show file tree
Hide file tree
Showing 22 changed files with 329 additions and 40 deletions.
12 changes: 0 additions & 12 deletions src/main/java/project/backend/domain/jwt/response/JwtResponse.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package project.backend.domain.like;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import project.backend.domain.like.entity.CulturalEventLike;
import project.backend.domain.notification.service.NotificationService;

import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
public class MediaDto {
private String mediaUrl;
private Integer ordering;
private Boolean isThumbnail;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@Transactional
public class MediaService {
private final MediaRepository mediaRepository;
private final MediaMapper mediaMapper;
private final ImageService imageService;

public Media createMedia(MultipartFile file) {
Expand All @@ -30,16 +29,9 @@ public Media createMedia(MultipartFile file) {
return media;
}

public Media setOrderThumbnail(MediaDto mediaDto) {
Media media;
Optional<Media> optionalMedia = mediaRepository.findFirstByMediaUrl(mediaDto.getMediaUrl());
if (optionalMedia.isPresent()) {
media = optionalMedia.get();
} else {
media = Media.builder().mediaUrl(mediaDto.getMediaUrl()).build();
}
public Media setMediaOrdering(MediaDto mediaDto) {
Media media = Media.builder().mediaUrl(mediaDto.getMediaUrl()).build();
media.setOrdering(mediaDto.getOrdering());
media.setIsThumbnail(mediaDto.getIsThumbnail());
return mediaRepository.save(media);
}
}
28 changes: 28 additions & 0 deletions src/main/java/project/backend/domain/member/MemberListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package project.backend.domain.member;

import org.springframework.stereotype.Component;
import project.backend.domain.member.entity.Member;
import project.backend.domain.ticketfolder.entity.TicketFolder;
import project.backend.domain.ticketfolder.repository.TicketFolderRepository;
import project.backend.global.config.SpringContext;

import javax.persistence.PostPersist;
import java.util.Arrays;
import java.util.List;


@Component
public class MemberListener {

List<String> defaultTicketFolderTitles = Arrays.asList("๋ฎค์ง€์ปฌ", "์˜ํ™”", "์—ฐ๊ทน", "์ฝ˜์„œํŠธ", "์ „์‹œํšŒ");
@PostPersist
public void postPersist(Member member) {
TicketFolderRepository ticketFolderRepository = SpringContext.getBean(TicketFolderRepository.class);
for (String title : defaultTicketFolderTitles) {
TicketFolder ticketFolder = TicketFolder.builder().isDefault(true).title(title).build();
ticketFolderRepository.save(ticketFolder);
ticketFolder.setMember(member);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import lombok.RequiredArgsConstructor;
import project.backend.domain.keyword.entity.CulturalEventSearchKeyword;
import project.backend.domain.like.entity.CulturalEventLike;
import project.backend.domain.member.MemberListener;
import project.backend.domain.member.dto.MemberInfoDto;
import project.backend.domain.common.entity.BaseEntity;
import project.backend.domain.onboardingmembercategory.entity.OnboardingMemberCategory;
import project.backend.domain.ticket.entity.Ticket;
import project.backend.domain.member.dto.MemberPatchRequestDto;
import project.backend.domain.ticketfolder.entity.TicketFolder;
import project.backend.domain.visit.entity.CulturalEventVisit;

import javax.persistence.*;
Expand All @@ -22,6 +24,7 @@

@Entity
@Getter
@EntityListeners(MemberListener.class)
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class Member extends BaseEntity {
@Id
Expand Down Expand Up @@ -69,6 +72,8 @@ public class Member extends BaseEntity {
@OneToMany(mappedBy = "member", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
public List<CulturalEventSearchKeyword> culturalEventSearchKeywordList = new ArrayList<>();

@OneToMany(mappedBy = "member", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
public List<TicketFolder> ticketFolderList = new ArrayList<>();
@Builder
public Member(SocialType socialType, String socialId, String nickname, String profileImageUrl, String refreshToken) {
this.socialType = socialType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package project.backend.domain.member.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import project.backend.domain.member.entity.Member;
import project.backend.domain.member.entity.SocialType;

Expand All @@ -13,5 +14,6 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findFirstBySocialIdAndSocialType(String socialId, SocialType socialType);

Optional<Member> findByNicknameAndIdNot(String nickname, Long id);

@Query("SELECT m FROM Member m LEFT JOIN FETCH m.ticketFolderList")
List<Member> findAllWithTicketFolders();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class TicketController {
private final TicketService ticketService;
private final TicketMapper ticketMapper;

@ApiOperation(value = "ํ‹ฐ์ผ“ ์ƒ์„ฑํ•˜๊ธฐ")
@ApiOperation(value = "ํ‹ฐ์ผ“ ์ƒ์„ฑ")
@PreAuthorize("isAuthenticated()")
@PostMapping
public ResponseEntity create(@Valid @RequestBody TicketCreateDto ticketCreateDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import project.backend.domain.media.dto.MediaDto;
import project.backend.global.annotation.ValidDateFormat;

import javax.validation.constraints.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Getter
Expand All @@ -19,7 +17,7 @@ public class TicketCreateDto {
// TODO(sprint4) : Category, place ์—ฐ๊ฒฐ ๋ฏธ๊ตฌํ˜„ ์ƒํƒœ

@NotBlank
@NotNull
@NotNull(message = "๋ฌธํ™”์ƒํ™œ์˜ ์ œ๋ชฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”")
@Size(min = 1, max = 20, message = "1์ž ~ 20์ž ์‚ฌ์ด๋งŒ ์ž…๋ ฅ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.")
@Schema(description = "์ œ๋ชฉ", example = "<๋ฎค์ง€์ปฌ> ์‹œ์นด๊ณ ", required = true)
public String title;
Expand All @@ -29,7 +27,7 @@ public class TicketCreateDto {
@Schema(description = "๋ฉ”์ธ ์ด๋ฏธ์ง€", example = "https://placehold.co/600x400/png", required = true)
public String mainImageUrl;

@NotNull
@NotNull(message = "๋‚ ์งœ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”")
@Schema(description = "๋‚ ์งœ", example = "2024-01-01", required = true)
public LocalDate date;

Expand All @@ -39,15 +37,18 @@ public class TicketCreateDto {
@Schema(description = "๋ณ„์ ", example = "3.5", required = true)
public Float score;

@Schema(description = "๋ณ„์ ", example = "2์ธต 2์—ด 8๋ฒˆ", required = false)
@Schema(description = "๋ณ„์ ", example = "2์ธต 2์—ด 8๋ฒˆ")
@NotNull(message = "์ขŒ์„ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”")
public String seat;

@Schema(description = "๊ฐ€๊ฒฉ", example = "156000", required = false)
@Schema(description = "๊ฐ€๊ฒฉ", example = "156000")
public Integer price;

@Size(max = 500, message = "Review must be up to 500 characters")
@Schema(description = "๋ฆฌ๋ทฐ", example = "์ •๋ง ์žฌ๋ฏธ์žˆ์—ˆ์–ด์š”", required = false)
private String review;
@Schema(description = "๋ฆฌ๋ทฐ", example = "์ •๋ง ์žฌ๋ฏธ์žˆ์—ˆ์–ด์š”")
public String review;

public Long ticketFolderId;

public List<MediaDto> medias;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package project.backend.domain.ticket.dto;

import lombok.*;
import project.backend.domain.ticketfolder.dto.TicketFolderRetrieveDto;

import java.time.LocalDateTime;

@Getter
Expand All @@ -19,4 +21,5 @@ public class TicketRetrieveDto {
public Integer price;
private String review;
public String mediasData;
public TicketFolderRetrieveDto ticketFolder;
}
14 changes: 14 additions & 0 deletions src/main/java/project/backend/domain/ticket/entity/Ticket.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import project.backend.domain.media.entity.Media;
import project.backend.domain.place.entity.Place;
import project.backend.domain.member.entity.Member;
import project.backend.domain.ticketfolder.entity.TicketFolder;
import project.backend.domain.ticketingsite.entity.TicketingSite;

import javax.persistence.*;
Expand Down Expand Up @@ -42,6 +43,9 @@ public class Ticket extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
public Place place;

@ManyToOne(fetch = FetchType.LAZY)
public TicketFolder ticketFolder;

@OneToMany(mappedBy = "ticket", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
public List<Media> medias = new ArrayList<>();

Expand Down Expand Up @@ -91,4 +95,14 @@ public void setPlace(Place place) {
this.place = Optional.ofNullable(place).orElse(this.place);
this.place.getTickets().add(this);
}

public void setTicketFolder(TicketFolder ticketFolder) {
if (this.ticketFolder != null) {
if (this.ticketFolder.getTickets().contains(this)) {
this.ticketFolder.getTickets().remove(this);
}
}
this.ticketFolder = Optional.ofNullable(ticketFolder).orElse(this.ticketFolder);
this.ticketFolder.getTickets().add(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,29 @@
import project.backend.domain.ticket.dto.TicketCreateDto;
import project.backend.domain.ticket.entity.Ticket;
import project.backend.domain.ticket.repository.TicketRepository;
import project.backend.domain.ticketfolder.entity.TicketFolder;
import project.backend.domain.ticketfolder.repository.TicketFolderRepository;
import project.backend.global.error.exception.BusinessException;
import project.backend.global.error.exception.ErrorCode;

import java.io.IOException;
import java.util.Optional;

@Service
@RequiredArgsConstructor
@Transactional
public class TicketService {
private final TicketRepository ticketRepository;
private final TicketFolderRepository ticketFolderRepository;
private final MediaService mediaService;
private final MemberJwtService memberJwtService;

public Ticket createTicket(TicketCreateDto ticketCreateDto) {
Media media;

Member member = memberJwtService.getMember();
TicketFolder ticketFolder = ticketFolderRepository.findById(ticketCreateDto.getTicketFolderId())
.orElseThrow(() -> new BusinessException(ErrorCode.TICKET_FOLDER_NOT_FOUND));

Ticket ticket = Ticket.builder()
.title(ticketCreateDto.getTitle())
.mainImageUrl(ticketCreateDto.getMainImageUrl())
Expand All @@ -45,13 +53,20 @@ public Ticket createTicket(TicketCreateDto ticketCreateDto) {

// Media ์—ฐ๊ฒฐ
for (MediaDto mediaDto : ticketCreateDto.medias) {
media = mediaService.setOrderThumbnail(mediaDto);
Media media = mediaService.setMediaOrdering(mediaDto);
media.setTicket(ticket);
}
ticket.setMember(memberJwtService.getMember());
ticketRepository.save(ticket);

return ticket;
// Ticket Folder ์—ฐ๊ฒฐ
if (ticketFolder.getMember() != member) {
throw new BusinessException(ErrorCode.TICKET_FOLDER_ADD_AUTH);
}
ticket.setTicketFolder(ticketFolder);

// Member ์—ฐ๊ฒฐ
ticket.setMember(member);

return ticketRepository.save(ticket);
}

public Ticket getTicket(Long id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package project.backend.domain.ticketfolder.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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import project.backend.domain.ticket.dto.TicketCreateDto;
import project.backend.domain.ticket.entity.Ticket;
import project.backend.domain.ticketfolder.dto.TicketFolderCreateDto;
import project.backend.domain.ticketfolder.dto.TicketFolderRetrieveDto;
import project.backend.domain.ticketfolder.entity.TicketFolder;
import project.backend.domain.ticketfolder.mapper.TicketFolderMapper;
import project.backend.domain.ticketfolder.service.TicketFolderService;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "TicketFolder - ํ‹ฐ์ผ“ ํด๋”")
@RestController
@RequestMapping("/api/ticket-folders")
@RequiredArgsConstructor
public class TicketFolderController {
private final TicketFolderService ticketFolderService;
private final TicketFolderMapper ticketFolderMapper;

@ApiOperation(value = "ํ‹ฐ์ผ“ ํด๋” ๋ฆฌ์ŠคํŠธ ์กฐํšŒ")
@PreAuthorize("isAuthenticated()")
@GetMapping
public ResponseEntity list() {
List<TicketFolder> ticketFolderList = ticketFolderService.getTicketFolderList();
List<TicketFolderRetrieveDto> ticketFolderRetrieveDtoList = ticketFolderMapper.ticketFolderToTicketFolderRetrieveDto(ticketFolderList);
return ResponseEntity.status(HttpStatus.OK).body(ticketFolderRetrieveDtoList);
}

@ApiOperation(value = "ํ‹ฐ์ผ“ ํด๋” ์ƒ์„ฑ")
@PreAuthorize("isAuthenticated()")
@PostMapping
public ResponseEntity create(@Valid @RequestBody TicketFolderCreateDto ticketFolderCreateDto) {
TicketFolder ticketFolder = ticketFolderService.createTicketFolder(ticketFolderCreateDto);
return ResponseEntity.status(HttpStatus.CREATED).body(ticketFolderMapper.ticketFolderToTicketFolderRetrieveDto(ticketFolder));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package project.backend.domain.ticketfolder.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;


@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TicketFolderCreateDto {
@NotBlank
@NotNull(message = "ํ‹ฐ์ผ“ ํด๋”์˜ ์ œ๋ชฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”")
@Size(min = 1, max = 12, message = "1์ž ~ 12์ž ์‚ฌ์ด๋งŒ ์ž…๋ ฅ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.")
@Schema(description = "์ œ๋ชฉ", example = "์„œ์šธ ๊ณต์—ฐ", required = true)
public String title;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package project.backend.domain.ticketfolder.dto;

import lombok.*;


@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TicketFolderRetrieveDto {
public Long id;
public String title;
}
Loading

0 comments on commit f0d61e5

Please sign in to comment.