Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#56/call_faceDetection_lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
redblackblossom committed Aug 10, 2024
2 parents db5da69 + 05f1c51 commit 31f39a8
Show file tree
Hide file tree
Showing 42 changed files with 735 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.umc.naoman.domain.agenda.converter.AgendaConverter;
import com.umc.naoman.domain.agenda.dto.AgendaRequest;
import com.umc.naoman.domain.agenda.dto.AgendaResponse;
import com.umc.naoman.domain.agenda.dto.AgendaResponse.AgendaDetailInfo;
import com.umc.naoman.domain.agenda.dto.AgendaResponse.PagedAgendaDetailInfo;
import com.umc.naoman.domain.agenda.entity.Agenda;
import com.umc.naoman.domain.agenda.service.AgendaService;
import com.umc.naoman.domain.member.entity.Member;
Expand All @@ -11,25 +13,42 @@
import com.umc.naoman.global.result.code.AgendaResultCode;
import com.umc.naoman.global.security.annotation.LoginMember;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.umc.naoman.global.result.code.AgendaResultCode.GET_AGENDA_LIST;

@RestController
@RequestMapping("/agendas")
@Tag(name = "04. 안건 관련 API", description = "안건 관련 API입니다.")
@RequiredArgsConstructor
@Slf4j
public class AgendaController {

private final AgendaService agendaService;
private final AgendaConverter agendaConverter;

@PostMapping("/agendas")
@PostMapping
@Operation(summary = "안건 생성 API", description = "[request]\n shareGroupId, title, 안건에 올릴 PhotoId 리스트" +
"\n[response]\n 생성된 안건의 agendaId, 생성시간 createdAt")
@ApiResponses({
Expand All @@ -46,5 +65,46 @@ public ResultResponse<AgendaResponse.AgendaInfo> createAgenda(@RequestBody @Vali
Agenda agenda = agendaService.createAgenda(member,request);
return ResultResponse.of(AgendaResultCode.CREATE_AGENDA, agendaConverter.toAgendaInfo(agenda));
}

@GetMapping()
@Operation(summary = "특정 공유 그룹의 안건 목록 조회 API", description = "특정 공유 그룹의 안건 목록을 조회하는 API입니다.")
@Parameters(value = {
@Parameter(name = "shareGroupId", description = "특정 안건 id를 입력해 주세요."),
@Parameter(name = "page", description = "조회할 페이지 번호를 입력해주세요.(0번부터)"),
@Parameter(name = "size", description = "한 페이지에 나타낼 안건 개수를 입력해 주세요.")
})
public ResultResponse<PagedAgendaDetailInfo> getAgendaList(@RequestParam("shareGroupId") Long shareGroupId,
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC)
@Parameter(hidden = true) Pageable pageable,
@LoginMember Member member) {
PagedAgendaDetailInfo pagedAgendaDetailInfo = agendaService.getAgendaList(shareGroupId, member, pageable);
return ResultResponse.of(GET_AGENDA_LIST, pagedAgendaDetailInfo);
}


@GetMapping("/{agendaId}")
@Operation(summary = "안건 상세 조회 API", description = "agendaId로 안건 상세를 조회하는 API입니다.")
@Parameters(value = {
@Parameter(name = "agendaId", description = "특정 안건 id를 입력해 주세요.")
})
public ResultResponse<AgendaDetailInfo> getAgendaDetail(@PathVariable(name = "agendaId") Long agendaId,
@LoginMember Member member) {
Agenda agenda = agendaService.getAgendaDetailInfo(agendaId, member);

return ResultResponse.of(AgendaResultCode.AGENDA_DETAIL,
agendaConverter.toAgendaDetailInfo(agenda));
}

@DeleteMapping("/{agendaId}")
@Operation(summary = "안건 삭제 API", description = "agendaId로 안건 삭제하는 API입니다.")
@Parameters(value = {
@Parameter(name = "agendaId", description = "특정 안건 id를 입력해 주세요.")
})
public ResultResponse<AgendaResponse.AgendaInfo> deleteAgenda(@PathVariable(name = "agendaId") Long agendaId,
@LoginMember Member member) {
Agenda agenda = agendaService.deleteAgenda(agendaId);

return ResultResponse.of(AgendaResultCode.AGENDA_DETAIL, agendaConverter.toAgendaInfo(agenda));
}
}

Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package com.umc.naoman.domain.agenda.converter;

import com.umc.naoman.domain.agenda.dto.AgendaPhotoResponse;
import com.umc.naoman.domain.agenda.dto.AgendaResponse;
import com.umc.naoman.domain.agenda.dto.AgendaResponse.AgendaDetailInfo;
import com.umc.naoman.domain.agenda.entity.Agenda;
import com.umc.naoman.domain.shareGroup.entity.Profile;
import com.umc.naoman.domain.shareGroup.entity.ShareGroup;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
@RequiredArgsConstructor
public class AgendaConverter {

private final AgendaPhotoConverter agendaPhotoConverter;

public AgendaResponse.AgendaInfo toAgendaInfo(Agenda agenda){
return AgendaResponse.AgendaInfo.builder()
.agendaId(agenda.getId())
Expand All @@ -23,4 +33,31 @@ public Agenda toEntity(Profile profile, String title, ShareGroup shareGroup){
.shareGroup(shareGroup)
.build();
}

public AgendaDetailInfo toAgendaDetailInfo(Agenda agenda) {
List<AgendaPhotoResponse.AgendaPhotoInfo> agendaPhotoInfoList = agenda.getAgendaPhotoList()
.stream()
.map(agendaPhotoConverter::toAgendaPhotoInfo)
.collect(Collectors.toList());

return AgendaDetailInfo.builder()
.agendaId(agenda.getId())
.title(agenda.getTitle())
.agendaPhotoInfoList(agendaPhotoInfoList)
.build();
}

public AgendaResponse.PagedAgendaDetailInfo toPageAgendaDetailInfo(Page<Agenda> agendaList) {
List<AgendaDetailInfo> agendaDetailInfoList = agendaList.stream()
.map(agenda -> toAgendaDetailInfo(agenda))
.toList();

return AgendaResponse.PagedAgendaDetailInfo.builder()
.agendaDetailInfoList(agendaDetailInfoList)
.totalPages(agendaList.getTotalPages())
.totalElements(agendaList.getTotalElements())
.isFirst(agendaList.isFirst())
.isLast(agendaList.isLast())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.umc.naoman.domain.agenda.converter;

import com.umc.naoman.domain.agenda.dto.AgendaPhotoResponse;
import com.umc.naoman.domain.agenda.entity.Agenda;
import com.umc.naoman.domain.agenda.entity.AgendaPhoto;
import com.umc.naoman.domain.photo.entity.Photo;
import org.springframework.stereotype.Component;

@Component
public class AgendaPhotoConverter {

public static AgendaPhoto toEntity(Agenda agenda, Photo photo) {
Expand All @@ -12,4 +15,12 @@ public static AgendaPhoto toEntity(Agenda agenda, Photo photo) {
.photo(photo)
.build();
}

public AgendaPhotoResponse.AgendaPhotoInfo toAgendaPhotoInfo(AgendaPhoto agendaPhoto) {
return AgendaPhotoResponse.AgendaPhotoInfo
.builder()
.agendaPhotoId(agendaPhoto.getId())
.url(agendaPhoto.getPhoto().getUrl())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.umc.naoman.domain.agenda.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

public abstract class AgendaPhotoResponse {

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class AgendaPhotoInfo {
private Long agendaPhotoId;
private String url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public static class CreateAgendaRequest {
@NotNull
private String title;
@Size(min = 2, max = 6, message = "안건에 등록하는 사진은 최소 2개 최대 6개로 한정 시켜 주세요.")
private List<Long> agendasPhotoList;
private List<Long> photoIdList;
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/umc/naoman/domain/agenda/dto/AgendaResponse.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.umc.naoman.domain.agenda.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.umc.naoman.domain.agenda.dto.AgendaPhotoResponse.AgendaPhotoInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

public abstract class AgendaResponse {

Expand All @@ -17,4 +20,26 @@ public static class AgendaInfo {
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDateTime createdAt;
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class AgendaDetailInfo {
private Long agendaId;
private String title;
private List<AgendaPhotoInfo> agendaPhotoInfoList;
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class PagedAgendaDetailInfo {
private List<AgendaDetailInfo> agendaDetailInfoList;
private int totalPages;
private long totalElements; // 해당 조건에 부합하는 요소의 총 개수
private boolean isFirst; // 첫 페이지 여부
private boolean isLast; // 마지막 페이지 여부
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/umc/naoman/domain/agenda/entity/Agenda.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.umc.naoman.domain.shareGroup.entity.Profile;
import com.umc.naoman.domain.shareGroup.entity.ShareGroup;
import com.umc.naoman.domain.vote.entity.Vote;
import com.umc.naoman.global.entity.BaseTimeEntity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Column;
import jakarta.persistence.ManyToOne;
Expand All @@ -20,6 +22,9 @@
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLRestriction;

import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "agendas")
@SQLRestriction("deleted_at is NULL")
Expand All @@ -40,4 +45,16 @@ public class Agenda extends BaseTimeEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "profile_id")
private Profile profile;

@OneToMany(mappedBy = "agenda")
@Builder.Default
private List<AgendaPhoto> agendaPhotoList = new ArrayList<>();

public void delete() {
//agendaPhoto 삭제
for (AgendaPhoto agendaPhoto : agendaPhotoList) {
agendaPhoto.delete();
}
super.delete();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.umc.naoman.domain.agenda.entity;

import com.umc.naoman.domain.photo.entity.Photo;
import com.umc.naoman.domain.vote.entity.Vote;
import com.umc.naoman.global.entity.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.SQLRestriction;

import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "agendas_photos")
@SQLRestriction("deleted_at is NULL")
Expand All @@ -24,4 +28,16 @@ public class AgendaPhoto extends BaseTimeEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "photo_id")
private Photo photo;
}

@OneToMany(mappedBy = "agendaPhoto")
@Builder.Default
private List<Vote> voteList = new ArrayList<>();

public void delete() {
//agendaPhoto 삭제
for (Vote vote : voteList) {
vote.delete();
}
super.delete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AgendaPhotoRepository extends JpaRepository<AgendaPhoto, Long> {
List<AgendaPhoto> findByAgendaId(Long agendaId);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.umc.naoman.domain.agenda.repository;

import com.umc.naoman.domain.agenda.entity.Agenda;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface AgendaRepository extends JpaRepository<Agenda,Long> {
Page<Agenda> findByShareGroupId(Long shareGroupId, Pageable pageable);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.umc.naoman.domain.agenda.service;

import com.umc.naoman.domain.agenda.entity.Agenda;
import com.umc.naoman.domain.agenda.entity.AgendaPhoto;

import java.util.List;

public interface AgendaPhotoService {
void saveAgendaPhotoList(Agenda agenda, List<Long> photos);

AgendaPhoto findAgendaPhoto(Long agendaPhotoId);
List<AgendaPhoto> findAgendaPhotoList(Long agendaId);
}
Loading

0 comments on commit 31f39a8

Please sign in to comment.