잡담방

우하하

화이팅

로그인

    @Transactional
    public TokenResponse login(String uuid, AttendeeLoginRequest request) {
        Meeting meeting = meetingRepository.findByUuid(uuid)
                .orElseThrow(() -> new MomoException(AttendeeErrorCode.INVALID_UUID));

        AttendeeName name = new AttendeeName(request.name());
        AttendeePassword password = new AttendeePassword(request.password());

        return attendeeRepository.findByMeetingAndName(meeting, name)
                .map(attendee -> handleExistingAttendee(attendee, password))
                .orElseGet(() -> handleNewAttendee(meeting, name, password));
    }

    private TokenResponse handleExistingAttendee(Attendee attendee, AttendeePassword password) {
        attendee.verifyPassword(password);
        return new TokenResponse(jwtManager.generate(attendee));
    }

    private TokenResponse handleNewAttendee(Meeting meeting, AttendeeName name, AttendeePassword password) {
        Attendee attendee = new Attendee(meeting, name, password, Role.GUEST);
        attendeeRepository.save(attendee);
        return new TokenResponse(jwtManager.generate(attendee));
    }
    @Transactional
    public TokenResponse login(String uuid, AttendeeLoginRequest request) {
        Meeting meeting = meetingRepository.findByUuid(uuid)
                .orElseThrow(() -> new MomoException(AttendeeErrorCode.INVALID_UUID));

        AttendeeName name = new AttendeeName(request.name());
        AttendeePassword password = new AttendeePassword(request.password());

        Optional<Attendee> optionalAttendee = attendeeRepository.findByMeetingAndName(meeting, name);
        if (optionalAttendee.isPresent()) {
            return handleExistingAttendee(optionalAttendee, password);
        }
        return handleNewAttendee(meeting, name, password);
    }

    private TokenResponse handleExistingAttendee(Optional<Attendee> optionalAttendee, AttendeePassword password) {
        Attendee attendee = optionalAttendee.get();
        attendee.verifyPassword(password);
        return new TokenResponse(jwtManager.generate(attendee));
    }

    private TokenResponse handleNewAttendee(Meeting meeting, AttendeeName name, AttendeePassword password) {
        Attendee attendee = new Attendee(meeting, name, password, Role.GUEST);
        attendeeRepository.save(attendee);
        return new TokenResponse(jwtManager.generate(attendee));
    }

AssertJ.SoftAssertions 성능 이슈

    @DisplayName("참가자의 정보를 이용하여 jwt 토큰을 발행한다 AssertJ")
    @Test
    void generateTestWithAssertJ() {
        String token = jwtManager.generate(attendee);
        TokenInfo tokenInfo = jwtManager.extract(token);

        SoftAssertions.assertSoftly(softAssertions -> {
            softAssertions.assertThat(tokenInfo.id()).isEqualTo(attendeeId);
            softAssertions.assertThat(tokenInfo.nickname()).isEqualTo(attendeeName);
        });
    }

    @DisplayName("참가자의 정보를 이용하여 jwt 토큰을 발행한다 Junit.")
    @Test
    void generateTestWithJunit() {
        String token = jwtManager.generate(attendee);
        TokenInfo tokenInfo = jwtManager.extract(token);

        Assertions.assertAll(
                () -> assertThat(tokenInfo.id()).isEqualTo(attendeeId),
                () -> assertThat(tokenInfo.nickname()).isEqualTo(attendeeName)
        );
    }

Untitled


attendee
+-------------+----------------------+------+-----+---------+----------------+
| Field       | Type                 | Null | Key | Default | Extra          |
+-------------+----------------------+------+-----+---------+----------------+
| id          | bigint               | NO   | PRI | NULL    | auto_increment |
| meeting_id  | bigint               | NO   | MUL | NULL    |                |
| name        | varchar(5)           | NO   |     | NULL    |                |
| password    | varchar(255)         | NO   |     | NULL    |                |
| role        | enum('GUEST','HOST') | NO   |     | NULL    |                |
| created_at  | timestamp(6)         | NO   |     | NULL    |                |
| modified_at | timestamp(6)         | NO   |     | NULL    |                |
+-------------+----------------------+------+-----+---------+----------------+

available_date
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | bigint       | NO   | PRI | NULL    | auto_increment |
| date        | date         | NO   | MUL | NULL    |                |
| meeting_id  | bigint       | NO   | MUL | NULL    |                |
| created_at  | timestamp(6) | NO   |     | NULL    |                |
| modified_at | timestamp(6) | NO   |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+

