Skip to content

Commit

Permalink
Merge pull request #12 from BapMate/feat/imageUpload
Browse files Browse the repository at this point in the history
Feat/image upload
  • Loading branch information
AlmondBreez3 authored Nov 17, 2023
2 parents db1b54c + 7c6236a commit bf19a37
Show file tree
Hide file tree
Showing 21 changed files with 754 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bapMate.bapMateServer.domain.meeting.controller;

import com.bapMate.bapMateServer.domain.meeting.dto.request.MeetUpRequestDto;
import com.bapMate.bapMateServer.domain.meeting.entity.MeetUp;
import com.bapMate.bapMateServer.domain.meeting.service.MeetUpService;
import com.bapMate.bapMateServer.domain.participation.entity.Participation;
import com.bapMate.bapMateServer.domain.participation.repository.ParticipationRepository;
Expand All @@ -14,8 +15,12 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

Expand All @@ -28,6 +33,19 @@ public class MeetUpController {
private final MeetUpService meetUpService;
private final ParticipationService participationService;
private final AuthentiatedUserUtils authentiatedUserUtils;

@Operation(description = "모임 대표 이미지")
@PostMapping(value = "/image/{meetUpId}", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE})
public SuccessResponse<Object> uploadImage(@PathVariable Long meetUpId,@RequestParam("file") MultipartFile file) throws IOException {
try {
meetUpService.uploadImage(meetUpId, file);
SuccessResponse<Object> successResponse = SuccessResponse.onSuccess(200);
return successResponse;
} catch (IOException e) {
throw new IllegalArgumentException("오류");
}
}

