Skip to content

Commit

Permalink
Merge pull request #16 from donggukthon/dev
Browse files Browse the repository at this point in the history
✨ [Feat] Swagger를 등록합니다.
  • Loading branch information
kurtyoon authored Dec 19, 2023
2 parents ad455f1 + e41c089 commit 8925081
Show file tree
Hide file tree
Showing 31 changed files with 673 additions and 264 deletions.
7 changes: 4 additions & 3 deletions src/main/java/donggukthon/volunmate/config/S3Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
@Configuration
@Getter
public class S3Config {
@Value("${cloud.aws.access_key}")
@Value("${cloud.aws.credentials.access-key}")
private String accessKey;

@Value("${cloud.aws.secret_key}")
@Value("${cloud.aws.credentials.secret-key}")
private String secretKey;

@Value("${cloud.aws.regions}")
@Value("${cloud.aws.region.static}")
private String region;

@Value("${cloud.aws.s3_bucket}")
Expand All @@ -28,6 +28,7 @@ public class S3Config {
@Bean
public AmazonS3Client amazonS3Client() {
return (AmazonS3Client) AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
.withRegion(region).enablePathStyleAccess()
.build();
}
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/donggukthon/volunmate/controller/HelpController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package donggukthon.volunmate.controller;

import donggukthon.volunmate.annotation.SocialId;
import donggukthon.volunmate.dto.exception.ResponseDto;
import donggukthon.volunmate.dto.help.*;
import donggukthon.volunmate.service.HelpService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Nullable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/help")
@Tag(name = "Help", description = "도와주세요 요청 관련 API입니다.")
public class HelpController {
private final HelpService helpService;

@Operation(summary = "도움 요청 생성", description = "도움 요청을 생성합니다.")
@PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseDto<Boolean> createHelp(@SocialId String socialId,
@RequestPart("data") CreateHelpDto createHelpDto,
@Nullable @RequestPart("file") MultipartFile imageFile) {
return ResponseDto.created(helpService.createHelp(socialId, createHelpDto, imageFile));
}

@Operation(summary = "도움 요청 리스트 조회", description = "도움 요청 리스트를 조회합니다.")
@GetMapping
public ResponseDto<HelpListDto> getHelp(@SocialId String socialId){
return ResponseDto.ok(helpService.getHelpList(socialId));
}

@Operation(summary = "긴급 도움 요청 리스트 조회", description = "긴급 도움 요청 리스트를 조회합니다.")
@GetMapping("/em")
public ResponseDto<EmergencyHelpListDto> getEmergencyHelp(@SocialId String socialId){
return ResponseDto.ok(helpService.getEmergencyHelpList(socialId));
}

@Operation(summary = "도움 요청 상세 조회", description = "도움 요청 상세 정보를 조회합니다.")
@GetMapping("/{helpId}")
public ResponseDto<ResponseHelpDetailDto> getHelpDetail(@PathVariable Long helpId){
return ResponseDto.ok(helpService.getHelpDetail(helpId));
}

@Operation(summary = "도움 요청 수정", description = "도움 요청을 수정합니다.")
@PatchMapping("/{helpId}")
public ResponseDto<Boolean> helpUpdate(@SocialId String socialId,
@RequestPart("data") CreateHelpDto createHelpDto,
@Nullable @RequestPart("file") MultipartFile imageFile,
@PathVariable Long helpId) {
return ResponseDto.ok(helpService.helpUpdate(socialId, createHelpDto, imageFile, helpId));
}

@Operation(summary = "도움 요청 삭제", description = "도움 요청을 삭제합니다.")
@DeleteMapping("/{helpId}")
public ResponseDto<Boolean> helpDelete(@SocialId String socialId,
@PathVariable Long helpId){
return ResponseDto.ok(helpService.helpDelete(socialId, helpId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,64 @@
import donggukthon.volunmate.dto.myPage.request.UserLocationDto;
import donggukthon.volunmate.dto.myPage.response.*;
import donggukthon.volunmate.service.MyPageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/me")
@RequiredArgsConstructor
@Tag(name = "MyPage", description = "마이페이지 관련 API입니다.")
public class MyPageController {
private final MyPageService myPageService;

@Operation(summary = "유저 정보 조회", description = "유저 정보를 조회합니다.")
@GetMapping
public ResponseDto<UserInfoDto> getUserInfo(@SocialId String socialId) {
return ResponseDto.ok(myPageService.getUserInfo(socialId));
}

@Operation(summary = "유저 위치 수정", description = "유저 위치를 수정합니다. 현재 위치를 기반으로 합니다.")
@PatchMapping
public ResponseDto<?> updateUserLocation(@SocialId String socialId,
@RequestBody UserLocationDto userLocationDto) {
return ResponseDto.ok(myPageService.updateUserLocation(socialId, userLocationDto));
}

@Operation(summary = "유저 팀 리스트 조회", description = "유저 팀 리스트를 조회합니다.")
@GetMapping("/team")
public ResponseDto<UserTeamListDto> getUserTeamList(@SocialId String socialId) {
return ResponseDto.ok(myPageService.getUserTeamList(socialId));
}

@Operation(summary = "유저 팀 가입 승인 / 거절", description = "유저 팀 가입을 승인하거나 거절합니다.")
@PatchMapping("/team/{teamId}")
public ResponseDto<?> patchUserTeam(@SocialId String socialId,
@PathVariable Long teamId,
@RequestParam boolean isAccept) {
return ResponseDto.ok(myPageService.patchUserTeam(socialId, teamId, isAccept));
}

@Operation(summary = "유저 팀 상세 조회", description = "유저가 작성한 봉사활동에 참여한 팀월들을 확인합니다.")
@GetMapping("/team/details")
public ResponseDto<TeamDetailListDto> getTeamDetails(@SocialId String socialId) {
return ResponseDto.ok(myPageService.getTeamDetails(socialId));
}

@Operation(summary = "유저 팀 상세 조회", description = "내가 작성한 봉사활동글을 조회합니다.")
@GetMapping("/mate")
public ResponseDto<TeammateListDto> getTeammateList(@SocialId String socialId) {
return ResponseDto.ok(myPageService.getTeammateList(socialId));
}

@Operation(summary = "유저 도와주세요 상세 조회", description = "내가 등록한 도와주세요글을 조회합니다.")
@GetMapping("/help")
public ResponseDto<HelpListDto> getHelpList(@SocialId String socialId) {
return ResponseDto.ok(myPageService.getHelpList(socialId));
}

@Operation(summary = "유저 좋아요글 상세 조회", description = "내가 좋아요한 봉사활동글을 조회합니다.")
@GetMapping("/heart")
public ResponseDto<TeammateListDto> getTeammateHeartedList(@SocialId String socialId) {
return ResponseDto.ok(myPageService.getTeammateHeartedList(socialId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
package donggukthon.volunmate.controller;

import donggukthon.volunmate.annotation.SocialId;
import donggukthon.volunmate.dto.CreateVolunteerDto;
import donggukthon.volunmate.dto.RequestVolunteerSignDto;
import donggukthon.volunmate.dto.ResponseVolunteerDetailDto;
import donggukthon.volunmate.dto.ResponseVolunteerDto;
import donggukthon.volunmate.dto.volunteer.request.CreateVolunteerDto;
import donggukthon.volunmate.dto.volunteer.request.VolunteerSignDto;
import donggukthon.volunmate.dto.volunteer.response.VolunteerDetailDto;
import donggukthon.volunmate.dto.exception.ResponseDto;
import donggukthon.volunmate.dto.volunteer.response.VolunteerListDto;
import donggukthon.volunmate.service.VolunteerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Nullable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.hibernate.annotations.Fetch;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/team")
@Tag(name = "Volunteer", description = "봉사활동 관련 API")
public class VolunteerController {

private final VolunteerService volunteerService;

@PostMapping("")
public ResponseDto<Boolean> createVolunteer(@SocialId String socialId, @RequestBody CreateVolunteerDto createVolunteerDto,
@Nullable @RequestPart("file") File imageFile) {

return ResponseDto.ok(volunteerService.createVolunteer(socialId,createVolunteerDto,imageFile));
@Operation(summary = "봉사활동 생성", description = "봉사활동 정보와 이미지를 통해 봉사활동을 생성힙니다.")
@PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseDto<Boolean> createVolunteer(@SocialId String socialId,
@RequestPart("image") MultipartFile image,
@RequestPart("data") CreateVolunteerDto createVolunteerDto) {
return ResponseDto.ok(volunteerService.createVolunteer(socialId, createVolunteerDto, image));
}

@PostMapping("/{team_id}")
public ResponseDto<Boolean> volunteerSignUp(@SocialId String socialId, @PathVariable Long team_id,
@RequestBody RequestVolunteerSignDto requestVolunteerSignDto) {

return ResponseDto.ok(volunteerService.volunteerSignUp(socialId,team_id,requestVolunteerSignDto));
@Operation(summary = "봉사활동 리스트 조회", description = "봉사활동 리스트를 조회합니다.")
@GetMapping
public ResponseDto<VolunteerListDto> volunteerHeart(@SocialId String socialId) {
return ResponseDto.ok(volunteerService.getVolunteerList(socialId));
}

@PostMapping("/{team_id}/heart")
public ResponseDto<Boolean> volunteerHeart(@SocialId String socialId, @PathVariable Long team_id) {
@Operation(summary = "봉사활동 상세 조회", description = "봉사활동 상세 정보를 조회합니다.")
@GetMapping("/{teamId}")
public ResponseDto<VolunteerDetailDto> volunteerHeart(@PathVariable Long teamId) {

return ResponseDto.ok(volunteerService.volunteerHeart(socialId,team_id));
return ResponseDto.ok(volunteerService.getVolunteerDetail(teamId));
}
@GetMapping("")
public ResponseDto<List<ResponseVolunteerDto>> volunteerHeart(@SocialId String socialId) {

return ResponseDto.ok(volunteerService.getVolunteerList(socialId));
@Operation(summary = "봉사활동 신청", description = "봉사활동에 신청합니다. 자신이 생성한 봉사는 참가할 수 없습니다.")
@PostMapping("/{teamId}")
public ResponseDto<Boolean> volunteerSignUp(@SocialId String socialId, @PathVariable Long teamId,
@RequestBody VolunteerSignDto volunteerSignDto) {
return ResponseDto.ok(volunteerService.volunteerSignUp(socialId, teamId, volunteerSignDto));
}

@GetMapping("/{team_id}")
public ResponseDto<ResponseVolunteerDetailDto> volunteerHeart(@PathVariable Long team_id) {

return ResponseDto.ok(volunteerService.getVolunteerDetail(team_id));
@Operation(summary = "봉사활동 좋아요하기", description = "내가 관심이 가는 봉사활동에 좋아요를 누릅니다.")
@PostMapping("/{teamId}/heart")
public ResponseDto<Boolean> volunteerHeart(@SocialId String socialId, @PathVariable Long teamId) {
return ResponseDto.ok(volunteerService.volunteerHeart(socialId, teamId));
}

@DeleteMapping("/{team_id}")
public ResponseDto<Boolean> volunteerDelete(@SocialId String socialId, @PathVariable Long team_id) {

return ResponseDto.ok(volunteerService.volunteerDelete(socialId,team_id));
@Operation(summary = "봉사활동 글을 삭제", description = "내가 생성한 봉사활동 글을 삭제합니다.")
@DeleteMapping("/{teamId}")
public ResponseDto<Boolean> volunteerDelete(@SocialId String socialId, @PathVariable Long teamId) {
return ResponseDto.ok(volunteerService.volunteerDelete(socialId, teamId));
}

@PatchMapping("/{team_id}")
public ResponseDto<Boolean> volunteerUpdate(@SocialId String socialId, @RequestBody CreateVolunteerDto createVolunteerDto,
@Nullable @RequestPart("file") File imageFile,@PathVariable Long team_id) {

return ResponseDto.ok(volunteerService.volunteerUpdate(socialId,createVolunteerDto,imageFile,team_id));
@Operation(summary = "봉사활동 글을 수정", description = "내가 생성한 봉사활동 글을 수정합니다.")
@PatchMapping(value = "/{teamId}", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseDto<Boolean> volunteerUpdate(@SocialId String socialId,
@RequestPart("data") CreateVolunteerDto createVolunteerDto,
@Nullable @RequestPart("image") MultipartFile imageFile,
@PathVariable Long teamId) {
return ResponseDto.ok(volunteerService.volunteerUpdate(socialId, createVolunteerDto, imageFile, teamId));
}



}
26 changes: 26 additions & 0 deletions src/main/java/donggukthon/volunmate/domain/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -47,4 +48,29 @@ public class Help {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
User user;

@Builder
public Help(String title, String content, String imageUrl, Double latitude, Double longitude,
Boolean emergency, User user) {
this.title = title;
this.content = content;
this.imageUrl = imageUrl;
this.latitude = latitude;
this.longitude = longitude;
this.emergency = emergency;
this.status = false;
this.createdAt = LocalDateTime.now();
this.user = user;
}

public void update(String title, String content, String imageUrl, Double latitude, Double longitude,
Boolean emergency) {
this.title = title;
this.content = content;
this.imageUrl = imageUrl;
this.latitude = latitude;
this.longitude = longitude;
this.emergency = emergency;
}

}
8 changes: 4 additions & 4 deletions src/main/java/donggukthon/volunmate/domain/Volunmate.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public class Volunmate {
@JoinColumn(name = "volun_id")
Volunteer volunteer;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
User user;

@Builder
public Volunmate(String username, String phoneNumber, String content, EStatusType status, Volunteer volunteer, User user) {
this.username = username;
Expand All @@ -47,10 +51,6 @@ public Volunmate(String username, String phoneNumber, String content, EStatusTyp
this.user = user;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
User user;

public boolean updateStatus(EStatusType status) {
this.volunteer.updateCurCount();
this.status = status;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/donggukthon/volunmate/domain/Volunteer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Volunteer {
private String imageUrl;

@Column(name = "volun_count")
private Integer volunCounet;
private Integer volunCount;

@Column(name = "cur_count")
private Integer curCount;
Expand All @@ -56,13 +56,13 @@ public class Volunteer {

// ============================= One To Many Relationship =============================

@OneToMany(mappedBy = "volunteer")
@OneToMany(mappedBy = "volunteer", cascade = CascadeType.ALL)
private List<Volunmate> volunmates = new ArrayList<>();

@OneToMany(mappedBy = "volunteer")
@OneToMany(mappedBy = "volunteer", cascade = CascadeType.ALL)
private List<Heart> hearts = new ArrayList<>();

@OneToMany(mappedBy = "volunteer")
@OneToMany(mappedBy = "volunteer", cascade = CascadeType.ALL)
private List<Tag> tags = new ArrayList<>();

@Builder
Expand All @@ -71,7 +71,7 @@ public Volunteer(String title, String content, String imageUrl, Double latitude,
this.title = title;
this.content = content;
this.imageUrl = imageUrl;
this.volunCounet = volunCount;
this.volunCount = volunCount;
this.curCount = 0;
this.latitude = latitude;
this.longitude = longitude;
Expand All @@ -93,7 +93,7 @@ public void update (String title, String content, String imageUrl, Double latitu
this.title = title;
this.content = content;
this.imageUrl = imageUrl;
this.volunCounet = volunCount;
this.volunCount = volunCount;
this.latitude = latitude;
this.longitude = longitude;
this.startDate = startDate;
Expand Down
Loading

0 comments on commit 8925081

Please sign in to comment.