confirmed_meeting
+-----------------+--------------+------+-----+---------+----------------+
| Field           | Type         | Null | Key | Default | Extra          |
+-----------------+--------------+------+-----+---------+----------------+
| id              | bigint       | NO   | PRI | NULL    | auto_increment |
| meeting_id      | bigint       | NO   | UNI | NULL    |                |
| start_date_time | timestamp(6) | NO   |     | NULL    |                |
| end_date_time   | timestamp(6) | NO   |     | NULL    |                |
| created_at      | timestamp(6) | NO   |     | NULL    |                |
| modified_at     | timestamp(6) | NO   |     | NULL    |                |
+-----------------+--------------+------+-----+---------+----------------+

meeting
+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------+-----+---------+----------------+
| Field          | Type                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Null | Key | Default | Extra          |
+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------+-----+---------+----------------+
| id             | bigint                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | NO   | PRI | NULL    | auto_increment |
| name           | varchar(20)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | NO   |     | NULL    |                |
| uuid           | varchar(8)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | NO   | UNI | NULL    |                |
| is_locked      | tinyint(1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | NO   |     | NULL    |                |
| start_timeslot | enum('TIME_0000','TIME_0030','TIME_0100','TIME_0130','TIME_0200','TIME_0230','TIME_0300','TIME_0330','TIME_0400','TIME_0430','TIME_0500','TIME_0530','TIME_0600','TIME_0630','TIME_0700','TIME_0730','TIME_0800','TIME_0830','TIME_0900','TIME_0930','TIME_1000','TIME_1030','TIME_1100','TIME_1130','TIME_1200','TIME_1230','TIME_1300','TIME_1330','TIME_1400','TIME_1430','TIME_1500','TIME_1530','TIME_1600','TIME_1630','TIME_1700','TIME_1730','TIME_1800','TIME_1830','TIME_1900','TIME_1930','TIME_2000','TIME_2030','TIME_2100','TIME_2130','TIME_2200','TIME_2230','TIME_2300','TIME_2330') | NO   |     | NULL    |                |
| end_timeslot   | enum('TIME_0000','TIME_0030','TIME_0100','TIME_0130','TIME_0200','TIME_0230','TIME_0300','TIME_0330','TIME_0400','TIME_0430','TIME_0500','TIME_0530','TIME_0600','TIME_0630','TIME_0700','TIME_0730','TIME_0800','TIME_0830','TIME_0900','TIME_0930','TIME_1000','TIME_1030','TIME_1100','TIME_1130','TIME_1200','TIME_1230','TIME_1300','TIME_1330','TIME_1400','TIME_1430','TIME_1500','TIME_1530','TIME_1600','TIME_1630','TIME_1700','TIME_1730','TIME_1800','TIME_1830','TIME_1900','TIME_1930','TIME_2000','TIME_2030','TIME_2100','TIME_2130','TIME_2200','TIME_2230','TIME_2300','TIME_2330') | NO   |     | NULL    |                |
| created_at     | timestamp(6)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | NO   |     | NULL    |                |
| modified_at    | timestamp(6)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | NO   |     | NULL    |                |
| type           | enum('DATETIME','DAYSONLY')                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | NO   |     | NULL    |                |
+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------+-----+---------+----------------+

schedule
+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------+-----+---------+----------------+
| attendee_id       | bigint                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | NO   | MUL | NULL    |                |
| available_date_id | bigint                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | NO   | MUL | NULL    |                |
| created_at        | timestamp(6)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | NO   |     | NULL    |                |
| id                | bigint                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | NO   | PRI | NULL    | auto_increment |
| modified_at       | timestamp(6)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | NO   |     | NULL    |                |
| timeslot          | enum('TIME_0000','TIME_0030','TIME_0100','TIME_0130','TIME_0200','TIME_0230','TIME_0300','TIME_0330','TIME_0400','TIME_0430','TIME_0500','TIME_0530','TIME_0600','TIME_0630','TIME_0700','TIME_0730','TIME_0800','TIME_0830','TIME_0900','TIME_0930','TIME_1000','TIME_1030','TIME_1100','TIME_1130','TIME_1200','TIME_1230','TIME_1300','TIME_1330','TIME_1400','TIME_1430','TIME_1500','TIME_1530','TIME_1600','TIME_1630','TIME_1700','TIME_1730','TIME_1800','TIME_1830','TIME_1900','TIME_1930','TIME_2000','TIME_2030','TIME_2100','TIME_2130','TIME_2200','TIME_2230','TIME_2300','TIME_2330') | NO   |     | NULL    |                |
+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------+-----+---------+----------------+
마지막 pk

attendee 543
available_date 1195
confirmed_meeting 36
meeting 413
schedule 15353