Skip to content

Commit

Permalink
PORTFOLIO-26801: ивенты для зпт (#57)
Browse files Browse the repository at this point in the history
* добавил модельки ивентов зпт

* удалил пустые MARK-и

* добавил hhMobileUUID в category в external event-е

* удалил лишние модели

* добавил пример зпт ивента

* добавил в event edition

* добавил eventEdition для event-а, чтобы отличать приложения

* пофиксил генерацию edition

* добавил примеры с edition в Example

* добавил accessModifier для сгенерированных edition

* убрал инфу о том, кто создал файл :)

* удалил лишнюю строку

* если edition не указан, то для внешних event-ов будет [.hh, .jtb]

---------

Co-authored-by: i.mnazhdin <>
  • Loading branch information
ilyarmnzhdn authored Feb 19, 2024
1 parent c19e421 commit e3e287c
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ description: Пользователь нажал на платный серви
category: Соискательские сервисы
application: applicant
platform: Android/iOS
edition: [zp, hh, jtb]

external:
category: anonymous/applicant
Expand Down
14 changes: 14 additions & 0 deletions Example/schemas/applicant/zarplata/zp_authorization_success.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Событие успешной авторизации (ZP)
description: Пользователь успешно авторизовался (отправляется только для ZP)
category: Авторизация
application: applicant
platform: Android/iOS
edition: [zp]

external:
category: hhmobile_uuid
action: eventLoginSuccessful
label:
type: string
description: hhmobile_uuid пользователя
8 changes: 7 additions & 1 deletion Example/specification/specification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ definitions:
# Категория события
category:
type: string
enum: [anonymous, applicant, anonymous/applicant, employer]
enum: [anonymous, applicant, anonymous/applicant, employer, hhmobile_uudid]
# Action события
action:
type: string
Expand Down Expand Up @@ -68,6 +68,12 @@ definitions:
application:
type: string
enum: [applicant, employer]
# Приложение (hh, jtb, zp)
edition:
type: array
items:
type: string
enum: [hh, jtb, zp]
# Эксперимент
experiment:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ final class DefaultEventGenerator: EventGenerator {

private func resolveExternalEventCategory(event: ExternalEvent) -> ExternalEventContext.Category {
switch event.category {
case .anonymous, .applicant, .employer:
case .anonymous, .applicant, .employer, .hhMobileUUID:
return .init(value: event.category.rawValue, oneOf: nil)
case .anonymousApplicant:
return .init(
Expand Down Expand Up @@ -103,6 +103,7 @@ final class DefaultEventGenerator: EventGenerator {
parameters.render.internalTemplate,
to: parameters.render.destination.appending(path: "\(filename)Event.swift"),
context: InternalEventContext(
edition: event.edition,
deprecated: event.deprecated ?? false,
name: event.name,
description: event.description,
Expand Down Expand Up @@ -135,6 +136,7 @@ final class DefaultEventGenerator: EventGenerator {
parameters.render.externalTemplate,
to: parameters.render.destination.appending(path: "\(filename)ExternalEvent.swift"),
context: ExternalEventContext(
edition: event.edition,
deprecated: event.deprecated ?? false,
name: event.name,
description: event.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct ExternalEventContext: Encodable {

// MARK: - Instance Properties

let edition: [EventEdition]?
let deprecated: Bool
let name: String
let description: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct InternalEventContext: Encodable {

// MARK: - Instance Properties

let edition: [EventEdition]?
let deprecated: Bool
let name: String
let description: String?
Expand Down
1 change: 1 addition & 0 deletions Sources/AnalyticsGen/Models/Event/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct Event: Decodable {
// MARK: - Instance Properties

let application: EventApplication
let edition: [EventEdition]?
let deprecated: Bool?
let category: String
let description: String?
Expand Down
10 changes: 10 additions & 0 deletions Sources/AnalyticsGen/Models/Event/EventEdition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Foundation

enum EventEdition: String, Codable {

// MARK: - Enumeration Cases

case hh
case jtb
case zp
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ enum ExternalEventAction: Decodable {
}
}

// MARK: -

extension ExternalEventAction {

// MARK: - Instance Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ enum ExternalEventCategory: String, Decodable {
case anonymousApplicant = "anonymous/applicant"
case applicant
case employer
case hhMobileUUID = "hhmobile_uuid"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ enum ExternalEventLabel: Decodable {
}
}

// MARK: -

extension ExternalEventLabel {

// MARK: - Instance Properties
Expand Down
9 changes: 9 additions & 0 deletions Templates/ExternalEvent.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ import Analytics
}
{% endif %}

{{ accessModifier }} var edition: [AnalyticsEventEdition] {
{% if edition %}
{% map edition into enumValueEdition %}.{{ maploop.item }}{% endmap %}
[{{ enumValueEdition|join:", " }}]
{% else %}
[.hh, .jtb]
{% endif %}
}

{% if category.oneOf %}
{{ accessModifier }} enum Category: String {
{% for oneOf in category.oneOf %}
Expand Down
9 changes: 9 additions & 0 deletions Templates/InternalEvent.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ import Analytics
*/
{{ accessModifier }} struct {{ structName }}: {{ protocol }} {

{{ accessModifier }} var edition: [AnalyticsEventEdition] {
{% if edition %}
{% map edition into enumValueEdition %}.{{ maploop.item }}{% endmap %}
[{{ enumValueEdition|join:", " }}]
{% else %}
.any
{% endif %}
}

{{ accessModifier }} enum CodingKeys: String, CodingKey {
{% for parameter in parameters %}
case {% call propertyName parameter.name %} = "{{ parameter.name }}"
Expand Down

0 comments on commit e3e287c

Please sign in to comment.