-
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 branch 'feat/ncloud' of https://github.com/403project/back-end …
…into feat/ncloud
- Loading branch information
Showing
20 changed files
with
300 additions
and
33 deletions.
There are no files selected for viewing
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
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
74 changes: 66 additions & 8 deletions
74
src/main/java/byulbyul/byulbyulpoll/controller/PollController.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 |
---|---|---|
@@ -1,31 +1,89 @@ | ||
package byulbyul.byulbyulpoll.controller; | ||
|
||
import byulbyul.byulbyulpoll.controller.dto.MessageResponseDto; | ||
import byulbyul.byulbyulpoll.controller.dto.PollRequestDto; | ||
import byulbyul.byulbyulpoll.controller.dto.PollsResponseDto; | ||
import byulbyul.byulbyulpoll.controller.dto.ProjectsResponseDto; | ||
import byulbyul.byulbyulpoll.entity.Member; | ||
import byulbyul.byulbyulpoll.service.PollService; | ||
import byulbyul.byulbyulpoll.service.ProjectService; | ||
import byulbyul.byulbyulpoll.service.VoteService; | ||
import byulbyul.byulbyulpoll.service.dto.NewProjectDto; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import jakarta.servlet.http.HttpSession; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController("/polls") | ||
@RestController | ||
@RequestMapping("/polls") | ||
@RequiredArgsConstructor | ||
public class PollController { | ||
|
||
private final PollService pollService; | ||
private final ProjectService projectService; | ||
private final VoteService voteService; | ||
|
||
@GetMapping | ||
public PollsResponseDto getPolls(){ | ||
@Operation(summary = "투표 목록 조회") | ||
public PollsResponseDto getPolls() { | ||
var polls = pollService.getPolls(); | ||
|
||
var pollInfoDtos = polls.stream() | ||
.map(poll -> new PollsResponseDto.PollInfoDto(poll.getTitle(), poll.isOngoing())) | ||
.map(poll -> new PollsResponseDto.PollInfoDto(poll.getId(), poll.getTitle(), poll.isOngoing(), poll.getStartDate(), poll.getEndDate())) | ||
.toArray(PollsResponseDto.PollInfoDto[]::new); | ||
|
||
return new PollsResponseDto(pollInfoDtos); | ||
} | ||
|
||
// @PostMapping | ||
// MessageResponseDto createPoll | ||
@PostMapping | ||
@Operation(summary = "투표 생성") | ||
public MessageResponseDto createPoll(@RequestBody PollRequestDto pollRequestDto) { | ||
MessageResponseDto response = new MessageResponseDto(); | ||
try { | ||
pollService.createPoll(pollRequestDto.getTitle(), pollRequestDto.getStartDate(), pollRequestDto.getEndDate()); | ||
response.setSuccess(true); | ||
response.setMessage("투표 생성에 성공했습니다."); | ||
} catch (IllegalArgumentException e) { | ||
response.setSuccess(false); | ||
response.setMessage(e.getMessage()); | ||
} | ||
return response; | ||
} | ||
|
||
@GetMapping("/{pollId}") | ||
@Operation(summary = "투표 내부의 프로젝트 조회") | ||
public ProjectsResponseDto getPoll(@PathVariable long pollId) { | ||
var projects = projectService.getProjects(pollId); | ||
|
||
var projectInfoDtos = projects.stream() | ||
.map(project -> new ProjectsResponseDto.ProjectInfoDto(project.getId(), project.getTitle(), project.getDescription(), project.getVoteCount())) | ||
.toArray(ProjectsResponseDto.ProjectInfoDto[]::new); | ||
|
||
return new ProjectsResponseDto(projectInfoDtos); | ||
} | ||
|
||
@GetMapping("/vote") | ||
@Operation(summary = "투표하기") | ||
public MessageResponseDto vote(@RequestParam long projectId, | ||
@Parameter(hidden = true) @SessionAttribute(name = "member", required = false) Member member) { | ||
MessageResponseDto response = new MessageResponseDto(); | ||
if (member == null) { | ||
response.setSuccess(false); | ||
response.setMessage("로그인이 필요합니다. (비회원 투표 개발중)"); | ||
return response; | ||
} | ||
|
||
try { | ||
voteService.voteByMember(projectId, member.getEmail()); | ||
response.setSuccess(true); | ||
response.setMessage("투표에 성공했습니다."); | ||
} catch (IllegalArgumentException e) { | ||
response.setSuccess(false); | ||
response.setMessage(e.getMessage()); | ||
} | ||
return response; | ||
} | ||
|
||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/byulbyul/byulbyulpoll/controller/ProjectController.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,57 @@ | ||
package byulbyul.byulbyulpoll.controller; | ||
|
||
import byulbyul.byulbyulpoll.controller.dto.AttachImageRequestDto; | ||
import byulbyul.byulbyulpoll.controller.dto.MessageResponseDto; | ||
import byulbyul.byulbyulpoll.controller.dto.ProjectResponseDto; | ||
import byulbyul.byulbyulpoll.service.ProjectService; | ||
import byulbyul.byulbyulpoll.service.dto.NewProjectDto; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/projects") | ||
public class ProjectController { | ||
|
||
private final ProjectService projectService; | ||
|
||
@PostMapping | ||
@Operation(summary = "프로젝트 생성") | ||
public MessageResponseDto createProject(@RequestBody NewProjectDto newProjectDto){ | ||
MessageResponseDto response = new MessageResponseDto(); | ||
try { | ||
projectService.createProject(newProjectDto); | ||
response.setSuccess(true); | ||
response.setMessage("프로젝트 생성에 성공했습니다."); | ||
} catch (IllegalArgumentException e) { | ||
response.setSuccess(false); | ||
response.setMessage(e.getMessage()); | ||
} | ||
return response; | ||
} | ||
|
||
@GetMapping("/{projectId}") | ||
@Operation(summary = "프로젝트 조회") | ||
public ProjectResponseDto getProject(@PathVariable long projectId){ | ||
var project = projectService.getProject(projectId); | ||
var imageUrls = projectService.getProjectImages(projectId); | ||
return new ProjectResponseDto(project.getId(), project.getTitle(), project.getDescription(), project.getVoteCount(), imageUrls); | ||
} | ||
|
||
@PostMapping("/{projectId}/images") | ||
@Operation(summary = "이미지 첨부") | ||
public MessageResponseDto addProjectImages(@PathVariable long projectId, @RequestBody AttachImageRequestDto requestDto){ | ||
MessageResponseDto response = new MessageResponseDto(); | ||
try { | ||
projectService.addProjectImages(projectId, requestDto.getImageUrls()); | ||
response.setSuccess(true); | ||
response.setMessage("이미지 첨부에 성공했습니다."); | ||
} catch (IllegalArgumentException e) { | ||
response.setSuccess(false); | ||
response.setMessage(e.getMessage()); | ||
} | ||
return response; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/byulbyul/byulbyulpoll/controller/dto/AttachImageRequestDto.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,16 @@ | ||
package byulbyul.byulbyulpoll.controller.dto; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class AttachImageRequestDto { | ||
private List<String> imageUrls; | ||
|
||
public AttachImageRequestDto(List<String> imageUrls) { | ||
this.imageUrls = imageUrls; | ||
} | ||
} |
8 changes: 7 additions & 1 deletion
8
src/main/java/byulbyul/byulbyulpoll/controller/dto/PollRequestDto.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 |
---|---|---|
@@ -1,8 +1,14 @@ | ||
package byulbyul.byulbyulpoll.controller.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class PollRequestDto { | ||
|
||
private String title; | ||
private LocalDateTime startDate; | ||
private LocalDateTime endDate; | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/byulbyul/byulbyulpoll/controller/dto/ProjectResponseDto.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,23 @@ | ||
package byulbyul.byulbyulpoll.controller.dto; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class ProjectResponseDto { | ||
private Long id; | ||
private String title; | ||
private String description; | ||
private int voteCount; | ||
private List<String> imageUrls; | ||
|
||
|
||
public ProjectResponseDto(Long id, String title, String description, int voteCount, List<String> imageUrls){ | ||
this.id = id; | ||
this.title = title; | ||
this.description = description; | ||
this.voteCount = voteCount; | ||
this.imageUrls = imageUrls; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/byulbyul/byulbyulpoll/controller/dto/ProjectsResponseDto.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,28 @@ | ||
package byulbyul.byulbyulpoll.controller.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class ProjectsResponseDto { | ||
ProjectInfoDto[] projects; | ||
|
||
public ProjectsResponseDto(ProjectInfoDto[] projects){ | ||
this.projects = projects; | ||
} | ||
|
||
@Data | ||
public static class ProjectInfoDto{ | ||
private Long id; | ||
private String title; | ||
private String description; | ||
private int voteCount; | ||
|
||
public ProjectInfoDto(Long id, String title, String description, int voteCount){ | ||
this.id = id; | ||
this.title = title; | ||
this.description = description; | ||
this.voteCount = voteCount; | ||
} | ||
|
||
} | ||
} |
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
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
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
6 changes: 6 additions & 0 deletions
6
src/main/java/byulbyul/byulbyulpoll/repository/ProjectImageRepository.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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
package byulbyul.byulbyulpoll.repository; | ||
|
||
import byulbyul.byulbyulpoll.entity.ProjectImage; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface ProjectImageRepository extends JpaRepository<ProjectImage, Long> { | ||
|
||
List<ProjectImage> findByProjectId(Long projectId, Sort sort); | ||
|
||
} |
Oops, something went wrong.