-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] location socket join and share
- Loading branch information
Showing
9 changed files
with
109 additions
and
4 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
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
31 changes: 31 additions & 0 deletions
31
backend/src/main/java/com/twtw/backend/domain/location/controller/LocationController.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,31 @@ | ||
package com.twtw.backend.domain.location.controller; | ||
|
||
import com.twtw.backend.domain.location.dto.request.LocationRequest; | ||
import com.twtw.backend.domain.location.service.LocationService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.stereotype.Controller; | ||
|
||
import java.util.UUID; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class LocationController { | ||
|
||
private static final String EXCHANGE_NAME = "map.exchange"; | ||
private static final String ROUTING_KEY = "plan.*"; | ||
private final RabbitTemplate rabbitTemplate; | ||
private final LocationService locationService; | ||
|
||
@MessageMapping("map.join.{planId}") | ||
public void join(@DestinationVariable final UUID planId, final LocationRequest locationRequest) { | ||
rabbitTemplate.convertAndSend(EXCHANGE_NAME, ROUTING_KEY + planId, locationService.addInfo(locationRequest)); | ||
} | ||
|
||
@MessageMapping("map.share.{planId}") | ||
public void share(@DestinationVariable final UUID planId, final LocationRequest locationRequest) { | ||
rabbitTemplate.convertAndSend(EXCHANGE_NAME, ROUTING_KEY + planId, locationService.addInfo(locationRequest)); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/com/twtw/backend/domain/location/dto/request/LocationRequest.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,14 @@ | ||
package com.twtw.backend.domain.location.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class LocationRequest { | ||
private String nickname; | ||
private Double x; | ||
private Double y; | ||
} |
17 changes: 17 additions & 0 deletions
17
backend/src/main/java/com/twtw/backend/domain/location/dto/response/LocationResponse.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,17 @@ | ||
package com.twtw.backend.domain.location.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class LocationResponse { | ||
private String nickname; | ||
private Double x; | ||
private Double y; | ||
private LocalDateTime time; | ||
} |
19 changes: 19 additions & 0 deletions
19
backend/src/main/java/com/twtw/backend/domain/location/mapper/LocationMapper.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,19 @@ | ||
package com.twtw.backend.domain.location.mapper; | ||
|
||
import com.twtw.backend.domain.location.dto.request.LocationRequest; | ||
import com.twtw.backend.domain.location.dto.response.LocationResponse; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Component | ||
public class LocationMapper { | ||
public LocationResponse toResponse(final LocationRequest locationRequest, final LocalDateTime now) { | ||
return LocationResponse.builder() | ||
.x(locationRequest.getX()) | ||
.y(locationRequest.getY()) | ||
.nickname(locationRequest.getNickname()) | ||
.time(now) | ||
.build(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/com/twtw/backend/domain/location/service/LocationService.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,20 @@ | ||
package com.twtw.backend.domain.location.service; | ||
|
||
import com.twtw.backend.domain.location.dto.request.LocationRequest; | ||
import com.twtw.backend.domain.location.dto.response.LocationResponse; | ||
import com.twtw.backend.domain.location.mapper.LocationMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class LocationService { | ||
|
||
private final LocationMapper locationMapper; | ||
|
||
public LocationResponse addInfo(final LocationRequest locationRequest) { | ||
return locationMapper.toResponse(locationRequest, LocalDateTime.now()); | ||
} | ||
} |