Skip to content

Commit

Permalink
Merge pull request #54 from JNU-econovation/network
Browse files Browse the repository at this point in the history
network-api 서버 리팩토링
  • Loading branch information
inferior3x authored Nov 27, 2024
2 parents 8ca2ad3 + de08728 commit 3c1fa7a
Show file tree
Hide file tree
Showing 23 changed files with 36 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

@Configuration
@EnableJpaAuditing
//멀티 모듈에서 명시적으로 엔티티와 JpaRepository의 위치를 지정하기 위함
@EnableJpaRepositories(basePackages = {"com.whoz_in.domain", "com.whoz_in.common_domain_jpa"})
//기본적으로 SpringApplication 모듈에서 찾기 때문에 이 모듈에서도 찾을 수 있도록 함
@EnableJpaRepositories(basePackages = {"com.whoz_in.domain_jpa"})
@EntityScan(basePackages = "com.whoz_in")
public class JpaConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@
import lombok.experimental.SuperBuilder;

@Entity
@Table(name = ManagedLog.TABLE_NAME)
@SuperBuilder(toBuilder = true)
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ManagedLog extends BaseEntity {

public static final String TABLE_NAME = "managed_log";

@EmbeddedId
private LogId logId;

@Column(name = TABLE_NAME + "_wifi_ssid", nullable = true)
private String wifiSsid;
private String ssid;

@Column(name = TABLE_NAME + "_device_name", nullable = true)
private String deviceName;

@Getter
Expand All @@ -38,10 +33,10 @@ public class ManagedLog extends BaseEntity {
@Embeddable
public static class LogId {

@Column(name = TABLE_NAME + "_mac", nullable = false)
@Column(name = "mac", nullable = false)
private String mac;

@Column(name = TABLE_NAME + "_ip", nullable = false)
@Column(name = "ip", nullable = false)
private String ip;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.whoz_in.domain_jpa.shared.BaseEntity;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class MonitorLog extends BaseEntity {
@Id
private String mac;
Expand Down
3 changes: 1 addition & 2 deletions modules/infrastructure/log-writer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ repositories {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:3.3.4'
implementation 'org.springframework.boot:spring-boot-starter-jdbc:3.3.4'
runtimeOnly 'com.mysql:mysql-connector-j:8.3.0'

compileOnly 'jakarta.annotation:jakarta.annotation-api:2.1.1'

testImplementation platform('org.junit:junit-bom:5.10.0')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.whoz_in.network_log.config;
package com.whoz_in.log_writer.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package com.whoz_in.log_writer.monitor;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import java.util.Collection;
import org.springframework.data.jpa.repository.Modifying;
import lombok.RequiredArgsConstructor;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@RequiredArgsConstructor
public class MonitorLogDAO {
@PersistenceContext
private EntityManager em;

@Modifying
@Transactional
private final JdbcTemplate jdbcTemplate;

public void upsertAll(Collection<String> macs) {
if (macs.isEmpty()) return;
StringBuilder sql = new StringBuilder("INSERT INTO monitor_log (mac, created_date, updated_date) VALUES ");
macs.forEach(mac -> sql.append(String.format("('%s', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),", mac)));
sql.setLength(sql.length() - 1);
sql.append(" ON DUPLICATE KEY UPDATE updated_date = CURRENT_TIMESTAMP");
em.createNativeQuery(sql.toString()).executeUpdate();

String sql = "INSERT INTO monitor_log (mac, created_at, updated_at) VALUES (?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) ON DUPLICATE KEY UPDATE updated_at = CURRENT_TIMESTAMP";
jdbcTemplate.batchUpdate(sql, macs, macs.size(),
(ps, mac) -> ps.setString(1, mac));
}


}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
spring:
config:
activate:
on-profile: network
datasource:
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
driver-class-name: ${DB_DRIVER_CLASS}

network:
process:
Expand All @@ -12,4 +14,4 @@ network:
monitor: ${MONITOR_COMMAND}
password: ${SUDO_PASSWORD}
interface:
monitor: ${MONITOR_INTERFACE}
monitor: ${MONITOR_INTERFACE}

This file was deleted.

9 changes: 0 additions & 9 deletions modules/log-api/src/main/resources/application.yml

This file was deleted.

File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions modules/network-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring:
application:
name: WhozIn-Network

profiles:
group:
local:
- log-writer
active: local
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
rootProject.name = 'whoz_in'
include 'modules:api'
findProject(':modules:api')?.name = 'api'
include 'modules:log-api'
findProject(':modules:log-api')?.name = 'log-api'
include 'modules:network-api'
findProject(':modules:network-api')?.name = 'network-api'
include 'modules:domain'
findProject(':modules:domain')?.name = 'domain'
include 'modules:infrastructure:domain-jpa'
Expand Down

0 comments on commit 3c1fa7a

Please sign in to comment.