Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…aeng-dong into feature/#61
  • Loading branch information
jinhokim98 committed Jul 24, 2024
2 parents 7ba559e + 8665f7a commit d443700
Show file tree
Hide file tree
Showing 15 changed files with 2,651 additions and 93 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/backend-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
steps:
- name: CheckOut
uses: actions/checkout@v4
with:
token: ${{secrets.CONFIG_SUBMODULE_TOKEN}}
submodules: true

- name: Set up JDK 17
uses: actions/setup-java@v4
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "server/src/main/resources/config"]
path = server/src/main/resources/config
url = https://github.com/woowacourse-teams/2024-haeng-dong-config.git
2,601 changes: 2,521 additions & 80 deletions client/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"devDependencies": {
"@eslint/compat": "^1.1.0",
"@eslint/js": "^9.6.0",
"@svgr/webpack": "^8.1.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.16.0",
Expand Down
8 changes: 8 additions & 0 deletions client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export default {
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.svg$/,
use: [
{
loader: '@svgr/webpack',
},
],
},
],
},
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ COPY --from=build /app/build/libs/*.jar /app/haengdong-0.0.1-SNAPSHOT.jar

EXPOSE 8080
ENTRYPOINT ["java"]
CMD ["-jar", "haengdong-0.0.1-SNAPSHOT.jar"]
CMD ["-Dspring.profiles.active=dev", "-jar", "haengdong-0.0.1-SNAPSHOT.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import org.springframework.stereotype.Service;
import server.haengdong.application.request.EventAppRequest;
import server.haengdong.application.response.EventAppResponse;
import server.haengdong.application.response.EventDetailAppResponse;
import server.haengdong.domain.event.Event;
import server.haengdong.domain.event.EventTokenProvider;
import server.haengdong.domain.event.EventRepository;
import server.haengdong.domain.event.EventTokenProvider;

@RequiredArgsConstructor
@Service
Expand All @@ -22,4 +23,10 @@ public EventAppResponse saveEvent(EventAppRequest request) {

return EventAppResponse.of(event);
}

public EventDetailAppResponse findEvent(String token) {
Event event = eventRepository.findByToken(token).orElseThrow(() -> new IllegalArgumentException(""));

return EventDetailAppResponse.of(event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package server.haengdong.application.response;

import server.haengdong.domain.event.Event;

public record EventDetailAppResponse(String eventName) {

public static EventDetailAppResponse of(Event event) {
return new EventDetailAppResponse(event.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import server.haengdong.application.EventService;
import server.haengdong.application.response.EventAppResponse;
import server.haengdong.presentation.request.EventSaveRequest;
import server.haengdong.presentation.response.EventDetailResponse;

@RequiredArgsConstructor
@RestController
Expand All @@ -16,11 +20,18 @@ public class EventController {
private final EventService eventService;

@PostMapping("/api/events")
public ResponseEntity<Void> saveEvent(EventSaveRequest request) {
public ResponseEntity<Void> saveEvent(@RequestBody EventSaveRequest request) {
EventAppResponse eventAppResponse = eventService.saveEvent(request.toAppRequest());

return ResponseEntity.ok()
.location(URI.create("events/" + eventAppResponse.token()))
.build();
}

@GetMapping("/api/events/{token}")
public ResponseEntity<EventDetailResponse> findEvent(@PathVariable("token") String token) {
EventDetailResponse eventDetailResponse = EventDetailResponse.of(eventService.findEvent(token));

return ResponseEntity.ok(eventDetailResponse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package server.haengdong.presentation.response;

import server.haengdong.application.response.EventDetailAppResponse;

public record EventDetailResponse(String eventName) {

public static EventDetailResponse of(EventDetailAppResponse response) {
return new EventDetailResponse(response.eventName());
}
}
28 changes: 18 additions & 10 deletions server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
spring:
h2:
console:
enabled: true
path: /h2-console
datasource:
url: jdbc:h2:mem:database
url: jdbc:mysql://localhost:3306/haengdong
username: root
password: 1234
driver-class-name: com.mysql.cj.jdbc.Driver

jpa:
defer-datasource-initialization: true
show-sql: true
hibernate:
ddl-auto: none
properties:
hibernate:
format_sql: true
hibernate:
ddl-auto: create-drop
dialect: org.hibernate.dialect.MySQL8Dialect
format_sql: true
show-sql: true

---

spring:
config:
import: classpath:config/application-dev.yml
activate:
on-profile: dev
1 change: 1 addition & 0 deletions server/src/main/resources/config
Submodule config added at c12697
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import server.haengdong.application.request.EventAppRequest;
import server.haengdong.application.response.EventAppResponse;
import server.haengdong.application.response.EventDetailAppResponse;
import server.haengdong.domain.event.Event;
import server.haengdong.domain.event.EventRepository;
import server.haengdong.domain.event.EventTokenProvider;

@SpringBootTest
Expand All @@ -22,6 +26,14 @@ class EventServiceTest {
@MockBean
private EventTokenProvider eventTokenProvider;

@Autowired
private EventRepository eventRepository;

@AfterEach
void tearDown() {
eventRepository.deleteAllInBatch();
}

@DisplayName("행사λ₯Ό μƒμ„±ν•œλ‹€")
@Test
void saveEventTest() {
Expand All @@ -32,4 +44,16 @@ void saveEventTest() {

assertThat(response.token()).isEqualTo("TOKEN");
}

@DisplayName("ν† ν°μœΌλ‘œ 행사λ₯Ό μ‘°νšŒν•œλ‹€.")
@Test
void findEventTest() {
String token = "TOKEN";
Event event = new Event("ν–‰λ™λŒ€μž₯ νšŒμ‹", token);
eventRepository.save(event);

EventDetailAppResponse eventDetailAppResponse = eventService.findEvent(token);

assertThat(eventDetailAppResponse.eventName()).isEqualTo("ν–‰λ™λŒ€μž₯ νšŒμ‹");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -18,6 +20,7 @@
import server.haengdong.application.EventService;
import server.haengdong.application.request.EventAppRequest;
import server.haengdong.application.response.EventAppResponse;
import server.haengdong.application.response.EventDetailAppResponse;
import server.haengdong.presentation.request.EventSaveRequest;

@WebMvcTest(EventController.class)
Expand Down Expand Up @@ -48,4 +51,17 @@ void saveEvent() throws Exception {
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.redirectedUrl("events/" + token));
}

@DisplayName("ν† ν°μœΌλ‘œ 행사λ₯Ό μ‘°νšŒν•œλ‹€.")
@Test
void findEventTest() throws Exception {
String token = "TOKEN";
EventDetailAppResponse eventDetailAppResponse = new EventDetailAppResponse("ν–‰λ™λŒ€μž₯ νšŒμ‹");
given(eventService.findEvent(token)).willReturn(eventDetailAppResponse);

mockMvc.perform(get("/api/events/" + token))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.eventName").value("ν–‰λ™λŒ€μž₯ νšŒμ‹"));
}
}
15 changes: 15 additions & 0 deletions server/src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
spring:
h2:
console:
enabled: true
path: /h2-console
datasource:
url: jdbc:h2:mem:database
jpa:
defer-datasource-initialization: true
show-sql: true
properties:
hibernate:
format_sql: true
hibernate:
ddl-auto: create-drop

0 comments on commit d443700

Please sign in to comment.