Skip to content

Commit

Permalink
Feat: 사용자 GPS 위치 변경 및 온/오프라인 상태 변경 API 구현 (#79)
Browse files Browse the repository at this point in the history
* Feat(#70): Member Entity 수정

* Feat(#70): 사용자 온 오프라인 API 구현

* Fix(#70): 오타 수정

* Feat(#70): GPS 갱신 API 구현

* Feat(#70): 온라인 전환 API 요청시 응답 값으로 멤버 id 반환

* Fix(#70): 위도, 경도 초기값 설정
  • Loading branch information
nohy6630 authored Nov 19, 2023
1 parent 4795551 commit 5d5b407
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import com.numberone.backend.domain.member.dto.request.OnboardingRequest;
import com.numberone.backend.domain.member.dto.request.BuyHeartRequest;
import com.numberone.backend.domain.member.dto.request.UpdateGpsRequest;
import com.numberone.backend.domain.member.dto.response.GetNotificationRegionResponse;
import com.numberone.backend.domain.member.dto.response.HeartCntResponse;
import com.numberone.backend.domain.member.dto.response.MemberIdResponse;
import com.numberone.backend.domain.member.dto.response.UploadProfileImageResponse;
import com.numberone.backend.domain.member.service.MemberService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -79,4 +82,32 @@ public void initMemberData(Authentication authentication, @Valid @RequestBody On
public ResponseEntity<GetNotificationRegionResponse> getNotificationRegions() {
return ResponseEntity.ok(memberService.getNotificationRegionLv2());
}

@Operation(summary = "온라인 전환 API", description = """
사용자가 어플을 시작할 때 이 API를 호출해 온라인 상태가 되었음을 서버에 알려주세요.
또한 가족 초대를 위해 필요한 사용자의 id값을 이때 응답으로 반환해줍니다.
""")
@GetMapping("/online")
public ResponseEntity<MemberIdResponse> online(Authentication authentication){
return ResponseEntity.ok(memberService.online(authentication.getName()));
}

@Operation(summary = "오프라인 전환 API", description = """
사용자가 어플을 종료할 때 이 API를 호출해 온라인 상태가 되었음을 서버에 알려주세요.
""")
@GetMapping("/offline")
public void offline(Authentication authentication){
memberService.offline(authentication.getName());
}

@Operation(summary = "사용자 GPS 위치 변경", description = """
사용자의 GPS 위치(위도, 경도) 정보를 갱신할 때 사용해주세요.
위도, 경도를 body에 담아 전달해주세요.
""")
@PostMapping("/gps")
public void updateGps(Authentication authentication, @Valid @RequestBody UpdateGpsRequest updateGpsRequest){
memberService.updateGps(authentication.getName(), updateGpsRequest);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.numberone.backend.domain.member.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class UpdateGpsRequest {
@Schema(defaultValue = "37.506136")
@NotNull(message = "위도 정보는 null일 수 없습니다.")
private Double latitude;

@Schema(defaultValue = "126.922046")
@NotNull(message = "경도 정보는 null일 수 없습니다.")
private Double longitude;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.numberone.backend.domain.member.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
public class MemberIdResponse {
private Long memberId;

public static MemberIdResponse of(long memberId){
return MemberIdResponse.builder()
.memberId(memberId)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ public class Member extends BaseTimeEntity {
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<ConversationLike> conversationLikes = new ArrayList<>();

@Comment("온/오프라인 유무")
private Boolean session;

public void update(Boolean session) {
@Comment("위도")
private Double latitude;

@Comment("경도")
private Double longitude;

public void updateSession(Boolean session) {
this.session = session;
}

Expand All @@ -76,7 +83,9 @@ public Member(String email, String nickName, String realName, Integer heartCnt,
this.realName = realName;
this.heartCnt = heartCnt;
this.fcmToken = fcmToken;
this.session = false;
this.session = true;
this.latitude = 0D;
this.longitude = 0D;
}

public static Member of(String email, String realName) {
Expand All @@ -103,4 +112,9 @@ public void plusHeart(int heart) {
public void minusHeart(int heart) {
heartCnt -= heart;
}

public void updateGps(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.numberone.backend.domain.member.service;

import com.numberone.backend.domain.disaster.util.DisasterType;
import com.numberone.backend.domain.member.dto.request.BuyHeartRequest;
import com.numberone.backend.domain.member.dto.request.OnboardingAddress;
import com.numberone.backend.domain.member.dto.request.OnboardingDisasterType;
import com.numberone.backend.domain.member.dto.request.OnboardingRequest;
import com.numberone.backend.domain.member.dto.request.*;
import com.numberone.backend.domain.member.dto.response.GetNotificationRegionResponse;
import com.numberone.backend.domain.member.dto.response.HeartCntResponse;
import com.numberone.backend.domain.member.dto.response.MemberIdResponse;
import com.numberone.backend.domain.member.dto.response.UploadProfileImageResponse;
import com.numberone.backend.domain.member.entity.Member;
import com.numberone.backend.domain.member.repository.MemberRepository;
Expand Down Expand Up @@ -103,4 +101,22 @@ public GetNotificationRegionResponse getNotificationRegionLv2() {
return GetNotificationRegionResponse.of(member.getNotificationRegions());
}

@Transactional
public MemberIdResponse online(String email) {
Member member = findByEmail(email);
member.updateSession(true);
return MemberIdResponse.of(member.getId());
}

@Transactional
public void offline(String email) {
Member member = findByEmail(email);
member.updateSession(false);
}

@Transactional
public void updateGps(String email, UpdateGpsRequest updateGpsRequest) {
Member member = findByEmail(email);
member.updateGps(updateGpsRequest.getLatitude(), updateGpsRequest.getLongitude());
}
}

0 comments on commit 5d5b407

Please sign in to comment.