-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from JNU-econovation/feat/147
- Loading branch information
Showing
41 changed files
with
701 additions
and
50 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...s/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/device/Device.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,36 @@ | ||
package com.whoz_in.api_query_jpa.device; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.OneToMany; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.Immutable; | ||
import org.hibernate.annotations.Subselect; | ||
|
||
@Entity | ||
@Getter | ||
@Subselect("SELECT d.id , d.member_id " | ||
+ "FROM device_entity d") | ||
@Immutable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Device { | ||
|
||
@Id | ||
@Column(name = "id", nullable = false) | ||
private UUID id; | ||
|
||
@Column(name ="member_id", nullable = false) | ||
private UUID memberId; | ||
|
||
@OneToMany(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "device_id", referencedColumnName = "id") | ||
private List<DeviceInfo> deviceInfos; | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...frastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/device/DeviceInfo.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,28 @@ | ||
package com.whoz_in.api_query_jpa.device; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import java.util.UUID; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.Immutable; | ||
import org.hibernate.annotations.Subselect; | ||
|
||
@Entity | ||
@Getter | ||
@Subselect("SELECT di.id, di.device_id, di.mac, di.ssid " | ||
+ "FROM device_info_entity di") | ||
@Immutable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class DeviceInfo { | ||
|
||
@Id | ||
private Long id; | ||
|
||
private UUID deviceId; | ||
|
||
private String mac; | ||
|
||
private String ssid; | ||
} |
21 changes: 21 additions & 0 deletions
21
...ure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/device/DeviceInfoJpaViewer.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,21 @@ | ||
package com.whoz_in.api_query_jpa.device; | ||
|
||
import com.whoz_in.main_api.query.device.view.DeviceInfoViewer; | ||
import com.whoz_in.main_api.query.device.view.RegisteredSsids; | ||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class DeviceInfoJpaViewer implements DeviceInfoViewer { | ||
private final DeviceInfoRepository deviceInfoRepository; | ||
@Override | ||
public RegisteredSsids findRegisteredSsids(UUID ownerId, String room, String mac) { | ||
return new RegisteredSsids( | ||
deviceInfoRepository.findAllByMac(ownerId, room, mac).stream() | ||
.map(DeviceInfo::getSsid) | ||
.toList()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...re/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/device/DeviceInfoRepository.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,18 @@ | ||
package com.whoz_in.api_query_jpa.device; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface DeviceInfoRepository extends JpaRepository<DeviceInfo, Long> { | ||
@Query(value = "SELECT di.id, di.device_id AS deviceId, di.mac, di.ssid " + | ||
"FROM device_entity d " + | ||
"JOIN device_info_entity di ON d.id = di.device_id " + | ||
"WHERE d.member_id = :ownerId " + | ||
"AND di.room = :room " + | ||
"AND di.mac = :mac", | ||
nativeQuery = true) | ||
List<DeviceInfo> findAllByMac(@Param("ownerId") UUID ownerId, @Param("room") String room, @Param("mac") String mac); | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...s/main-api/src/main/java/com/whoz_in/main_api/command/private_ip/PrivateIpController.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,22 @@ | ||
package com.whoz_in.main_api.command.private_ip; | ||
|
||
import com.whoz_in.main_api.command.shared.application.CommandBus; | ||
import com.whoz_in.main_api.command.shared.presentation.CommandController; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
public class PrivateIpController extends CommandController { | ||
|
||
public PrivateIpController(CommandBus commandBus) { | ||
super(commandBus); | ||
} | ||
|
||
@PutMapping("/private-ip") | ||
public void updatePrivateIp(@RequestBody PrivateIpUpdate req){ | ||
dispatch(req); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
modules/main-api/src/main/java/com/whoz_in/main_api/command/private_ip/PrivateIpUpdate.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,15 @@ | ||
package com.whoz_in.main_api.command.private_ip; | ||
|
||
import com.whoz_in.domain.device.model.IpAddress; | ||
import com.whoz_in.main_api.command.shared.application.Command; | ||
import java.util.Map; | ||
|
||
public record PrivateIpUpdate( | ||
String room, | ||
Map<String, String> privateIpList //Map<와이파이이름, 아이피> | ||
) implements Command { | ||
|
||
public PrivateIpUpdate { | ||
privateIpList.values().forEach(IpAddress::create); //아이피 형식 검증 | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ain-api/src/main/java/com/whoz_in/main_api/command/private_ip/PrivateIpUpdateHandler.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,18 @@ | ||
package com.whoz_in.main_api.command.private_ip; | ||
|
||
import com.whoz_in.main_api.command.shared.application.CommandHandler; | ||
import com.whoz_in.main_api.shared.application.Handler; | ||
import com.whoz_in.main_api.shared.caching.private_ip.PrivateIpStore; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Handler | ||
@RequiredArgsConstructor | ||
public class PrivateIpUpdateHandler implements CommandHandler<PrivateIpUpdate, Void> { | ||
private final PrivateIpStore privateIpStore; | ||
|
||
@Override | ||
public Void handle(PrivateIpUpdate command) { | ||
privateIpStore.put(command.room(), command.privateIpList()); | ||
return null; | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...in-api/src/main/java/com/whoz_in/main_api/config/security/ServerAuthenticationFilter.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,37 @@ | ||
package com.whoz_in.main_api.config.security; | ||
|
||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
@Component | ||
public class ServerAuthenticationFilter extends OncePerRequestFilter { | ||
private final String apiKey; | ||
|
||
public ServerAuthenticationFilter(@Value("${api-key}") String apiKey) { | ||
this.apiKey = apiKey; | ||
} | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, | ||
FilterChain filterChain) throws ServletException, IOException { | ||
Optional<String> extractedKey = extractApiKey(request); | ||
|
||
if (extractedKey.filter(apiKey::equals).isEmpty()) { | ||
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid API Key"); | ||
return; | ||
} | ||
|
||
filterChain.doFilter(request, response); | ||
} | ||
|
||
private Optional<String> extractApiKey(HttpServletRequest request){ | ||
return Optional.ofNullable(request.getHeader("Authorization")); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...ed/utils/SpringSecurityRequesterInfo.java → ...security/SpringSecurityRequesterInfo.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
Oops, something went wrong.