Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/IT-Cotato/9th-Midpoint-BE
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
yooooonshine committed Aug 7, 2024
2 parents 4edfb32 + 57770ee commit 8ab8667
Show file tree
Hide file tree
Showing 31 changed files with 754 additions and 498 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ out/
src/main/resources/application-security.properties
### applcation-api ###
src/main/resources/application-api.properties
src/main/resources/application.properties
src/main/resources/application.properties

### log file
/log/
8 changes: 8 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ dependencies {
testImplementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-api', version: '2.5.0'
//bucket4j
implementation group: 'com.github.vladimir-bukhtoyarov', name: 'bucket4j-core', version: '8.0.1'
//aop
implementation 'org.springframework.boot:spring-boot-starter-aop'
}

tasks.named('test') {
useJUnitPlatform()
}

//profile별로 실행시
bootRun {
String activeProfile = System.properties['spring.profiles.active']
systemProperty "spring.profiles.active", activeProfile
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package middle_point_search.backend;

import java.util.TimeZone;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import jakarta.annotation.PostConstruct;
import middle_point_search.backend.common.filter.RateLimitFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import jakarta.annotation.PostConstruct;
import middle_point_search.backend.common.filter.RateLimitFilter;
import java.util.TimeZone;

@SpringBootApplication
@EnableJpaAuditing
@EnableAspectJAutoProxy
@OpenAPIDefinition(servers = {@Server(url = "/", description = "https://www.api.cotato-midpoint.site")})
public class BackendApplication {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package middle_point_search.backend.common.aop;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Aspect
@Slf4j
@Component
public class LogAspect {

@Pointcut("execution(* middle_point_search.backend..*.*(..)) && !execution(* middle_point_search.backend.common..*(..))")
public void all() {
}

@Pointcut("execution(* middle_point_search.backend..*Controller.*(..))")
public void controller() {
}

@Around("all()")
public Object logging(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
try {
Object result = joinPoint.proceed();
return result;
} finally {
long end = System.currentTimeMillis();
long timeinMs = end - start;
log.info("{} | time = {}ms", joinPoint.getSignature(), timeinMs);
}
}

@Around("controller()")
public Object loggingBefore(ProceedingJoinPoint joinPoint) throws Throwable {
final HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
final String ipAddr = request.getRemoteAddr();
final String method = request.getMethod();
final String requestURI = request.getRequestURI();
final Object[] args = joinPoint.getArgs();

log.info("[REQUEST] {} {} {} args={}", ipAddr, method, requestURI, args);
try {
Object result = joinPoint.proceed();
log.info("[RESPONSE] {}", result);
return result;
} catch (Exception e) {
log.error("[RESPONSE] exception message = {} {}", e.getMessage(), e.getStackTrace()[0]);
throw e;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public ResponseEntity<BaseResponse> placesSaveOrUpdateBySelf(@RequestBody Places
@Operation(
summary = "개개인 장소 조회하기",
description = """
개개인이 저장한 장소 조회하기.
개개인이 저장한 장소 및 다른 사람들이 저장한 장소들 조회하기.
다른 사람들이 저장한 장소(otherPlaces)에는 당사자가 저장한 장소는 포함되지 않는다.
AccessToken 필요.""",
parameters = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public static class PlacesSaveOrUpdateBySelfRequest {
@AllArgsConstructor
public static class PlaceFindResponse {

private final Boolean existence;
private final PlaceVO place;
private final Boolean myPlaceExistence;
private final PlaceVO myPlace;
private final Boolean otherPlacesExistence;
private final List<PlaceVO> otherPlaces;
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import io.lettuce.core.dynamic.annotation.Param;
import middle_point_search.backend.domains.member.domain.Member;
import middle_point_search.backend.domains.place.domain.Place;
import middle_point_search.backend.domains.room.domain.Room;
Expand All @@ -22,4 +24,7 @@ public interface PlaceRepository extends JpaRepository<Place, Long> {
Optional<Place> findByRoom_IdentityNumberAndMember_Name(String roomId, String name);

void deleteAllByRoom_IdentityNumber(String roomId);

@Query("select p from Place p where p.member.name != :memberName and p.room.identityNumber = :roomId")
List<Place> findAllByRoom_IdentityNumberAndMember_Name(@Param(value = "roomId") String roomId ,@Param(value = "memberName") String memberName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import middle_point_search.backend.domains.member.domain.Role;
import middle_point_search.backend.domains.member.service.MemberService;
import middle_point_search.backend.domains.place.domain.Place;
import middle_point_search.backend.domains.place.dto.PlaceDTO;
import middle_point_search.backend.domains.place.dto.PlaceDTO.PlaceFindResponse;
import middle_point_search.backend.domains.place.dto.PlaceDTO.PlaceSaveOrUpdateRequest;
import middle_point_search.backend.domains.place.dto.PlaceDTO.PlaceVO;
Expand Down Expand Up @@ -97,9 +98,23 @@ private void saveOrUpdatePlacesBySelf(Room room, PlacesSaveOrUpdateBySelfRequest
//개개인 장소 조회
public PlaceFindResponse findPlace(String roomId, String memberName) {

return placeRepository.findByRoom_IdentityNumberAndMember_Name(roomId, memberName)
.map(place -> new PlaceFindResponse(true, place.toVO()))
.orElseGet(() -> new PlaceFindResponse(false, null));
//내 장소 조회
PlaceVO myPlace = placeRepository.findByRoom_IdentityNumberAndMember_Name(roomId, memberName)
.map(Place:: toVO)
.orElse(null);

//내 장소 존재 유무
Boolean myPlaceExistence = myPlace != null;

//다른 사람들 장소 조회
List<PlaceVO> otherPlaces = placeRepository.findAllByRoom_IdentityNumberAndMember_Name(roomId, memberName)
.stream().map(Place::toVO)
.toList();

//다른 사람들 장소 유무
boolean otherPlacesExistence = !otherPlaces.isEmpty();

return new PlaceDTO.PlaceFindResponse(myPlaceExistence, myPlace, otherPlacesExistence, otherPlaces);
}

//개인 장소 조회
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package middle_point_search.backend.domains.placeVoteRoom.controller;

import static middle_point_search.backend.domains.placeVoteRoom.dto.PlaceVoteRoomDTO.*;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -15,19 +16,16 @@
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.validation.Valid;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import middle_point_search.backend.common.dto.BaseResponse;
import middle_point_search.backend.common.dto.DataResponse;
import middle_point_search.backend.common.dto.ErrorResponse;
import middle_point_search.backend.common.util.MemberLoader;
import middle_point_search.backend.domains.placeVoteRoom.service.PlaceVoteRoomService;
import middle_point_search.backend.domains.member.domain.Member;
import middle_point_search.backend.domains.placeVoteRoom.service.PlaceVoteRoomService;
import middle_point_search.backend.domains.room.domain.Room;
import static middle_point_search.backend.domains.placeVoteRoom.dto.PlaceVoteRoomDTO.*;



@Tag(name = "PLACE VOTE ROOM API", description = "장소 투표에 대한 API입니다.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

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

Expand All @@ -14,48 +15,49 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PlaceVoteCandidate {

@Id
@Column(name = "place_vote_candidate_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Id
@Column(name = "place_vote_candidate_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String name;
@Column(nullable = false)
private String name;

@Column(nullable = false)
private String siDo;
@Column(nullable = false)
private String siDo;

@Column(nullable = false)
private String siGunGu;
@Column(nullable = false)
private String siGunGu;

@Column(nullable = false)
private String roadNameAddress;
@Column(nullable = false)
private String roadNameAddress;

@Column(nullable = false)
private Double addressLatitude;
@Column(nullable = false)
private Double addressLatitude;

@Column(nullable = false)
private Double addressLongitude;
@Column(nullable = false)
private Double addressLongitude;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "place_vote_room_id")
private PlaceVoteRoom placeVoteRoom;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "place_vote_room_id")
private PlaceVoteRoom placeVoteRoom;

@OneToMany(mappedBy = "placeVoteCandidate", cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true)
private List<PlaceVoteCandidateMember> voters = new ArrayList<>();
@OneToMany(mappedBy = "placeVoteCandidate", cascade = {CascadeType.PERSIST,
CascadeType.MERGE}, orphanRemoval = true)
private List<PlaceVoteCandidateMember> voters = new ArrayList<>();

public PlaceVoteCandidate(PlaceCandidateInfo candidate, PlaceVoteRoom placeVoteRoom) {
this.name = candidate.getName();
this.siDo = candidate.getSiDo();
this.siGunGu = candidate.getSiGunGu();
this.roadNameAddress = candidate.getRoadNameAddress();
this.addressLatitude = candidate.getAddressLat();
this.addressLongitude = candidate.getAddressLong();
this.placeVoteRoom = placeVoteRoom;
}
public PlaceVoteCandidate(PlaceCandidateInfo candidate, PlaceVoteRoom placeVoteRoom) {
this.name = candidate.getName();
this.siDo = candidate.getSiDo();
this.siGunGu = candidate.getSiGunGu();
this.roadNameAddress = candidate.getRoadNameAddress();
this.addressLatitude = candidate.getAddressLat();
this.addressLongitude = candidate.getAddressLong();
this.placeVoteRoom = placeVoteRoom;
}

public int getCount() {
return voters.size();
}
public int getCount() {
return voters.size();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PlaceVoteCandidateMember {

@Id
@Column(name = "place_vote_candidate_member_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Id
@Column(name = "place_vote_candidate_member_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "place_vote_candidate_id")
private PlaceVoteCandidate placeVoteCandidate;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "place_vote_candidate_id")
private PlaceVoteCandidate placeVoteCandidate;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;
public PlaceVoteCandidateMember(PlaceVoteCandidate placeVoteCandidate, Member member) {
this.placeVoteCandidate = placeVoteCandidate;
this.member = member;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

public PlaceVoteCandidateMember(PlaceVoteCandidate placeVoteCandidate, Member member) {
this.placeVoteCandidate = placeVoteCandidate;
this.member = member;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PlaceVoteRoom {

@Id
@Column(name = "place_vote_room_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne
@JoinColumn(name = "room_id")
private Room room;

@OneToMany(mappedBy = "placeVoteRoom", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<PlaceVoteCandidate> placeVoteCandidates = new ArrayList<>();

public PlaceVoteRoom(Room room, List<PlaceCandidateInfo> candidates) {
this.room = room;
this.placeVoteCandidates.clear();
for (PlaceCandidateInfo candidate : candidates) {
addPlaceVoteCandidate(candidate);
}
}

public void addPlaceVoteCandidate(PlaceCandidateInfo candidate) {
this.placeVoteCandidates.add(new PlaceVoteCandidate(candidate, this));
}
@Id
@Column(name = "place_vote_room_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne
@JoinColumn(name = "room_id")
private Room room;

@OneToMany(mappedBy = "placeVoteRoom", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<PlaceVoteCandidate> placeVoteCandidates = new ArrayList<>();

public PlaceVoteRoom(Room room, List<PlaceCandidateInfo> candidates) {
this.room = room;
this.placeVoteCandidates.clear();
for (PlaceCandidateInfo candidate : candidates) {
addPlaceVoteCandidate(candidate);
}
}

public void addPlaceVoteCandidate(PlaceCandidateInfo candidate) {
this.placeVoteCandidates.add(new PlaceVoteCandidate(candidate, this));
}
}

Loading

0 comments on commit 8ab8667

Please sign in to comment.