@Operation(summary = "모임을 생성합니다.")
@PostMapping("/host")
public SuccessResponse<Object> createMeetUp(@RequestBody MeetUpRequestDto meetUpRequestDto) {
Expand All @@ -40,13 +58,40 @@ public SuccessResponse<Object> createMeetUp(@RequestBody MeetUpRequestDto meetUp
}
@Operation(summary = "생성한 모임을 확인합니다.")
@GetMapping("/host")
public SuccessResponse<Object> getCreatedMeetUp() {
public SuccessResponse<List<MeetUp>> getCreatedMeetUp() {
User user = authentiatedUserUtils.getCurrentUser();

Participation participation = participationService.getParticipation(user);
SuccessResponse<Object> successResponse = SuccessResponse.onSuccess(200,participation);
List<MeetUp> participation = participationService.getParticipation(user);
System.out.println(participation.size());
System.out.println(participation.get(0).getName());
SuccessResponse<List<MeetUp>> successResponse = SuccessResponse.onSuccess(200, participation);
System.out.println(successResponse.getData());
return successResponse;
}

@Operation(summary = "참여한 모임을 확인합니다.")
@GetMapping("/participate")
public SuccessResponse<List<MeetUp>> getParticipatedMeetUp() {
User user = authentiatedUserUtils.getCurrentUser();

List<MeetUp> participation = participationService.getParticipations(user);

SuccessResponse<List<MeetUp>> successResponse = SuccessResponse.onSuccess(200, participation);
System.out.println(successResponse.getData());
return successResponse;
}

@Operation(summary = "모임에 참여합니다")
@PostMapping("/participate/{meetUpId}")
public SuccessResponse<Object> participateMeetUp(@RequestParam Long meetUpId){
User user = authentiatedUserUtils.getCurrentUser();

meetUpService.participateMeetUp(user,meetUpId);

SuccessResponse<Object> successResponse = SuccessResponse.onSuccess(200);
return successResponse;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ public class MeetUpRequestDto {
private LocalDateTime date;
private String restaurant;
private int numberOfPeople;
private MeetUpAtmosphere meetUpAtmosphere;
private RegionAtmosphere regionAtmosphere;
private String meetUpAtmosphere;
private String regionAtmosphere;
private String representationImage;

public MeetUp toEntity() {
RegionAtmosphere regionAtmosphereEnum = RegionAtmosphere.fromTitle(regionAtmosphere);
MeetUpAtmosphere meetUpAtmosphereEnum = MeetUpAtmosphere.fromTitle(meetUpAtmosphere);
return MeetUp.builder()
.chatRoomLink(chatRoomLink)
.date(date)
.meetUpAtmosphere(meetUpAtmosphere)
.meetUpAtmosphere(meetUpAtmosphereEnum)
.introduce(introduce)
.restaurant(restaurant)
.numberOfPeople(numberOfPeople)
.region(region)
.regionAtmosphere(regionAtmosphere)
.regionAtmosphere(regionAtmosphereEnum)
.representationImage(representationImage)
.name(name)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.bapMate.bapMateServer.domain.meeting.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;

import java.time.LocalDateTime;

@AllArgsConstructor
@Builder
public class MeetUpResponseDto {
private Long id;
private String name;
private String introduce;
private String chatRoomLink;
private String region;
private LocalDateTime date;
private String restaurant;
private int numberOfPeople;
private String meetUpAtmosphere;
private String regionAtmosphere;
private String representationImage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import com.bapMate.bapMateServer.domain.meeting.enums.MeetUpAtmosphere;
import com.bapMate.bapMateServer.domain.meeting.enums.RegionAtmosphere;
import com.bapMate.bapMateServer.domain.participation.entity.Participation;
import com.bapMate.bapMateServer.domain.user.entity.User;
import com.bapMate.bapMateServer.global.entity.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.*;

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

@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -15,21 +19,29 @@
@Builder
public class MeetUp extends BaseTimeEntity {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "meeting_id")
private Long id;

private String name;
private String introduce;
private String chatRoomLink;
private String region;
private LocalDateTime date;
private String restaurant;
private int currentNumberOfPeople;
private int numberOfPeople;
@Enumerated(EnumType.STRING)
private MeetUpAtmosphere meetUpAtmosphere;
@Enumerated(EnumType.STRING)
private RegionAtmosphere regionAtmosphere;
private String representationImage;

public int updateNumberOfPeople(int currentNumber) {
this.currentNumberOfPeople = currentNumber + 1;
return currentNumberOfPeople;
}
public void updateImgUrl(String imageUrl) {
this.representationImage = imageUrl;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ public enum MeetUpAtmosphere {

public String getTitle() {return title;}
public int getCheck() {return check;}

public static MeetUpAtmosphere fromTitle(String title) {
for (MeetUpAtmosphere atmosphere : MeetUpAtmosphere.values()) {
if (atmosphere.title.equals(title)) {
return atmosphere;
}
}
return null; // 매칭되는 값이 없을 경우
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@ public enum RegionAtmosphere {

public String getTitle() {return title;}
public int getCheck() {return check;}

// String 값을 Enum으로 변환하는 메서드
public static RegionAtmosphere fromTitle(String title) {
for (RegionAtmosphere atmosphere : RegionAtmosphere.values()) {
if (atmosphere.title.equals(title)) {
return atmosphere;
}
}
throw new IllegalArgumentException("Unknown title: " + title);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.bapMate.bapMateServer.domain.meeting.exception;

import com.bapMate.bapMateServer.global.exception.base.BaseException;

public class AlreadyParticipatedException extends BaseException {
public AlreadyParticipatedException() {super(MeetingErrorCode.ALREADY_PARTICIPATED_ERROR);}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bapMate.bapMateServer.domain.meeting.exception;

import com.bapMate.bapMateServer.global.exception.base.BaseException;

public class FullCapacityException extends BaseException {
public FullCapacityException() {
super(MeetingErrorCode.FULL_CAPACITY_ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.bapMate.bapMateServer.domain.meeting.exception;

import com.bapMate.bapMateServer.global.exception.base.BaseErrorCode;
import com.bapMate.bapMateServer.global.exception.dto.ErrorReason;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import static com.bapMate.bapMateServer.global.constant.StaticValue.*;

@Getter
@AllArgsConstructor
public enum MeetingErrorCode implements BaseErrorCode {
FULL_CAPACITY_ERROR(BAD_REQUEST,"MEETING_404","인원이 다 찼습니다"),
MEETING_NOT_FOUND(BAD_REQUEST,"MEETING_404","모임이 존재하지 않습니다"),
ALREADY_PARTICIPATED_ERROR(BAD_REQUEST,"MEETING_404","이미 참여한 모임입니다"),
NOT_ALLOWED_TO_PARTICIPATE_ERROR(BAD_REQUEST,"MEETING_404","생성한 모임에는 참여할 수 없습니다");

private final int status;
private final String code;
private final String reason;

@Override
public ErrorReason getErrorReason() {
return ErrorReason.of(status, code, reason);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bapMate.bapMateServer.domain.meeting.exception;

import com.bapMate.bapMateServer.global.exception.base.BaseException;

public class MeetingNotFoundException extends BaseException {
public MeetingNotFoundException() {
super(MeetingErrorCode.MEETING_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.bapMate.bapMateServer.domain.meeting.exception;

import com.bapMate.bapMateServer.global.exception.base.BaseException;

public class NotAllowedToParticipateException extends BaseException {
public NotAllowedToParticipateException() {super(MeetingErrorCode.NOT_ALLOWED_TO_PARTICIPATE_ERROR);}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

import com.bapMate.bapMateServer.domain.meeting.entity.MeetUp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface MeetUpRepository extends JpaRepository<MeetUp, Long> {
@Modifying
@Query("UPDATE MeetUp m SET m.currentNumberOfPeople = m.currentNumberOfPeople + 1 WHERE m.id = :meetUpId")
void incrementCurrentNumberOfPeople(@Param("meetUpId") Long meetUpId);
}
Loading

0 comments on commit bf19a37

Please sign in to comment.