Skip to content

Commit

Permalink
Merge branch 'be-dev' into feature/#282
Browse files Browse the repository at this point in the history
  • Loading branch information
Arachneee authored Aug 9, 2024
2 parents c4db8d4 + 63fbbc9 commit 761a028
Show file tree
Hide file tree
Showing 16 changed files with 282 additions and 114 deletions.
17 changes: 11 additions & 6 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,36 @@ ext {
snippetsDir = file('build/generated-snippets')
}

tasks.named('test') {
test {
useJUnitPlatform()
outputs.dir snippetsDir
}

asciidoctor {
inputs.dir snippetsDir
configurations 'asciidoctorExt'
dependsOn test
baseDirFollowsSourceFile()
dependsOn test
}

tasks.resolveMainClassName {
dependsOn 'copyApiDocuments'
}

tasks.register('copyApiDocuments', Copy) {
doFirst {
delete file('src/main/resources/static/docs')
}
dependsOn asciidoctor
from file("build/docs/asciidoc")
into file("src/main/resources/static/docs")
into file("build/resources/main/static/docs")
}

bootJar {
dependsOn copyApiDocuments
}

jar {
enabled = false
}

build {
dependsOn copyApiDocuments
}
11 changes: 10 additions & 1 deletion server/src/docs/asciidoc/event.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ operation::updateEventMemberName[snippets="path-parameters,http-request,request-
[source,json,options="nowrap"]
----
[
{
"code":"MEMBER_NAME_CHANGE_DUPLICATE",
"message":"μ€‘λ³΅λœ μ°Έμ—¬ 인원 이름 λ³€κ²½ μš”μ²­μ΄ μ‘΄μž¬ν•©λ‹ˆλ‹€."
},
{
"code":"MEMBER_NOT_EXIST",
"message":"ν˜„μž¬ μ°Έμ—¬ν•˜κ³  μžˆμ§€ μ•ŠλŠ” 인원이 μ‘΄μž¬ν•©λ‹ˆλ‹€."
},
{
"code":"REQUEST_EMPTY",
"message":"멀버 이름은 곡백일 수 μ—†μŠ΅λ‹ˆλ‹€."
Expand All @@ -128,7 +137,7 @@ operation::updateEventMemberName[snippets="path-parameters,http-request,request-
},
{
"code":"TOKEN_EXPIRED",
"message":"토큰이 μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."
"message":"만료된 ν† ν°μž…λ‹ˆλ‹€."
},
{
"code":"TOKEN_INVALID",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package server.haengdong;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@Slf4j
@SpringBootApplication
public class HaengdongApplication {

public static void main(String[] args) {
log.error("################### μ•ˆλ…•ν•˜μ„Έμš”. CI/CD ν…ŒμŠ€νŠΈμž…λ‹ˆλ‹€. ###################");
SpringApplication.run(HaengdongApplication.class, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import server.haengdong.application.request.EventAppRequest;
import server.haengdong.application.request.EventLoginAppRequest;
import server.haengdong.application.request.MemberUpdateAppRequest;
import server.haengdong.application.request.MemberNameUpdateAppRequest;
import server.haengdong.application.request.MemberNamesUpdateAppRequest;
import server.haengdong.application.response.ActionAppResponse;
import server.haengdong.application.response.EventAppResponse;
import server.haengdong.application.response.EventDetailAppResponse;
Expand Down Expand Up @@ -100,22 +102,55 @@ public MembersAppResponse findAllMembers(String token) {
}

@Transactional
public void updateMember(String token, String memberName, MemberUpdateAppRequest request) {
public void updateMember(String token, MemberNamesUpdateAppRequest request) {
Event event = getEvent(token);
String updatedMemberName = request.name();
validateMemberNameUnique(event, updatedMemberName);
List<MemberNameUpdateAppRequest> members = request.members();

memberActionRepository.findAllByAction_EventAndMemberName(event, memberName)
.forEach(memberAction -> memberAction.updateMemberName(updatedMemberName));
validateBeforeNames(members, event);
validateAfterNames(members, event);

members.forEach(member -> updateMemberName(event, member.before(), member.after()));
}

private void validateBeforeNames(List<MemberNameUpdateAppRequest> members, Event event) {
List<String> beforeNames = members.stream()
.map(MemberNameUpdateAppRequest::before)
.toList();
if (beforeNames.size() != Set.copyOf(beforeNames).size()) {
throw new HaengdongException(HaengdongErrorCode.MEMBER_NAME_CHANGE_DUPLICATE);
}
beforeNames.forEach(beforeName -> validateBeforeMemberNameExist(event, beforeName));
}

private void validateBeforeMemberNameExist(Event event, String beforeName) {
boolean isMemberNameExist = memberActionRepository.existsByAction_EventAndMemberName(event, beforeName);
if (!isMemberNameExist) {
throw new HaengdongException(HaengdongErrorCode.MEMBER_NOT_EXIST);
}
}

private void validateAfterNames(List<MemberNameUpdateAppRequest> members, Event event) {
List<String> afterNames = members.stream()
.map(MemberNameUpdateAppRequest::after)
.toList();
if (afterNames.size() != Set.copyOf(afterNames).size()) {
throw new HaengdongException(HaengdongErrorCode.MEMBER_NAME_CHANGE_DUPLICATE);
}
afterNames.forEach(afterName -> validateAfterMemberNameNotExist(event, afterName));
}

private void validateMemberNameUnique(Event event, String updatedMemberName) {
boolean isMemberNameExist = memberActionRepository.existsByAction_EventAndMemberName(event, updatedMemberName);
private void validateAfterMemberNameNotExist(Event event, String afterName) {
boolean isMemberNameExist = memberActionRepository.existsByAction_EventAndMemberName(event, afterName);
if (isMemberNameExist) {
throw new HaengdongException(HaengdongErrorCode.MEMBER_NAME_DUPLICATE);
}
}

private void updateMemberName(Event event, String beforeName, String afterName) {
memberActionRepository.findAllByAction_EventAndMemberName(event, beforeName)
.forEach(memberAction -> memberAction.updateMemberName(afterName));
}

public void validatePassword(EventLoginAppRequest request) throws HaengdongException {
Event event = getEvent(request.token());
if (event.isNotSamePassword(request.password())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package server.haengdong.application.request;

public record MemberNameUpdateAppRequest(
String before,
String after
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package server.haengdong.application.request;

import java.util.List;

public record MemberNamesUpdateAppRequest(
List<MemberNameUpdateAppRequest> members
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum HaengdongErrorCode {
MEMBER_NAME_DUPLICATE("μ€‘λ³΅λœ 행사 μ°Έμ—¬ 인원 이름이 μ‘΄μž¬ν•©λ‹ˆλ‹€."),
MEMBER_NOT_EXIST("ν˜„μž¬ μ°Έμ—¬ν•˜κ³  μžˆμ§€ μ•ŠλŠ” 인원이 μ‘΄μž¬ν•©λ‹ˆλ‹€."),
MEMBER_ALREADY_EXIST("ν˜„μž¬ μ°Έμ—¬ν•˜κ³  μžˆλŠ” 인원이 μ‘΄μž¬ν•©λ‹ˆλ‹€."),
MEMBER_NAME_CHANGE_DUPLICATE("μ€‘λ³΅λœ μ°Έμ—¬ 인원 이름 λ³€κ²½ μš”μ²­μ΄ μ‘΄μž¬ν•©λ‹ˆλ‹€."),

MEMBER_ACTION_NOT_FOUND("μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” 멀버 μ•‘μ…˜μž…λ‹ˆλ‹€."),
MEMBER_ACTION_STATUS_INVALID("멀버 μ•‘μ…˜μ€ IN, OUT만 κ°€λŠ₯ν•©λ‹ˆλ‹€. μž…λ ₯ν•œ 멀버 μ•‘μ…˜: %s"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseCookie;
Expand All @@ -17,12 +18,13 @@
import server.haengdong.infrastructure.auth.CookieProperties;
import server.haengdong.presentation.request.EventLoginRequest;
import server.haengdong.presentation.request.EventSaveRequest;
import server.haengdong.presentation.request.MemberUpdateRequest;
import server.haengdong.presentation.request.MemberNamesUpdateRequest;
import server.haengdong.presentation.response.EventDetailResponse;
import server.haengdong.presentation.response.EventResponse;
import server.haengdong.presentation.response.MembersResponse;
import server.haengdong.presentation.response.StepsResponse;

@Slf4j
@RequiredArgsConstructor
@EnableConfigurationProperties(CookieProperties.class)
@RestController
Expand All @@ -34,6 +36,8 @@ public class EventController {

@PostMapping("/api/events")
public ResponseEntity<EventResponse> saveEvent(@Valid @RequestBody EventSaveRequest request) {
log.error("################### μ•ˆλ…•ν•˜μ„Έμš”. CI/CD ν…ŒμŠ€νŠΈμž…λ‹ˆλ‹€. ###################");

EventResponse eventResponse = EventResponse.of(eventService.saveEvent(request.toAppRequest()));

String jwtToken = authService.createToken(eventResponse.eventId());
Expand Down Expand Up @@ -65,13 +69,12 @@ public ResponseEntity<MembersResponse> findAllMembers(@PathVariable("eventId") S
return ResponseEntity.ok(response);
}

@PutMapping("/api/events/{eventId}/members/{memberName}")
@PutMapping("/api/events/{eventId}/members/nameChange")
public ResponseEntity<Void> updateMember(
@PathVariable("eventId") String token,
@PathVariable("memberName") String memberName,
@Valid @RequestBody MemberUpdateRequest request
@Valid @RequestBody MemberNamesUpdateRequest request
) {
eventService.updateMember(token, memberName, request.toAppRequest());
eventService.updateMember(token, request.toAppRequest());

return ResponseEntity.ok().build();
}
Expand All @@ -90,7 +93,7 @@ public ResponseEntity<Void> loginEvent(
.build();
}

@GetMapping("/api/events/{eventId}/auth")
@PostMapping("/api/events/{eventId}/auth")
public ResponseEntity<Void> authenticate(@PathVariable("eventId") String token) {
return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package server.haengdong.presentation.request;

import jakarta.validation.constraints.NotBlank;
import server.haengdong.application.request.MemberNameUpdateAppRequest;

public record MemberNameUpdateRequest(

@NotBlank(message = "멀버 이름은 곡백일 수 μ—†μŠ΅λ‹ˆλ‹€.")
String before,

@NotBlank(message = "멀버 이름은 곡백일 수 μ—†μŠ΅λ‹ˆλ‹€.")
String after
) {

public MemberNameUpdateAppRequest toAppRequest() {
return new MemberNameUpdateAppRequest(before, after);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package server.haengdong.presentation.request;

import jakarta.validation.Valid;
import java.util.List;
import server.haengdong.application.request.MemberNamesUpdateAppRequest;

public record MemberNamesUpdateRequest(
@Valid List<MemberNameUpdateRequest> members
) {

public MemberNamesUpdateAppRequest toAppRequest() {
return new MemberNamesUpdateAppRequest(members.stream()
.map(MemberNameUpdateRequest::toAppRequest)
.toList());
}
}

This file was deleted.

7 changes: 6 additions & 1 deletion server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ management:
endpoints:
web:
exposure:
include: logfile
include: logfile, metrics

logging:
level:
root: debug
org.springframework.web: debug
server.haengdong: debug

file:
name: logs/spring-boot-application.log
path: logs
config: classpath:logback-spring.xml

server:
servlet:
encoding:
Expand Down
Loading

0 comments on commit 761a028

Please sign in to comment.